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 1643 S_Internals_V ()
26 # perl -ne'(/^S_Internals_V/../^}/)&&s/^\s+"( .*)"/$1/ and print' perl.c
27 # perl.h line 4566 PL_bincompat_options
28 # perl -ne'(/^\w.*PL_bincompat/../^\w}/)&&s/^\s+"( .*)"/$1/ and print' perl.h
29 my %BTD = map { $_ => 0 } qw(
39 PERL_HASH_FUNC_SIPHASH
42 PERL_HASH_FUNC_SUPERFAST
43 PERL_HASH_FUNC_MURMUR3
44 PERL_HASH_FUNC_ONE_AT_A_TIME
45 PERL_HASH_FUNC_ONE_AT_A_TIME_HARD
46 PERL_HASH_FUNC_ONE_AT_A_TIME_OLD
54 PERL_MEM_LOG_TIMESTAMP
55 PERL_NEW_COPY_ON_WRITE
56 PERL_PERTURB_KEYS_DETERMINISTIC
57 PERL_PERTURB_KEYS_DISABLED
58 PERL_PERTURB_KEYS_RANDOM
60 PERL_RELOCATABLE_INCPUSH
64 USE_ATTRIBUTES_FOR_PERLIO
66 USE_HASH_SEED_EXPLICIT
73 DEBUG_LEAKING_SCALARS_FORK_DUMP
82 PERL_DEBUG_READONLY_COW
83 PERL_DEBUG_READONLY_OPS
91 PERL_OLD_COPY_ON_WRITE
95 PERL_USES_PL_PIDSTATUS
111 VMS_SHORTEN_LONG_SYMBOLS
112 VMS_SYMBOL_CASE_AS_IS
115 # These are all the keys that are
116 # 1. Always present in %Config - lib/Config.pm #87 tie %Config
117 # 2. Reported by 'perl -V' (the rest)
118 my @config_vars = qw(
144 git_uncommitted_changes
148 package revision version_patchlevel_string
150 osname osvers archname
153 hint useposix d_sigaction
154 useithreads usemultiplicity
155 useperlio d_sfio uselargefiles usesocks
156 use64bitint use64bitall uselongdouble
157 usemymalloc bincompat5005
162 ccversion gccversion gccosandvers
163 intsize longsize ptrsize doublesize byteorder
164 d_longlong longlongsize d_longdbl longdblsize
165 ivtype ivsize nvtype nvsize lseektype lseeksize
172 libc so useshrplib libperl
175 dlsrc dlext d_dlsymun ccdlflags
190 for ( [ lseektype
=> "Off_t" ],
191 [ myuname
=> "uname" ],
192 [ perl_patchlevel
=> "patch" ],
194 my ($official, $derived) = @
$_;
195 $conf->{config
}{$derived} ||= $conf->{config
}{$official};
196 $conf->{config
}{$official} ||= $conf->{config
}{$derived};
197 $conf->{derived
}{$derived} = delete $conf->{config
}{$derived};
200 if (exists $conf->{config
}{version_patchlevel_string
} &&
201 !exists $conf->{config
}{api_version
}) {
202 my $vps = $conf->{config
}{version_patchlevel_string
};
203 $vps =~ s{\b revision \s+ (\S+) }{}x and
204 $conf->{config
}{revision
} ||= $1;
206 $vps =~ s{\b version \s+ (\S+) }{}x and
207 $conf->{config
}{api_version
} ||= $1;
208 $vps =~ s{\b subversion \s+ (\S+) }{}x and
209 $conf->{config
}{subversion
} ||= $1;
210 $vps =~ s{\b patch \s+ (\S+) }{}x and
211 $conf->{config
}{perl_patchlevel
} ||= $1;
214 ($conf->{config
}{version_patchlevel_string
} ||= join " ",
215 map { ($_, $conf->{config
}{$_} ) }
216 grep { $conf->{config
}{$_} }
217 qw( api_version subversion perl_patchlevel )) =~ s/\bperl_//;
219 $conf->{config
}{perl_patchlevel
} ||= ""; # 0 is not a valid patchlevel
221 if ($conf->{config
}{perl_patchlevel
} =~ m{^git\w*-([^-]+)}i) {
222 $conf->{config
}{git_branch
} ||= $1;
223 $conf->{config
}{git_describe
} ||= $conf->{config
}{perl_patchlevel
};
233 my $pv = join "\n" => @_;
235 if ($pv =~ m/^Summary of my\s+(\S+)\s+\(\s*(.*?)\s*\)/m) {
236 $config{"package"} = $1;
238 $rev =~ s/^ revision \s+ (\S+) \s*//x and $config{revision
} = $1;
239 $rev and $config{version_patchlevel_string
} = $rev;
240 my ($rel) = $config{"package"} =~ m{perl(\d)};
241 my ($vers, $subvers) = $rev =~ m{version\s+(\d+)\s+subversion\s+(\d+)};
242 defined $vers && defined $subvers && defined $rel and
243 $config{version
} = "$rel.$vers.$subvers";
246 if ($pv =~ m/^\s+(Snapshot of:)\s+(\S+)/) {
247 $config{git_commit_id_title
} = $1;
248 $config{git_commit_id
} = $2;
251 if (my %kv = ($pv =~ m/\b(\w+)\s*=\s*('[^']+?'|\S+)/g)) {
253 while (my ($k, $v) = each %kv) {
256 $v =~ m/^'(.*)'$/ and $v = $1;
263 my $build = { %empty_build };
265 $pv =~ m{^\s+Compiled at\s+(.*)}m
266 and $build->{stamp
} = $1;
267 $pv =~ m{^\s+Locally applied patches:(?:\s+|\n)(.*)}m
268 and $build->{patches
} = [ split m/\n+/, $1 ];
269 $pv =~ m{^\s+Compile-time options:(?:\s+|\n)(.*)}m
270 and map { $build->{options
}{$_} = 1 } split m/\s+|\n/ => $1;
272 $build->{osname
} = $config{osname
};
273 $pv =~ m{^\s+Built under\s+(.*)}m
274 and $build->{osname
} = $1;
275 $config{osname
} ||= $build->{osname
};
277 return _make_derived
({
288 my $conf = shift || myconfig
();
289 ref $conf eq "HASH" &&
290 exists $conf->{config
} && exists $conf->{build
} or return;
293 exists $conf->{config
}{$_} ?
( $_ => $conf->{config
}{$_} ) : () }
294 qw( archname osname osvers revision patchlevel subversion version
295 cc ccversion gccversion config_args inc_version_list
296 d_longdbl d_longlong use64bitall use64bitint useithreads
297 uselongdouble usemultiplicity usemymalloc useperlio useshrplib
298 doublesize intsize ivsize nvsize longdblsize longlongsize lseeksize
300 $info{$_}++ for grep { $conf->{build
}{options
}{$_} } keys %{$conf->{build
}{options
}};
307 eval { require Digest
::MD5
};
308 $@
and return "00000000000000000000000000000000";
310 my $conf = shift || summary
();
311 delete $conf->{config_args
};
312 return Digest
::MD5
::md5_hex
(join "\xFF" => map {
313 "$_=".(defined $conf->{$_} ?
$conf->{$_} : "\xFE");
320 my %args = ref $args eq "HASH" ?
%$args :
321 ref $args eq "ARRAY" ? @
$args : ();
323 my $build = { %empty_build };
325 # 5.14.0 and later provide all the information without shelling out
326 my $stamp = eval { Config
::compile_date
() };
327 if (defined $stamp) {
328 $stamp =~ s/^Compiled at //;
329 $build->{osname
} = $^O
;
330 $build->{stamp
} = $stamp;
331 $build->{patches
} = [ Config
::local_patches
() ];
332 $build->{options
}{$_} = 1 for Config
::bincompat_options
(),
333 Config
::non_bincompat_options
();
336 #y $pv = qx[$^X -e"sub Config::myconfig{};" -V];
337 my $cnf = plv2hash
(qx[$^X
-V
]);
339 $build->{$_} = $cnf->{build
}{$_} for qw( osname stamp patches options );
342 my @KEYS = keys %ENV;
344 map { $_ => $ENV{$_} } grep m/^PERL/ => @KEYS;
346 map { $env{$_} = $ENV{$_} } grep m{$args{env}} => @KEYS;
348 my %config = map { $_ => $Config{$_} } @config_vars;
350 return _make_derived
({
352 environment
=> \
%env,
365 Config::Perl::V - Structured data retrieval of perl -V output
371 my $local_config = Config::Perl::V::myconfig ();
372 print $local_config->{config}{osname};
376 =head2 $conf = myconfig ()
378 This function will collect the data described in L<the hash structure> below,
379 and return that as a hash reference. It optionally accepts an option to
380 include more entries from %ENV. See L<environment> below.
382 Note that this will not work on uninstalled perls when called with
383 C<-I/path/to/uninstalled/perl/lib>, but it works when that path is in
384 C<$PERL5LIB> or in C<$PERL5OPT>, as paths passed using C<-I> are not
385 known when the C<-V> information is collected.
387 =head2 $conf = plv2hash ($text [, ...])
389 Convert a sole 'perl -V' text block, or list of lines, to a complete
390 myconfig hash. All unknown entries are defaulted.
392 =head2 $info = summary ([$conf])
394 Return an arbitrary selection of the information. If no C<$conf> is
395 given, C<myconfig ()> is used instead.
397 =head2 $md5 = signature ([$conf])
399 Return the MD5 of the info returned by C<summary ()> without the
400 C<config_args> entry.
402 If C<Digest::MD5> is not available, it return a string with only C<0>'s.
404 =head2 The hash structure
406 The returned hash consists of 4 parts:
412 This information is extracted from the second block that is emitted by
413 C<perl -V>, and usually looks something like
415 Characteristics of this binary (from libperl):
416 Compile-time options: DEBUGGING USE_64_BIT_INT USE_LARGE_FILES
417 Locally applied patches:
421 Compiled at Jun 13 2005 10:44:20
423 /usr/lib/perl5/5.8.7/i686-linux-64int
425 /usr/lib/perl5/site_perl/5.8.7/i686-linux-64int
426 /usr/lib/perl5/site_perl/5.8.7
427 /usr/lib/perl5/site_perl
432 Characteristics of this binary (from libperl):
433 Compile-time options: DEBUGGING MULTIPLICITY
434 PERL_DONT_CREATE_GVSV PERL_IMPLICIT_CONTEXT
435 PERL_MALLOC_WRAP PERL_TRACK_MEMPOOL
436 PERL_USE_SAFE_PUTENV USE_ITHREADS
437 USE_LARGE_FILES USE_PERLIO
440 Compiled at Jan 28 2009 15:26:59
442 This information is not available anywhere else, including C<%Config>,
443 but it is the information that is only known to the perl binary.
445 The extracted information is stored in 5 entries in the C<build> hash:
451 This is most likely the same as C<$Config{osname}>, and was the name
452 known when perl was built. It might be different if perl was cross-compiled.
454 The default for this field, if it cannot be extracted, is to copy
455 C<$Config{osname}>. The two may be differing in casing (OpenBSD vs openbsd).
459 This is the time string for which the perl binary was compiled. The default
464 This is a hash with all the known defines as keys. The value is either 0,
465 which means unknown or unset, or 1, which means defined.
469 As some variables are reported by a different name in the output of C<perl -V>
470 than their actual name in C<%Config>, I decided to leave the C<config> entry
471 as close to reality as possible, and put in the entries that might have been
472 guessed by the printed output in a separate block.
476 This is a list of optionally locally applied patches. Default is an empty list.
482 By default this hash is only filled with the environment variables
483 out of %ENV that start with C<PERL>, but you can pass the C<env> option
484 to myconfig to get more
486 my $conf = Config::Perl::V::myconfig ({ env => qr/^ORACLE/ });
487 my $conf = Config::Perl::V::myconfig ([ env => qr/^ORACLE/ ]);
491 This hash is filled with the variables that C<perl -V> fills its report
492 with, and it has the same variables that C<Config::myconfig> returns
497 This is the list of default @INC.
503 This module was written to be able to return the configuration for the
504 currently used perl as deeply as needed for the CPANTESTERS framework.
505 Up until now they used the output of myconfig as a single text blob,
506 and so it was missing the vital binary characteristics of the running
507 perl and the optional applied patches.
511 Please feedback what is wrong
515 * Implement retrieval functions/methods
522 H.Merijn Brand <h.m.brand@xs4all.nl>
524 =head1 COPYRIGHT AND LICENSE
526 Copyright (C) 2009-2014 H.Merijn Brand
528 This library is free software; you can redistribute it and/or modify
529 it under the same terms as Perl itself.