8 use Scalar::Util 'blessed';
10 our $VERSION = '0.65';
11 our $AUTHORITY = 'cpan:STEVAN';
18 if (!defined($_[0]) || $_[0] =~ /^(attribute|method|instance)_metaclass/) {
19 $metaclass = 'Class::MOP::Class';
23 #make sure the custom metaclass gets loaded
24 Class::MOP::load_class($metaclass);
25 ($metaclass->isa('Class::MOP::Class'))
26 || confess "The metaclass ($metaclass) must be derived from Class::MOP::Class";
30 # make sure the custom metaclasses get loaded
31 foreach my $class (grep {
32 /^(attribute|method|instance)_metaclass/
34 Class::MOP::load_class($options{$class})
37 my $package = caller();
39 # create a meta object so we can install &meta
40 my $meta = $metaclass->initialize($package => %options);
41 $meta->add_method('meta' => sub {
42 # we must re-initialize so that it
43 # works as expected in subclasses,
44 # since metaclass instances are
45 # singletons, this is not really a
47 $metaclass->initialize((blessed($_[0]) || $_[0]) => %options)
59 metaclass - a pragma for installing and using Class::MOP metaclasses
65 # use Class::MOP::Class
68 # ... or use a custom metaclass
69 use metaclass 'MyMetaClass';
71 # ... or use a custom metaclass
72 # and custom attribute and method
74 use metaclass 'MyMetaClass' => (
75 'attribute_metaclass' => 'MyAttributeMetaClass',
76 'method_metaclass' => 'MyMethodMetaClass',
79 # ... or just specify custom attribute
80 # and method classes, and Class::MOP::Class
81 # is the assumed metaclass
83 'attribute_metaclass' => 'MyAttributeMetaClass',
84 'method_metaclass' => 'MyMethodMetaClass',
89 This is a pragma to make it easier to use a specific metaclass
90 and a set of custom attribute and method metaclasses. It also
91 installs a C<meta> method to your class as well.
95 Stevan Little E<lt>stevan@iinteractive.comE<gt>
97 =head1 COPYRIGHT AND LICENSE
99 Copyright 2006-2008 by Infinity Interactive, Inc.
101 L<http://www.iinteractive.com>
103 This library is free software; you can redistribute it and/or modify
104 it under the same terms as Perl itself.