12 use Scalar::Util 'weaken';
14 use Sub::Identify 'get_code_info';
20 Sub::Name->import(qw(subname));
22 } or eval 'sub subname { $_[1] }';
24 # this is either part of core or set up appropriately by MRO::Compat
25 *check_package_cache_flag = \&mro::get_pkg_gen;
28 require Devel::GlobalDestruction;
29 Devel::GlobalDestruction->import("in_global_destruction");
31 } or *in_global_destruction = sub () { !1 };
35 use Class::MOP::Class;
36 use Class::MOP::Attribute;
37 use Class::MOP::Method;
39 use Class::MOP::Immutable;
42 *IS_RUNNING_ON_5_10 = ($] < 5.009_005)
46 *HAVE_ISAREV = defined(&mro::get_isarev)
51 our $VERSION = '0.64_02';
52 $VERSION = eval $VERSION;
53 our $AUTHORITY = 'cpan:STEVAN';
55 # after that everything is loaded, if we're allowed try to load faster XS
56 # versions of various things
57 unless ($ENV{CLASS_MOP_NO_XS}) {
62 __PACKAGE__->XSLoader::load($VERSION);
67 die $e if $e && $e !~ /object version|loadable object/;
71 # Metaclasses are singletons, so we cache them here.
72 # there is no need to worry about destruction though
73 # because they should die only when the program dies.
74 # After all, do package definitions even get reaped?
77 # means of accessing all the metaclasses that have
78 # been initialized thus far (for mugwumps obj browser)
79 sub get_all_metaclasses { %METAS }
80 sub get_all_metaclass_instances { values %METAS }
81 sub get_all_metaclass_names { keys %METAS }
82 sub get_metaclass_by_name { $METAS{$_[0]} }
83 sub store_metaclass_by_name { $METAS{$_[0]} = $_[1] }
84 sub weaken_metaclass { weaken($METAS{$_[0]}) }
85 sub does_metaclass_exist { exists $METAS{$_[0]} && defined $METAS{$_[0]} }
86 sub remove_metaclass_by_name { $METAS{$_[0]} = undef }
89 # We only cache metaclasses, meaning instances of
90 # Class::MOP::Class. We do not cache instance of
91 # Class::MOP::Package or Class::MOP::Module. Mostly
92 # because I don't yet see a good reason to do so.
98 if (ref($class) || !defined($class) || !length($class)) {
99 my $display = defined($class) ? $class : 'undef';
100 confess "Invalid class name ($display)";
103 # if the class is not already loaded in the symbol table..
104 unless (is_class_loaded($class)) {
106 my $file = $class . '.pm';
108 my $e = do { local $@; eval { require($file) }; $@ };
109 confess "Could not load class ($class) because : $e" if $e;
112 # initialize a metaclass if necessary
113 unless (does_metaclass_exist($class)) {
114 my $e = do { local $@; eval { Class::MOP::Class->initialize($class) }; $@ };
115 confess "Could not initialize class ($class) because : $e" if $e;
118 return get_metaclass_by_name($class) if defined wantarray;
121 sub is_class_loaded {
124 return 0 if ref($class) || !defined($class) || !length($class);
126 # walk the symbol table tree to avoid autovififying
127 # \*{${main::}{"Foo::"}} == \*main::Foo::
130 foreach my $part (split('::', $class)) {
131 return 0 unless exists ${$$pack}{"${part}::"};
132 $pack = \*{${$$pack}{"${part}::"}};
135 # check for $VERSION or @ISA
136 return 1 if exists ${$$pack}{VERSION}
137 && defined *{${$$pack}{VERSION}}{SCALAR};
138 return 1 if exists ${$$pack}{ISA}
139 && defined *{${$$pack}{ISA}}{ARRAY};
141 # check for any method
142 foreach ( keys %{$$pack} ) {
143 next if substr($_, -2, 2) eq '::';
145 my $glob = ${$$pack}{$_} || next;
148 if ( IS_RUNNING_ON_5_10 ) {
149 return 1 if ref $glob eq 'SCALAR';
152 return 1 if defined *{$glob}{CODE};
160 ## ----------------------------------------------------------------------------
161 ## Setting up our environment ...
162 ## ----------------------------------------------------------------------------
163 ## Class::MOP needs to have a few things in the global perl environment so
164 ## that it can operate effectively. Those things are done here.
165 ## ----------------------------------------------------------------------------
167 # ... nothing yet actually ;)
169 ## ----------------------------------------------------------------------------
171 ## ----------------------------------------------------------------------------
172 ## The code below here is to bootstrap our MOP with itself. This is also
173 ## sometimes called "tying the knot". By doing this, we make it much easier
174 ## to extend the MOP through subclassing and such since now you can use the
175 ## MOP itself to extend itself.
177 ## Yes, I know, thats weird and insane, but it's a good thing, trust me :)
178 ## ----------------------------------------------------------------------------
180 # We need to add in the meta-attributes here so that
181 # any subclass of Class::MOP::* will be able to
182 # inherit them using &construct_instance
184 ## --------------------------------------------------------
185 ## Class::MOP::Package
187 Class::MOP::Package->meta->add_attribute(
188 Class::MOP::Attribute->new('package' => (
190 # NOTE: we need to do this in order
191 # for the instance meta-object to
192 # not fall into meta-circular death
194 # we just alias the original method
195 # rather than re-produce it here
196 'name' => \&Class::MOP::Package::name
201 Class::MOP::Package->meta->add_attribute(
202 Class::MOP::Attribute->new('namespace' => (
205 # we just alias the original method
206 # rather than re-produce it here
207 'namespace' => \&Class::MOP::Package::namespace
210 default => sub { \undef }
214 ## --------------------------------------------------------
215 ## Class::MOP::Module
218 # yeah this is kind of stretching things a bit,
219 # but truthfully the version should be an attribute
220 # of the Module, the weirdness comes from having to
221 # stick to Perl 5 convention and store it in the
222 # $VERSION package variable. Basically if you just
223 # squint at it, it will look how you want it to look.
224 # Either as a package variable, or as a attribute of
225 # the metaclass, isn't abstraction great :)
227 Class::MOP::Module->meta->add_attribute(
228 Class::MOP::Attribute->new('version' => (
231 # we just alias the original method
232 # rather than re-produce it here
233 'version' => \&Class::MOP::Module::version
236 default => sub { \undef }
241 # By following the same conventions as version here,
242 # we are opening up the possibility that people can
243 # use the $AUTHORITY in non-Class::MOP modules as
246 Class::MOP::Module->meta->add_attribute(
247 Class::MOP::Attribute->new('authority' => (
250 # we just alias the original method
251 # rather than re-produce it here
252 'authority' => \&Class::MOP::Module::authority
255 default => sub { \undef }
259 ## --------------------------------------------------------
262 Class::MOP::Class->meta->add_attribute(
263 Class::MOP::Attribute->new('attributes' => (
265 # NOTE: we need to do this in order
266 # for the instance meta-object to
267 # not fall into meta-circular death
269 # we just alias the original method
270 # rather than re-produce it here
271 'get_attribute_map' => \&Class::MOP::Class::get_attribute_map
273 default => sub { {} }
277 Class::MOP::Class->meta->add_attribute(
278 Class::MOP::Attribute->new('methods' => (
281 # we just alias the original method
282 # rather than re-produce it here
283 'get_method_map' => \&Class::MOP::Class::get_method_map
285 default => sub { {} }
289 Class::MOP::Class->meta->add_attribute(
290 Class::MOP::Attribute->new('superclasses' => (
293 # we just alias the original method
294 # rather than re-produce it here
295 'superclasses' => \&Class::MOP::Class::superclasses
298 default => sub { \undef }
302 Class::MOP::Class->meta->add_attribute(
303 Class::MOP::Attribute->new('attribute_metaclass' => (
306 # we just alias the original method
307 # rather than re-produce it here
308 'attribute_metaclass' => \&Class::MOP::Class::attribute_metaclass
310 default => 'Class::MOP::Attribute',
314 Class::MOP::Class->meta->add_attribute(
315 Class::MOP::Attribute->new('method_metaclass' => (
318 # we just alias the original method
319 # rather than re-produce it here
320 'method_metaclass' => \&Class::MOP::Class::method_metaclass
322 default => 'Class::MOP::Method',
326 Class::MOP::Class->meta->add_attribute(
327 Class::MOP::Attribute->new('instance_metaclass' => (
329 # NOTE: we need to do this in order
330 # for the instance meta-object to
331 # not fall into meta-circular death
333 # we just alias the original method
334 # rather than re-produce it here
335 'instance_metaclass' => \&Class::MOP::Class::instance_metaclass
337 default => 'Class::MOP::Instance',
342 # we don't actually need to tie the knot with
343 # Class::MOP::Class here, it is actually handled
344 # within Class::MOP::Class itself in the
345 # construct_class_instance method.
347 ## --------------------------------------------------------
348 ## Class::MOP::Attribute
350 Class::MOP::Attribute->meta->add_attribute(
351 Class::MOP::Attribute->new('name' => (
353 # NOTE: we need to do this in order
354 # for the instance meta-object to
355 # not fall into meta-circular death
357 # we just alias the original method
358 # rather than re-produce it here
359 'name' => \&Class::MOP::Attribute::name
364 Class::MOP::Attribute->meta->add_attribute(
365 Class::MOP::Attribute->new('associated_class' => (
367 # NOTE: we need to do this in order
368 # for the instance meta-object to
369 # not fall into meta-circular death
371 # we just alias the original method
372 # rather than re-produce it here
373 'associated_class' => \&Class::MOP::Attribute::associated_class
378 Class::MOP::Attribute->meta->add_attribute(
379 Class::MOP::Attribute->new('accessor' => (
380 reader => { 'accessor' => \&Class::MOP::Attribute::accessor },
381 predicate => { 'has_accessor' => \&Class::MOP::Attribute::has_accessor },
385 Class::MOP::Attribute->meta->add_attribute(
386 Class::MOP::Attribute->new('reader' => (
387 reader => { 'reader' => \&Class::MOP::Attribute::reader },
388 predicate => { 'has_reader' => \&Class::MOP::Attribute::has_reader },
392 Class::MOP::Attribute->meta->add_attribute(
393 Class::MOP::Attribute->new('initializer' => (
394 reader => { 'initializer' => \&Class::MOP::Attribute::initializer },
395 predicate => { 'has_initializer' => \&Class::MOP::Attribute::has_initializer },
399 Class::MOP::Attribute->meta->add_attribute(
400 Class::MOP::Attribute->new('writer' => (
401 reader => { 'writer' => \&Class::MOP::Attribute::writer },
402 predicate => { 'has_writer' => \&Class::MOP::Attribute::has_writer },
406 Class::MOP::Attribute->meta->add_attribute(
407 Class::MOP::Attribute->new('predicate' => (
408 reader => { 'predicate' => \&Class::MOP::Attribute::predicate },
409 predicate => { 'has_predicate' => \&Class::MOP::Attribute::has_predicate },
413 Class::MOP::Attribute->meta->add_attribute(
414 Class::MOP::Attribute->new('clearer' => (
415 reader => { 'clearer' => \&Class::MOP::Attribute::clearer },
416 predicate => { 'has_clearer' => \&Class::MOP::Attribute::has_clearer },
420 Class::MOP::Attribute->meta->add_attribute(
421 Class::MOP::Attribute->new('builder' => (
422 reader => { 'builder' => \&Class::MOP::Attribute::builder },
423 predicate => { 'has_builder' => \&Class::MOP::Attribute::has_builder },
427 Class::MOP::Attribute->meta->add_attribute(
428 Class::MOP::Attribute->new('init_arg' => (
429 reader => { 'init_arg' => \&Class::MOP::Attribute::init_arg },
430 predicate => { 'has_init_arg' => \&Class::MOP::Attribute::has_init_arg },
434 Class::MOP::Attribute->meta->add_attribute(
435 Class::MOP::Attribute->new('default' => (
436 # default has a custom 'reader' method ...
437 predicate => { 'has_default' => \&Class::MOP::Attribute::has_default },
441 Class::MOP::Attribute->meta->add_attribute(
442 Class::MOP::Attribute->new('associated_methods' => (
443 reader => { 'associated_methods' => \&Class::MOP::Attribute::associated_methods },
444 default => sub { [] }
448 Class::MOP::Attribute->meta->add_method('clone' => sub {
450 $self->meta->clone_object($self, @_);
453 ## --------------------------------------------------------
454 ## Class::MOP::Method
455 Class::MOP::Method->meta->add_attribute(
456 Class::MOP::Attribute->new('body' => (
457 reader => { 'body' => \&Class::MOP::Method::body },
461 Class::MOP::Method->meta->add_attribute(
462 Class::MOP::Attribute->new('associated_metaclass' => (
463 reader => { 'associated_metaclass' => \&Class::MOP::Method::associated_metaclass },
467 Class::MOP::Method->meta->add_attribute(
468 Class::MOP::Attribute->new('package_name' => (
469 reader => { 'package_name' => \&Class::MOP::Method::package_name },
473 Class::MOP::Method->meta->add_attribute(
474 Class::MOP::Attribute->new('name' => (
475 reader => { 'name' => \&Class::MOP::Method::name },
479 Class::MOP::Method->meta->add_method('clone' => sub {
481 $self->meta->clone_object($self, @_);
484 ## --------------------------------------------------------
485 ## Class::MOP::Method::Wrapped
488 # the way this item is initialized, this
489 # really does not follow the standard
490 # practices of attributes, but we put
491 # it here for completeness
492 Class::MOP::Method::Wrapped->meta->add_attribute(
493 Class::MOP::Attribute->new('modifier_table')
496 ## --------------------------------------------------------
497 ## Class::MOP::Method::Generated
499 Class::MOP::Method::Generated->meta->add_attribute(
500 Class::MOP::Attribute->new('is_inline' => (
501 reader => { 'is_inline' => \&Class::MOP::Method::Generated::is_inline },
506 ## --------------------------------------------------------
507 ## Class::MOP::Method::Accessor
509 Class::MOP::Method::Accessor->meta->add_attribute(
510 Class::MOP::Attribute->new('attribute' => (
512 'associated_attribute' => \&Class::MOP::Method::Accessor::associated_attribute
517 Class::MOP::Method::Accessor->meta->add_attribute(
518 Class::MOP::Attribute->new('accessor_type' => (
519 reader => { 'accessor_type' => \&Class::MOP::Method::Accessor::accessor_type },
523 ## --------------------------------------------------------
524 ## Class::MOP::Method::Constructor
526 Class::MOP::Method::Constructor->meta->add_attribute(
527 Class::MOP::Attribute->new('options' => (
529 'options' => \&Class::MOP::Method::Constructor::options
531 default => sub { +{} }
535 Class::MOP::Method::Constructor->meta->add_attribute(
536 Class::MOP::Attribute->new('associated_metaclass' => (
537 init_arg => "metaclass", # FIXME alias and rename
539 'associated_metaclass' => \&Class::MOP::Method::Constructor::associated_metaclass
544 ## --------------------------------------------------------
545 ## Class::MOP::Instance
548 # these don't yet do much of anything, but are just
549 # included for completeness
551 Class::MOP::Instance->meta->add_attribute(
552 Class::MOP::Attribute->new('associated_metaclass',
553 reader => { associated_metaclass => \&Class::MOP::Instance::associated_metaclass },
557 Class::MOP::Instance->meta->add_attribute(
558 Class::MOP::Attribute->new('_class_name',
560 reader => { _class_name => \&Class::MOP::Instance::_class_name },
561 #lazy => 1, # not yet supported by Class::MOP but out our version does it anyway
562 #default => sub { $_[0]->associated_metaclass->name },
566 Class::MOP::Instance->meta->add_attribute(
567 Class::MOP::Attribute->new('attributes',
568 reader => { attributes => \&Class::MOP::Instance::get_all_attributes },
572 Class::MOP::Instance->meta->add_attribute(
573 Class::MOP::Attribute->new('slots',
574 reader => { slots => \&Class::MOP::Instance::slots },
578 Class::MOP::Instance->meta->add_attribute(
579 Class::MOP::Attribute->new('slot_hash',
580 reader => { slot_hash => \&Class::MOP::Instance::slot_hash },
585 # we need the meta instance of the meta instance to be created now, in order
586 # for the constructor to be able to use it
587 Class::MOP::Instance->meta->get_meta_instance;
589 # pretend the add_method never happenned. it hasn't yet affected anything
590 undef Class::MOP::Instance->meta->{_package_cache_flag};
592 ## --------------------------------------------------------
593 ## Now close all the Class::MOP::* classes
596 # we don't need to inline the
597 # constructors or the accessors
598 # this only lengthens the compile
599 # time of the MOP, and gives us
600 # no actual benefits.
602 $_->meta->make_immutable(
603 inline_constructor => 1,
604 replace_constructor => 1,
605 constructor_name => "_new",
606 inline_accessors => 0,
612 Class::MOP::Attribute
618 Class::MOP::Method::Generated
620 Class::MOP::Method::Accessor
621 Class::MOP::Method::Constructor
622 Class::MOP::Method::Wrapped
633 Class::MOP - A Meta Object Protocol for Perl 5
637 This module is a fully functioning meta object protocol for the
638 Perl 5 object system. It makes no attempt to change the behavior or
639 characteristics of the Perl 5 object system, only to create a
640 protocol for its manipulation and introspection.
642 That said, it does attempt to create the tools for building a rich
643 set of extensions to the Perl 5 object system. Every attempt has been
644 made for these tools to keep to the spirit of the Perl 5 object
645 system that we all know and love.
647 This documentation is admittedly sparse on details, as time permits
648 I will try to improve them. For now, I suggest looking at the items
649 listed in the L<SEE ALSO> section for more information. In particular
650 the book "The Art of the Meta Object Protocol" was very influential
651 in the development of this system.
653 =head2 What is a Meta Object Protocol?
655 A meta object protocol is an API to an object system.
657 To be more specific, it is a set of abstractions of the components of
658 an object system (typically things like; classes, object, methods,
659 object attributes, etc.). These abstractions can then be used to both
660 inspect and manipulate the object system which they describe.
662 It can be said that there are two MOPs for any object system; the
663 implicit MOP, and the explicit MOP. The implicit MOP handles things
664 like method dispatch or inheritance, which happen automatically as
665 part of how the object system works. The explicit MOP typically
666 handles the introspection/reflection features of the object system.
667 All object systems have implicit MOPs, without one, they would not
668 work. Explict MOPs however as less common, and depending on the
669 language can vary from restrictive (Reflection in Java or C#) to
670 wide open (CLOS is a perfect example).
672 =head2 Yet Another Class Builder!! Why?
674 This is B<not> a class builder so much as it is a I<class builder
675 B<builder>>. My intent is that an end user does not use this module
676 directly, but instead this module is used by module authors to
677 build extensions and features onto the Perl 5 object system.
679 =head2 Who is this module for?
681 This module is specifically for anyone who has ever created or
682 wanted to create a module for the Class:: namespace. The tools which
683 this module will provide will hopefully make it easier to do more
684 complex things with Perl 5 classes by removing such barriers as
685 the need to hack the symbol tables, or understand the fine details
688 =head2 What changes do I have to make to use this module?
690 This module was designed to be as unintrusive as possible. Many of
691 its features are accessible without B<any> change to your existsing
692 code at all. It is meant to be a compliment to your existing code and
693 not an intrusion on your code base. Unlike many other B<Class::>
694 modules, this module B<does not> require you subclass it, or even that
695 you C<use> it in within your module's package.
697 The only features which requires additions to your code are the
698 attribute handling and instance construction features, and these are
699 both completely optional features. The only reason for this is because
700 Perl 5's object system does not actually have these features built
701 in. More information about this feature can be found below.
703 =head2 A Note about Performance?
705 It is a common misconception that explict MOPs are performance drains.
706 But this is not a universal truth at all, it is an side-effect of
707 specific implementations. For instance, using Java reflection is much
708 slower because the JVM cannot take advantage of any compiler
709 optimizations, and the JVM has to deal with much more runtime type
710 information as well. Reflection in C# is marginally better as it was
711 designed into the language and runtime (the CLR). In contrast, CLOS
712 (the Common Lisp Object System) was built to support an explicit MOP,
713 and so performance is tuned for it.
715 This library in particular does it's absolute best to avoid putting
716 B<any> drain at all upon your code's performance. In fact, by itself
717 it does nothing to affect your existing code. So you only pay for
718 what you actually use.
720 =head2 About Metaclass compatibility
722 This module makes sure that all metaclasses created are both upwards
723 and downwards compatible. The topic of metaclass compatibility is
724 highly esoteric and is something only encountered when doing deep and
725 involved metaclass hacking. There are two basic kinds of metaclass
726 incompatibility; upwards and downwards.
728 Upwards metaclass compatibility means that the metaclass of a
729 given class is either the same as (or a subclass of) all of the
732 Downward metaclass compatibility means that the metaclasses of a
733 given class's anscestors are all either the same as (or a subclass
736 Here is a diagram showing a set of two classes (C<A> and C<B>) and
737 two metaclasses (C<Meta::A> and C<Meta::B>) which have correct
738 metaclass compatibility both upwards and downwards.
740 +---------+ +---------+
741 | Meta::A |<----| Meta::B | <....... (instance of )
742 +---------+ +---------+ <------- (inherits from)
745 +---------+ +---------+
747 +---------+ +---------+
749 As I said this is a highly esoteric topic and one you will only run
750 into if you do a lot of subclassing of B<Class::MOP::Class>. If you
751 are interested in why this is an issue see the paper
752 I<Uniform and safe metaclass composition> linked to in the
753 L<SEE ALSO> section of this document.
755 =head2 Using custom metaclasses
757 Always use the metaclass pragma when using a custom metaclass, this
758 will ensure the proper initialization order and not accidentely
759 create an incorrect type of metaclass for you. This is a very rare
760 problem, and one which can only occur if you are doing deep metaclass
761 programming. So in other words, don't worry about it.
765 The protocol is divided into 4 main sub-protocols:
769 =item The Class protocol
771 This provides a means of manipulating and introspecting a Perl 5
772 class. It handles all of symbol table hacking for you, and provides
773 a rich set of methods that go beyond simple package introspection.
775 See L<Class::MOP::Class> for more details.
777 =item The Attribute protocol
779 This provides a consistent represenation for an attribute of a
780 Perl 5 class. Since there are so many ways to create and handle
781 attributes in Perl 5 OO, this attempts to provide as much of a
782 unified approach as possible, while giving the freedom and
783 flexibility to subclass for specialization.
785 See L<Class::MOP::Attribute> for more details.
787 =item The Method protocol
789 This provides a means of manipulating and introspecting methods in
790 the Perl 5 object system. As with attributes, there are many ways to
791 approach this topic, so we try to keep it pretty basic, while still
792 making it possible to extend the system in many ways.
794 See L<Class::MOP::Method> for more details.
796 =item The Instance protocol
798 This provides a layer of abstraction for creating object instances.
799 Since the other layers use this protocol, it is relatively easy to
800 change the type of your instances from the default HASH ref to other
801 types of references. Several examples are provided in the F<examples/>
802 directory included in this distribution.
804 See L<Class::MOP::Instance> for more details.
814 =item I<IS_RUNNING_ON_5_10>
816 We set this constant depending on what version perl we are on, this
817 allows us to take advantage of new 5.10 features and stay backwards
822 Whether or not C<mro> provides C<get_isarev>, a much faster way to get all the
823 subclasses of a certain class.
827 =head2 Utility functions
831 =item B<load_class ($class_name)>
833 This will load a given C<$class_name> and if it does not have an
834 already initialized metaclass, then it will intialize one for it.
835 This function can be used in place of tricks like
836 C<eval "use $module"> or using C<require>.
838 =item B<is_class_loaded ($class_name)>
840 This will return a boolean depending on if the C<$class_name> has
843 NOTE: This does a basic check of the symbol table to try and
844 determine as best it can if the C<$class_name> is loaded, it
845 is probably correct about 99% of the time.
847 =item B<check_package_cache_flag ($pkg)>
849 This will return an integer that is managed by C<Class::MOP::Class>
850 to determine if a module's symbol table has been altered.
852 In Perl 5.10 or greater, this flag is package specific. However in
853 versions prior to 5.10, this will use the C<PL_sub_generation> variable
854 which is not package specific.
856 =item B<get_code_info ($code)>
858 This function returns two values, the name of the package the C<$code>
859 is from and the name of the C<$code> itself. This is used by several
860 elements of the MOP to detemine where a given C<$code> reference is from.
862 =item B<subname ($name, $code)>
864 B<NOTE: DO NOT USE THIS FUNCTION, IT IS FOR INTERNAL USE ONLY!>
866 If possible, we will load the L<Sub::Name> module and this will function
867 as C<Sub::Name::subname> does, otherwise it will just return the C<$code>
870 =item B<in_global_destruction>
872 If L<Devel::GlobalDestruction> is available, this returns true under global
875 Otherwise it's a constant returning false.
879 =head2 Metaclass cache functions
881 Class::MOP holds a cache of metaclasses, the following are functions
882 (B<not methods>) which can be used to access that cache. It is not
883 recommended that you mess with this, bad things could happen. But if
884 you are brave and willing to risk it, go for it.
888 =item B<get_all_metaclasses>
890 This will return an hash of all the metaclass instances that have
891 been cached by B<Class::MOP::Class> keyed by the package name.
893 =item B<get_all_metaclass_instances>
895 This will return an array of all the metaclass instances that have
896 been cached by B<Class::MOP::Class>.
898 =item B<get_all_metaclass_names>
900 This will return an array of all the metaclass names that have
901 been cached by B<Class::MOP::Class>.
903 =item B<get_metaclass_by_name ($name)>
905 This will return a cached B<Class::MOP::Class> instance of nothing
906 if no metaclass exist by that C<$name>.
908 =item B<store_metaclass_by_name ($name, $meta)>
910 This will store a metaclass in the cache at the supplied C<$key>.
912 =item B<weaken_metaclass ($name)>
914 In rare cases it is desireable to store a weakened reference in
915 the metaclass cache. This function will weaken the reference to
916 the metaclass stored in C<$name>.
918 =item B<does_metaclass_exist ($name)>
920 This will return true of there exists a metaclass stored in the
921 C<$name> key and return false otherwise.
923 =item B<remove_metaclass_by_name ($name)>
925 This will remove a the metaclass stored in the C<$name> key.
933 There are very few books out on Meta Object Protocols and Metaclasses
934 because it is such an esoteric topic. The following books are really
935 the only ones I have found. If you know of any more, B<I<please>>
936 email me and let me know, I would love to hear about them.
940 =item "The Art of the Meta Object Protocol"
942 =item "Advances in Object-Oriented Metalevel Architecture and Reflection"
944 =item "Putting MetaClasses to Work"
946 =item "Smalltalk: The Language"
954 =item Uniform and safe metaclass composition
956 An excellent paper by the people who brought us the original Traits paper.
957 This paper is on how Traits can be used to do safe metaclass composition,
958 and offers an excellent introduction section which delves into the topic of
959 metaclass compatibility.
961 L<http://www.iam.unibe.ch/~scg/Archive/Papers/Duca05ySafeMetaclassTrait.pdf>
963 =item Safe Metaclass Programming
965 This paper seems to precede the above paper, and propose a mix-in based
966 approach as opposed to the Traits based approach. Both papers have similar
967 information on the metaclass compatibility problem space.
969 L<http://citeseer.ist.psu.edu/37617.html>
977 =item The Perl 6 MetaModel work in the Pugs project
981 =item L<http://svn.openfoundry.org/pugs/perl5/Perl6-MetaModel>
983 =item L<http://svn.openfoundry.org/pugs/perl5/Perl6-ObjectSpace>
993 =item CPAN Module Review of Class::MOP
995 L<http://www.oreillynet.com/onlamp/blog/2006/06/cpan_module_review_classmop.html>
999 =head1 SIMILAR MODULES
1001 As I have said above, this module is a class-builder-builder, so it is
1002 not the same thing as modules like L<Class::Accessor> and
1003 L<Class::MethodMaker>. That being said there are very few modules on CPAN
1004 with similar goals to this module. The one I have found which is most
1005 like this module is L<Class::Meta>, although it's philosophy and the MOP it
1006 creates are very different from this modules.
1010 All complex software has bugs lurking in it, and this module is no
1011 exception. If you find a bug please either email me, or add the bug
1014 =head1 ACKNOWLEDGEMENTS
1020 Thanks to Rob for actually getting the development of this module kick-started.
1026 Stevan Little E<lt>stevan@iinteractive.comE<gt>
1028 B<with contributions from:>
1030 Brandon (blblack) Black
1032 Guillermo (groditi) Roditi
1036 Rob (robkinyon) Kinyon
1038 Yuval (nothingmuch) Kogman
1040 Scott (konobi) McWhirter
1042 =head1 COPYRIGHT AND LICENSE
1044 Copyright 2006-2008 by Infinity Interactive, Inc.
1046 L<http://www.iinteractive.com>
1048 This library is free software; you can redistribute it and/or modify
1049 it under the same terms as Perl itself.