Permalink
Browse files

Add load_first_existing_class()

  • Loading branch information...
1 parent 7fd22c8 commit d3338652451f844ca935009f38a9cf4c1f484b73 @gfx gfx committed with May 19, 2010
Showing with 15 additions and 3 deletions.
  1. +9 −1 lib/Any/Moose.pm
  2. +3 −1 t/005-aliases-moose.t
  3. +3 −1 t/005-aliases-mouse.t
View
10 lib/Any/Moose.pm
@@ -176,7 +176,15 @@ sub any_moose {
return $fragment;
}
-for my $name (qw/load_class is_class_loaded class_of get_metaclass_by_name get_all_metaclass_instances get_all_metaclass_names/) {
+for my $name (qw/
+ load_class
+ is_class_loaded
+ class_of
+ get_metaclass_by_name
+ get_all_metaclass_instances
+ get_all_metaclass_names
+ load_first_existing_class
+ /) {
no strict 'refs';
*{__PACKAGE__."::$name"} = moose_is_preferred()
? *{"Class::MOP::$name"}
View
4 t/005-aliases-moose.t
@@ -8,7 +8,7 @@ BEGIN { delete $ENV{ANY_MOOSE} }
BEGIN {
eval 'require Moose;';
plan skip_all => 'Moose not available' if $@;
- plan tests => 20;
+ plan tests => 21;
}
package MyClass;
@@ -46,3 +46,5 @@ is((grep { $_ eq 'MyClass' } Any::Moose::get_all_metaclass_names()), 1);
is((grep { $_ eq 'AnyMooseTest' } Any::Moose::get_all_metaclass_names()), 1);
is((grep { $_ eq 'NonexistentTest' } Any::Moose::get_all_metaclass_names()), 0);
+my $c = Any::Moose::load_first_existing_class('Any::Moose::No::Such::Module', 'strict');
+is $c, 'strict', 'load_first_existing_class';
View
4 t/005-aliases-mouse.t
@@ -8,7 +8,7 @@ BEGIN { delete $ENV{ANY_MOOSE} }
BEGIN {
eval 'require Mouse;';
plan skip_all => 'Mouse not available' if $@;
- plan tests => 20;
+ plan tests => 21;
}
package MyClass;
@@ -46,3 +46,5 @@ is((grep { $_ eq 'MyClass' } Any::Moose::get_all_metaclass_names()), 1);
is((grep { $_ eq 'AnyMooseTest' } Any::Moose::get_all_metaclass_names()), 1);
is((grep { $_ eq 'NonexistentTest' } Any::Moose::get_all_metaclass_names()), 0);
+my $c = Any::Moose::load_first_existing_class('Any::Moose::No::Such::Module', 'strict');
+is $c, 'strict', 'load_first_existing_class';

0 comments on commit d333865

Please sign in to comment.