- updated docs to explain this
* metaclass
- - load custom metaclass automatically.
- - modified tests to test this behavior
+ - load custom metaclasses automatically.
+ - added tests for this behavior
0.37 Sat. March 10, 2007
~~ Many, many documentation updates ~~
}
else {
$metaclass = shift;
+ #make sure the custom metaclass gets loaded
Class::MOP::load_class($metaclass);
($metaclass->isa('Class::MOP::Class'))
|| confess "The metaclass ($metaclass) must be derived from Class::MOP::Class";
}
my %options = @_;
+ #make sure the custom metaclasses get loaded
+ map{ Class::MOP::load_class($options{$_}) }
+ grep{ /^(attribute|method|instance)_metaclass/ } keys %options;
my $package = caller();
# create a meta object so we can install &meta
--- /dev/null
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use FindBin;
+use File::Spec::Functions;
+
+use Test::More tests => 9;
+
+BEGIN {
+ use_ok('Class::MOP');
+}
+
+use lib catdir($FindBin::Bin, 'lib');
+
+{
+ package Foo;
+
+ use strict;
+ use warnings;
+
+ use metaclass 'MyMetaClass' => (
+ 'attribute_metaclass' => 'MyMetaClass::Attribute',
+ 'instance_metaclass' => 'MyMetaClass::Instance',
+ 'method_metaclass' => 'MyMetaClass::Method',
+ 'random_metaclass' => 'MyMetaClass::Random',
+ );
+}
+
+my $meta = Foo->meta;
+
+isa_ok($meta, 'MyMetaClass', '... Correct metaclass');
+ok(Class::MOP::is_class_loaded('MyMetaClass'), '... metaclass loaded');
+
+is($meta->attribute_metaclass, 'MyMetaClass::Attribute', '... Correct attribute metaclass');
+ok(Class::MOP::is_class_loaded('MyMetaClass::Attribute'), '... attribute metaclass loaded');
+
+is($meta->instance_metaclass, 'MyMetaClass::Instance', '... Correct instance metaclass');
+ok(Class::MOP::is_class_loaded('MyMetaClass::Instance'), '... instance metaclass loaded');
+
+is($meta->method_metaclass, 'MyMetaClass::Method', '... Correct method metaclass');
+ok(Class::MOP::is_class_loaded('MyMetaClass::Method'), '... method metaclass loaded');