8 use Class::Load 'load_class';
9 use Scalar::Util 'blessed';
15 my ( $class, @args ) = @_;
17 unshift @args, "metaclass" if @args % 2 == 1;
20 my $meta_name = exists $options{meta_name} ? $options{meta_name} : 'meta';
21 my $metaclass = delete $options{metaclass};
23 unless ( defined $metaclass ) {
24 $metaclass = "Class::MOP::Class";
26 load_class($metaclass);
29 ($metaclass->isa('Class::MOP::Class'))
30 || confess "The metaclass ($metaclass) must be derived from Class::MOP::Class";
32 # make sure the custom metaclasses get loaded
33 foreach my $key (grep { /_(?:meta)?class$/ } keys %options) {
34 unless ( ref( my $class = $options{$key} ) ) {
39 my $package = caller();
41 # create a meta object so we can install &meta
42 my $meta = $metaclass->initialize($package => %options);
43 $meta->_add_meta_method($meta_name)
44 if defined $meta_name;
49 # ABSTRACT: a pragma for installing and using Class::MOP metaclasses
59 # use Class::MOP::Class
62 # ... or use a custom metaclass
63 use metaclass 'MyMetaClass';
65 # ... or use a custom metaclass
66 # and custom attribute and method
68 use metaclass 'MyMetaClass' => (
69 'attribute_metaclass' => 'MyAttributeMetaClass',
70 'method_metaclass' => 'MyMethodMetaClass',
73 # ... or just specify custom attribute
74 # and method classes, and Class::MOP::Class
75 # is the assumed metaclass
77 'attribute_metaclass' => 'MyAttributeMetaClass',
78 'method_metaclass' => 'MyMethodMetaClass',
81 # if we'd rather not install a 'meta' method, we can do this
82 use metaclass meta_name => undef;
83 # or if we'd like it to have a different name,
84 use metaclass meta_name => 'my_meta';
88 This is a pragma to make it easier to use a specific metaclass
89 and a set of custom attribute and method metaclasses. It also
90 installs a C<meta> method to your class as well, unless C<undef>
91 is passed to the C<meta_name> option.
93 Note that if you are using Moose, you most likely do B<not> want
94 to be using this - look into L<Moose::Util::MetaRole> instead.