CPANPLUS
view release on metacpan or search on metacpan
inc/bundle/Module/Load/Conditional.pm view on Meta::CPAN
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<requires> 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<requires> 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<require> 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.
( run in 2.850 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )