[Bast-commits] r7083 - in Class-C3-Componentised/trunk: .
lib/Class/C3 t t/lib
ribasushi at dev.catalyst.perl.org
ribasushi at dev.catalyst.perl.org
Tue Jul 21 23:01:35 GMT 2009
Author: ribasushi
Date: 2009-07-21 23:01:35 +0000 (Tue, 21 Jul 2009)
New Revision: 7083
Added:
Class-C3-Componentised/trunk/t/02-explicit.t
Class-C3-Componentised/trunk/t/lib/MyModuleNoBase.pm
Modified:
Class-C3-Componentised/trunk/Changes
Class-C3-Componentised/trunk/lib/Class/C3/Componentised.pm
Class-C3-Componentised/trunk/t/lib/MyModule.pm
Log:
Do not call component_base_class unless it is actually necessary
Modified: Class-C3-Componentised/trunk/Changes
===================================================================
--- Class-C3-Componentised/trunk/Changes 2009-07-21 16:16:34 UTC (rev 7082)
+++ Class-C3-Componentised/trunk/Changes 2009-07-21 23:01:35 UTC (rev 7083)
@@ -1,5 +1,8 @@
Revision history for Class-C3-Componentised
+ Allow derived classes without component_base_class(), given all
+ arguments to load_components are absolute class names (+Classname)
+
1.0005 22 Apr 2009
Add load_optional_class method
Modified: Class-C3-Componentised/trunk/lib/Class/C3/Componentised.pm
===================================================================
--- Class-C3-Componentised/trunk/lib/Class/C3/Componentised.pm 2009-07-21 16:16:34 UTC (rev 7082)
+++ Class-C3-Componentised/trunk/lib/Class/C3/Componentised.pm 2009-07-21 23:01:35 UTC (rev 7083)
@@ -60,8 +60,12 @@
sub load_components {
my $class = shift;
- my $base = $class->component_base_class;
- my @comp = map { /^\+(.*)$/ ? $1 : "${base}::$_" } grep { $_ !~ /^#/ } @_;
+ my @comp = map {
+ /^\+(.*)$/
+ ? $1
+ : join ('::', $class->component_base_class, $_)
+ }
+ grep { $_ !~ /^#/ } @_;
$class->_load_components(@comp);
}
@@ -95,9 +99,12 @@
sub load_optional_components {
my $class = shift;
- my $base = $class->component_base_class;
my @comp = grep { $class->load_optional_class( $_ ) }
- map { /^\+(.*)$/ ? $1 : "${base}::$_" }
+ map {
+ /^\+(.*)$/
+ ? $1
+ : join ('::', $class->component_base_class, $_)
+ }
grep { $_ !~ /^#/ } @_;
$class->_load_components( @comp ) if scalar @comp;
Added: Class-C3-Componentised/trunk/t/02-explicit.t
===================================================================
--- Class-C3-Componentised/trunk/t/02-explicit.t (rev 0)
+++ Class-C3-Componentised/trunk/t/02-explicit.t 2009-07-21 23:01:35 UTC (rev 7083)
@@ -0,0 +1,35 @@
+use strict;
+use warnings;
+
+use FindBin;
+use Test::More;
+use Test::Exception;
+
+use lib "$FindBin::Bin/lib";
+
+plan tests => 7;
+
+use_ok('MyModuleNoBase');
+is(MyModuleNoBase->new->message, " MyModuleNoBase", "initial message matches");
+lives_ok (
+ sub { MyModuleNoBase->load_components('+MyModule::Plugin::Foo') },
+ 'explicit load_components does not throw',
+);
+is(MyModuleNoBase->new->message, "Foo MyModuleNoBase", "component works");
+
+throws_ok (
+ sub { MyModuleNoBase->load_components('ClassC3ComponentFooThatShouldntExist') },
+ qr/Can't locate object method "component_base_class"/,
+ 'non-explicit component specification fails without component_base_class()',
+);
+
+throws_ok (
+ sub { MyModuleNoBase->load_optional_components('ClassC3ComponentFooThatShouldntExist') },
+ qr/Can't locate object method "component_base_class"/,
+ 'non-explicit component specification fails without component_base_class()',
+);
+
+lives_ok (
+ sub { MyModuleNoBase->load_optional_components('+ClassC3ComponentFooThatShouldntExist') },
+ 'explicit optional component specification does not throw',
+);
Modified: Class-C3-Componentised/trunk/t/lib/MyModule.pm
===================================================================
--- Class-C3-Componentised/trunk/t/lib/MyModule.pm 2009-07-21 16:16:34 UTC (rev 7082)
+++ Class-C3-Componentised/trunk/t/lib/MyModule.pm 2009-07-21 23:01:35 UTC (rev 7083)
@@ -8,7 +8,7 @@
sub message {
my $msg = $_[0]->maybe::next::method() || '';
- return $msg . " MyModule";
+ return $msg . ' ' . __PACKAGE__;
}
sub new {
Added: Class-C3-Componentised/trunk/t/lib/MyModuleNoBase.pm
===================================================================
--- Class-C3-Componentised/trunk/t/lib/MyModuleNoBase.pm (rev 0)
+++ Class-C3-Componentised/trunk/t/lib/MyModuleNoBase.pm 2009-07-21 23:01:35 UTC (rev 7083)
@@ -0,0 +1,16 @@
+package # hide from pause
+ MyModuleNoBase;
+
+use base 'Class::C3::Componentised';
+
+sub message {
+ my $msg = $_[0]->maybe::next::method() || '';
+
+ return $msg . ' ' . __PACKAGE__;
+}
+
+sub new {
+ return bless {}, shift;
+}
+
+1;
More information about the Bast-commits
mailing list