3 package Config
::Perl
::V
;
12 # Characteristics of this binary (from libperl):
13 # Compile-time options: DEBUGGING PERL_DONT_CREATE_GVSV PERL_MALLOC_WRAP
14 # USE_64_BIT_INT USE_LARGE_FILES USE_PERLIO
16 # The list are as the perl binary has stored it in PL_bincompat_options
18 # perl.c line 1768 (first block)
19 # perl.h line 4454 (second block),
20 my %BTD = map { $_ => 0 } qw(
30 PERL_MEM_LOG_TIMESTAMP
37 DEBUG_LEAKING_SCALARS_FORK_DUMP
42 PERL_DEBUG_READONLY_OPS
49 PERL_OLD_COPY_ON_WRITE
52 PERL_USES_PL_PIDSTATUS
69 # These are all the keys that are
70 # 1. Always present in %Config (first block)
71 # 2. Reported by 'perl -V' (the rest)
98 git_uncommitted_changes
102 package revision version_patchlevel_string
104 osname osvers archname
107 hint useposix d_sigaction
108 useithreads usemultiplicity
109 useperlio d_sfio uselargefiles usesocks
110 use64bitint use64bitall uselongdouble
111 usemymalloc bincompat5005
116 ccversion gccversion gccosandvers
117 intsize longsize ptrsize doublesize byteorder
118 d_longlong longlongsize d_longdbl longdblsize
119 ivtype ivsize nvtype nvsize lseektype lseeksize
126 libc so useshrplib libperl
129 dlsrc dlext d_dlsymun ccdlflags
144 for ( [ lseektype
=> "Off_t" ],
145 [ myuname
=> "uname" ],
146 [ perl_patchlevel
=> "patch" ],
148 my ($official, $derived) = @
$_;
149 $conf->{config
}{$derived} ||= $conf->{config
}{$official};
150 $conf->{config
}{$official} ||= $conf->{config
}{$derived};
151 $conf->{derived
}{$derived} = delete $conf->{config
}{$derived};
154 if (exists $conf->{config
}{version_patchlevel_string
} &&
155 !exists $conf->{config
}{api_version
}) {
156 my $vps = $conf->{config
}{version_patchlevel_string
};
157 $vps =~ s{\b revision \s+ (\S+) }{}x and
158 $conf->{config
}{revision
} ||= $1;
160 $vps =~ s{\b version \s+ (\S+) }{}x and
161 $conf->{config
}{api_version
} ||= $1;
162 $vps =~ s{\b subversion \s+ (\S+) }{}x and
163 $conf->{config
}{subversion
} ||= $1;
164 $vps =~ s{\b patch \s+ (\S+) }{}x and
165 $conf->{config
}{perl_patchlevel
} ||= $1;
168 ($conf->{config
}{version_patchlevel_string
} ||= join " ",
169 map { ($_, $conf->{config
}{$_} ) }
170 grep { $conf->{config
}{$_} }
171 qw( api_version subversion perl_patchlevel )) =~ s/\bperl_//;
173 $conf->{config
}{perl_patchlevel
} ||= ""; # 0 is not a valid patchlevel
175 if ($conf->{config
}{perl_patchlevel
} =~ m{^git\w*-([^-]+)}i) {
176 $conf->{config
}{git_branch
} ||= $1;
177 $conf->{config
}{git_describe
} ||= $conf->{config
}{perl_patchlevel
};
186 for (split m/\n+/ => join "\n", @_) {
188 if (s/^Summary of my\s+(\S+)\s+\(\s*(.*?)\s*\)//) {
189 $config{"package"} = $1;
191 $rev =~ s/^ revision \s+ (\S+) \s*//x and $config{revision
} = $1;
192 $rev and $config{version_patchlevel_string
} = $rev;
196 if (s/^\s+(Snapshot of:)\s+(\S+)//) {
197 $config{git_commit_id_title
} = $1;
198 $config{git_commit_id
} = $2;
202 my %kv = m/\G,?\s*([^=]+)=('[^']+?'|\S+)/gc;
204 while (my ($k, $v) = each %kv) {
207 $v =~ m/^'(.*)'$/ and $v = $1;
213 my $build = { %empty_build };
214 $build->{osname
} = $config{osname
};
215 return _make_derived
({
227 ref $conf eq "HASH" &&
228 exists $conf->{config
} && exists $conf->{build
} or return;
231 exists $conf->{config
}{$_} ?
( $_ => $conf->{config
}{$_} ) : () }
232 qw( archname osname osvers revision patchlevel subversion version
233 cc ccversion gccversion config_args inc_version_list
234 d_longdbl d_longlong use64bitall use64bitint useithreads
235 uselongdouble usemultiplicity usemymalloc useperlio useshrplib
236 doublesize intsize ivsize nvsize longdblsize longlongsize lseeksize
238 $info{$_}++ for grep { $conf->{build
}{options
}{$_} } keys %{$conf->{build
}{options
}};
246 my %args = ref $args eq "HASH" ?
%$args :
247 ref $args eq "ARRAY" ? @
$args : ();
249 #y $pv = qx[$^X -e"sub Config::myconfig{};" -V];
251 $pv =~ s{.*?\n\n}{}s;
252 $pv =~ s{\n(?: \s+|\t\s*)}{ }g;
256 my $build = { %empty_build };
257 $pv =~ m{^\s+Built under (.*)}m and $build->{osname
} = $1;
258 $pv =~ m{^\s+Compiled at (.*)}m and $build->{stamp
} = $1;
259 $pv =~ m{^\s+Locally applied patches:\s+(.*)}m and $build->{patches
} = [ split m/\s+/, $1 ];
260 $pv =~ m{^\s+Compile-time options:\s+(.*)}m and map { $build->{options
}{$_} = 1 } split m/\s+/, $1;
262 my @KEYS = keys %ENV;
264 map { $_ => $ENV{$_} } grep m/^PERL/ => @KEYS;
266 map { $env{$_} = $ENV{$_} } grep m{$args{env}} => @KEYS;
268 my %config = map { $_ => $Config{$_} } @config_vars;
270 return _make_derived
({
272 environment
=> \
%env,
285 Config::Perl::V - Structured data retreival of perl -V output
291 my $local_config = Config::Perl::V::myconfig ();
292 print $local_config->{config}{osname};
296 =head2 $conf = myconfig ()
298 This function will collect the data decribed in L<the hash structure> below,
299 and return that as a hash reference. It optionally accepts an option to
300 include more entries from %ENV. See L<environment> below.
302 Note that this will not work on uninstalled perls when called with
303 C<-I/path/to/uninstalled/perl/lib>, but it works when that path is in
304 C<$PERL5LIB> or in C<$PERL5OPT>, as paths passed using C<-I> are not
305 known when the C<-V> information is collected.
307 =head2 $conf = plv2hash ($text [, ...])
309 Convert a sole 'perl -V' text block, or list of lines, to a complete
310 myconfig hash. All unknown entries are defaulted.
312 =head2 $info = summary ($conf)
314 Return an arbitrary selection of the information.
316 =head2 The hash structure
318 The returned hash consists of 4 parts:
324 This information is extracted from the second block that is emitted by
325 C<perl -V>, and usually looks something like
327 Characteristics of this binary (from libperl):
328 Compile-time options: DEBUGGING USE_64_BIT_INT USE_LARGE_FILES
329 Locally applied patches:
333 Compiled at Jun 13 2005 10:44:20
335 /usr/lib/perl5/5.8.7/i686-linux-64int
337 /usr/lib/perl5/site_perl/5.8.7/i686-linux-64int
338 /usr/lib/perl5/site_perl/5.8.7
339 /usr/lib/perl5/site_perl
344 Characteristics of this binary (from libperl):
345 Compile-time options: DEBUGGING MULTIPLICITY
346 PERL_DONT_CREATE_GVSV PERL_IMPLICIT_CONTEXT
347 PERL_MALLOC_WRAP PERL_TRACK_MEMPOOL
348 PERL_USE_SAFE_PUTENV USE_ITHREADS
349 USE_LARGE_FILES USE_PERLIO
352 Compiled at Jan 28 2009 15:26:59
354 This information is not available anywhere else, including C<%Config>,
355 but it is the information that is only known to the perl binary.
357 The extracted information is stored in 5 entries in the C<build> hash:
363 This is most likely the same as C$Config{osname}>, and was the name
364 known when perl was built. It might be different if perl was cross-compiled.
366 The default for this field, if it cannot be extracted, is to copy C<$Config{osname}>.
370 This is the time string for which the perl binary was compiled. The default
375 This is a hash with all the known defines as keys. The value is either 0,
376 which means unknown or unset, or 1, which means defined.
380 As some verables are reported by a different name in the output of C<perl -V>
381 than their actual name in C<%Config>, I decided to leave the C<config> entry
382 as close to reality as possible, and put in the entries that might have been
383 guessed by the printed output in a seperate block.
387 This is a list of optionally locally applied patches. Default is an empty list.
393 By default this hash is only filled with the environment variables
394 out of %ENV that start with C<PERL>, but you can pass the C<env> option
395 to myconfig to get more
397 my $conf = Config::Perl::V::myconfig ({ env => qr/^ORACLE/ });
398 my $conf = Config::Perl::V::myconfig ([ env => qr/^ORACLE/ ]);
402 This hash is filled with the variables that C<perl -V> fills its report
403 with, and it has the same variables that C<Config::myconfig> returns
408 This is the list of default @INC.
414 This module was written to be able to return the configuration for the
415 currently used perl as deeply as needed for the CPANTESTERS framework.
416 Up until now they used the output of myconfig as a single text blob,
417 and so it was missing the vital binary characteristics of the running
418 perl and the optional applied patches.
422 Please feedback what is wrong
426 * Implement retrieval functions/methods
433 H.Merijn Brand <h.m.brand@xs4all.nl>
435 =head1 COPYRIGHT AND LICENSE
437 Copyright (C) 2009 H.Merijn Brand
439 This library is free software; you can redistribute it and/or modify
440 it under the same terms as Perl itself.