8 use Scalar::Util 'blessed';
10 our $VERSION = '1.08';
11 $VERSION = eval $VERSION;
12 our $AUTHORITY = 'cpan:STEVAN';
17 my ( $class, @args ) = @_;
19 unshift @args, "metaclass" if @args % 2 == 1;
22 my $metaclass = delete $options{metaclass};
24 unless ( defined $metaclass ) {
25 $metaclass = "Class::MOP::Class";
27 Class::MOP::load_class($metaclass);
30 ($metaclass->isa('Class::MOP::Class'))
31 || confess "The metaclass ($metaclass) must be derived from Class::MOP::Class";
33 # make sure the custom metaclasses get loaded
34 foreach my $key (grep { /_(?:meta)?class$/ } keys %options) {
35 unless ( ref( my $class = $options{$key} ) ) {
36 Class::MOP::load_class($class)
40 my $package = caller();
42 # create a meta object so we can install &meta
43 my $meta = $metaclass->initialize($package => %options);
44 my $should_install = !delete $options{no_meta};
45 $meta->add_method('meta' => sub {
46 # we must re-initialize so that it
47 # works as expected in subclasses,
48 # since metaclass instances are
49 # singletons, this is not really a
51 $metaclass->initialize((blessed($_[0]) || $_[0]) => %options)
52 }) if $should_install;
63 metaclass - a pragma for installing and using Class::MOP metaclasses
69 # use Class::MOP::Class
72 # ... or use a custom metaclass
73 use metaclass 'MyMetaClass';
75 # ... or use a custom metaclass
76 # and custom attribute and method
78 use metaclass 'MyMetaClass' => (
79 'attribute_metaclass' => 'MyAttributeMetaClass',
80 'method_metaclass' => 'MyMethodMetaClass',
83 # ... or just specify custom attribute
84 # and method classes, and Class::MOP::Class
85 # is the assumed metaclass
87 'attribute_metaclass' => 'MyAttributeMetaClass',
88 'method_metaclass' => 'MyMethodMetaClass',
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.
99 Stevan Little E<lt>stevan@iinteractive.comE<gt>
101 =head1 COPYRIGHT AND LICENSE
103 Copyright 2006-2010 by Infinity Interactive, Inc.
105 L<http://www.iinteractive.com>
107 This library is free software; you can redistribute it and/or modify
108 it under the same terms as Perl itself.