15 my $metaclass = shift || 'Class::MOP::Class';
17 my $package = caller();
19 ($metaclass->isa('Class::MOP::Class'))
20 || confess 'The metaclass must be derived from Class::MOP::Class';
22 # create a meta object so we can install &meta
23 my $meta = $metaclass->initialize($package => %options);
24 $meta->add_method('meta' => sub {
25 # we must re-initialize so that it
26 # works as expected in subclasses,
27 # since metaclass instances are
28 # singletons, this is not really a
30 $metaclass->initialize($_[0] => %options)
38 Okay, the metaclass constraint issue is a bit of a PITA.
40 Especially in the context of MI, where we end up with an
41 explosion of metaclasses.
45 Instead of auto-composing metaclasses using inheritance
46 (which is problematic at best, and totally wrong at worst,
47 especially in the light of methods of Class::MOP::Class
48 which are overridden by subclasses (try to figure out how
49 LazyClass and InsideOutClass could be composed, it is not
50 even possible)) we use a trait model.
52 It will be similar to Class::Trait, except that there is
53 no such thing as a trait, a class isa trait and a trait
54 isa class, more like Scala really.
56 This way we get several benefits:
58 1) Classes can be composed like traits, and it Just Works.
60 2) Metaclasses can be composed this way too :)
62 3) When solving the metaclass constraint, we create an
63 anon-metaclass, and compose the parent's metaclasses
64 into it. This allows for conflict checking trait-style
65 which should inform us of any issues right away.
69 Class metaclasses must be composed, but so must any
70 associated Attribute and Method metaclasses. However, this
71 is not always relevant since I should be able to create a
72 class which has lazy attributes, and then create a subclass
73 of that class whose attributes are not lazy.
86 metaclass - a pragma for installing using Class::MOP metaclasses
90 use metaclass 'MyMetaClass';
92 use metaclass 'MyMetaClass' => (
93 ':attribute_metaclass' => 'MyAttributeMetaClass',
94 ':method_metaclass' => 'MyMethodMetaClass',
99 This is a pragma to make it easier to use a specific metaclass
104 Stevan Little E<lt>stevan@iinteractive.comE<gt>
106 =head1 COPYRIGHT AND LICENSE
108 Copyright 2006 by Infinity Interactive, Inc.
110 L<http://www.iinteractive.com>
112 This library is free software; you can redistribute it and/or modify
113 it under the same terms as Perl itself.