Alt-Module-Runtime-ButEUMM

 view release on metacpan or  search on metacpan

MANIFEST  view on Meta::CPAN

t/lib/t/Context.pm
t/lib/t/Eval.pm
t/lib/t/Hints.pm
t/lib/t/Nest0.pm
t/lib/t/Nest1.pm
t/lib/t/Simple.pm
t/mnf.t
t/pod_cvg.t
t/pod_syn.t
t/rm.t
t/taint.t
t/um.t
t/upo.t
t/upo_overridden.t

lib/Module/Runtime.pm  view on Meta::CPAN

sub use_module($;$) {
	my($name, $version) = @_;
	require_module($name);
	$name->VERSION($version) if @_ >= 2;
	return $name;
}

=item use_package_optimistically(NAME[, VERSION])

This is an analogue of L</use_module> for the situation where there is
uncertainty as to whether a package/class is defined in its own module
or by some other means.  It attempts to arrange for the named package to
be available, either by loading a module or by doing nothing and hoping.

An attempt is made to load the named module (as if by the bareword form
of C<require>).  If the module cannot be found then it is assumed that
the package was actually already loaded by other means, and no error
is signalled.  That's the optimistic bit.

I<Warning:> this optional module loading is liable to cause unreliable
behaviour, including security problems.  It interacts especially badly

t/taint.t  view on Meta::CPAN

#!perl -T
# above line is required to enable taint mode

use warnings;
use strict;

BEGIN {
	if(eval { eval("1".substr($^X,0,0)) }) {
		require Test::More;
		Test::More::plan(skip_all =>
			"tainting not supported on this Perl");
	}
}

use Test::More tests => 5;

BEGIN {
	use_ok "Module::Runtime",
		qw(require_module use_module use_package_optimistically);
}

unshift @INC, "./t/lib";
my $tainted_modname = substr($^X, 0, 0) . "t::Simple";
eval { require_module($tainted_modname) };
like $@, qr/\AInsecure dependency /;
eval { use_module($tainted_modname) };
like $@, qr/\AInsecure dependency /;
eval { use_package_optimistically($tainted_modname) };
like $@, qr/\AInsecure dependency /;
eval { require_module("Module::Runtime") };
is $@, "";

1;



( run in 0.495 second using v1.01-cache-2.11-cpan-4e96b696675 )