From: Graham Knop Date: Thu, 15 Feb 2018 14:38:00 +0000 (+0100) Subject: update Class::Inspector prereq X-Git-Tag: v1.001_001~4 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=2c7eda43a413ba523579dc118262d715596faf21;p=p5sagit%2FClass-C3-Componentised.git update Class::Inspector prereq --- diff --git a/Changes b/Changes index 76b9607..75ea306 100644 --- a/Changes +++ b/Changes @@ -12,6 +12,8 @@ Revision history for Class-C3-Componentised RT#120826 - fixed typo in documentation - fixed module abstracts + - increase Class::Inspector prereq to 1.32 to fix ensure_class_found on + modules provided by @INC hooks, such as PAR. (RT#42845) 1.001000 08 Aug 2011 - Add Class::C3::Componentised::ApplyHooks features diff --git a/Makefile.PL b/Makefile.PL index e73a9e3..cf5ec7b 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -21,7 +21,7 @@ my %META = ( 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 diff --git a/lib/Class/C3/Componentised.pm b/lib/Class/C3/Componentised.pm index 5358e28..2007b27 100644 --- a/lib/Class/C3/Componentised.pm +++ b/lib/Class/C3/Componentised.pm @@ -161,11 +161,6 @@ sub ensure_class_loaded { 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 { diff --git a/t/01-basic.t b/t/01-basic.t index f0a35b4..33d05db 100644 --- a/t/01-basic.t +++ b/t/01-basic.t @@ -8,7 +8,7 @@ use Class::Inspector; use lib "$FindBin::Bin/lib"; -plan tests => 23; +plan tests => 25; BEGIN { package TestPackage::A; @@ -62,7 +62,7 @@ like( $@, qr/Invalid class name 'ENDS::WITH::COLONS::'/, 'Throw on Class::' ); 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 { @@ -77,21 +77,21 @@ like( $@, qr/Invalid class name 'ENDS::WITH::COLONS::'/, 'Throw on Class::' ); # 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"' ); @@ -99,4 +99,13 @@ like( $@, qr/Invalid class name 'ENDS::WITH::COLONS::'/, 'Throw on Class::' ); $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"' ); }