[Bast-commits] r5914 - in Class-C3-Componentised/trunk: .
lib/Class/C3 t
arcanez at dev.catalyst.perl.org
arcanez at dev.catalyst.perl.org
Mon Apr 20 22:00:43 GMT 2009
Author: arcanez
Date: 2009-04-20 23:00:43 +0100 (Mon, 20 Apr 2009)
New Revision: 5914
Modified:
Class-C3-Componentised/trunk/Changes
Class-C3-Componentised/trunk/lib/Class/C3/Componentised.pm
Class-C3-Componentised/trunk/t/01-basic.t
Log:
rip load_optional_class from DBIx::Class::Componentised and put it in Class::C3::Componentised
Modified: Class-C3-Componentised/trunk/Changes
===================================================================
--- Class-C3-Componentised/trunk/Changes 2009-04-20 00:11:07 UTC (rev 5913)
+++ Class-C3-Componentised/trunk/Changes 2009-04-20 22:00:43 UTC (rev 5914)
@@ -1,5 +1,8 @@
Revision history for Class-C3-Componentised
+1.0005 19 Apr 2009
+ Add load_optional_class method
+
1.0004 18 Mar 2009
Port to use MRO::Compat (rafl)
Modified: Class-C3-Componentised/trunk/lib/Class/C3/Componentised.pm
===================================================================
--- Class-C3-Componentised/trunk/lib/Class/C3/Componentised.pm 2009-04-20 00:11:07 UTC (rev 5913)
+++ Class-C3-Componentised/trunk/lib/Class/C3/Componentised.pm 2009-04-20 22:00:43 UTC (rev 5914)
@@ -46,7 +46,7 @@
use Class::Inspector;
use Carp;
-our $VERSION = 1.0004;
+our $VERSION = 1.0005;
=head2 load_components( @comps )
@@ -168,6 +168,25 @@
mro::set_mro($target, 'c3');
}
+=head2 load_optional_class
+
+Returns a true value if the specified class is installed and loaded
+successfully, throws an exception if the class is found but not loaded
+successfully, and false if the class is not installed
+
+=cut
+
+sub load_optional_class {
+ my ($class, $f_class) = @_;
+ if ($class->ensure_class_found($f_class)) {
+ eval { $class->ensure_class_loaded($f_class) };
+ croak "Failed to load $f_class: $@" if $@;
+ return 1;
+ }
+ return 0;
+}
+
+
=head1 AUTHOR
Matt S. Trout and the DBIx::Class team
Modified: Class-C3-Componentised/trunk/t/01-basic.t
===================================================================
--- Class-C3-Componentised/trunk/t/01-basic.t 2009-04-20 00:11:07 UTC (rev 5913)
+++ Class-C3-Componentised/trunk/t/01-basic.t 2009-04-20 22:00:43 UTC (rev 5914)
@@ -8,7 +8,7 @@
use lib "$FindBin::Bin/lib";
-plan tests => 3;
+plan tests => 6;
use_ok('MyModule');
@@ -23,3 +23,7 @@
is(MyModule->new->message, "Foo MyModule", "it worked");
+is(MyModule->load_optional_class('ClassC3ComponentFooThatShouldntExist'), 0, "load_optional_class NonexistantClass returned false");
+is(MyModule->load_optional_class('MyModule::Plugin::Foo'), 1, "load_optional_class MyModule::Plugin::Foo (previously loaded module) returned true");
+is(MyModule->load_optional_class('MyModule::OwnComponent'), 1, "load_optional_class MyModule::OwnComponent (not previously loaded module) returned true");
+
More information about the Bast-commits
mailing list