Module-Load-Conditional-0.68/000755 001751 001751 00000000000 12746600057 016627 5ustar00bingosbingos000000 000000 Module-Load-Conditional-0.68/t/000755 001751 001751 00000000000 12746600057 017072 5ustar00bingosbingos000000 000000 Module-Load-Conditional-0.68/lib/000755 001751 001751 00000000000 12746600057 017375 5ustar00bingosbingos000000 000000 Module-Load-Conditional-0.68/MANIFEST000644 001751 001751 00000001033 12746600057 017755 0ustar00bingosbingos000000 000000 CHANGES lib/Module/Load/Conditional.pm Makefile.PL MANIFEST This list of files README t/01_Module_Load_Conditional.t t/test_lib/a/X.pm t/test_lib/b/X.pm t/to_load/AutoLoad.pm t/to_load/NotAutoLoad.pm t/to_load/Commented.pm t/to_load/InPod.pm t/to_load/LoadIt.pm t/to_load/LoadMe.pl t/to_load/MustBe/Loaded.pm t/to_load/NotMain.pm t/to_load/NotX.pm t/to_load/ToBeLoaded META.yml Module YAML meta-data (added by MakeMaker) META.json Module JSON meta-data (added by MakeMaker) Module-Load-Conditional-0.68/CHANGES000644 001751 001751 00000010643 12746577553 017644 0ustar00bingosbingos000000 000000 0.68 Fri Jul 29 08:01:12 BST 2016 * Fix unconditional @INC localisation 0.66 Wed Jul 27 08:22:53 BST 2016 * Add FORCE_SAFE_INC option to fix CVE-2016-1238 0.64 Sat Jan 17 13:33:57 GMT 2015 * Resolve an edge-case with DEPRECATED [ https://rt.cpan.org/Public/Bug/Display.html?id=101555 ] 0.62 Fri Jan 24 15:52:44 GMT 2014 * Resolve test failures on v5.16.x 0.60 Thu Jan 16 12:28:24 GMT 2014 * Added autoload option to can_load() 0.58 Sun Sep 1 11:21:59 BST 2013 * RT#83728 make quoting work portably and remove prototypes from one-liner in requires() 0.56 Thu Aug 29 21:29:22 BST 2013 * RT#83728 make requires() more robust 0.54 Sun Aug 12 09:10:13 BST 2012 * VMS test fixes from Craig Berry 0.52 Sun Jul 29 10:06:44 BST 2012 * Various enhancements, including now uses Module::Metadata (vpit) 0.50 Fri Apr 27 22:22:13 BST 2012 * Speed enhancements with thanks to Vincent Pit 0.48 Thu Mar 15 13:55:50 GMT 2012 * Wrap $^X in "" to foil paths with spaces Reported by Samuel Ferencik (via email) 0.46 Wed Sep 7 23:57:03 BST 2011 * Use || instead of "or" (perl#78708) (chorny) 0.44 Wed Feb 9 21:48:42 GMT 2011 * Apply podchecker patch from Michael Stevens RT #65601 0.42 Wed Feb 9 15:27:14 GMT 2011 * Apply patch from Phillip Moore RT #60916, which fixes an edge-case with obj/ref @INC entries. 0.40 Fri Jan 7 21:45:01 GMT 2011 * Apply blead patch from Peter Acklam 0.38 Fri Apr 23 15:52:38 BST 2010 * New release of version raises exceptions on parse errors. Use eval to guard ourselves against this. 0.36 Tue Feb 9 14:16:21 GMT 2010 * Apply patch from Pavel Shaydo RT #53546 to improve the performance of _parse_version() 0.34 Thu Oct 29 09:22:48 GMT 2009 * Remove DOS line endings from test files RT#50926 reported by Steve Hay 0.32 Fri Oct 23 21:56:11 BST 2009 * Version bump 0.31_01 Fri Oct 23 09:47:12 BST 2009 * Added DEPRECATED and support for determining if a core module is loaded from perl lib path and setting uptodate accordingly. 0.30 Mon Jan 19 16:25:55 CET 2009 * This is a test-suite fix release only. Users of 0.28 need not upgrade. * Address #42140: 01_Module_Load_Conditional.t support VMS in UNIX compatible mode. * Address #42282: test fail on MSWin32 0.28 Wed Dec 17 13:54:17 CET 2008 * Add the directory the package was found in to the return value of check_install() 0.26 Fri Feb 29 16:01:15 CET 2008 * Address #32817: $INC{'Module/Load/Conditional.pm'} isn't canonicalized under Win32. This exposed an issue in the test suite under ActivePerl for Win32, but not the code itself. Users of 0.24 do not need to upgrade. 0.24 Wed Jan 2 16:53:19 CET 2008 * Readdress #29348 to make sure version comparisons handle alpha versions (XX_YY type) gracefully. * Address #31680 to make sure $FIND_VERSION works nicely with taint mode enabled. 0.22 Mon Oct 15 10:10:21 CEST 2007 * Promote 0.21_01 to stable. Users who already have 0.20 installed do not need to upgrade. This is merely a test suit portability fix for perl 5.005 0.21_01 Fri Oct 12 10:48:06 CEST 2007 * Patch to make test-suite work with 5.005 weirdness as reported by Slaven Rezic. 0.20 Wed Oct 3 16:24:46 CEST 2007 * Update directory depth of test files to be less than 8 under perl core for old VAX and VMS compatibility. Users who have installed 0.18 do not need to upgrade. 0.18 Sat Sep 15 14:22:23 CEST 2007 * Promoted 0.17_02 to stable. 0.17_02 Fri Sep 14 11:55:52 CEST 2007 * Some more VMS fixes as suggested by John Malmberg * Address #29348: Version compare logic doesn't handle alphas? by always using qv() to compare version strings. 0.17_01 Sun Sep 9 11:55:54 CEST 2007 * Most VMS specifics can now be removed from the test suite, as we now depend on a newer version of Module::Load, which will hide this all away. 0.16 Thu Jan 25 22:24:36 CET 2007 * Address #23995: Version parsing code has been improved and now partly relies on version.pm. Previously, versions declared with qv() or ($VERSION) (note the braces) could fail to parse under certain conditions. * Add 02_Parse_Version.t to specifically test for this behaviour. 0.14 Wed Jan 3 18:27:36 CET 2007 * Skip $VERSION declarations that are part of the POD as reported in #24062 0.12 Sun Aug 13 14:55:54 CEST 2006 * Make %INC look ups work correctly under win32, where the directory seperator is not the same as the %INC path seperator Module-Load-Conditional-0.68/Makefile.PL000644 001751 001751 00000004672 12265243176 020613 0ustar00bingosbingos000000 000000 use ExtUtils::MakeMaker; use strict; WriteMakefile1( NAME => 'Module::Load::Conditional', VERSION_FROM => 'lib/Module/Load/Conditional.pm', # finds $VERSION dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz' }, BUILD_REQUIRES => { 'Test::More' => 0, }, PREREQ_PM => { 'Params::Check' => 0, 'Module::Load' => '0.28', 'Locale::Maketext::Simple' => 0, ### XXX version.pm 0.69 pure perl fails ### tests under 5.6.2. XS version is OK ### see t/02_Parse_Version.t for details 'version' => '0.69', ### We need 2.22 for is_deprecated() 'Module::CoreList' => '2.22', ### We need 1.000_005 for new_from_handle() 'Module::Metadata' => '1.000005', }, INSTALLDIRS => ( $] >= 5.009005 and $] < 5.012 ? 'perl' : 'site' ), AUTHOR => 'Jos Boumans ', ABSTRACT => 'Looking up module information / loading at runtime', LICENSE => 'perl', META_MERGE => { resources => { repository => 'https://github.com/jib/module-load-conditional', }, }, ); sub WriteMakefile1 { #Written by Alexandr Ciornii, version 0.21. Added by eumm-upgrade. my %params=@_; my $eumm_version=$ExtUtils::MakeMaker::VERSION; $eumm_version=eval $eumm_version; die "EXTRA_META is deprecated" if exists $params{EXTRA_META}; die "License not specified" if not exists $params{LICENSE}; if ($params{BUILD_REQUIRES} and $eumm_version < 6.5503) { #EUMM 6.5502 has problems with BUILD_REQUIRES $params{PREREQ_PM}={ %{$params{PREREQ_PM} || {}} , %{$params{BUILD_REQUIRES}} }; delete $params{BUILD_REQUIRES}; } delete $params{CONFIGURE_REQUIRES} if $eumm_version < 6.52; delete $params{MIN_PERL_VERSION} if $eumm_version < 6.48; delete $params{META_MERGE} if $eumm_version < 6.46; delete $params{META_ADD} if $eumm_version < 6.46; delete $params{LICENSE} if $eumm_version < 6.31; delete $params{AUTHOR} if $] < 5.005; delete $params{ABSTRACT_FROM} if $] < 5.005; delete $params{BINARY_LOCATION} if $] < 5.005; WriteMakefile(%params); } Module-Load-Conditional-0.68/README000644 001751 001751 00000002274 12143731332 017504 0ustar00bingosbingos000000 000000 This is the README file for Module::Load::Conditional -- a way to conditionally load and query modules. Please type "perldoc Module::Load::Conditional" after installation to see the module usage information. ##################################################################### * Description Module::Load::Conditional Allows you to query the state of modules on your system. It can tell you if you have certain modules installed without attempting to C them and can do smart loading of modules. Also it can tell you what *other* modules a certain module requires. ##################################################################### * Installation Module::Load::Conditional uses the standard perl module install process: perl Makefile.PL make make test make install The module uses no C or XS parts, so no c-compiler is required. ###################################################################### AUTHOR This module by Jos Boumans . COPYRIGHT This module is copyright (c) 2002 Jos Boumans . All rights reserved. This library is free software; you may redistribute and/or modify it under the same terms as Perl itself. Module-Load-Conditional-0.68/META.yml000644 001751 001751 00000001420 12746600057 020075 0ustar00bingosbingos000000 000000 --- abstract: 'Looking up module information / loading at runtime' author: - 'Jos Boumans ' build_requires: Test::More: '0' configure_requires: ExtUtils::MakeMaker: '0' dynamic_config: 1 generated_by: 'ExtUtils::MakeMaker version 7.18, CPAN::Meta::Converter version 2.150005' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: Module-Load-Conditional no_index: directory: - t - inc requires: Locale::Maketext::Simple: '0' Module::CoreList: '2.22' Module::Load: '0.28' Module::Metadata: '1.000005' Params::Check: '0' version: '0.69' resources: repository: https://github.com/jib/module-load-conditional version: '0.68' x_serialization_backend: 'CPAN::Meta::YAML version 0.018' Module-Load-Conditional-0.68/META.json000644 001751 001751 00000002403 12746600057 020247 0ustar00bingosbingos000000 000000 { "abstract" : "Looking up module information / loading at runtime", "author" : [ "Jos Boumans " ], "dynamic_config" : 1, "generated_by" : "ExtUtils::MakeMaker version 7.18, CPAN::Meta::Converter version 2.150005", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "Module-Load-Conditional", "no_index" : { "directory" : [ "t", "inc" ] }, "prereqs" : { "build" : { "requires" : { "Test::More" : "0" } }, "configure" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "runtime" : { "requires" : { "Locale::Maketext::Simple" : "0", "Module::CoreList" : "2.22", "Module::Load" : "0.28", "Module::Metadata" : "1.000005", "Params::Check" : "0", "version" : "0.69" } } }, "release_status" : "stable", "resources" : { "repository" : { "url" : "https://github.com/jib/module-load-conditional" } }, "version" : "0.68", "x_serialization_backend" : "JSON::PP version 2.27400" } Module-Load-Conditional-0.68/lib/Module/000755 001751 001751 00000000000 12746600057 020622 5ustar00bingosbingos000000 000000 Module-Load-Conditional-0.68/lib/Module/Load/000755 001751 001751 00000000000 12746600057 021501 5ustar00bingosbingos000000 000000 Module-Load-Conditional-0.68/lib/Module/Load/Conditional.pm000644 001751 001751 00000045331 12746577454 024326 0ustar00bingosbingos000000 000000 package Module::Load::Conditional; use strict; use Module::Load qw/load autoload_remote/; use Params::Check qw[check]; use Locale::Maketext::Simple Style => 'gettext'; use Carp (); use File::Spec (); use FileHandle (); use version; use Module::Metadata (); 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 $FORCE_SAFE_INC ]; use Exporter; @ISA = qw[Exporter]; $VERSION = '0.68'; $VERBOSE = 0; $DEPRECATED = 0; $FIND_VERSION = 1; $CHECK_INC_HASH = 0; $FORCE_SAFE_INC = 0; @EXPORT_OK = qw[check_install can_load requires]; } =pod =head1 NAME Module::Load::Conditional - Looking up module information / loading at runtime =head1 SYNOPSIS use Module::Load::Conditional qw[can_load check_install requires]; my $use_list = { CPANPLUS => 0.05, LWP => 5.60, 'Test::More' => undef, }; print can_load( modules => $use_list ) ? 'all modules loaded successfully' : 'failed to load required modules'; my $rv = check_install( module => 'LWP', version => 5.60 ) or print 'LWP is not installed!'; print 'LWP up to date' if $rv->{uptodate}; print "LWP version is $rv->{version}\n"; print "LWP is installed as file $rv->{file}\n"; print "LWP requires the following modules to be installed:\n"; print join "\n", requires('LWP'); ### allow M::L::C to peek in your %INC rather than just ### scanning @INC $Module::Load::Conditional::CHECK_INC_HASH = 1; ### reset the 'can_load' cache undef $Module::Load::Conditional::CACHE; ### don't have Module::Load::Conditional issue warnings -- ### default is '1' $Module::Load::Conditional::VERBOSE = 0; ### The last error that happened during a call to 'can_load' my $err = $Module::Load::Conditional::ERROR; =head1 DESCRIPTION Module::Load::Conditional provides simple ways to query and possibly load any of the modules you have installed on your system during runtime. It is able to load multiple modules at once or none at all if one of them was not able to load. It also takes care of any error checking and so forth. =head1 Methods =head2 $href = check_install( module => NAME [, version => VERSION, verbose => BOOL ] ); C allows you to verify if a certain module is installed or not. You may call it with the following arguments: =over 4 =item module The name of the module you wish to verify -- this is a required key =item version The version this module needs to be -- this is optional =item verbose Whether or not to be verbose about what it is doing -- it will default to $Module::Load::Conditional::VERBOSE =back It will return undef if it was not able to find where the module was installed, or a hash reference with the following keys if it was able to find the file: =over 4 =item file Full path to the file that contains the module =item dir Directory, or more exact the C<@INC> entry, where the module was loaded from. =item version The version number of the installed module - this will be C if the module had no (or unparsable) version number, or if the variable C<$Module::Load::Conditional::FIND_VERSION> was set to true. (See the C section below for details) =item uptodate A boolean value indicating whether or not the module was found to be at least the version you specified. If you did not specify a version, uptodate will always be true if the module was found. If no parsable version was found in the module, uptodate will also be true, since C had no way to verify clearly. See also C<$Module::Load::Conditional::DEPRECATED>, which affects the outcome of this value. =back =cut ### this checks if a certain module is installed already ### ### if it returns true, the module in question is already installed ### or we found the file, but couldn't open it, OR there was no version ### to be found in the module ### it will return 0 if the version in the module is LOWER then the one ### we are looking for, or if we couldn't find the desired module to begin with ### if the installed version is higher or equal to the one we want, it will return ### a hashref with he module name and version in it.. so 'true' as well. sub check_install { my %hash = @_; my $tmpl = { version => { default => '0.0' }, module => { required => 1 }, verbose => { default => $VERBOSE }, }; my $args; unless( $args = check( $tmpl, \%hash, $VERBOSE ) ) { warn loc( q[A problem occurred checking arguments] ) if $VERBOSE; return; } my $file = File::Spec->catfile( split /::/, $args->{module} ) . '.pm'; my $file_inc = File::Spec::Unix->catfile( split /::/, $args->{module} ) . '.pm'; ### where we store the return value ### my $href = { file => undef, version => undef, uptodate => undef, }; my $filename; ### check the inc hash if we're allowed to if( $CHECK_INC_HASH ) { $filename = $href->{'file'} = $INC{ $file_inc } if defined $INC{ $file_inc }; ### find the version by inspecting the package if( defined $filename && $FIND_VERSION ) { no strict 'refs'; $href->{version} = ${ "$args->{module}"."::VERSION" }; } } ### we didn't find the filename yet by looking in %INC, ### so scan the dirs unless( $filename ) { local @INC = @INC[0..$#INC-1] if $FORCE_SAFE_INC && $INC[-1] eq '.'; DIR: for my $dir ( @INC ) { my $fh; if ( ref $dir ) { ### @INC hook -- we invoke it and get the filehandle back ### this is actually documented behaviour as of 5.8 ;) my $existed_in_inc = $INC{$file_inc}; if (UNIVERSAL::isa($dir, 'CODE')) { ($fh) = $dir->($dir, $file); } elsif (UNIVERSAL::isa($dir, 'ARRAY')) { ($fh) = $dir->[0]->($dir, $file, @{$dir}{1..$#{$dir}}) } elsif (UNIVERSAL::can($dir, 'INC')) { ($fh) = $dir->INC($file); } if (!UNIVERSAL::isa($fh, 'GLOB')) { warn loc(q[Cannot open file '%1': %2], $file, $!) if $args->{verbose}; next; } $filename = $INC{$file_inc} || $file; delete $INC{$file_inc} if not $existed_in_inc; } else { $filename = File::Spec->catfile($dir, $file); next unless -e $filename; $fh = new FileHandle; if (!$fh->open($filename)) { warn loc(q[Cannot open file '%1': %2], $file, $!) if $args->{verbose}; next; } } ### store the directory we found the file in $href->{dir} = $dir; ### files need to be in unix format under vms, ### or they might be loaded twice $href->{file} = ON_VMS ? VMS::Filespec::unixify( $filename ) : $filename; ### if we don't need the version, we're done last DIR unless $FIND_VERSION; ### otherwise, the user wants us to find the version from files my $mod_info = Module::Metadata->new_from_handle( $fh, $filename ); my $ver = $mod_info->version( $args->{module} ); if( defined $ver ) { $href->{version} = $ver; last DIR; } } } ### if we couldn't find the file, return undef ### return unless defined $href->{file}; ### only complain if we're expected to find a version higher than 0.0 anyway if( $FIND_VERSION and not defined $href->{version} ) { { ### don't warn about the 'not numeric' stuff ### local $^W; ### if we got here, we didn't find the version warn loc(q[Could not check version on '%1'], $args->{module} ) if $args->{verbose} and $args->{version} > 0; } $href->{uptodate} = 1; } else { ### don't warn about the 'not numeric' stuff ### local $^W; ### use qv(), as it will deal with developer release number ### ie ones containing _ as well. This addresses bug report ### #29348: Version compare logic doesn't handle alphas? ### ### Update from JPeacock: apparently qv() and version->new ### are different things, and we *must* use version->new ### here, or things like #30056 might start happening ### We have to wrap this in an eval as version-0.82 raises ### exceptions and not warnings now *sigh* eval { $href->{uptodate} = version->new( $args->{version} ) <= version->new( $href->{version} ) ? 1 : 0; }; } if ( $DEPRECATED and "$]" >= 5.011 ) { local @INC = @INC[0..$#INC-1] if $FORCE_SAFE_INC && $INC[-1] eq '.'; require Module::CoreList; require Config; $href->{uptodate} = 0 if exists $Module::CoreList::version{ 0+$] }{ $args->{module} } and Module::CoreList::is_deprecated( $args->{module} ) and $Config::Config{privlibexp} eq $href->{dir} and $Config::Config{privlibexp} ne $Config::Config{sitelibexp}; } return $href; } =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* of them, it will. If one or more are unloadable, none will be loaded. 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 or the C function from Module::Load under the hood. C takes the following arguments: =over 4 =item modules This is a hashref of module/version pairs. The version indicates the minimum version to load. If no version is provided, any version is assumed to be good enough. =item verbose This controls whether warnings should be printed if a module failed to load. The default is to use the value of $Module::Load::Conditional::VERBOSE. =item nocache C keeps its results in a cache, so it will not load the 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 { my %hash = @_; my $tmpl = { modules => { default => {}, strict_type => 1 }, verbose => { default => $VERBOSE }, nocache => { default => 0 }, autoload => { default => 0 }, }; my $args; unless( $args = check( $tmpl, \%hash, $VERBOSE ) ) { $ERROR = loc(q[Problem validating arguments!]); warn $ERROR if $VERBOSE; return; } ### layout of $CACHE: ### $CACHE = { ### $ module => { ### usable => BOOL, ### version => \d, ### file => /path/to/file, ### }, ### }; $CACHE ||= {}; # in case it was undef'd my $error; BLOCK: { my $href = $args->{modules}; my @load; for my $mod ( keys %$href ) { next if $CACHE->{$mod}->{usable} && !$args->{nocache}; ### else, check if the hash key is defined already, ### meaning $mod => 0, ### indicating UNSUCCESSFUL prior attempt of usage ### use qv(), as it will deal with developer release number ### ie ones containing _ as well. This addresses bug report ### #29348: Version compare logic doesn't handle alphas? ### ### Update from JPeacock: apparently qv() and version->new ### are different things, and we *must* use version->new ### here, or things like #30056 might start happening if ( !$args->{nocache} && defined $CACHE->{$mod}->{usable} && (version->new( $CACHE->{$mod}->{version}||0 ) >= version->new( $href->{$mod} ) ) ) { $error = loc( q[Already tried to use '%1', which was unsuccessful], $mod); last BLOCK; } my $mod_data = check_install( module => $mod, version => $href->{$mod} ); if( !$mod_data or !defined $mod_data->{file} ) { $error = loc(q[Could not find or check module '%1'], $mod); $CACHE->{$mod}->{usable} = 0; last BLOCK; } map { $CACHE->{$mod}->{$_} = $mod_data->{$_} } qw[version file uptodate]; push @load, $mod; } for my $mod ( @load ) { if ( $CACHE->{$mod}->{uptodate} ) { local @INC = @INC[0..$#INC-1] if $FORCE_SAFE_INC && $INC[-1] eq '.'; 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; if( $@ ) { $error = $@; $CACHE->{$mod}->{usable} = 0; last BLOCK; } else { $CACHE->{$mod}->{usable} = 1; } ### module not found in @INC, store the result in ### $CACHE and return 0 } else { $error = loc(q[Module '%1' is not uptodate!], $mod); $CACHE->{$mod}->{usable} = 0; last BLOCK; } } } # BLOCK if( defined $error ) { $ERROR = $error; Carp::carp( loc(q|%1 [THIS MAY BE A PROBLEM!]|,$error) ) if $args->{verbose}; return; } else { return 1; } } =back =head2 @list = requires( MODULE ); C can tell you what other modules a particular module requires. This is particularly useful when you're intending to write a module for public release and are listing its prerequisites. C takes but one argument: the name of a module. It will then first check if it can actually load this module, and return undef if it can't. Otherwise, it will return a list of modules and pragmas that would have been loaded on the module's behalf. Note: The list C returns has originated from your current perl and your current install. =cut sub requires { my $who = shift; unless( check_install( module => $who ) ) { warn loc(q[You do not have module '%1' installed], $who) if $VERBOSE; return undef; } local @INC = @INC[0..$#INC-1] if $FORCE_SAFE_INC && $INC[-1] eq '.'; my $lib = join " ", map { qq["-I$_"] } @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`; } 1; __END__ =head1 Global Variables The behaviour of Module::Load::Conditional can be altered by changing the following global variables: =head2 $Module::Load::Conditional::VERBOSE This controls whether Module::Load::Conditional will issue warnings and explanations as to why certain things may have failed. If you set it to 0, Module::Load::Conditional will not output any warnings. The default is 0; =head2 $Module::Load::Conditional::FIND_VERSION This controls whether Module::Load::Conditional will try to parse (and eval) the version from the module you're trying to load. If you don't wish to do this, set this variable to C. Understand then that version comparisons are not possible, and Module::Load::Conditional can not tell you what module version you have installed. This may be desirable from a security or performance point of view. Note that C<$FIND_VERSION> code runs safely under C. The default is 1; =head2 $Module::Load::Conditional::CHECK_INC_HASH This controls whether C checks your C<%INC> hash to see if a module is available. By default, only C<@INC> is scanned to see if a module is physically on your filesystem, or available via an C<@INC-hook>. Setting this variable to C will trust any entries in C<%INC> and return them for you. The default is 0; =head2 $Module::Load::Conditional::FORCE_SAFE_INC This controls whether C sanitises C<@INC> by removing "C<.>". The current default setting is C<0>, but this may change in a future release. =head2 $Module::Load::Conditional::CACHE This holds the cache of the C function. If you explicitly want to remove the current cache, you can set this variable to C =head2 $Module::Load::Conditional::ERROR This holds a string of the last error that happened during a call to C. It is useful to inspect this when C returns C. =head2 $Module::Load::Conditional::DEPRECATED This controls whether C checks if a dual-life core module has been deprecated. If this is set to true C will return false to C, if a dual-life module is found to be loaded from C<$Config{privlibexp}> The default is 0; =head1 See Also C =head1 BUG REPORTS Please report bugs or other issues to Ebug-module-load-conditional@rt.cpan.orgE. =head1 AUTHOR This module by Jos Boumans Ekane@cpan.orgE. =head1 COPYRIGHT This library is free software; you may redistribute and/or modify it under the same terms as Perl itself. =cut Module-Load-Conditional-0.68/t/to_load/000755 001751 001751 00000000000 12746600057 020513 5ustar00bingosbingos000000 000000 Module-Load-Conditional-0.68/t/test_lib/000755 001751 001751 00000000000 12746600057 020677 5ustar00bingosbingos000000 000000 Module-Load-Conditional-0.68/t/01_Module_Load_Conditional.t000644 001751 001751 00000021273 12270505603 024264 0ustar00bingosbingos000000 000000 ### Module::Load::Conditional test suite ### ### this should no longer be needed # BEGIN { # if( $ENV{PERL_CORE} ) { # chdir '../lib/Module/Load/Conditional' # if -d '../lib/Module/Load/Conditional'; # unshift @INC, '../../../..'; # # ### fix perl location too # $^X = '../../../../../t/' . $^X; # } # } BEGIN { use FindBin; } BEGIN { chdir 't' if -d 't' } use strict; use File::Spec (); use Test::More 'no_plan'; use constant ON_VMS => $^O eq 'VMS'; use lib File::Spec->catdir($FindBin::Bin, qw[.. lib] ); use lib File::Spec->catdir($FindBin::Bin, q[to_load] ); use_ok( 'Module::Load::Conditional' ); ### stupid stupid warnings ### { $Module::Load::Conditional::VERBOSE = $Module::Load::Conditional::VERBOSE = 0; *can_load = *Module::Load::Conditional::can_load = *Module::Load::Conditional::can_load; *check_install = *Module::Load::Conditional::check_install = *Module::Load::Conditional::check_install; *requires = *Module::Load::Conditional::requires = *Module::Load::Conditional::requires; } { my $rv = check_install( module => 'Module::Load::Conditional', version => $Module::Load::Conditional::VERSION, ); ok( $rv->{uptodate}, q[Verify self] ); is( $rv->{version}, $Module::Load::Conditional::VERSION, q[ Found proper version] ); ok( $rv->{dir}, q[ Found directory information] ); { my $dir = File::Spec->canonpath( $rv->{dir} ); ### special rules apply on VMS, as always... if (ON_VMS) { ### Need path syntax for VMS compares. $dir = VMS::Filespec::pathify($dir); ### Remove the trailing VMS specific directory delimiter $dir =~ s/\]//; } ### quote for Win32 paths, use | to avoid slash confusion my $dir_re = qr|^\Q$dir\E|i; like( File::Spec->canonpath( $rv->{file} ), $dir_re, q[ Dir subset of file path] ); } ### break up the specification my @rv_path = do { ### Use the UNIX specific method, as the VMS one currently ### converts the file spec back to VMS format. my $class = ON_VMS ? 'File::Spec::Unix' : 'File::Spec'; my($vol, $path, $file) = $class->splitpath( $rv->{'file'} ); my @path = ($vol, $class->splitdir( $path ), $file ); ### First element could be blank for some system types like VMS shift @path if $vol eq ''; ### and return it @path; }; my $inc_path = $INC{'Module/Load/Conditional.pm'}; if ( $^O eq 'MSWin32' ) { $inc_path = File::Spec->canonpath( $inc_path ); $inc_path =~ s{\\}{/}g; # to meet with unix path } is( $inc_path, File::Spec::Unix->catfile(@rv_path), q[ Found proper file] ); } ### the version may contain an _, which means perl will warn about 'not ### numeric' -- turn off that warning here. { local $^W; my $rv = check_install( module => 'Module::Load::Conditional', version => $Module::Load::Conditional::VERSION + 1, ); ok( !$rv->{uptodate} && $rv->{version} && $rv->{file}, q[Verify out of date module] ); } { my $rv = check_install( module => 'Module::Load::Conditional' ); ok( $rv->{uptodate} && $rv->{version} && $rv->{file}, q[Verify any module] ); } { my $rv = check_install( module => 'Module::Does::Not::Exist' ); ok( !$rv->{uptodate} && !$rv->{version} && !$rv->{file}, q[Verify non-existent module] ); } ### test finding a version of a module that mentions $VERSION in pod { my $rv = check_install( module => 'InPod' ); ok( $rv, 'Testing $VERSION in POD' ); ok( $rv->{version}, " Version found" ); is( $rv->{version}, 2, " Version is correct" ); } ### test that no package statement means $VERSION is $main::VERSION { my $rv = check_install( module => 'NotMain' ); ok( $rv, 'Testing $VERSION without package' ); is( $rv->{version}, undef, " No version info returned" ); } ### test that the right $VERSION is picked when there are several packages { my $rv = check_install( module => 'NotX' ); ok( $rv, 'Testing $VERSION with many packages' ); ok( $rv->{version}, " Version found" ); is( $rv->{version}, 3, " Version is correct" ); } ### test beta/developer release versions { my $test_ver = $Module::Load::Conditional::VERSION; ### strip beta tags $test_ver =~ s/_\d+//g; $test_ver .= '_99'; my $rv = check_install( module => 'Module::Load::Conditional', version => $test_ver, ); ok( $rv, "Checking beta versions" ); ok( !$rv->{'uptodate'}, " Beta version is higher" ); } ### test $FIND_VERSION { local $Module::Load::Conditional::FIND_VERSION = 0; my $rv = check_install( module => 'Module::Load::Conditional' ); ok( $rv, 'Testing $FIND_VERSION' ); is( $rv->{version}, undef, " No version info returned" ); ok( $rv->{uptodate}, " Module marked as uptodate" ); } ### test that check_install() picks up the first match { my ($dir_a, $dir_b) = map File::Spec->catdir($FindBin::Bin, 'test_lib', $_), qw[a b]; my $x_pm = File::Spec->catfile($dir_a, 'X.pm'); $x_pm = VMS::Filespec::unixify($x_pm) if ON_VMS; local @INC = ($dir_a, $dir_b); my $rv = check_install( module => 'X' ); ok( $rv, 'Testing the file picked by check_install ($FIND_VERSION == 1)' ); is( $rv->{file}, $x_pm, " First file was picked" ); is( $rv->{version}, '0.01', " Correct version for first file" ); local $Module::Load::Conditional::FIND_VERSION = 0; $rv = check_install( module => 'X' ); ok( $rv, 'Testing the file picked by check_install ($FIND_VERSION == 0)' ); is( $rv->{file}, $x_pm, " First file was also picked" ); is( $rv->{version}, undef, " But its VERSION was not required" ); } ### test 'can_load' ### { my $use_list = { 'LoadIt' => 1 }; my $bool = can_load( modules => $use_list ); ok( $bool, q[Load simple module] ); } { my $use_list = { 'Commented' => 2 }; my $bool = can_load( modules => $use_list ); ok( $bool, q[Load module with a second, commented-out $VERSION] ); } { my $use_list = { 'MustBe::Loaded' => 1 }; my $bool = can_load( modules => $use_list ); ok( !$bool, q[Detect out of date module] ); } { delete $INC{'LoadIt.pm'}; delete $INC{'MustBe/Loaded.pm'}; my $use_list = { 'LoadIt' => 1, 'MustBe::Loaded' => 1 }; my $bool = can_load( modules => $use_list ); ok( !$INC{'LoadIt.pm'} && !$INC{'MustBe/Loaded.pm'}, q[Do not load if one prerequisite fails] ); } # 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:{ skip "Depends on \$^X, which doesn't work well when testing the Perl core", 1 if $ENV{PERL_CORE}; my %list = map { $_ => 1 } requires('Carp'); my $flag; $flag++ unless delete $list{'Exporter'}; ok( !$flag, q[Detecting requirements] ); } ### test using the %INC lookup for check_install { local $Module::Load::Conditional::CHECK_INC_HASH = 1; local $Module::Load::Conditional::CHECK_INC_HASH = 1; { package A::B::C::D; $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'; } 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' ); ok( $href->{'uptodate'}, ' Marked as uptodate' ); ok( can_load( modules => { 'A::B::C::D' => 0 } ), ' can_load successful' ); } Module-Load-Conditional-0.68/t/test_lib/b/000755 001751 001751 00000000000 12746600057 021120 5ustar00bingosbingos000000 000000 Module-Load-Conditional-0.68/t/test_lib/a/000755 001751 001751 00000000000 12746600057 021117 5ustar00bingosbingos000000 000000 Module-Load-Conditional-0.68/t/test_lib/a/X.pm000644 001751 001751 00000000047 12143731332 021655 0ustar00bingosbingos000000 000000 package X; our $VERSION = '0.01'; 1; Module-Load-Conditional-0.68/t/test_lib/b/X.pm000644 001751 001751 00000000047 12143731332 021656 0ustar00bingosbingos000000 000000 package X; our $VERSION = '0.02'; 1; Module-Load-Conditional-0.68/t/to_load/NotAutoLoad.pm000644 001751 001751 00000000264 12265243176 023245 0ustar00bingosbingos000000 000000 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; Module-Load-Conditional-0.68/t/to_load/AutoLoad.pm000644 001751 001751 00000000261 12265243176 022561 0ustar00bingosbingos000000 000000 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; Module-Load-Conditional-0.68/t/to_load/Commented.pm000644 001751 001751 00000000066 12143731332 022756 0ustar00bingosbingos000000 000000 package Commented; # $VERSION = 1; $VERSION = 2; 1; Module-Load-Conditional-0.68/t/to_load/NotX.pm000644 001751 001751 00000000146 12143731332 021732 0ustar00bingosbingos000000 000000 $VERSION = 1; package Y; $VERSION = 2; package NotX; $VERSION = 3; package X; $VERSION = 4; 1; Module-Load-Conditional-0.68/t/to_load/LoadMe.pl000644 001751 001751 00000000002 12143731332 022171 0ustar00bingosbingos000000 000000 1;Module-Load-Conditional-0.68/t/to_load/LoadIt.pm000644 001751 001751 00000000043 12143731332 022212 0ustar00bingosbingos000000 000000 package LoadIt; $VERSION = 1; 1; Module-Load-Conditional-0.68/t/to_load/NotMain.pm000644 001751 001751 00000000025 12143731332 022403 0ustar00bingosbingos000000 000000 $VERSION = 1.23; 1; Module-Load-Conditional-0.68/t/to_load/MustBe/000755 001751 001751 00000000000 12746600057 021712 5ustar00bingosbingos000000 000000 Module-Load-Conditional-0.68/t/to_load/InPod.pm000644 001751 001751 00000000075 12143731332 022054 0ustar00bingosbingos000000 000000 =pod $VERSION = 1; =cut package InPod; $VERSION = 2; 1; Module-Load-Conditional-0.68/t/to_load/ToBeLoaded000644 001751 001751 00000000002 12143731332 022360 0ustar00bingosbingos000000 000000 1;Module-Load-Conditional-0.68/t/to_load/MustBe/Loaded.pm000644 001751 001751 00000000056 12143731332 023431 0ustar00bingosbingos000000 000000 package MustBe::Loaded; $VERSION = 0.01; 1;