diff options
Diffstat (limited to 'gnu/usr.bin/perl/cpan/Module-Load-Conditional')
4 files changed, 96 insertions, 13 deletions
diff --git a/gnu/usr.bin/perl/cpan/Module-Load-Conditional/lib/Module/Load/Conditional.pm b/gnu/usr.bin/perl/cpan/Module-Load-Conditional/lib/Module/Load/Conditional.pm index 342371f8794..422f56b4d5c 100644 --- a/gnu/usr.bin/perl/cpan/Module-Load-Conditional/lib/Module/Load/Conditional.pm +++ b/gnu/usr.bin/perl/cpan/Module-Load-Conditional/lib/Module/Load/Conditional.pm @@ -2,7 +2,7 @@ package Module::Load::Conditional; use strict; -use Module::Load; +use Module::Load qw/load autoload_remote/; use Params::Check qw[check]; use Locale::Maketext::Simple Style => 'gettext'; @@ -13,14 +13,16 @@ use version; use Module::Metadata (); -use constant ON_VMS => $^O eq 'VMS'; +use constant ON_VMS => $^O eq 'VMS'; +use constant ON_WIN32 => $^O eq 'MSWin32' ? 1 : 0; +use constant QUOTE => do { ON_WIN32 ? q["] : q['] }; BEGIN { use vars qw[ $VERSION @ISA $VERBOSE $CACHE @EXPORT_OK $DEPRECATED $FIND_VERSION $ERROR $CHECK_INC_HASH]; use Exporter; @ISA = qw[Exporter]; - $VERSION = '0.54'; + $VERSION = '0.62'; $VERBOSE = 0; $DEPRECATED = 0; $FIND_VERSION = 1; @@ -195,7 +197,7 @@ sub check_install { } } - ### we didnt find the filename yet by looking in %INC, + ### we didn't find the filename yet by looking in %INC, ### so scan the dirs unless( $filename ) { @@ -317,7 +319,7 @@ sub check_install { return $href; } -=head2 $bool = can_load( modules => { NAME => VERSION [,NAME => VERSION] }, [verbose => BOOL, nocache => BOOL] ) +=head2 $bool = can_load( modules => { NAME => VERSION [,NAME => VERSION] }, [verbose => BOOL, nocache => BOOL, autoload => BOOL] ) C<can_load> will take a list of modules, optionally with version numbers and determine if it is able to load them. If it can load *ALL* @@ -327,8 +329,8 @@ This is particularly useful if you have More Than One Way (tm) to solve a problem in a program, and only wish to continue down a path if all modules could be loaded, and not load them if they couldn't. -This function uses the C<load> function from Module::Load under the -hood. +This function uses the C<load> function or the C<autoload_remote> function +from Module::Load under the hood. C<can_load> takes the following arguments: @@ -353,6 +355,12 @@ same module twice, nor will it attempt to load a module that has already failed to load before. By default, C<can_load> will check its cache, but you can override that by setting C<nocache> to true. +=item autoload + +This controls whether imports the functions of a loaded modules to the caller package. The default is no importing any functions. + +See the C<autoload> function and the C<autoload_remote> function from L<Module::Load> for details. + =cut sub can_load { @@ -362,6 +370,7 @@ sub can_load { modules => { default => {}, strict_type => 1 }, verbose => { default => $VERBOSE }, nocache => { default => 0 }, + autoload => { default => 0 }, }; my $args; @@ -434,7 +443,12 @@ sub can_load { if ( $CACHE->{$mod}->{uptodate} ) { - eval { load $mod }; + if ( $args->{autoload} ) { + my $who = (caller())[0]; + eval { autoload_remote $who, $mod }; + } else { + eval { load $mod }; + } ### in case anything goes wrong, log the error, the fact ### we tried to use this module and return 0; @@ -495,12 +509,15 @@ sub requires { } my $lib = join " ", map { qq["-I$_"] } @INC; - my $cmd = qq["$^X" $lib -M$who -e"print(join(qq[\\n],keys(%INC)))"]; + my $oneliner = 'print(join(qq[\n],map{qq[BONG=$_]}keys(%INC)),qq[\n])'; + my $cmd = join '', qq["$^X" $lib -M$who -e], QUOTE, $oneliner, QUOTE; return sort grep { !/^$who$/ } map { chomp; s|/|::|g; $_ } grep { s|\.pm$||i; } + map { s!^BONG\=!!; $_ } + grep { m!^BONG\=! } `$cmd`; } diff --git a/gnu/usr.bin/perl/cpan/Module-Load-Conditional/t/01_Module_Load_Conditional.t b/gnu/usr.bin/perl/cpan/Module-Load-Conditional/t/01_Module_Load_Conditional.t index 99fa1fe72db..1bfa1a10d8f 100755 --- a/gnu/usr.bin/perl/cpan/Module-Load-Conditional/t/01_Module_Load_Conditional.t +++ b/gnu/usr.bin/perl/cpan/Module-Load-Conditional/t/01_Module_Load_Conditional.t @@ -234,6 +234,34 @@ use_ok( 'Module::Load::Conditional' ); ); } +# test for autoload + +# autoload +{ + my $use_list = { 'AutoLoad' => 0 }; + my $bool = can_load( modules => $use_list, autoload => 1 ); + ok( $bool, q[autoloaded] ); + + eval { func1(); }; + is( $@, '', q[exported function] ); + + eval { func2(); }; + ok( $@, q[not exported function] ); +} + +# not autoload +{ + my $use_list = { 'NotAutoLoad' => 0 }; + my $bool = can_load( modules => $use_list ); + ok( $bool, q[not autoloaded] ); + + eval { func3(); }; + ok( $@, q[not exported function - func3] ); + + eval { func4(); }; + ok( $@, q[not exported function - func4] ); +} + ### test 'requires' ### SKIP:{ @@ -253,8 +281,8 @@ SKIP:{ local $Module::Load::Conditional::CHECK_INC_HASH = 1; { package A::B::C::D; - $A::B::C::D::VERSION = $$; - $INC{'A/B/C/D.pm'} = $$.$$; + $A::B::C::D::VERSION = "$$"; + $INC{'A/B/C/D.pm'} = "$$"."$$"; ### XXX this is no longer needed with M::Load 0.11_01 #$INC{'[.A.B.C]D.pm'} = $$.$$ if $^O eq 'VMS'; @@ -263,8 +291,8 @@ SKIP:{ my $href = check_install( module => 'A::B::C::D', version => 0 ); ok( $href, 'Found package in %INC' ); - is( $href->{'file'}, $$.$$, ' Found correct file' ); - is( $href->{'version'}, $$, ' Found correct version' ); + is( $href->{'file'}, "$$"."$$", ' Found correct file' ); + is( $href->{'version'}, "$$", ' Found correct version' ); ok( $href->{'uptodate'}, ' Marked as uptodate' ); ok( can_load( modules => { 'A::B::C::D' => 0 } ), ' can_load successful' ); diff --git a/gnu/usr.bin/perl/cpan/Module-Load-Conditional/t/to_load/AutoLoad.pm b/gnu/usr.bin/perl/cpan/Module-Load-Conditional/t/to_load/AutoLoad.pm new file mode 100644 index 00000000000..40706f10391 --- /dev/null +++ b/gnu/usr.bin/perl/cpan/Module-Load-Conditional/t/to_load/AutoLoad.pm @@ -0,0 +1,19 @@ +package AutoLoad; + +use strict; +use warnings; + +require Exporter; + +our @ISA = qw/Exporter/; +our @EXPORT = qw/func1/; + +sub func1 { + return 1; +} + +sub func2 { + return 1; +} + +1; diff --git a/gnu/usr.bin/perl/cpan/Module-Load-Conditional/t/to_load/NotAutoLoad.pm b/gnu/usr.bin/perl/cpan/Module-Load-Conditional/t/to_load/NotAutoLoad.pm new file mode 100644 index 00000000000..34642fb483f --- /dev/null +++ b/gnu/usr.bin/perl/cpan/Module-Load-Conditional/t/to_load/NotAutoLoad.pm @@ -0,0 +1,19 @@ +package NotAutoLoad; + +use strict; +use warnings; + +require Exporter; + +our @ISA = qw/Exporter/; +our @EXPORT = qw/func3/; + +sub func3 { + return 1; +} + +sub func4 { + return 1; +} + +1; |