CPAN-Smoker-Utils

 view release on metacpan or  search on metacpan

lib/CPAN/Smoker/Utils/PerlConfig.pm  view on Meta::CPAN

package CPAN::Smoker::Utils::PerlConfig;

use strict;
use warnings;
use Config;
use Hash::Util qw(lock_hash);

our $VERSION = 'v1.0.1'; # VERSION

=pod

=head1 NAME

CPAN::Smoker::Utils::PerlConfig - class representing a perl configuration

=head1 SYNOPSIS

    use CPAN::Smoker::Utils::PerlConfig;

    my $cfg = CPAN::Smoker::Utils::PerlConfig->new;

=head1 DESCRIPTION

This class represents a C<perl> configuration in a way that can be used by the
C<dblock> CLI.

It was created to handle the details of a distroprefs implementation, specially
regarding dealing with C<undef> values.

=head1 METHODS

=head2 new

Creates a new instance of this class.

Expects nothing, returns a new instance.

=cut

sub new {
    my $class = shift;
    my $self  = {
        osname   => $Config{osname},
        archname => $Config{archname}
    };
    my $attrib_name = 'useithreads';

    if ( defined( $Config{$attrib_name} ) ) {
        $self->{$attrib_name} = 1;
    }
    else {
        $self->{$attrib_name} = 0;
    }

    bless $self, $class;
    lock_hash( %{$self} );
    return $self;
}

=head2 dump

This methods returns a instance attributes as a hash reference.

This is particulary useful to use with YAML modules C<DumpFile> function.

=cut

sub dump {
    my $self        = shift;
    my %attribs     = %{$self};
    my $attrib_name = 'useithreads';

    if ( $self->{$attrib_name} ) {
        $attribs{$attrib_name} = 'define';
    }
    else {
        $attribs{$attrib_name} = '^$';
    }

    return \%attribs;
}

=head1 SEE ALSO

=over

=item *



( run in 0.787 second using v1.01-cache-2.11-cpan-e1769b4cff6 )