requires => {
'perl' => '5.006002',
'MRO::Compat' => '0.09',
- 'Class::Inspector' => '1.23',
+ 'Class::Inspector' => '1.32',
# we don't actually need Class::C3. MRO::Compat loads it on 5.8. On 5.10
# it isn't needed. However, some existing code relies on us loading
# Class::C3. We don't want to break it just yet. Therefore we depend
Returns true if the specified class is installed or already loaded, false
otherwise.
-Note that the underlying mechanism (Class::Inspector->installed()) used by this
-sub will not, at the time of writing, correctly function when @INC includes
-coderefs. Since PAR relies upon coderefs in @INC, this function should be
-avoided in modules that are likely to be included within a PAR.
-
=cut
sub ensure_class_found {
use lib "$FindBin::Bin/lib";
-plan tests => 23;
+plan tests => 25;
BEGIN {
package TestPackage::A;
my @code;
local @INC = @INC;
unshift @INC, sub {
- if ($_[1] eq 'VIRTUAL/PAR/PACKAGE.pm') {
+ if ($_[1] =~ m{^VIRTUAL/PAR/PACKAGE[0-9]*\.pm$}) {
return (sub { return 0 unless @code; $_ = shift @code; 1; } );
}
else {
# simulate a class which does load but does not return true
@code = (
- q/package VIRTUAL::PAR::PACKAGE;/,
+ q/package VIRTUAL::PAR::PACKAGE1;/,
q/0;/,
);
- $retval = eval { MyModule->load_optional_class('VIRTUAL::PAR::PACKAGE') };
+ $retval = eval { MyModule->load_optional_class('VIRTUAL::PAR::PACKAGE1') };
ok( $@, 'load_optional_class of a no-true-returning PAR module did throw' );
ok( !$retval, 'no-true-returning PAR package not loaded' );
- # simulate a normal class (no one adjusted %INC so it will be tried again
+ # simulate a normal class
@code = (
- q/package VIRTUAL::PAR::PACKAGE;/,
+ q/package VIRTUAL::PAR::PACKAGE2;/,
q/1;/,
);
- $retval = eval { MyModule->load_optional_class('VIRTUAL::PAR::PACKAGE') };
+ $retval = eval { MyModule->load_optional_class('VIRTUAL::PAR::PACKAGE2') };
ok( !$@, 'load_optional_class of a PAR module did not throw' );
ok( $retval, 'PAR package "loaded"' );
$retval = eval { MyModule->load_optional_class('AnotherModule') };
ok( !$@, 'load_optional_class did not throw' ) || diag $@;
ok( $retval, 'AnotherModule loaded' );
+
+ @code = (
+ q/package VIRTUAL::PAR::PACKAGE3;/,
+ q/1;/,
+ );
+
+ $retval = eval { MyModule->ensure_class_found('VIRTUAL::PAR::PACKAGE3') };
+ ok( !$@, 'ensure_class_found of a PAR module did not throw' );
+ ok( $retval, 'PAR package "found"' );
}