Revision history for Perl extension Class-MOP.
0.63
+ * Class::MOP
+ - load_class will initialize a metaclass even if
+ the class is already loaded (sartak)
+ - load_class now returns the metaclass instance
+ instead of just 1 (sartak)
0.62 Wed June 18, 2008
- in is_class_loaded, recognize scalar references (as opposed to globs) in
confess "Invalid class name ($display)";
}
- # see if this is already
- # loaded in the symbol table
- return 1 if is_class_loaded($class);
- # otherwise require it ...
- my $file = $class . '.pm';
- $file =~ s{::}{/}g;
- eval { CORE::require($file) };
- confess "Could not load class ($class) because : $@" if $@;
+ # if the class is not already loaded in the symbol table..
+ unless (is_class_loaded($class)) {
+ # require it
+ my $file = $class . '.pm';
+ $file =~ s{::}{/}g;
+ eval { CORE::require($file) };
+ confess "Could not load class ($class) because : $@" if $@;
+ }
+
+ # initialize a metaclass if necessary
unless (does_metaclass_exist($class)) {
eval { Class::MOP::Class->initialize($class) };
confess "Could not initialize class ($class) because : $@" if $@;
}
- 1; # return true if it worked
+
+ return get_metaclass_by_name($class);
}
sub is_class_loaded {
#!/usr/bin/env perl
use strict;
use warnings;
-use Test::More tests => 13;
+use Test::More tests => 14;
use Test::Exception;
require Class::MOP;
throws_ok { Class::MOP::load_class('') } qr/Invalid class name \(\)/;
throws_ok { Class::MOP::load_class(\"foo") } qr/Invalid class name \(SCALAR\(\w+\)\)/;
-ok(Class::MOP::load_class('BinaryTree'));
+my $meta = Class::MOP::load_class('BinaryTree');
+ok($meta, "successfully loaded the class BinaryTree");
+is($meta->name, "BinaryTree", "load_class returns the metaclass");
can_ok('BinaryTree' => 'traverse');
do {