3 package Config
::Perl
::V
;
10 use vars
qw($VERSION @ISA @EXPORT_OK %EXPORT_TAGS);
13 @EXPORT_OK = qw( plv2hash summary myconfig signature );
15 all
=> [ @EXPORT_OK ],
16 sig
=> [ "signature" ],
19 # Characteristics of this binary (from libperl):
20 # Compile-time options: DEBUGGING PERL_DONT_CREATE_GVSV PERL_MALLOC_WRAP
21 # USE_64_BIT_INT USE_LARGE_FILES USE_PERLIO
23 # The list are as the perl binary has stored it in PL_bincompat_options
25 # perl.c line 1661 S_Internals_V ()
26 # perl.h line 4664 (second block),
27 my %BTD = map { $_ => 0 } qw(
40 PERL_MEM_LOG_TIMESTAMP
42 PERL_RELOCATABLE_INCPUSH
46 USE_ATTRIBUTES_FOR_PERLIO
53 DEBUG_LEAKING_SCALARS_FORK_DUMP
61 PERL_DEBUG_READONLY_OPS
69 PERL_OLD_COPY_ON_WRITE
70 PERL_NEW_COPY_ON_WRITE
74 PERL_USES_PL_PIDSTATUS
90 VMS_SHORTEN_LONG_SYMBOLS
94 # These are all the keys that are
95 # 1. Always present in %Config (first block)
96 # 2. Reported by 'perl -V' (the rest)
123 git_uncommitted_changes
127 package revision version_patchlevel_string
129 osname osvers archname
132 hint useposix d_sigaction
133 useithreads usemultiplicity
134 useperlio d_sfio uselargefiles usesocks
135 use64bitint use64bitall uselongdouble
136 usemymalloc bincompat5005
141 ccversion gccversion gccosandvers
142 intsize longsize ptrsize doublesize byteorder
143 d_longlong longlongsize d_longdbl longdblsize
144 ivtype ivsize nvtype nvsize lseektype lseeksize
151 libc so useshrplib libperl
154 dlsrc dlext d_dlsymun ccdlflags
169 for ( [ lseektype
=> "Off_t" ],
170 [ myuname
=> "uname" ],
171 [ perl_patchlevel
=> "patch" ],
173 my ($official, $derived) = @
$_;
174 $conf->{config
}{$derived} ||= $conf->{config
}{$official};
175 $conf->{config
}{$official} ||= $conf->{config
}{$derived};
176 $conf->{derived
}{$derived} = delete $conf->{config
}{$derived};
179 if (exists $conf->{config
}{version_patchlevel_string
} &&
180 !exists $conf->{config
}{api_version
}) {
181 my $vps = $conf->{config
}{version_patchlevel_string
};
182 $vps =~ s{\b revision \s+ (\S+) }{}x and
183 $conf->{config
}{revision
} ||= $1;
185 $vps =~ s{\b version \s+ (\S+) }{}x and
186 $conf->{config
}{api_version
} ||= $1;
187 $vps =~ s{\b subversion \s+ (\S+) }{}x and
188 $conf->{config
}{subversion
} ||= $1;
189 $vps =~ s{\b patch \s+ (\S+) }{}x and
190 $conf->{config
}{perl_patchlevel
} ||= $1;
193 ($conf->{config
}{version_patchlevel_string
} ||= join " ",
194 map { ($_, $conf->{config
}{$_} ) }
195 grep { $conf->{config
}{$_} }
196 qw( api_version subversion perl_patchlevel )) =~ s/\bperl_//;
198 $conf->{config
}{perl_patchlevel
} ||= ""; # 0 is not a valid patchlevel
200 if ($conf->{config
}{perl_patchlevel
} =~ m{^git\w*-([^-]+)}i) {
201 $conf->{config
}{git_branch
} ||= $1;
202 $conf->{config
}{git_describe
} ||= $conf->{config
}{perl_patchlevel
};
211 for (split m/\n+/ => join "\n", @_) {
213 if (s/^Summary of my\s+(\S+)\s+\(\s*(.*?)\s*\)//) {
214 $config{"package"} = $1;
216 $rev =~ s/^ revision \s+ (\S+) \s*//x and $config{revision
} = $1;
217 $rev and $config{version_patchlevel_string
} = $rev;
218 my ($rel) = $config{package} =~ m{perl(\d)};
219 my ($vers, $subvers) = $rev =~ m{version\s+(\d+)\s+subversion\s+(\d+)};
220 defined $vers && defined $subvers && defined $rel and
221 $config{version
} = "$rel.$vers.$subvers";
225 if (s/^\s+(Snapshot of:)\s+(\S+)//) {
226 $config{git_commit_id_title
} = $1;
227 $config{git_commit_id
} = $2;
231 my %kv = m/\G,?\s*([^=]+)=('[^']+?'|\S+)/gc;
233 while (my ($k, $v) = each %kv) {
236 $v =~ m/^'(.*)'$/ and $v = $1;
242 my $build = { %empty_build };
243 $build->{osname
} = $config{osname
};
244 return _make_derived
({
255 my $conf = shift || myconfig
();
256 ref $conf eq "HASH" &&
257 exists $conf->{config
} && exists $conf->{build
} or return;
260 exists $conf->{config
}{$_} ?
( $_ => $conf->{config
}{$_} ) : () }
261 qw( archname osname osvers revision patchlevel subversion version
262 cc ccversion gccversion config_args inc_version_list
263 d_longdbl d_longlong use64bitall use64bitint useithreads
264 uselongdouble usemultiplicity usemymalloc useperlio useshrplib
265 doublesize intsize ivsize nvsize longdblsize longlongsize lseeksize
267 $info{$_}++ for grep { $conf->{build
}{options
}{$_} } keys %{$conf->{build
}{options
}};
274 eval { require Digest
::MD5
};
275 $@
and return "00000000000000000000000000000000";
277 my $conf = shift || summary
();
278 delete $conf->{config_args
};
279 return Digest
::MD5
::md5_hex
(join "\xFF" => map {
280 "$_=".(defined $conf->{$_} ?
$conf->{$_} : "\xFE");
287 my %args = ref $args eq "HASH" ?
%$args :
288 ref $args eq "ARRAY" ? @
$args : ();
290 my $build = { %empty_build };
292 # 5.14.0 and later provide all the information without shelling out
293 my $stamp = eval { Config
::compile_date
() };
294 if (defined $stamp) {
295 $stamp =~ s/^Compiled at //;
296 $build->{osname
} = $^O
;
297 $build->{stamp
} = $stamp;
298 $build->{patches
} = [ Config
::local_patches
() ];
299 $build->{options
}{$_} = 1 for Config
::bincompat_options
(),
300 Config
::non_bincompat_options
();
303 #y $pv = qx[$^X -e"sub Config::myconfig{};" -V];
305 $pv =~ s{.*?\n\n}{}s;
306 $pv =~ s{\n(?: \s+|\t\s*)}{ }g;
310 $pv =~ m{^\s+Built under (.*)}m and $build->{osname
} = $1;
311 $pv =~ m{^\s+Compiled at (.*)}m and $build->{stamp
} = $1;
312 $pv =~ m{^\s+Locally applied patches:\s+(.*)}m and $build->{patches
} = [ split m/\s+/, $1 ];
313 $pv =~ m{^\s+Compile-time options:\s+(.*)}m and map { $build->{options
}{$_} = 1 } split m/\s+/, $1;
316 my @KEYS = keys %ENV;
318 map { $_ => $ENV{$_} } grep m/^PERL/ => @KEYS;
320 map { $env{$_} = $ENV{$_} } grep m{$args{env}} => @KEYS;
322 my %config = map { $_ => $Config{$_} } @config_vars;
324 return _make_derived
({
326 environment
=> \
%env,
339 Config::Perl::V - Structured data retrieval of perl -V output
345 my $local_config = Config::Perl::V::myconfig ();
346 print $local_config->{config}{osname};
350 =head2 $conf = myconfig ()
352 This function will collect the data described in L<the hash structure> below,
353 and return that as a hash reference. It optionally accepts an option to
354 include more entries from %ENV. See L<environment> below.
356 Note that this will not work on uninstalled perls when called with
357 C<-I/path/to/uninstalled/perl/lib>, but it works when that path is in
358 C<$PERL5LIB> or in C<$PERL5OPT>, as paths passed using C<-I> are not
359 known when the C<-V> information is collected.
361 =head2 $conf = plv2hash ($text [, ...])
363 Convert a sole 'perl -V' text block, or list of lines, to a complete
364 myconfig hash. All unknown entries are defaulted.
366 =head2 $info = summary ([$conf])
368 Return an arbitrary selection of the information. If no C<$conf> is
369 given, C<myconfig ()> is used instead.
371 =head2 $md5 = signature ([$conf])
373 Return the MD5 of the info returned by C<summary ()> without the
374 C<config_args> entry.
376 If C<Digest::MD5> is not available, it return a string with only C<0>'s.
378 =head2 The hash structure
380 The returned hash consists of 4 parts:
386 This information is extracted from the second block that is emitted by
387 C<perl -V>, and usually looks something like
389 Characteristics of this binary (from libperl):
390 Compile-time options: DEBUGGING USE_64_BIT_INT USE_LARGE_FILES
391 Locally applied patches:
395 Compiled at Jun 13 2005 10:44:20
397 /usr/lib/perl5/5.8.7/i686-linux-64int
399 /usr/lib/perl5/site_perl/5.8.7/i686-linux-64int
400 /usr/lib/perl5/site_perl/5.8.7
401 /usr/lib/perl5/site_perl
406 Characteristics of this binary (from libperl):
407 Compile-time options: DEBUGGING MULTIPLICITY
408 PERL_DONT_CREATE_GVSV PERL_IMPLICIT_CONTEXT
409 PERL_MALLOC_WRAP PERL_TRACK_MEMPOOL
410 PERL_USE_SAFE_PUTENV USE_ITHREADS
411 USE_LARGE_FILES USE_PERLIO
414 Compiled at Jan 28 2009 15:26:59
416 This information is not available anywhere else, including C<%Config>,
417 but it is the information that is only known to the perl binary.
419 The extracted information is stored in 5 entries in the C<build> hash:
425 This is most likely the same as C<$Config{osname}>, and was the name
426 known when perl was built. It might be different if perl was cross-compiled.
428 The default for this field, if it cannot be extracted, is to copy
429 C<$Config{osname}>. The two may be differing in casing (OpenBSD vs openbsd).
433 This is the time string for which the perl binary was compiled. The default
438 This is a hash with all the known defines as keys. The value is either 0,
439 which means unknown or unset, or 1, which means defined.
443 As some variables are reported by a different name in the output of C<perl -V>
444 than their actual name in C<%Config>, I decided to leave the C<config> entry
445 as close to reality as possible, and put in the entries that might have been
446 guessed by the printed output in a separate block.
450 This is a list of optionally locally applied patches. Default is an empty list.
456 By default this hash is only filled with the environment variables
457 out of %ENV that start with C<PERL>, but you can pass the C<env> option
458 to myconfig to get more
460 my $conf = Config::Perl::V::myconfig ({ env => qr/^ORACLE/ });
461 my $conf = Config::Perl::V::myconfig ([ env => qr/^ORACLE/ ]);
465 This hash is filled with the variables that C<perl -V> fills its report
466 with, and it has the same variables that C<Config::myconfig> returns
471 This is the list of default @INC.
477 This module was written to be able to return the configuration for the
478 currently used perl as deeply as needed for the CPANTESTERS framework.
479 Up until now they used the output of myconfig as a single text blob,
480 and so it was missing the vital binary characteristics of the running
481 perl and the optional applied patches.
485 Please feedback what is wrong
489 * Implement retrieval functions/methods
496 H.Merijn Brand <h.m.brand@xs4all.nl>
498 =head1 COPYRIGHT AND LICENSE
500 Copyright (C) 2009-2013 H.Merijn Brand
502 This library is free software; you can redistribute it and/or modify
503 it under the same terms as Perl itself.