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)
use Class::Inspector;
use Carp;
-our $VERSION = 1.0004;
+our $VERSION = 1.0005;
=head2 load_components( @comps )
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
use lib "$FindBin::Bin/lib";
-plan tests => 3;
+plan tests => 6;
use_ok('MyModule');
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");
+