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)
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
# 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($@);
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'";
+ }
+ else {
+ my $fn = quotemeta( (join ('/', split ('::', $f_class) ) ) . '.pm' );
+ return 0 if ($err =~ /Can't locate ${fn} in \@INC/ );
}
- elsif ($class->can('throw_exception')) {
+
+ if ($class->can('throw_exception')) {
$class->throw_exception($err);
}
else {
use lib "$FindBin::Bin/lib";
-plan tests => 22;
+plan tests => 23;
BEGIN {
package TestPackage::A;
'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;