From cb6fb7b1b448577e902700e005c3f2a7c1ac5bc2 Mon Sep 17 00:00:00 2001 From: "H.Merijn Brand" Date: Sun, 29 Mar 2009 15:17:46 +0200 Subject: [PATCH] Checking version 0.01 --- .gitignore | 8 ++ Changelog | 3 + MANIFEST | 9 +++ MANIFEST.SKIP | 8 ++ Makefile.PL | 50 +++++++++++++ README | 31 ++++++++ V.pm | 216 +++++++++++++++++++++++++++++++++++++++++++++++++++++ examples/show-v.pl | 9 +++ sandbox/genMETA.pl | 86 +++++++++++++++++++++ t/00_pod.t | 7 ++ t/01_pod.t | 7 ++ t/10_base.t | 17 +++++ 12 files changed, 451 insertions(+) create mode 100644 .gitignore create mode 100644 Changelog create mode 100644 MANIFEST create mode 100644 MANIFEST.SKIP create mode 100644 Makefile.PL create mode 100644 README create mode 100644 V.pm create mode 100755 examples/show-v.pl create mode 100755 sandbox/genMETA.pl create mode 100644 t/00_pod.t create mode 100644 t/01_pod.t create mode 100755 t/10_base.t diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a1f8837 --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +blib +cover_db +Makefile +pm_to_blib +Tk +*.tar.gz +*.tgz +*.old diff --git a/Changelog b/Changelog new file mode 100644 index 0000000..ea50736 --- /dev/null +++ b/Changelog @@ -0,0 +1,3 @@ +0.01 - 29 Mar 2009, H.Merijn Brand + + - Initial release diff --git a/MANIFEST b/MANIFEST new file mode 100644 index 0000000..905c6ac --- /dev/null +++ b/MANIFEST @@ -0,0 +1,9 @@ +MANIFEST +Changelog +Makefile.PL +README +V.pm +t/00_pod.t +t/01_pod.t +t/10_base.t +examples/show-v.pl diff --git a/MANIFEST.SKIP b/MANIFEST.SKIP new file mode 100644 index 0000000..4d08d67 --- /dev/null +++ b/MANIFEST.SKIP @@ -0,0 +1,8 @@ +\.git +blib/ +cover_db/ +Makefile +MANIFEST.SKIP +pm_to_blib +sandbox/ +.releaserc diff --git a/Makefile.PL b/Makefile.PL new file mode 100644 index 0000000..6714a6f --- /dev/null +++ b/Makefile.PL @@ -0,0 +1,50 @@ +#!/usr/bin/perl + +# Copyright PROCURA B.V. (c) 2009 H.Merijn Brand + +use strict; + +use ExtUtils::MakeMaker; + +my %wm = ( + NAME => "Config::Perl::V", + DISTNAME => "Config-Perl-V", + AUTHOR => "H.Merijn Brand ", + VERSION_FROM => "V.pm", + ABSTRACT_FROM => "V.pm", + + PREREQ_PM => { "Config" => 0, + "Test::More" => 0, + "Test::NoWarnings" => 0, + }, + ); +$ExtUtils::MakeMaker::VERSION > 6.30 and $wm{LICENSE} = "perl"; + +my $rv = WriteMakefile (%wm); + +1; + +package MY; + +sub postamble +{ + join "\n" => + 'cover test_cover:', + ' ccache -C', + ' cover -test', + '', + 'checkmeta:', + ' perl sandbox/genMETA.pl -c', + '', + 'fixmeta: distmeta', + ' perl sandbox/genMETA.pl', + ' ls -l */META.yml', + '', + 'tgzdist: checkmeta fixmeta $(DISTVNAME).tar.gz distcheck', + ' -@mv -f $(DISTVNAME).tar.gz $(DISTVNAME).tgz', + ' -@cpants_lint.pl $(DISTVNAME).tgz', + ' -@rm -f Debian_CPANTS.txt', + ''; + } # postamble + +1; diff --git a/README b/README new file mode 100644 index 0000000..1cca0b2 --- /dev/null +++ b/README @@ -0,0 +1,31 @@ +Config::Perl::V + + A module that will return you the output of 'perl -V' in a structure. + +DESCRIPTION + + The command 'perl -V' will return you an excerpt from the %Config hash + combined with the output of 'perl -V' that is not stored inside %Config, + but only available to the perl binary itself. + +PREREQUISITES + + A working perl + +BUILDING AND INSTALLATION + + As most perl modules + + $ perl Makefile.PL + $ make test + $ make install UNINST=1 + +CHANGES + + See Changelog + +COPYRIGHT AND LICENSE + Copyright (C) 2009 H.Merijn Brand + + This library is free software; you can redistribute it and/or modify + it under the same terms as Perl itself. diff --git a/V.pm b/V.pm new file mode 100644 index 0000000..5e04930 --- /dev/null +++ b/V.pm @@ -0,0 +1,216 @@ +#!/pro/bin/perl + +package Config::Perl::V; + +use strict; +use warnings; + +our $VERSION = "0.01"; + +use Config; + +# Characteristics of this binary (from libperl): +# Compile-time options: DEBUGGING PERL_DONT_CREATE_GVSV PERL_MALLOC_WRAP +# USE_64_BIT_INT USE_LARGE_FILES USE_PERLIO + +# The list are as the perl binary has stored it in PL_bincompat_options +# search for it in +# perl.c line 1768 (first block) +# perl.h line 4454 (second block), +my %BTD = map { $_ => 0 } qw( + + DEBUGGING + NO_MATHOMS + PERL_DONT_CREATE_GVSV + PERL_MALLOC_WRAP + PERL_MEM_LOG + PERL_MEM_LOG_ENV + PERL_MEM_LOG_ENV_FD + PERL_MEM_LOG_STDERR + PERL_MEM_LOG_TIMESTAMP + PERL_USE_DEVEL + PERL_USE_SAFE_PUTENV + USE_FAST_STDIO + USE_SITECUSTOMIZE + + DEBUG_LEAKING_SCALARS + DEBUG_LEAKING_SCALARS_FORK_DUMP + DECCRTL_SOCKETS + FAKE_THREADS + MULTIPLICITY + MYMALLOC + PERL_DEBUG_READONLY_OPS + PERL_GLOBAL_STRUCT + PERL_IMPLICIT_CONTEXT + PERL_IMPLICIT_SYS + PERL_MAD + PERL_NEED_APPCTX + PERL_NEED_TIMESBASE + PERL_OLD_COPY_ON_WRITE + PERL_POISON + PERL_TRACK_MEMPOOL + PERL_USES_PL_PIDSTATUS + PL_OP_SLAB_ALLOC + THREADS_HAVE_PIDS + USE_64_BIT_ALL + USE_64_BIT_INT + USE_IEEE + USE_ITHREADS + USE_LARGE_FILES + USE_LONG_DOUBLE + USE_PERLIO + USE_REENTRANT_API + USE_SFIO + USE_SOCKS + VMS_DO_SOCKETS + VMS_SYMBOL_CASE_AS_IS + ); + +# These are all the keys that are +# 1. Always present in %Config (first block) +# 2. Reported by 'perl -V' (the rest) +my @config_vars = qw( + + archlibexp + dont_use_nlink + d_readlink + d_symlink + exe_ext + inc_version_list + ldlibpthname + path_sep + privlibexp + scriptdir + sitearchexp + sitelibexp + usevendorprefix + version + + package revision version_patchlevel_string + + osname osvers archname + myuname + config_args + hint useposix d_sigaction + useithreads usemultiplicity + useperlio d_sfio uselargefiles usesocks + use64bitint use64bitall uselongdouble + usemymalloc bincompat5005 + + cc ccflags + optimize + cppflags + ccversion gccversion gccosandvers + intsize longsize ptrsize doublesize byteorder + d_longlong longlongsize d_longdbl longdblsize + ivtype ivsize nvtype nvsize lseektype lseeksize + alignbytes prototype + + ld ldflags + libpth + libs + perllibs + libc so useshrplib libperl + gnulibc_version + + dlsrc dlext d_dlsymun ccdlflags + cccdlflags lddlflags + ); + +sub myconfig +{ + my $args = shift; + my %args = ref $args eq "HASH" ? % $args : + ref $args eq "ARRAY" ? %{@$args} : (); + + #y $pv = qx[$^X -e"sub Config::myconfig{};" -V]; + my $pv = qx[$^X -V]; + $pv =~ s{.*?\n\n}{}s; + $pv =~ s{\n(?: \s+|\t\s*)}{ }g; + + #print $pv; + + my $build = { + osname => "", + stamp => "", + options => \%BTD, + patches => [], + }; + $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 ]; + $pv =~ m{^\s+Compile-time options:\s+(.*)}m and map { $build->{options}{$_} = 1 } split m/\s+/, $1; + + my @KEYS = keys %ENV; + my %env = + map { $_ => $ENV{$_} } grep m/^PERL/ => @ENV; + $args{db} || $args{pg} || $args{postgres} and + map { $env{$_} = $ENV{$_} } grep m{^PG} => @KEYS; + $args{db} || $args{oracle} and + map { $env{$_} = $ENV{$_} } grep m{^ORACLE} => @KEYS; + $args{db} || $args{mysql} and + map { $env{$_} = $ENV{$_} } grep m{^M[yY]SQL} => @KEYS; + $args{env} and + map { $env{$_} = $ENV{$_} } grep m{$args{env}} => @KEYS; + + my %config = map { $_ => $Config{$_} } @config_vars; + + return { + build => $build, + environment => \%env, + config => \%config, + inc => \@INC, + }; + } # myconfig + +1; + +__END__ + +=head1 NAME + +Config::Perl::V - Structured data retreival of perl -V output + +=head1 SYNOPSIS + +use Config::Perl::V; + +my $local_config = Config::Perl::V::myconfig (); +print $local_config->{config}{osname}; + +=head1 DESCRIPTION + +=head2 myconfig () + +Currently the only function. Documentation will follow. + +=head1 REASONING + +This module was written to be able to return the configuration for the +currently used perl as deeply as needed for the CPANTESTERS framework. +Up until now they used the output of myconfig as a single text blob, +and so it was missing the vital binary characteristics of the running +perl and the optional applied patches. + +=head1 BUGS + +Please feedback what is wrong + +=head1 TODO + +* Implement retreival functions/methods +* Document what is done and why +* Include the perl -V parse block from Andreas + +=head1 AUTHOR + +H.Merijn Brand + +=head1 COPYRIGHT AND LICENSE + +Copyright (C) 1999-2009 H.Merijn Brand + +This library is free software; you can redistribute it and/or modify +it under the same terms as Perl itself. + +=cut diff --git a/examples/show-v.pl b/examples/show-v.pl new file mode 100755 index 0000000..1f1cc8a --- /dev/null +++ b/examples/show-v.pl @@ -0,0 +1,9 @@ +#!/pro/bin/perl + +use strict; +use warnings; + +use Data::Peek; +use Config::Perl::V; + +DDumper Config::Perl::V::myconfig; diff --git a/sandbox/genMETA.pl b/sandbox/genMETA.pl new file mode 100755 index 0000000..98e4467 --- /dev/null +++ b/sandbox/genMETA.pl @@ -0,0 +1,86 @@ +#!/pro/bin/perl + +use strict; +use warnings; + +use Getopt::Long qw(:config bundling nopermute); +my $check = 0; +my $opt_v = 0; +GetOptions ( + "c|check" => \$check, + "v|verbose:1" => \$opt_v, + ) or die "usage: $0 [--check]\n"; + +my $version; +open my $pm, "<", "V.pm" or die "Cannot read V.pm"; +while (<$pm>) { + m/^our .VERSION\s*=\s*"?([-0-9._]+)"?\s*;\s*$/ or next; + $version = $1; + last; + } +close $pm; + +my @yml; +while () { + s/VERSION/$version/o; + push @yml, $_; + } + +if ($check) { + use YAML::Syck; + use Test::YAML::Meta::Version; + my $h; + my $yml = join "", @yml; + eval { $h = Load ($yml) }; + $@ and die "$@\n"; + $opt_v and print Dump $h; + my $t = Test::YAML::Meta::Version->new (yaml => $h); + $t->parse () and die join "\n", $t->errors, ""; + + use Parse::CPAN::Meta; + eval { Parse::CPAN::Meta::Load ($yml) }; + $@ and die "$@\n"; + + print "Checking if 5.006 is still OK as minimal version for examples\n"; + use Test::MinimumVersion; + # All other minimum version checks done in xt + all_minimum_version_ok ("5.006"); + } +elsif ($opt_v) { + print @yml; + } +else { + my @my = glob <*/META.yml>; + @my == 1 && open my $my, ">", $my[0] or die "Cannot update META.yml|n"; + print $my @yml; + close $my; + chmod 0644, glob <*/META.yml>; + } + +__END__ +--- #YAML:1.1 +name: Config::Perl::V +version: VERSION +abstract: Structured data retreival of perl -V output +license: perl +author: + - H.Merijn Brand +generated_by: Author +distribution_type: module +provides: + Config::Perl::V: + file: V.pm + version: VERSION +requires: + perl: 5.005 +build_requires: + perl: 5.005 + Test::Harness: 0 + Test::More: 0 + Test::NoWarnings: 0 +resources: + license: http://dev.perl.org/licenses/ + repository: http://repo.or.cz/w/Config-Perl-V.git +meta-spec: + version: 1.4 + url: http://module-build.sourceforge.net/META-spec-v1.4.html diff --git a/t/00_pod.t b/t/00_pod.t new file mode 100644 index 0000000..67d0815 --- /dev/null +++ b/t/00_pod.t @@ -0,0 +1,7 @@ +#!/usr/bin/perl + +use Test::More; + +eval "use Test::Pod 1.00"; +plan skip_all => "Test::Pod 1.00 required for testing POD" if $@; +all_pod_files_ok (); diff --git a/t/01_pod.t b/t/01_pod.t new file mode 100644 index 0000000..c99abc7 --- /dev/null +++ b/t/01_pod.t @@ -0,0 +1,7 @@ +#!/usr/bin/perl + +use Test::More; + +eval "use Test::Pod::Coverage tests => 1"; +plan skip_all => "Test::Pod::Covarage required for testing POD Coverage" if $@; +pod_coverage_ok ("Config::Perl::V", "Config::Perl::V is covered"); diff --git a/t/10_base.t b/t/10_base.t new file mode 100755 index 0000000..02f2c46 --- /dev/null +++ b/t/10_base.t @@ -0,0 +1,17 @@ +#!/pro/bin/perl + +use strict; +use warnings; + +use Test::More tests => 8; +use Test::NoWarnings; + +BEGIN { + use_ok ("Config::Perl::V"); + } + +ok (my $conf = Config::Perl::V::myconfig, "Read config"); +for (qw( build environment config inc )) { + ok (exists $conf->{build}, "Has build entry"); + } +is ($conf->{build}{osname}, $conf->{config}{osname}, "osname"); -- 2.11.4.GIT