8 use Scalar::Util 'blessed';
11 our $VERSION = '1.11';
12 $VERSION = eval $VERSION;
13 our $AUTHORITY = 'cpan:STEVAN';
18 my ( $class, @args ) = @_;
20 unshift @args, "metaclass" if @args % 2 == 1;
23 my $meta_name = exists $options{meta_name} ? $options{meta_name} : 'meta';
24 my $metaclass = delete $options{metaclass};
26 unless ( defined $metaclass ) {
27 $metaclass = "Class::MOP::Class";
29 Class::MOP::load_class($metaclass);
32 ($metaclass->isa('Class::MOP::Class'))
33 || confess "The metaclass ($metaclass) must be derived from Class::MOP::Class";
35 # make sure the custom metaclasses get loaded
36 foreach my $key (grep { /_(?:meta)?class$/ } keys %options) {
37 unless ( ref( my $class = $options{$key} ) ) {
38 Class::MOP::load_class($class)
42 my $package = caller();
44 # create a meta object so we can install &meta
45 my $meta = $metaclass->initialize($package => %options);
46 $meta->_add_meta_method($meta_name)
47 if defined $meta_name;
58 metaclass - a pragma for installing and using Class::MOP metaclasses
64 # use Class::MOP::Class
67 # ... or use a custom metaclass
68 use metaclass 'MyMetaClass';
70 # ... or use a custom metaclass
71 # and custom attribute and method
73 use metaclass 'MyMetaClass' => (
74 'attribute_metaclass' => 'MyAttributeMetaClass',
75 'method_metaclass' => 'MyMethodMetaClass',
78 # ... or just specify custom attribute
79 # and method classes, and Class::MOP::Class
80 # is the assumed metaclass
82 'attribute_metaclass' => 'MyAttributeMetaClass',
83 'method_metaclass' => 'MyMethodMetaClass',
86 # if we'd rather not install a 'meta' method, we can do this
87 use metaclass meta_name => undef;
88 # or if we'd like it to have a different name,
89 use metaclass meta_name => 'my_meta';
93 This is a pragma to make it easier to use a specific metaclass
94 and a set of custom attribute and method metaclasses. It also
95 installs a C<meta> method to your class as well, unless C<undef>
96 is passed to the C<meta_name> option.
100 Stevan Little E<lt>stevan@iinteractive.comE<gt>
102 =head1 COPYRIGHT AND LICENSE
104 Copyright 2006-2010 by Infinity Interactive, Inc.
106 L<http://www.iinteractive.com>
108 This library is free software; you can redistribute it and/or modify
109 it under the same terms as Perl itself.