From 0ec58bfa3d152b9e214f52a7f2ca0aa9d7a09d6e Mon Sep 17 00:00:00 2001 From: Chris 'BinGOs' Williams Date: Thu, 16 Jan 2014 20:06:49 +0000 Subject: [PATCH] Update Module-Load-Conditional to CPAN version 0.60 [DELTA] 0.60 Thu Jan 16 12:28:24 GMT 2014 * Added autoload option to can_load() --- MANIFEST | 2 ++ Porting/Maintainers.pl | 2 +- .../lib/Module/Load/Conditional.pm | 24 ++++++++++++++----- .../t/01_Module_Load_Conditional.t | 28 ++++++++++++++++++++++ cpan/Module-Load-Conditional/t/to_load/AutoLoad.pm | 19 +++++++++++++++ .../t/to_load/NotAutoLoad.pm | 19 +++++++++++++++ 6 files changed, 87 insertions(+), 7 deletions(-) create mode 100644 cpan/Module-Load-Conditional/t/to_load/AutoLoad.pm create mode 100644 cpan/Module-Load-Conditional/t/to_load/NotAutoLoad.pm diff --git a/MANIFEST b/MANIFEST index 055beb9..a80c164 100644 --- a/MANIFEST +++ b/MANIFEST @@ -1608,11 +1608,13 @@ cpan/Module-Load-Conditional/lib/Module/Load/Conditional.pm Module::Conditional cpan/Module-Load-Conditional/t/01_Module_Load_Conditional.t Module::Conditional tests cpan/Module-Load-Conditional/t/test_lib/a/X.pm Module::Conditional tests cpan/Module-Load-Conditional/t/test_lib/b/X.pm Module::Conditional tests +cpan/Module-Load-Conditional/t/to_load/AutoLoad.pm Module::Conditional tests cpan/Module-Load-Conditional/t/to_load/Commented.pm Module::Conditional tests cpan/Module-Load-Conditional/t/to_load/InPod.pm Module::Load::Conditional tests cpan/Module-Load-Conditional/t/to_load/LoadIt.pm Module::Conditional tests cpan/Module-Load-Conditional/t/to_load/LoadMe.pl Module::Conditional tests cpan/Module-Load-Conditional/t/to_load/MustBe/Loaded.pm Module::Load::Conditional tests +cpan/Module-Load-Conditional/t/to_load/NotAutoLoad.pm Module::Conditional tests cpan/Module-Load-Conditional/t/to_load/NotMain.pm Module::Conditional tests cpan/Module-Load-Conditional/t/to_load/NotX.pm Module::Conditional tests cpan/Module-Load-Conditional/t/to_load/ToBeLoaded Module::Conditional tests diff --git a/Porting/Maintainers.pl b/Porting/Maintainers.pl index 8acfb0e..65e49e5 100755 --- a/Porting/Maintainers.pl +++ b/Porting/Maintainers.pl @@ -814,7 +814,7 @@ use File::Glob qw(:case); }, 'Module::Load::Conditional' => { - 'DISTRIBUTION' => 'BINGOS/Module-Load-Conditional-0.58.tar.gz', + 'DISTRIBUTION' => 'BINGOS/Module-Load-Conditional-0.60.tar.gz', 'FILES' => q[cpan/Module-Load-Conditional], }, diff --git a/cpan/Module-Load-Conditional/lib/Module/Load/Conditional.pm b/cpan/Module-Load-Conditional/lib/Module/Load/Conditional.pm index c890df0..6e60998 100644 --- a/cpan/Module-Load-Conditional/lib/Module/Load/Conditional.pm +++ b/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'; @@ -22,7 +22,7 @@ BEGIN { $FIND_VERSION $ERROR $CHECK_INC_HASH]; use Exporter; @ISA = qw[Exporter]; - $VERSION = '0.58'; + $VERSION = '0.60'; $VERBOSE = 0; $DEPRECATED = 0; $FIND_VERSION = 1; @@ -319,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 will take a list of modules, optionally with version numbers and determine if it is able to load them. If it can load *ALL* @@ -329,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 function from Module::Load under the -hood. +This function uses the C function or the C function +from Module::Load under the hood. C takes the following arguments: @@ -355,6 +355,12 @@ same module twice, nor will it attempt to load a module that has already failed to load before. By default, C will check its cache, but you can override that by setting C 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 function and the C function from L for details. + =cut sub can_load { @@ -364,6 +370,7 @@ sub can_load { modules => { default => {}, strict_type => 1 }, verbose => { default => $VERBOSE }, nocache => { default => 0 }, + autoload => { default => 0 }, }; my $args; @@ -436,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; diff --git a/cpan/Module-Load-Conditional/t/01_Module_Load_Conditional.t b/cpan/Module-Load-Conditional/t/01_Module_Load_Conditional.t index 99fa1fe..1b8728f 100644 --- a/cpan/Module-Load-Conditional/t/01_Module_Load_Conditional.t +++ b/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:{ diff --git a/cpan/Module-Load-Conditional/t/to_load/AutoLoad.pm b/cpan/Module-Load-Conditional/t/to_load/AutoLoad.pm new file mode 100644 index 0000000..40706f1 --- /dev/null +++ b/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/cpan/Module-Load-Conditional/t/to_load/NotAutoLoad.pm b/cpan/Module-Load-Conditional/t/to_load/NotAutoLoad.pm new file mode 100644 index 0000000..34642fb --- /dev/null +++ b/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; -- 2.7.4