ÿØÿà JFIF    ÿÛ „ ( %!1!%*+...983,7(-.- Extensions.pm000064400000002516152342705610007252 0ustar00package Config::Extensions; use strict; use vars qw(%Extensions $VERSION @ISA @EXPORT_OK); use Config; require Exporter; $VERSION = '0.01'; @ISA = 'Exporter'; @EXPORT_OK = '%Extensions'; foreach my $type (qw(static dynamic nonxs)) { foreach (split /\s+/, $Config{$type . '_ext'}) { s!/!::!g; $Extensions{$_} = $type; } } 1; __END__ =head1 NAME Config::Extensions - hash lookup of which core extensions were built. =head1 SYNOPSIS use Config::Extensions '%Extensions'; if ($Extensions{PerlIO::via}) { # This perl has PerlIO::via built } =head1 DESCRIPTION The Config::Extensions module provides a hash C<%Extensions> containing all the core extensions that were enabled for this perl. The hash is keyed by extension name, with each entry having one of 3 possible values: =over 4 =item dynamic The extension is dynamically linked =item nonxs The extension is pure perl, so doesn't need linking to the perl executable =item static The extension is statically linked to the perl binary =back As all values evaluate to true, a simple C test is good enough to determine whether an extension is present. All the data uses to generate the C<%Extensions> hash is already present in the C module, but not in such a convenient format to quickly reference. =head1 AUTHOR Nicholas Clark =cut Tiny.pm000044400000035262152345050010006026 0ustar00package Config::Tiny; # If you thought Config::Simple was small... use strict; use 5.008001; # For the utf8 stuff. # Warning: There is another version line, in t/02.main.t. our $VERSION = '2.30'; BEGIN { $Config::Tiny::errstr = ''; } # Create an object. sub new { return bless defined $_[1] ? $_[1] : {}, $_[0] } # Create an object from a file. sub read { my($class) = ref $_[0] ? ref shift : shift; my($file, $encoding) = @_; return $class -> _error('No file name provided') if (! defined $file || ($file eq '') ); # Slurp in the file. $encoding = $encoding ? "<:$encoding" : '<'; local $/ = undef; open(my $CFG, $encoding, $file) or return $class -> _error( "Failed to open file '$file' for reading: $!" ); my $contents = <$CFG>; close($CFG ); return $class -> _error("Reading from '$file' returned undef") if (! defined $contents); return $class -> read_string( $contents ); } # End of read. # Create an object from a string. sub read_string { my($class) = ref $_[0] ? ref shift : shift; my($self) = bless {}, $class; return undef unless defined $_[0]; # Parse the file. my $ns = '_'; my $counter = 0; foreach ( split /(?:\015{1,2}\012|\015|\012)/, shift ) { $counter++; # Skip comments and empty lines. next if /^\s*(?:\#|\;|$)/; # Remove inline comments. s/\s\;\s.+$//g; # Handle section headers. if ( /^\s*\[\s*(.+?)\s*\]\s*$/ ) { # Create the sub-hash if it doesn't exist. # Without this sections without keys will not # appear at all in the completed struct. $self->{$ns = $1} ||= {}; next; } # Handle properties. if ( /^\s*([^=]+?)\s*=\s*(.*?)\s*$/ ) { if ( substr($1, -2) eq '[]' ) { my $k = substr $1, 0, -2; $self->{$ns}->{$k} ||= []; return $self -> _error ("Can't mix arrays and scalars at line $counter" ) unless ref $self->{$ns}->{$k} eq 'ARRAY'; push @{$self->{$ns}->{$k}}, $2; next; } $self->{$ns}->{$1} = $2; next; } return $self -> _error( "Syntax error at line $counter: '$_'" ); } return $self; } # Save an object to a file. sub write { my($self) = shift; my($file, $encoding) = @_; return $self -> _error('No file name provided') if (! defined $file or ($file eq '') ); $encoding = $encoding ? ">:$encoding" : '>'; # Write it to the file. my($string) = $self->write_string; return undef unless defined $string; open(my $CFG, $encoding, $file) or return $self->_error("Failed to open file '$file' for writing: $!"); print $CFG $string; close($CFG); return 1; } # End of write. # Save an object to a string. sub write_string { my($self) = shift; my($contents) = ''; for my $section ( sort { (($b eq '_') <=> ($a eq '_')) || ($a cmp $b) } keys %$self ) { # Check for several known-bad situations with the section # 1. Leading whitespace # 2. Trailing whitespace # 3. Newlines in section name. return $self->_error("Illegal whitespace in section name '$section'") if $section =~ /(?:^\s|\n|\s$)/s; my $block = $self->{$section}; $contents .= "\n" if length $contents; $contents .= "[$section]\n" unless $section eq '_'; for my $property ( sort keys %$block ) { return $self->_error("Illegal newlines in property '$section.$property'") if $block->{$property} =~ /(?:\012|\015)/s; if (ref $block->{$property} eq 'ARRAY') { for my $element ( @{$block->{$property}} ) { $contents .= "${property}[]=$element\n"; } next; } $contents .= "$property=$block->{$property}\n"; } } return $contents; } # End of write_string. # Error handling. sub errstr { $Config::Tiny::errstr } sub _error { $Config::Tiny::errstr = $_[1]; undef } 1; __END__ =pod =head1 NAME Config::Tiny - Read/Write .ini style files with as little code as possible =head1 SYNOPSIS # In your configuration file rootproperty=blah [section] one=twp greetings[]=Hello three= four Foo =Bar greetings[]=World! empty= # In your program use Config::Tiny; # Create an empty config my $Config = Config::Tiny->new; # Create a config with data my $config = Config::Tiny->new({ _ => { rootproperty => "Bar" }, section => { one => "value", Foo => 42 } }); # Open the config $Config = Config::Tiny->read( 'file.conf' ); $Config = Config::Tiny->read( 'file.conf', 'utf8' ); # Neither ':' nor '<:' prefix! $Config = Config::Tiny->read( 'file.conf', 'encoding(iso-8859-1)'); # Reading properties my $rootproperty = $Config->{_}->{rootproperty}; my $one = $Config->{section}->{one}; my $Foo = $Config->{section}->{Foo}; # Changing data $Config->{newsection} = { this => 'that' }; # Add a section $Config->{section}->{Foo} = 'Not Bar!'; # Change a value delete $Config->{_}; # Delete a value or section # Save a config $Config->write( 'file.conf' ); $Config->write( 'file.conf', 'utf8' ); # Neither ':' nor '>:' prefix! # Shortcuts my($rootproperty) = $$Config{_}{rootproperty}; my($config) = Config::Tiny -> read_string('alpha=bet'); my($value) = $$config{_}{alpha}; # $value is 'bet'. my($config) = Config::Tiny -> read_string("[init]\nalpha=bet"); my($value) = $$config{init}{alpha}; # $value is 'bet'. =head1 DESCRIPTION C is a Perl class to read and write .ini style configuration files with as little code as possible, reducing load time and memory overhead. Most of the time it is accepted that Perl applications use a lot of memory and modules. The C<*::Tiny> family of modules is specifically intended to provide an ultralight alternative to the standard modules. This module is primarily for reading human written files, and anything we write shouldn't need to have documentation/comments. If you need something with more power move up to L, L or one of the many other C modules. Lastly, L does B preserve your comments, whitespace, or the order of your config file. See L (and possibly others) for the preservation of the order of the entries in the file. =head1 CONFIGURATION FILE SYNTAX Files are the same format as for MS Windows C<*.ini> files. For example: [section] var1=value1 var2=value2 But see also ARRAY SYNTAX just below. If a property is outside of a section at the beginning of a file, it will be assigned to the C<"root section">, available at C<$Config-E{_}>. Lines starting with C<'#'> or C<';'> are considered comments and ignored, as are blank lines. When writing back to the config file, all comments, custom whitespace, and the ordering of your config file elements are discarded. If you need to keep the human elements of a config when writing back, upgrade to something better, this module is not for you. =head1 ARRAY SYNTAX =head2 Basic Syntax As of V 2.30, this module supports the case of a key having an array of values. Sample data (copied from t/test.conf): root=something [section] greetings[]=Hello one=two Foo=Bar greetings[]=World! this=Your Mother! blank= [Section Two] something else=blah remove = whitespace Note specifically that the key name greetings has the empty bracket pair [] as a suffix. This tells the code that it is not to overwrite the 1st value with the 2nd value, but rather to push these values onto a stack called 'greetings'. Note also that you could have used: [section] greetings[]=Hello greetings[]=World! one=two Foo=Bar this=Your Mother! blank= Clearly, the 2 lines using greetings[] do not have to be side-by-side. If you use e.g. Data::Dumper::Concise to give you a Dumper() function (not method), then 'say Dumper($Config)' the output will look like: bless( { "Section Two" => { remove => "whitespace", "something else" => "blah", }, _ => { root => "something", }, section => { Foo => "Bar", blank => "", greetings => [ "Hello", "World!", ], one => "two", this => "Your Mother!", }, }, 'Config::Tiny' ) You can see this structure in t/02.main.t starting at line 45. Observe too that the key names are reported in alphabetical order (by the module Data::Dumper::Concise) despite the differing order in the setting of these keys, and that the array syntax result is that greetings has an array for a value. To access these values, use code like this: Dumper($Config); Dumper($Config->{section}); Dumper($Config->{section}->{greetings}); Dumper($Config->{section}->{greetings}->[0]); Dumper($Config->{section}->{greetings}->[1]); Dumper(ref $Config); =head2 Warning $Config is a blessed value, which means it is accessed differently than if it was a hash ref. The latter could be accessed as: Dumper($$Config{section}{greetings}); # Don't do this for blessed values! Finally, if a hash ref rather than a blessed value, you could also use, as above: Dumper($Config->{section}->{greetings}); # Don't do this for blessed values! My (Ron Savage) personal preference for hashrefs is the one without the gross '->' chars, but that requires you to double up the initial $ character (which I hope you noticed!). =head1 METHODS =head2 errstr() Returns a string representing the most recent error, or the empty string. You can also retrieve the error message from the C<$Config::Tiny::errstr> variable. =head2 new([$config]) Here, the [] indicate an optional parameter. The constructor C creates and returns a C object. This will normally be a new, empty configuration, but you may also pass a hashref here which will be turned into an object of this class. This hashref should have a structure suitable for a configuration file, that is, a hash of hashes where the key C<_> is treated specially as the root section. =head2 read($filename, [$encoding]) Here, the [] indicate an optional parameter. The C constructor reads a config file, $filename, and returns a new C object containing the properties in the file. $encoding may be used to indicate the encoding of the file, e.g. 'utf8' or 'encoding(iso-8859-1)'. Do not add a prefix to $encoding, such as '<' or '<:'. Returns the object on success, or C on error. When C fails, C sets an error message internally you can recover via Cerrstr>. Although in B cases a failed C will also set the operating system error variable C<$!>, not all errors do and you should not rely on using the C<$!> variable. See t/04.utf8.t and t/04.utf8.txt. =head2 read_string($string) The C method takes as argument the contents of a config file as a string and returns the C object for it. =head2 write($filename, [$encoding]) Here, the [] indicate an optional parameter. The C method generates the file content for the properties, and writes it to disk to the filename specified. $encoding may be used to indicate the encoding of the file, e.g. 'utf8' or 'encoding(iso-8859-1)'. Do not add a prefix to $encoding, such as '>' or '>:'. Returns true on success or C on error. See t/04.utf8.t and t/04.utf8.txt. =head2 write_string() Generates the file content for the object and returns it as a string. =head1 FAQ =head2 What happens if a key is repeated? Case 1: The last value is retained, overwriting any previous values. See t/06.repeat.key.t for sample code. Case 2: However, by using the new array syntax, as of V 2.30, you can assign a set of values to a key. For details, see the L section above for sample code. See t/test.conf for sample data. =head2 Why can't I put comments at the ends of lines? =over 4 =item o The # char is only introduces a comment when it's at the start of a line. So a line like: key=value # A comment Sets key to 'value # A comment', which, presumably, you did not intend. This conforms to the syntax discussed in L. =item o Comments matching /\s\;\s.+$//g; are ignored. This means you can't preserve the suffix using: key = Prefix ; Suffix Result: key is now 'Prefix'. But you can do this: key = Prefix;Suffix Result: key is now 'Prefix;Suffix'. Or this: key = Prefix; Suffix Result: key is now 'Prefix; Suffix'. =back See t/07.trailing.comment.t. =head2 Why can't I omit the '=' signs? E.g.: [Things] my = list = of = things = Instead of: [Things] my list of things Because the use of '=' signs is a type of mandatory documentation. It indicates that that section contains 4 items, and not 1 odd item split over 4 lines. =head2 Why do I have to assign the result of a method call to a variable? This question comes from RT#85386. Yes, the syntax may seem odd, but you don't have to call both new() and read_string(). Try: perl -MData::Dumper -MConfig::Tiny -E 'my $c=Config::Tiny->read_string("one=s"); say Dumper $c' Or: my($config) = Config::Tiny -> read_string('alpha=bet'); my($value) = $$config{_}{alpha}; # $value is 'bet'. Or even, a bit ridiculously: my($value) = ${Config::Tiny -> read_string('alpha=bet')}{_}{alpha}; # $value is 'bet'. =head2 Can I use a file called '0' (zero)? Yes. See t/05.zero.t (test code) and t/0 (test data). =head1 CAVEATS Some edge cases in section headers are not supported, and additionally may not be detected when writing the config file. Specifically, section headers with leading whitespace, trailing whitespace, or newlines anywhere in the section header, will not be written correctly to the file and may cause file corruption. =head1 Repository L =head1 SUPPORT Bugs should be reported via the CPAN bug tracker at L For other issues, or commercial enhancement or support, contact the author. =head1 AUTHOR Adam Kennedy Eadamk@cpan.orgE Maintanence from V 2.15: Ron Savage L. =head1 ACKNOWLEGEMENTS Thanks to Sherzod Ruzmetov Esherzodr@cpan.orgE for L, which inspired this module by being not quite "simple" enough for me :). =head1 SEE ALSO See, amongst many: L and L. See L (and possibly others) for the preservation of the order of the entries in the file. L. Ini On Drugs. L L L L. Config data from Perl itself. L L L L. Allows nested data. L. Author: RJBS. Uses Moose. Extremely complex. L. See next few lines: L L. 1 Star rating. L =head1 COPYRIGHT Copyright 2002 - 2011 Adam Kennedy. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. The full text of the license can be found in the LICENSE file included with this module. =cut Tiny/.packlist000064400000000121152345754120007304 0ustar00/usr/local/share/man/man3/Config::Tiny.3pm /usr/local/share/perl5/Config/Tiny.pm Perl/V.pm000064400000035042152346273750006233 0ustar00package Config::Perl::V; use strict; use warnings; use Config; use Exporter; use vars qw($VERSION @ISA @EXPORT_OK %EXPORT_TAGS); $VERSION = "0.30"; @ISA = qw( Exporter ); @EXPORT_OK = qw( plv2hash summary myconfig signature ); %EXPORT_TAGS = ( all => [ @EXPORT_OK ], sig => [ "signature" ], ); # Characteristics of this binary (from libperl): # Compile-time options: DEBUGGING PERL_DONT_CREATE_GVSV PERL_MALLOC_WRAP # USE_64_BIT_INT USE_LARGE_FILES USE_PERLIO # The list are as the perl binary has stored it in PL_bincompat_options # search for it in # perl.c line 1643 S_Internals_V () # perl -ne'(/^S_Internals_V/../^}/)&&s/^\s+"( .*)"/$1/ and print' perl.c # perl.h line 4566 PL_bincompat_options # perl -ne'(/^\w.*PL_bincompat/../^\w}/)&&s/^\s+"( .*)"/$1/ and print' perl.h my %BTD = map { $_ => 0 } qw( DEBUGGING NO_HASH_SEED NO_MATHOMS NO_TAINT_SUPPORT PERL_BOOL_AS_CHAR PERL_COPY_ON_WRITE PERL_DISABLE_PMC PERL_DONT_CREATE_GVSV PERL_EXTERNAL_GLOB PERL_HASH_FUNC_DJB2 PERL_HASH_FUNC_MURMUR3 PERL_HASH_FUNC_ONE_AT_A_TIME PERL_HASH_FUNC_ONE_AT_A_TIME_HARD PERL_HASH_FUNC_ONE_AT_A_TIME_OLD PERL_HASH_FUNC_SDBM PERL_HASH_FUNC_SIPHASH PERL_HASH_FUNC_SUPERFAST PERL_IS_MINIPERL PERL_MALLOC_WRAP PERL_MEM_LOG PERL_MEM_LOG_ENV PERL_MEM_LOG_ENV_FD PERL_MEM_LOG_NOIMPL PERL_MEM_LOG_STDERR PERL_MEM_LOG_TIMESTAMP PERL_NEW_COPY_ON_WRITE PERL_OP_PARENT PERL_PERTURB_KEYS_DETERMINISTIC PERL_PERTURB_KEYS_DISABLED PERL_PERTURB_KEYS_RANDOM PERL_PRESERVE_IVUV PERL_RELOCATABLE_INCPUSH PERL_USE_DEVEL PERL_USE_SAFE_PUTENV SILENT_NO_TAINT_SUPPORT UNLINK_ALL_VERSIONS USE_ATTRIBUTES_FOR_PERLIO USE_FAST_STDIO USE_HASH_SEED_EXPLICIT USE_LOCALE USE_LOCALE_CTYPE USE_NO_REGISTRY USE_PERL_ATOF USE_SITECUSTOMIZE DEBUG_LEAKING_SCALARS DEBUG_LEAKING_SCALARS_FORK_DUMP DECCRTL_SOCKETS FAKE_THREADS FCRYPT HAS_TIMES HAVE_INTERP_INTERN MULTIPLICITY MYMALLOC PERL_DEBUG_READONLY_COW PERL_DEBUG_READONLY_OPS PERL_GLOBAL_STRUCT PERL_GLOBAL_STRUCT_PRIVATE PERL_IMPLICIT_CONTEXT PERL_IMPLICIT_SYS PERLIO_LAYERS PERL_MAD PERL_MICRO PERL_NEED_APPCTX PERL_NEED_TIMESBASE PERL_OLD_COPY_ON_WRITE PERL_POISON PERL_SAWAMPERSAND PERL_TRACK_MEMPOOL PERL_USES_PL_PIDSTATUS PL_OP_SLAB_ALLOC THREADS_HAVE_PIDS USE_64_BIT_ALL USE_64_BIT_INT USE_IEEE USE_ITHREADS USE_LARGE_FILES USE_LOCALE_COLLATE USE_LOCALE_NUMERIC USE_LOCALE_TIME USE_LONG_DOUBLE USE_PERLIO USE_QUADMATH USE_REENTRANT_API USE_SFIO USE_SOCKS VMS_DO_SOCKETS VMS_SHORTEN_LONG_SYMBOLS VMS_SYMBOL_CASE_AS_IS ); # These are all the keys that are # 1. Always present in %Config - lib/Config.pm #87 tie %Config # 2. Reported by 'perl -V' (the rest) my @config_vars = qw( api_subversion api_version api_versionstring archlibexp dont_use_nlink d_readlink d_symlink exe_ext inc_version_list ldlibpthname patchlevel path_sep perl_patchlevel privlibexp scriptdir sitearchexp sitelibexp subversion usevendorprefix version git_commit_id git_describe git_branch git_uncommitted_changes git_commit_id_title git_snapshot_date package revision version_patchlevel_string osname osvers archname myuname config_args hint useposix d_sigaction useithreads usemultiplicity useperlio d_sfio uselargefiles usesocks use64bitint use64bitall uselongdouble usemymalloc default_inc_excludes_dot bincompat5005 cc ccflags optimize cppflags ccversion gccversion gccosandvers intsize longsize ptrsize doublesize byteorder d_longlong longlongsize d_longdbl longdblsize ivtype ivsize nvtype nvsize lseektype lseeksize alignbytes prototype ld ldflags libpth libs perllibs libc so useshrplib libperl gnulibc_version dlsrc dlext d_dlsymun ccdlflags cccdlflags lddlflags ); my %empty_build = ( osname => "", stamp => 0, options => { %BTD }, patches => [], ); sub _make_derived { my $conf = shift; for ( [ lseektype => "Off_t" ], [ myuname => "uname" ], [ perl_patchlevel => "patch" ], ) { my ($official, $derived) = @$_; $conf->{config}{$derived} ||= $conf->{config}{$official}; $conf->{config}{$official} ||= $conf->{config}{$derived}; $conf->{derived}{$derived} = delete $conf->{config}{$derived}; } if (exists $conf->{config}{version_patchlevel_string} && !exists $conf->{config}{api_version}) { my $vps = $conf->{config}{version_patchlevel_string}; $vps =~ s{\b revision \s+ (\S+) }{}x and $conf->{config}{revision} ||= $1; $vps =~ s{\b version \s+ (\S+) }{}x and $conf->{config}{api_version} ||= $1; $vps =~ s{\b subversion \s+ (\S+) }{}x and $conf->{config}{subversion} ||= $1; $vps =~ s{\b patch \s+ (\S+) }{}x and $conf->{config}{perl_patchlevel} ||= $1; } ($conf->{config}{version_patchlevel_string} ||= join " ", map { ($_, $conf->{config}{$_} ) } grep { $conf->{config}{$_} } qw( api_version subversion perl_patchlevel )) =~ s/\bperl_//; $conf->{config}{perl_patchlevel} ||= ""; # 0 is not a valid patchlevel if ($conf->{config}{perl_patchlevel} =~ m{^git\w*-([^-]+)}i) { $conf->{config}{git_branch} ||= $1; $conf->{config}{git_describe} ||= $conf->{config}{perl_patchlevel}; } $conf->{config}{$_} ||= "undef" for grep m/^(?:use|def)/ => @config_vars; $conf; } # _make_derived sub plv2hash { my %config; my $pv = join "\n" => @_; if ($pv =~ m/^Summary of my\s+(\S+)\s+\(\s*(.*?)\s*\)/m) { $config{"package"} = $1; my $rev = $2; $rev =~ s/^ revision \s+ (\S+) \s*//x and $config{revision} = $1; $rev and $config{version_patchlevel_string} = $rev; my ($rel) = $config{"package"} =~ m{perl(\d)}; my ($vers, $subvers) = $rev =~ m{version\s+(\d+)\s+subversion\s+(\d+)}; defined $vers && defined $subvers && defined $rel and $config{version} = "$rel.$vers.$subvers"; } if ($pv =~ m/^\s+(Snapshot of:)\s+(\S+)/) { $config{git_commit_id_title} = $1; $config{git_commit_id} = $2; } # these are always last on line and can have multiple quotation styles for my $k (qw( ccflags ldflags lddlflags )) { $pv =~ s{, \s* $k \s*=\s* (.*) \s*$}{}mx or next; my $v = $1; $v =~ s/\s*,\s*$//; $v =~ s/^(['"])(.*)\1$/$2/; $config{$k} = $v; } if (my %kv = ($pv =~ m{\b (\w+) # key \s*= # assign ( '\s*[^']*?\s*' # quoted value | \S+[^=]*?\s*\n # unquoted running till end of line | \S+ # unquoted value | \s*\n # empty ) (?:,?\s+|\s*\n)? # separator (5.8.x reports did not have a ',' }gx)) { # between every kv pair while (my ($k, $v) = each %kv) { $k =~ s/\s+$//; $v =~ s/\s*\n\z//; $v =~ s/,$//; $v =~ m/^'(.*)'$/ and $v = $1; $v =~ s/\s+$//; $config{$k} = $v; } } my $build = { %empty_build }; $pv =~ m{^\s+Compiled at\s+(.*)}m and $build->{stamp} = $1; $pv =~ m{^\s+Locally applied patches:(?:\s+|\n)(.*?)(?:[\s\n]+Buil[td] under)}ms and $build->{patches} = [ split m/\n+\s*/, $1 ]; $pv =~ m{^\s+Compile-time options:(?:\s+|\n)(.*?)(?:[\s\n]+(?:Locally applied|Buil[td] under))}ms and map { $build->{options}{$_} = 1 } split m/\s+|\n/ => $1; $build->{osname} = $config{osname}; $pv =~ m{^\s+Built under\s+(.*)}m and $build->{osname} = $1; $config{osname} ||= $build->{osname}; return _make_derived ({ build => $build, environment => {}, config => \%config, derived => {}, inc => [], }); } # plv2hash sub summary { my $conf = shift || myconfig (); ref $conf eq "HASH" && exists $conf->{config} && exists $conf->{build} && ref $conf->{config} eq "HASH" && ref $conf->{build} eq "HASH" or return; my %info = map { exists $conf->{config}{$_} ? ( $_ => $conf->{config}{$_} ) : () } qw( archname osname osvers revision patchlevel subversion version cc ccversion gccversion config_args inc_version_list d_longdbl d_longlong use64bitall use64bitint useithreads uselongdouble usemultiplicity usemymalloc useperlio useshrplib doublesize intsize ivsize nvsize longdblsize longlongsize lseeksize default_inc_excludes_dot ); $info{$_}++ for grep { $conf->{build}{options}{$_} } keys %{$conf->{build}{options}}; return \%info; } # summary sub signature { my $no_md5 = "0" x 32; my $conf = summary (shift) or return $no_md5; eval { require Digest::MD5 }; $@ and return $no_md5; $conf->{cc} =~ s{.*\bccache\s+}{}; $conf->{cc} =~ s{.*[/\\]}{}; delete $conf->{config_args}; return Digest::MD5::md5_hex (join "\xFF" => map { "$_=".(defined $conf->{$_} ? $conf->{$_} : "\xFE"); } sort keys %$conf); } # signature sub myconfig { my $args = shift; my %args = ref $args eq "HASH" ? %$args : ref $args eq "ARRAY" ? @$args : (); my $build = { %empty_build }; # 5.14.0 and later provide all the information without shelling out my $stamp = eval { Config::compile_date () }; if (defined $stamp) { $stamp =~ s/^Compiled at //; $build->{osname} = $^O; $build->{stamp} = $stamp; $build->{patches} = [ Config::local_patches () ]; $build->{options}{$_} = 1 for Config::bincompat_options (), Config::non_bincompat_options (); } else { #y $pv = qx[$^X -e"sub Config::myconfig{};" -V]; my $cnf = plv2hash (qx[$^X -V]); $build->{$_} = $cnf->{build}{$_} for qw( osname stamp patches options ); } my @KEYS = keys %ENV; my %env = map { $_ => $ENV{$_} } grep m/^PERL/ => @KEYS; $args{env} and map { $env{$_} = $ENV{$_} } grep m{$args{env}} => @KEYS; my %config = map { $_ => $Config{$_} } @config_vars; return _make_derived ({ build => $build, environment => \%env, config => \%config, derived => {}, inc => \@INC, }); } # myconfig 1; __END__ =head1 NAME Config::Perl::V - Structured data retrieval of perl -V output =head1 SYNOPSIS use Config::Perl::V; my $local_config = Config::Perl::V::myconfig (); print $local_config->{config}{osname}; =head1 DESCRIPTION =head2 $conf = myconfig () This function will collect the data described in L below, and return that as a hash reference. It optionally accepts an option to include more entries from %ENV. See L below. Note that this will not work on uninstalled perls when called with C<-I/path/to/uninstalled/perl/lib>, but it works when that path is in C<$PERL5LIB> or in C<$PERL5OPT>, as paths passed using C<-I> are not known when the C<-V> information is collected. =head2 $conf = plv2hash ($text [, ...]) Convert a sole 'perl -V' text block, or list of lines, to a complete myconfig hash. All unknown entries are defaulted. =head2 $info = summary ([$conf]) Return an arbitrary selection of the information. If no C<$conf> is given, C is used instead. =head2 $md5 = signature ([$conf]) Return the MD5 of the info returned by C without the C entry. If C is not available, it return a string with only C<0>'s. =head2 The hash structure The returned hash consists of 4 parts: =over 4 =item build This information is extracted from the second block that is emitted by C, and usually looks something like Characteristics of this binary (from libperl): Compile-time options: DEBUGGING USE_64_BIT_INT USE_LARGE_FILES Locally applied patches: defined-or MAINT24637 Built under linux Compiled at Jun 13 2005 10:44:20 @INC: /usr/lib/perl5/5.8.7/i686-linux-64int /usr/lib/perl5/5.8.7 /usr/lib/perl5/site_perl/5.8.7/i686-linux-64int /usr/lib/perl5/site_perl/5.8.7 /usr/lib/perl5/site_perl . or Characteristics of this binary (from libperl): Compile-time options: DEBUGGING MULTIPLICITY PERL_DONT_CREATE_GVSV PERL_IMPLICIT_CONTEXT PERL_MALLOC_WRAP PERL_TRACK_MEMPOOL PERL_USE_SAFE_PUTENV USE_ITHREADS USE_LARGE_FILES USE_PERLIO USE_REENTRANT_API Built under linux Compiled at Jan 28 2009 15:26:59 This information is not available anywhere else, including C<%Config>, but it is the information that is only known to the perl binary. The extracted information is stored in 5 entries in the C hash: =over 4 =item osname This is most likely the same as C<$Config{osname}>, and was the name known when perl was built. It might be different if perl was cross-compiled. The default for this field, if it cannot be extracted, is to copy C<$Config{osname}>. The two may be differing in casing (OpenBSD vs openbsd). =item stamp This is the time string for which the perl binary was compiled. The default value is 0. =item options This is a hash with all the known defines as keys. The value is either 0, which means unknown or unset, or 1, which means defined. =item derived As some variables are reported by a different name in the output of C than their actual name in C<%Config>, I decided to leave the C entry as close to reality as possible, and put in the entries that might have been guessed by the printed output in a separate block. =item patches This is a list of optionally locally applied patches. Default is an empty list. =back =item environment By default this hash is only filled with the environment variables out of %ENV that start with C, but you can pass the C option to myconfig to get more my $conf = Config::Perl::V::myconfig ({ env => qr/^ORACLE/ }); my $conf = Config::Perl::V::myconfig ([ env => qr/^ORACLE/ ]); =item config This hash is filled with the variables that C fills its report with, and it has the same variables that C returns from C<%Config>. =item inc This is the list of default @INC. =back =head1 REASONING This module was written to be able to return the configuration for the currently used perl as deeply as needed for the CPANTESTERS framework. Up until now they used the output of myconfig as a single text blob, and so it was missing the vital binary characteristics of the running perl and the optional applied patches. =head1 BUGS Please feedback what is wrong =head1 TODO * Implement retrieval functions/methods * Documentation * Error checking * Tests =head1 AUTHOR H.Merijn Brand =head1 COPYRIGHT AND LICENSE Copyright (C) 2009-2018 H.Merijn Brand This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut