[Bps-public-commit] r13030 - in Perl-Invoke: lib lib/Perl t
clkao at bestpractical.com
clkao at bestpractical.com
Sat Jun 7 11:17:58 EDT 2008
Author: clkao
Date: Sat Jun 7 11:17:58 2008
New Revision: 13030
Added:
Perl-Invoke/Changes
Perl-Invoke/MANIFEST
Perl-Invoke/META.yml
Perl-Invoke/Makefile.PL
Perl-Invoke/lib/
Perl-Invoke/lib/Perl/
Perl-Invoke/lib/Perl/Invoke.pm
Perl-Invoke/t/
Perl-Invoke/t/0use.t
Perl-Invoke/t/basic.t
Log:
Perl::Invoke.
Added: Perl-Invoke/Changes
==============================================================================
--- (empty file)
+++ Perl-Invoke/Changes Sat Jun 7 11:17:58 2008
@@ -0,0 +1,4 @@
+Revision history for Perl extension Perl::Invoke
+
+0.26 Sat Jun 7 23:16:33 CST 2008
+ - initial CPAN release
Added: Perl-Invoke/MANIFEST
==============================================================================
--- (empty file)
+++ Perl-Invoke/MANIFEST Sat Jun 7 11:17:58 2008
@@ -0,0 +1,15 @@
+Changes
+inc/Module/Install.pm
+inc/Module/Install/Base.pm
+inc/Module/Install/Can.pm
+inc/Module/Install/Fetch.pm
+inc/Module/Install/Makefile.pm
+inc/Module/Install/Metadata.pm
+inc/Module/Install/Win32.pm
+inc/Module/Install/WriteAll.pm
+lib/Perl/Invoke.pm
+Makefile.PL
+MANIFEST This list of files
+META.yml
+t/0use.t
+t/basic.t
Added: Perl-Invoke/META.yml
==============================================================================
--- (empty file)
+++ Perl-Invoke/META.yml Sat Jun 7 11:17:58 2008
@@ -0,0 +1,18 @@
+--- #YAML:1.0
+name: autobox
+version: 2.23
+abstract: call methods on builtin types
+license: ~
+author:
+ - chocolateboy <chocolate.boy at email.com>
+generated_by: ExtUtils::MakeMaker version 6.42
+distribution_type: module
+requires:
+ Scalar::Util: 1.19
+ Scope::Guard: 0.03
+ Storable: 0
+ Test::More: 0
+ XSLoader: 0
+meta-spec:
+ url: http://module-build.sourceforge.net/META-spec-v1.3.html
+ version: 1.3
Added: Perl-Invoke/Makefile.PL
==============================================================================
--- (empty file)
+++ Perl-Invoke/Makefile.PL Sat Jun 7 11:17:58 2008
@@ -0,0 +1,7 @@
+use strict;
+use inc::Module::Install;
+
+name 'Perl-Invoke';
+all_from 'lib/Perl/Invoke.pm';
+
+WriteAll;
Added: Perl-Invoke/lib/Perl/Invoke.pm
==============================================================================
--- (empty file)
+++ Perl-Invoke/lib/Perl/Invoke.pm Sat Jun 7 11:17:58 2008
@@ -0,0 +1,134 @@
+package Perl::Invoke;
+
+use 5.008;
+
+use strict;
+use warnings;
+
+use Config;
+use IPC::Run3 'run3';
+use Cwd 'abs_path';
+
+use base 'Exporter';
+
+our @EXPORT_OK = qw(this_perl default_inc user_inc abs_user_inc this_perl_cmd this_perl_script_header);
+
+our $DEFAULT_INC;
+
+
+=head1 NAME
+
+Perl::Invoke - Obtain information to invoke the current perl environment
+
+=head1 SYNOPSIS
+
+ use strict;
+ use Perl::Invoke (this_perl_cmd);
+
+=head1 DESCRIPTION
+
+This module gives you the information for invoking the current perl
+environment, giving you a hint about how to invoke perl with proper
+INC path. This is particularly useful in tests that generate perl
+scripts to be invoked indirectly but require the Perl library that we
+are testing against.
+
+This module does not export functions by default.
+
+=head1 FUNCTIONS
+
+=head2 this_perl
+
+Returns the string for the current perl path.
+
+=cut
+
+sub this_perl {
+ return $ENV{SHIPWRIGHT_PERL} || $Config{perlpath};
+}
+
+=head2 default_inc
+
+Returns INC paths defined when this perl got compiled as arrayref.
+
+=cut
+
+sub default_inc {
+ return $DEFAULT_INC if $DEFAULT_INC;
+
+ local $ENV{PERL5LIB} = '';
+ my $sep = $Config{path_sep};
+ my $inc = '';
+ run3 [ this_perl(), '-e', "print join('$sep', \@INC)" ],
+ undef, \$inc, undef;
+
+ $DEFAULT_INC = [split /$sep/, $inc];
+}
+
+=head2 user_inc
+
+Returns the additional INC paths in the current environment as arrayref.
+
+=cut
+
+sub user_inc {
+ my @user_inc;
+ my @default = @{ default_inc() };
+ for my $inc (@INC) {
+ push @user_inc, $inc
+ unless grep { $inc eq $_ } @default;
+ }
+ return \@user_inc;
+}
+
+=head2 abs_user_inc
+
+Like L<user_inc>, but turn the paths into absolute form and remove the
+paths that don't actually exist.
+
+=cut
+
+sub abs_user_inc {
+ [ grep defined, map { abs_path($_) } @{ user_inc() } ];
+}
+
+=head2 this_perl_cmd
+
+Returns a string for executing this Perl includes the appropriate
+C<-I> flags to reflect the current environment.
+
+=cut
+
+sub this_perl_cmd {
+ return join( ' ', this_perl(), map {"-I$_"} @{abs_user_inc()} );
+}
+
+=head2 this_perl_script_header
+
+Returns a string that contains the hash-bang line for excuting this
+Perl, followed by C<use lib> lines. This is useful if you have very
+long L<this_perl_cmd> which doesn't fit in the hash-bang line.
+
+=cut
+
+sub this_perl_script_header {
+ return '#!'.this_perl()."\n".
+ join("\n", map { "use lib '$_';" } @{ abs_user_inc() } );
+}
+
+=head1 AUTHORS
+
+Chia-liang Kao E<lt>clkao at clkao.orgE<gt>
+
+=head1 COPYRIGHT
+
+Copyright 2008 by Chia-liang Kao and others.
+
+This program is free software; you can redistribute it and/or modify it
+under the same terms as Perl itself.
+
+See L<http://www.perl.com/perl/misc/Artistic.html>
+
+=cut
+
+1;
Added: Perl-Invoke/t/0use.t
==============================================================================
--- (empty file)
+++ Perl-Invoke/t/0use.t Sat Jun 7 11:17:58 2008
@@ -0,0 +1,4 @@
+#!perl
+use strict;
+use Test::More tests => 1;
+use_ok('Perl::Invoke');
Added: Perl-Invoke/t/basic.t
==============================================================================
--- (empty file)
+++ Perl-Invoke/t/basic.t Sat Jun 7 11:17:58 2008
@@ -0,0 +1,7 @@
+#!perl
+use strict;
+use Test::More tests => 1;
+use Perl::Invoke;
+
+use lib '/orz/orz/zzz';
+ok(scalar grep { $_ eq '/orz/orz/zzz' } @{ Perl::Invoke::user_inc() }, 'found custom inc path');
More information about the Bps-public-commit
mailing list