Checking version 0.01
[Config-Perl-V.git] / V.pm
blob5e049308b021a2bd60746a0a6527695e68130069
1 #!/pro/bin/perl
3 package Config::Perl::V;
5 use strict;
6 use warnings;
8 our $VERSION = "0.01";
10 use Config;
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
17 # search for it in
18 # perl.c line 1768 (first block)
19 # perl.h line 4454 (second block),
20 my %BTD = map { $_ => 0 } qw(
22 DEBUGGING
23 NO_MATHOMS
24 PERL_DONT_CREATE_GVSV
25 PERL_MALLOC_WRAP
26 PERL_MEM_LOG
27 PERL_MEM_LOG_ENV
28 PERL_MEM_LOG_ENV_FD
29 PERL_MEM_LOG_STDERR
30 PERL_MEM_LOG_TIMESTAMP
31 PERL_USE_DEVEL
32 PERL_USE_SAFE_PUTENV
33 USE_FAST_STDIO
34 USE_SITECUSTOMIZE
36 DEBUG_LEAKING_SCALARS
37 DEBUG_LEAKING_SCALARS_FORK_DUMP
38 DECCRTL_SOCKETS
39 FAKE_THREADS
40 MULTIPLICITY
41 MYMALLOC
42 PERL_DEBUG_READONLY_OPS
43 PERL_GLOBAL_STRUCT
44 PERL_IMPLICIT_CONTEXT
45 PERL_IMPLICIT_SYS
46 PERL_MAD
47 PERL_NEED_APPCTX
48 PERL_NEED_TIMESBASE
49 PERL_OLD_COPY_ON_WRITE
50 PERL_POISON
51 PERL_TRACK_MEMPOOL
52 PERL_USES_PL_PIDSTATUS
53 PL_OP_SLAB_ALLOC
54 THREADS_HAVE_PIDS
55 USE_64_BIT_ALL
56 USE_64_BIT_INT
57 USE_IEEE
58 USE_ITHREADS
59 USE_LARGE_FILES
60 USE_LONG_DOUBLE
61 USE_PERLIO
62 USE_REENTRANT_API
63 USE_SFIO
64 USE_SOCKS
65 VMS_DO_SOCKETS
66 VMS_SYMBOL_CASE_AS_IS
69 # These are all the keys that are
70 # 1. Always present in %Config (first block)
71 # 2. Reported by 'perl -V' (the rest)
72 my @config_vars = qw(
74 archlibexp
75 dont_use_nlink
76 d_readlink
77 d_symlink
78 exe_ext
79 inc_version_list
80 ldlibpthname
81 path_sep
82 privlibexp
83 scriptdir
84 sitearchexp
85 sitelibexp
86 usevendorprefix
87 version
89 package revision version_patchlevel_string
91 osname osvers archname
92 myuname
93 config_args
94 hint useposix d_sigaction
95 useithreads usemultiplicity
96 useperlio d_sfio uselargefiles usesocks
97 use64bitint use64bitall uselongdouble
98 usemymalloc bincompat5005
100 cc ccflags
101 optimize
102 cppflags
103 ccversion gccversion gccosandvers
104 intsize longsize ptrsize doublesize byteorder
105 d_longlong longlongsize d_longdbl longdblsize
106 ivtype ivsize nvtype nvsize lseektype lseeksize
107 alignbytes prototype
109 ld ldflags
110 libpth
111 libs
112 perllibs
113 libc so useshrplib libperl
114 gnulibc_version
116 dlsrc dlext d_dlsymun ccdlflags
117 cccdlflags lddlflags
120 sub myconfig
122 my $args = shift;
123 my %args = ref $args eq "HASH" ? % $args :
124 ref $args eq "ARRAY" ? %{@$args} : ();
126 #y $pv = qx[$^X -e"sub Config::myconfig{};" -V];
127 my $pv = qx[$^X -V];
128 $pv =~ s{.*?\n\n}{}s;
129 $pv =~ s{\n(?: \s+|\t\s*)}{ }g;
131 #print $pv;
133 my $build = {
134 osname => "",
135 stamp => "",
136 options => \%BTD,
137 patches => [],
139 $pv =~ m{^\s+Built under (.*)}m and $build->{osname} = $1;
140 $pv =~ m{^\s+Compiled at (.*)}m and $build->{stamp} = $1;
141 $pv =~ m{^\s+Locally applied patches:\s+(.*)}m and $build->{patches} = [ split m/\s+/, $1 ];
142 $pv =~ m{^\s+Compile-time options:\s+(.*)}m and map { $build->{options}{$_} = 1 } split m/\s+/, $1;
144 my @KEYS = keys %ENV;
145 my %env =
146 map { $_ => $ENV{$_} } grep m/^PERL/ => @ENV;
147 $args{db} || $args{pg} || $args{postgres} and
148 map { $env{$_} = $ENV{$_} } grep m{^PG} => @KEYS;
149 $args{db} || $args{oracle} and
150 map { $env{$_} = $ENV{$_} } grep m{^ORACLE} => @KEYS;
151 $args{db} || $args{mysql} and
152 map { $env{$_} = $ENV{$_} } grep m{^M[yY]SQL} => @KEYS;
153 $args{env} and
154 map { $env{$_} = $ENV{$_} } grep m{$args{env}} => @KEYS;
156 my %config = map { $_ => $Config{$_} } @config_vars;
158 return {
159 build => $build,
160 environment => \%env,
161 config => \%config,
162 inc => \@INC,
164 } # myconfig
168 __END__
170 =head1 NAME
172 Config::Perl::V - Structured data retreival of perl -V output
174 =head1 SYNOPSIS
176 use Config::Perl::V;
178 my $local_config = Config::Perl::V::myconfig ();
179 print $local_config->{config}{osname};
181 =head1 DESCRIPTION
183 =head2 myconfig ()
185 Currently the only function. Documentation will follow.
187 =head1 REASONING
189 This module was written to be able to return the configuration for the
190 currently used perl as deeply as needed for the CPANTESTERS framework.
191 Up until now they used the output of myconfig as a single text blob,
192 and so it was missing the vital binary characteristics of the running
193 perl and the optional applied patches.
195 =head1 BUGS
197 Please feedback what is wrong
199 =head1 TODO
201 * Implement retreival functions/methods
202 * Document what is done and why
203 * Include the perl -V parse block from Andreas
205 =head1 AUTHOR
207 H.Merijn Brand <h.m.brand@xs4all.nl>
209 =head1 COPYRIGHT AND LICENSE
211 Copyright (C) 1999-2009 H.Merijn Brand
213 This library is free software; you can redistribute it and/or modify
214 it under the same terms as Perl itself.
216 =cut