[Bast-commits] r9834 - in Class-C3-Componentised/trunk: .
lib/Class/C3 t
ribasushi at dev.catalyst.perl.org
ribasushi at dev.catalyst.perl.org
Wed Feb 23 13:39:03 GMT 2011
Author: ribasushi
Date: 2011-02-23 13:39:03 +0000 (Wed, 23 Feb 2011)
New Revision: 9834
Modified:
Class-C3-Componentised/trunk/Changes
Class-C3-Componentised/trunk/lib/Class/C3/Componentised.pm
Class-C3-Componentised/trunk/t/01-basic.t
Log:
Fix load_optional_class inspired by RT#56565
Modified: Class-C3-Componentised/trunk/Changes
===================================================================
--- Class-C3-Componentised/trunk/Changes 2011-02-23 00:01:00 UTC (rev 9833)
+++ Class-C3-Componentised/trunk/Changes 2011-02-23 13:39:03 UTC (rev 9834)
@@ -1,5 +1,8 @@
Revision history for Class-C3-Componentised
+ Throw a readable exception when load_optional_class is given an
+ invalid class name
+
1.0006 08 Sep 2009
Allow derived classes without component_base_class(), given all
arguments to load_components are absolute class names (+Classname)
Modified: Class-C3-Componentised/trunk/lib/Class/C3/Componentised.pm
===================================================================
--- Class-C3-Componentised/trunk/lib/Class/C3/Componentised.pm 2011-02-23 00:01:00 UTC (rev 9833)
+++ Class-C3-Componentised/trunk/lib/Class/C3/Componentised.pm 2011-02-23 13:39:03 UTC (rev 9834)
@@ -51,6 +51,8 @@
our $VERSION = 1.0006;
+my $invalid_class = qr/(?: \b:\b | \:{3,} | \:\:$ )/x;
+
=head2 load_components( @comps )
Loads the given components into the current module. If a module begins with a
@@ -144,8 +146,7 @@
# require always returns true on success
eval { require($file) } or do {
- $@ = "Invalid class name $f_class"
- if ($f_class=~m/(?:\b:\b|\:{3,})/);
+ $@ = "Invalid class name '$f_class'" if $f_class =~ $invalid_class;
if ($class->can('throw_exception')) {
$class->throw_exception($@);
@@ -218,11 +219,15 @@
my $err = $@; # so we don't lose it
- my $fn = quotemeta( (join ('/', split ('::', $f_class) ) ) . '.pm' );
- if ($err =~ /Can't locate ${fn} in \@INC/ ) {
- return 0;
+ if ($f_class =~ $invalid_class) {
+ $err = "Invalid class name '$f_class'";
}
- elsif ($class->can('throw_exception')) {
+ else {
+ my $fn = quotemeta( (join ('/', split ('::', $f_class) ) ) . '.pm' );
+ return 0 if ($err =~ /Can't locate ${fn} in \@INC/ );
+ }
+
+ if ($class->can('throw_exception')) {
$class->throw_exception($err);
}
else {
Modified: Class-C3-Componentised/trunk/t/01-basic.t
===================================================================
--- Class-C3-Componentised/trunk/t/01-basic.t 2011-02-23 00:01:00 UTC (rev 9833)
+++ Class-C3-Componentised/trunk/t/01-basic.t 2011-02-23 13:39:03 UTC (rev 9834)
@@ -8,7 +8,7 @@
use lib "$FindBin::Bin/lib";
-plan tests => 22;
+plan tests => 23;
BEGIN {
package TestPackage::A;
@@ -54,6 +54,9 @@
'MyModule::ErrorComponent threw ok'
);
+eval { MyModule->load_optional_class('ENDS::WITH::COLONS::') };
+like( $@, qr/Invalid class name 'ENDS::WITH::COLONS::'/, 'Throw on Class::' );
+
# Simulate a PAR environment
{
my @code;
More information about the Bast-commits
mailing list