From a320f1f62f4722476b41813c6c267480dfe56c2f Mon Sep 17 00:00:00 2001 From: "H.Merijn Brand" Date: Sun, 29 Mar 2009 16:21:15 +0200 Subject: [PATCH] Added plv2hash --- Changelog | 4 ++++ MANIFEST | 1 + V.pm | 55 ++++++++++++++++++++++++++++++++++++++++++++++++------- t/20_plv.t | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 100 insertions(+), 7 deletions(-) create mode 100644 t/20_plv.t diff --git a/Changelog b/Changelog index ea50736..d21774f 100644 --- a/Changelog +++ b/Changelog @@ -1,3 +1,7 @@ +0.02 - 29 Mar 2009, H.Merijn Brand + + - Added plv2hash + 0.01 - 29 Mar 2009, H.Merijn Brand - Initial release diff --git a/MANIFEST b/MANIFEST index 905c6ac..50d21bb 100644 --- a/MANIFEST +++ b/MANIFEST @@ -6,4 +6,5 @@ V.pm t/00_pod.t t/01_pod.t t/10_base.t +t/20_plv.t examples/show-v.pl diff --git a/V.pm b/V.pm index 5e04930..ae647ce 100644 --- a/V.pm +++ b/V.pm @@ -5,7 +5,7 @@ package Config::Perl::V; use strict; use warnings; -our $VERSION = "0.01"; +our $VERSION = "0.02"; use Config; @@ -117,6 +117,47 @@ my @config_vars = qw( cccdlflags lddlflags ); +my %empty_build = ( + osname => "", + stamp => 0, + options => { %BTD }, + patches => [], + ); + +sub plv2hash +{ + my %config; + for (split m/\n+/ => join "\n", @_) { + + if (s/^Summary of my\s+(\S+)\s+\(\s*(.*?)\s*\)//) { + $config{"package"} = $1; + my $rev = $2; + $rev =~ s/^ revision \s+ (\S+) \s*//x and $config{revision} = $1; + $rev and $config{version_patchlevel_string} = $rev; + next; + } + + my %kv = m/\G,?\s*([^=]+)=('[^']+?'|\S+)/gc; + + while (my ($k, $v) = each %kv) { + $k =~ s/\s+$//; + $v =~ s/,$//; + $v =~ m/^'(.*)'$/ and $v = $1; + $v =~ s/^\s+//; + $v =~ s/\s+$//; + $config{$k} = $v; + } + } + my $build = { %empty_build }; + $build->{osname} = $config{osname}; + return { + build => $build, + environment => {}, + config => \%config, + inc => [], + }; + } # plv2hash + sub myconfig { my $args = shift; @@ -130,12 +171,7 @@ sub myconfig #print $pv; - my $build = { - osname => "", - stamp => "", - options => \%BTD, - patches => [], - }; + my $build = { %empty_build }; $pv =~ m{^\s+Built under (.*)}m and $build->{osname} = $1; $pv =~ m{^\s+Compiled at (.*)}m and $build->{stamp} = $1; $pv =~ m{^\s+Locally applied patches:\s+(.*)}m and $build->{patches} = [ split m/\s+/, $1 ]; @@ -184,6 +220,11 @@ print $local_config->{config}{osname}; Currently the only function. Documentation will follow. +=head2 plv2hash () + +Convert a sole 'perl -V' text block to a complete myconfig hash. +All unknown entries are defaulted. + =head1 REASONING This module was written to be able to return the configuration for the diff --git a/t/20_plv.t b/t/20_plv.t new file mode 100644 index 0000000..be54928 --- /dev/null +++ b/t/20_plv.t @@ -0,0 +1,47 @@ +#!/pro/bin/perl + +use strict; +use warnings; + +use Test::More tests => 8; +use Test::NoWarnings; + +use Config::Perl::V; + +ok (my $conf = Config::Perl::V::plv2hash (), "Read perl -v block"); +for (qw( build environment config inc )) { + ok (exists $conf->{build}, "Has build entry"); + } +is ($conf->{build}{osname}, $conf->{config}{osname}, "osname"); +is ($conf->{build}{stamp}, 0, "No build time known"); + +__END__ +Summary of my perl5 (revision 5 version 10 subversion 0) configuration: + Platform: + osname=linux, osvers=2.6.22.13-0.3-default, archname=i686-linux-64int + uname='linux nb09 2.6.22.13-0.3-default #1 smp 20071119 15:02:58 utc i686 i686 i386 gnulinux ' + config_args='-Duse64bitint -des' + hint=recommended, useposix=true, d_sigaction=define + useithreads=undef, usemultiplicity=undef + useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef + use64bitint=define, use64bitall=undef, uselongdouble=undef + usemymalloc=n, bincompat5005=undef + Compiler: + cc='cc', ccflags ='-fno-strict-aliasing -pipe -I/pro/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64', + optimize='-O2 -g', + cppflags='-fno-strict-aliasing -pipe -I/pro/local/include' + ccversion='', gccversion='4.2.1 (SUSE Linux)', gccosandvers='' + intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=12345678 + d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12 + ivtype='long long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8 + alignbytes=4, prototype=define + Linker and Libraries: + ld='cc', ldflags ='-L/pro/local/lib' + libpth=/pro/local/lib /lib /usr/lib /usr/local/lib + libs=-lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil -lc + perllibs=-lnsl -ldl -lm -lcrypt -lutil -lc + libc=/lib/libc-2.6.1.so, so=so, useshrplib=false, libperl=libperl.a + gnulibc_version='2.6.1' + Dynamic Linking: + dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E' + cccdlflags='-fPIC', lddlflags='-shared -O2 -L/pro/local/lib' -- 2.11.4.GIT