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_04';
52 our $XS_VERSION = $VERSION;
53 $VERSION = eval $VERSION;
54 our $AUTHORITY = 'cpan:STEVAN';
56 # after that everything is loaded, if we're allowed try to load faster XS
57 # versions of various things
58 unless ($ENV{CLASS_MOP_NO_XS}) {
63 __PACKAGE__->XSLoader::load($XS_VERSION);
68 die $e if $e && $e !~ /object version|loadable object/;
72 # Metaclasses are singletons, so we cache them here.
73 # there is no need to worry about destruction though
74 # because they should die only when the program dies.
75 # After all, do package definitions even get reaped?
78 # means of accessing all the metaclasses that have
79 # been initialized thus far (for mugwumps obj browser)
80 sub get_all_metaclasses { %METAS }
81 sub get_all_metaclass_instances { values %METAS }
82 sub get_all_metaclass_names { keys %METAS }
83 sub get_metaclass_by_name { $METAS{$_[0]} }
84 sub store_metaclass_by_name { $METAS{$_[0]} = $_[1] }
85 sub weaken_metaclass { weaken($METAS{$_[0]}) }
86 sub does_metaclass_exist { exists $METAS{$_[0]} && defined $METAS{$_[0]} }
87 sub remove_metaclass_by_name { $METAS{$_[0]} = undef }
90 # We only cache metaclasses, meaning instances of
91 # Class::MOP::Class. We do not cache instance of
92 # Class::MOP::Package or Class::MOP::Module. Mostly
93 # because I don't yet see a good reason to do so.
99 if (ref($class) || !defined($class) || !length($class)) {
100 my $display = defined($class) ? $class : 'undef';
101 confess "Invalid class name ($display)";
104 # if the class is not already loaded in the symbol table..
105 unless (is_class_loaded($class)) {
107 my $file = $class . '.pm';
109 my $e = do { local $@; eval { require($file) }; $@ };
110 confess "Could not load class ($class) because : $e" if $e;
113 # initialize a metaclass if necessary
114 unless (does_metaclass_exist($class)) {
115 my $e = do { local $@; eval { Class::MOP::Class->initialize($class) }; $@ };
116 confess "Could not initialize class ($class) because : $e" if $e;
119 return get_metaclass_by_name($class) if defined wantarray;
122 sub is_class_loaded {
125 return 0 if ref($class) || !defined($class) || !length($class);
127 # walk the symbol table tree to avoid autovififying
128 # \*{${main::}{"Foo::"}} == \*main::Foo::
131 foreach my $part (split('::', $class)) {
132 return 0 unless exists ${$$pack}{"${part}::"};
133 $pack = \*{${$$pack}{"${part}::"}};
136 # check for $VERSION or @ISA
137 return 1 if exists ${$$pack}{VERSION}
138 && defined *{${$$pack}{VERSION}}{SCALAR};
139 return 1 if exists ${$$pack}{ISA}
140 && defined *{${$$pack}{ISA}}{ARRAY};
142 # check for any method
143 foreach ( keys %{$$pack} ) {
144 next if substr($_, -2, 2) eq '::';
146 my $glob = ${$$pack}{$_} || next;
149 if ( IS_RUNNING_ON_5_10 ) {
150 return 1 if ref $glob eq 'SCALAR';
153 return 1 if defined *{$glob}{CODE};
161 ## ----------------------------------------------------------------------------
162 ## Setting up our environment ...
163 ## ----------------------------------------------------------------------------
164 ## Class::MOP needs to have a few things in the global perl environment so
165 ## that it can operate effectively. Those things are done here.
166 ## ----------------------------------------------------------------------------
168 # ... nothing yet actually ;)
170 ## ----------------------------------------------------------------------------
172 ## ----------------------------------------------------------------------------
173 ## The code below here is to bootstrap our MOP with itself. This is also
174 ## sometimes called "tying the knot". By doing this, we make it much easier
175 ## to extend the MOP through subclassing and such since now you can use the
176 ## MOP itself to extend itself.
178 ## Yes, I know, thats weird and insane, but it's a good thing, trust me :)
179 ## ----------------------------------------------------------------------------
181 # We need to add in the meta-attributes here so that
182 # any subclass of Class::MOP::* will be able to
183 # inherit them using &construct_instance
185 ## --------------------------------------------------------
186 ## Class::MOP::Package
188 Class::MOP::Package->meta->add_attribute(
189 Class::MOP::Attribute->new('package' => (
191 # NOTE: we need to do this in order
192 # for the instance meta-object to
193 # not fall into meta-circular death
195 # we just alias the original method
196 # rather than re-produce it here
197 'name' => \&Class::MOP::Package::name
202 Class::MOP::Package->meta->add_attribute(
203 Class::MOP::Attribute->new('namespace' => (
206 # we just alias the original method
207 # rather than re-produce it here
208 'namespace' => \&Class::MOP::Package::namespace
211 default => sub { \undef }
215 ## --------------------------------------------------------
216 ## Class::MOP::Module
219 # yeah this is kind of stretching things a bit,
220 # but truthfully the version should be an attribute
221 # of the Module, the weirdness comes from having to
222 # stick to Perl 5 convention and store it in the
223 # $VERSION package variable. Basically if you just
224 # squint at it, it will look how you want it to look.
225 # Either as a package variable, or as a attribute of
226 # the metaclass, isn't abstraction great :)
228 Class::MOP::Module->meta->add_attribute(
229 Class::MOP::Attribute->new('version' => (
232 # we just alias the original method
233 # rather than re-produce it here
234 'version' => \&Class::MOP::Module::version
237 default => sub { \undef }
242 # By following the same conventions as version here,
243 # we are opening up the possibility that people can
244 # use the $AUTHORITY in non-Class::MOP modules as
247 Class::MOP::Module->meta->add_attribute(
248 Class::MOP::Attribute->new('authority' => (
251 # we just alias the original method
252 # rather than re-produce it here
253 'authority' => \&Class::MOP::Module::authority
256 default => sub { \undef }
260 ## --------------------------------------------------------
263 Class::MOP::Class->meta->add_attribute(
264 Class::MOP::Attribute->new('attributes' => (
266 # NOTE: we need to do this in order
267 # for the instance meta-object to
268 # not fall into meta-circular death
270 # we just alias the original method
271 # rather than re-produce it here
272 'get_attribute_map' => \&Class::MOP::Class::get_attribute_map
274 default => sub { {} }
278 Class::MOP::Class->meta->add_attribute(
279 Class::MOP::Attribute->new('methods' => (
282 # we just alias the original method
283 # rather than re-produce it here
284 'get_method_map' => \&Class::MOP::Class::get_method_map
286 default => sub { {} }
290 Class::MOP::Class->meta->add_attribute(
291 Class::MOP::Attribute->new('superclasses' => (
294 # we just alias the original method
295 # rather than re-produce it here
296 'superclasses' => \&Class::MOP::Class::superclasses
299 default => sub { \undef }
303 Class::MOP::Class->meta->add_attribute(
304 Class::MOP::Attribute->new('attribute_metaclass' => (
307 # we just alias the original method
308 # rather than re-produce it here
309 'attribute_metaclass' => \&Class::MOP::Class::attribute_metaclass
311 default => 'Class::MOP::Attribute',
315 Class::MOP::Class->meta->add_attribute(
316 Class::MOP::Attribute->new('method_metaclass' => (
319 # we just alias the original method
320 # rather than re-produce it here
321 'method_metaclass' => \&Class::MOP::Class::method_metaclass
323 default => 'Class::MOP::Method',
327 Class::MOP::Class->meta->add_attribute(
328 Class::MOP::Attribute->new('instance_metaclass' => (
330 # NOTE: we need to do this in order
331 # for the instance meta-object to
332 # not fall into meta-circular death
334 # we just alias the original method
335 # rather than re-produce it here
336 'instance_metaclass' => \&Class::MOP::Class::instance_metaclass
338 default => 'Class::MOP::Instance',
343 # we don't actually need to tie the knot with
344 # Class::MOP::Class here, it is actually handled
345 # within Class::MOP::Class itself in the
346 # construct_class_instance method.
348 ## --------------------------------------------------------
349 ## Class::MOP::Attribute
351 Class::MOP::Attribute->meta->add_attribute(
352 Class::MOP::Attribute->new('name' => (
354 # NOTE: we need to do this in order
355 # for the instance meta-object to
356 # not fall into meta-circular death
358 # we just alias the original method
359 # rather than re-produce it here
360 'name' => \&Class::MOP::Attribute::name
365 Class::MOP::Attribute->meta->add_attribute(
366 Class::MOP::Attribute->new('associated_class' => (
368 # NOTE: we need to do this in order
369 # for the instance meta-object to
370 # not fall into meta-circular death
372 # we just alias the original method
373 # rather than re-produce it here
374 'associated_class' => \&Class::MOP::Attribute::associated_class
379 Class::MOP::Attribute->meta->add_attribute(
380 Class::MOP::Attribute->new('accessor' => (
381 reader => { 'accessor' => \&Class::MOP::Attribute::accessor },
382 predicate => { 'has_accessor' => \&Class::MOP::Attribute::has_accessor },
386 Class::MOP::Attribute->meta->add_attribute(
387 Class::MOP::Attribute->new('reader' => (
388 reader => { 'reader' => \&Class::MOP::Attribute::reader },
389 predicate => { 'has_reader' => \&Class::MOP::Attribute::has_reader },
393 Class::MOP::Attribute->meta->add_attribute(
394 Class::MOP::Attribute->new('initializer' => (
395 reader => { 'initializer' => \&Class::MOP::Attribute::initializer },
396 predicate => { 'has_initializer' => \&Class::MOP::Attribute::has_initializer },
400 Class::MOP::Attribute->meta->add_attribute(
401 Class::MOP::Attribute->new('writer' => (
402 reader => { 'writer' => \&Class::MOP::Attribute::writer },
403 predicate => { 'has_writer' => \&Class::MOP::Attribute::has_writer },
407 Class::MOP::Attribute->meta->add_attribute(
408 Class::MOP::Attribute->new('predicate' => (
409 reader => { 'predicate' => \&Class::MOP::Attribute::predicate },
410 predicate => { 'has_predicate' => \&Class::MOP::Attribute::has_predicate },
414 Class::MOP::Attribute->meta->add_attribute(
415 Class::MOP::Attribute->new('clearer' => (
416 reader => { 'clearer' => \&Class::MOP::Attribute::clearer },
417 predicate => { 'has_clearer' => \&Class::MOP::Attribute::has_clearer },
421 Class::MOP::Attribute->meta->add_attribute(
422 Class::MOP::Attribute->new('builder' => (
423 reader => { 'builder' => \&Class::MOP::Attribute::builder },
424 predicate => { 'has_builder' => \&Class::MOP::Attribute::has_builder },
428 Class::MOP::Attribute->meta->add_attribute(
429 Class::MOP::Attribute->new('init_arg' => (
430 reader => { 'init_arg' => \&Class::MOP::Attribute::init_arg },
431 predicate => { 'has_init_arg' => \&Class::MOP::Attribute::has_init_arg },
435 Class::MOP::Attribute->meta->add_attribute(
436 Class::MOP::Attribute->new('default' => (
437 # default has a custom 'reader' method ...
438 predicate => { 'has_default' => \&Class::MOP::Attribute::has_default },
442 Class::MOP::Attribute->meta->add_attribute(
443 Class::MOP::Attribute->new('associated_methods' => (
444 reader => { 'associated_methods' => \&Class::MOP::Attribute::associated_methods },
445 default => sub { [] }
449 Class::MOP::Attribute->meta->add_method('clone' => sub {
451 $self->meta->clone_object($self, @_);
454 ## --------------------------------------------------------
455 ## Class::MOP::Method
456 Class::MOP::Method->meta->add_attribute(
457 Class::MOP::Attribute->new('body' => (
458 reader => { 'body' => \&Class::MOP::Method::body },
462 Class::MOP::Method->meta->add_attribute(
463 Class::MOP::Attribute->new('associated_metaclass' => (
464 reader => { 'associated_metaclass' => \&Class::MOP::Method::associated_metaclass },
468 Class::MOP::Method->meta->add_attribute(
469 Class::MOP::Attribute->new('package_name' => (
470 reader => { 'package_name' => \&Class::MOP::Method::package_name },
474 Class::MOP::Method->meta->add_attribute(
475 Class::MOP::Attribute->new('name' => (
476 reader => { 'name' => \&Class::MOP::Method::name },
480 Class::MOP::Method->meta->add_method('clone' => sub {
482 $self->meta->clone_object($self, @_);
485 ## --------------------------------------------------------
486 ## Class::MOP::Method::Wrapped
489 # the way this item is initialized, this
490 # really does not follow the standard
491 # practices of attributes, but we put
492 # it here for completeness
493 Class::MOP::Method::Wrapped->meta->add_attribute(
494 Class::MOP::Attribute->new('modifier_table')
497 ## --------------------------------------------------------
498 ## Class::MOP::Method::Generated
500 Class::MOP::Method::Generated->meta->add_attribute(
501 Class::MOP::Attribute->new('is_inline' => (
502 reader => { 'is_inline' => \&Class::MOP::Method::Generated::is_inline },
507 ## --------------------------------------------------------
508 ## Class::MOP::Method::Accessor
510 Class::MOP::Method::Accessor->meta->add_attribute(
511 Class::MOP::Attribute->new('attribute' => (
513 'associated_attribute' => \&Class::MOP::Method::Accessor::associated_attribute
518 Class::MOP::Method::Accessor->meta->add_attribute(
519 Class::MOP::Attribute->new('accessor_type' => (
520 reader => { 'accessor_type' => \&Class::MOP::Method::Accessor::accessor_type },
524 ## --------------------------------------------------------
525 ## Class::MOP::Method::Constructor
527 Class::MOP::Method::Constructor->meta->add_attribute(
528 Class::MOP::Attribute->new('options' => (
530 'options' => \&Class::MOP::Method::Constructor::options
532 default => sub { +{} }
536 Class::MOP::Method::Constructor->meta->add_attribute(
537 Class::MOP::Attribute->new('associated_metaclass' => (
538 init_arg => "metaclass", # FIXME alias and rename
540 'associated_metaclass' => \&Class::MOP::Method::Constructor::associated_metaclass
545 ## --------------------------------------------------------
546 ## Class::MOP::Instance
549 # these don't yet do much of anything, but are just
550 # included for completeness
552 Class::MOP::Instance->meta->add_attribute(
553 Class::MOP::Attribute->new('associated_metaclass',
554 reader => { associated_metaclass => \&Class::MOP::Instance::associated_metaclass },
558 Class::MOP::Instance->meta->add_attribute(
559 Class::MOP::Attribute->new('_class_name',
561 reader => { _class_name => \&Class::MOP::Instance::_class_name },
562 #lazy => 1, # not yet supported by Class::MOP but out our version does it anyway
563 #default => sub { $_[0]->associated_metaclass->name },
567 Class::MOP::Instance->meta->add_attribute(
568 Class::MOP::Attribute->new('attributes',
569 reader => { attributes => \&Class::MOP::Instance::get_all_attributes },
573 Class::MOP::Instance->meta->add_attribute(
574 Class::MOP::Attribute->new('slots',
575 reader => { slots => \&Class::MOP::Instance::slots },
579 Class::MOP::Instance->meta->add_attribute(
580 Class::MOP::Attribute->new('slot_hash',
581 reader => { slot_hash => \&Class::MOP::Instance::slot_hash },
586 # we need the meta instance of the meta instance to be created now, in order
587 # for the constructor to be able to use it
588 Class::MOP::Instance->meta->get_meta_instance;
590 # pretend the add_method never happenned. it hasn't yet affected anything
591 undef Class::MOP::Instance->meta->{_package_cache_flag};
593 ## --------------------------------------------------------
594 ## Now close all the Class::MOP::* classes
597 # we don't need to inline the
598 # constructors or the accessors
599 # this only lengthens the compile
600 # time of the MOP, and gives us
601 # no actual benefits.
603 $_->meta->make_immutable(
604 inline_constructor => 1,
605 replace_constructor => 1,
606 constructor_name => "_new",
607 inline_accessors => 0,
613 Class::MOP::Attribute
619 Class::MOP::Method::Generated
621 Class::MOP::Method::Accessor
622 Class::MOP::Method::Constructor
623 Class::MOP::Method::Wrapped
634 Class::MOP - A Meta Object Protocol for Perl 5
638 This module is a fully functioning meta object protocol for the
639 Perl 5 object system. It makes no attempt to change the behavior or
640 characteristics of the Perl 5 object system, only to create a
641 protocol for its manipulation and introspection.
643 That said, it does attempt to create the tools for building a rich
644 set of extensions to the Perl 5 object system. Every attempt has been
645 made for these tools to keep to the spirit of the Perl 5 object
646 system that we all know and love.
648 This documentation is admittedly sparse on details, as time permits
649 I will try to improve them. For now, I suggest looking at the items
650 listed in the L<SEE ALSO> section for more information. In particular
651 the book "The Art of the Meta Object Protocol" was very influential
652 in the development of this system.
654 =head2 What is a Meta Object Protocol?
656 A meta object protocol is an API to an object system.
658 To be more specific, it is a set of abstractions of the components of
659 an object system (typically things like; classes, object, methods,
660 object attributes, etc.). These abstractions can then be used to both
661 inspect and manipulate the object system which they describe.
663 It can be said that there are two MOPs for any object system; the
664 implicit MOP, and the explicit MOP. The implicit MOP handles things
665 like method dispatch or inheritance, which happen automatically as
666 part of how the object system works. The explicit MOP typically
667 handles the introspection/reflection features of the object system.
668 All object systems have implicit MOPs, without one, they would not
669 work. Explict MOPs however as less common, and depending on the
670 language can vary from restrictive (Reflection in Java or C#) to
671 wide open (CLOS is a perfect example).
673 =head2 Yet Another Class Builder!! Why?
675 This is B<not> a class builder so much as it is a I<class builder
676 B<builder>>. My intent is that an end user does not use this module
677 directly, but instead this module is used by module authors to
678 build extensions and features onto the Perl 5 object system.
680 =head2 Who is this module for?
682 This module is specifically for anyone who has ever created or
683 wanted to create a module for the Class:: namespace. The tools which
684 this module will provide will hopefully make it easier to do more
685 complex things with Perl 5 classes by removing such barriers as
686 the need to hack the symbol tables, or understand the fine details
689 =head2 What changes do I have to make to use this module?
691 This module was designed to be as unintrusive as possible. Many of
692 its features are accessible without B<any> change to your existsing
693 code at all. It is meant to be a compliment to your existing code and
694 not an intrusion on your code base. Unlike many other B<Class::>
695 modules, this module B<does not> require you subclass it, or even that
696 you C<use> it in within your module's package.
698 The only features which requires additions to your code are the
699 attribute handling and instance construction features, and these are
700 both completely optional features. The only reason for this is because
701 Perl 5's object system does not actually have these features built
702 in. More information about this feature can be found below.
704 =head2 A Note about Performance?
706 It is a common misconception that explict MOPs are performance drains.
707 But this is not a universal truth at all, it is an side-effect of
708 specific implementations. For instance, using Java reflection is much
709 slower because the JVM cannot take advantage of any compiler
710 optimizations, and the JVM has to deal with much more runtime type
711 information as well. Reflection in C# is marginally better as it was
712 designed into the language and runtime (the CLR). In contrast, CLOS
713 (the Common Lisp Object System) was built to support an explicit MOP,
714 and so performance is tuned for it.
716 This library in particular does it's absolute best to avoid putting
717 B<any> drain at all upon your code's performance. In fact, by itself
718 it does nothing to affect your existing code. So you only pay for
719 what you actually use.
721 =head2 About Metaclass compatibility
723 This module makes sure that all metaclasses created are both upwards
724 and downwards compatible. The topic of metaclass compatibility is
725 highly esoteric and is something only encountered when doing deep and
726 involved metaclass hacking. There are two basic kinds of metaclass
727 incompatibility; upwards and downwards.
729 Upwards metaclass compatibility means that the metaclass of a
730 given class is either the same as (or a subclass of) all of the
733 Downward metaclass compatibility means that the metaclasses of a
734 given class's anscestors are all either the same as (or a subclass
737 Here is a diagram showing a set of two classes (C<A> and C<B>) and
738 two metaclasses (C<Meta::A> and C<Meta::B>) which have correct
739 metaclass compatibility both upwards and downwards.
741 +---------+ +---------+
742 | Meta::A |<----| Meta::B | <....... (instance of )
743 +---------+ +---------+ <------- (inherits from)
746 +---------+ +---------+
748 +---------+ +---------+
750 As I said this is a highly esoteric topic and one you will only run
751 into if you do a lot of subclassing of B<Class::MOP::Class>. If you
752 are interested in why this is an issue see the paper
753 I<Uniform and safe metaclass composition> linked to in the
754 L<SEE ALSO> section of this document.
756 =head2 Using custom metaclasses
758 Always use the metaclass pragma when using a custom metaclass, this
759 will ensure the proper initialization order and not accidentely
760 create an incorrect type of metaclass for you. This is a very rare
761 problem, and one which can only occur if you are doing deep metaclass
762 programming. So in other words, don't worry about it.
766 The protocol is divided into 4 main sub-protocols:
770 =item The Class protocol
772 This provides a means of manipulating and introspecting a Perl 5
773 class. It handles all of symbol table hacking for you, and provides
774 a rich set of methods that go beyond simple package introspection.
776 See L<Class::MOP::Class> for more details.
778 =item The Attribute protocol
780 This provides a consistent represenation for an attribute of a
781 Perl 5 class. Since there are so many ways to create and handle
782 attributes in Perl 5 OO, this attempts to provide as much of a
783 unified approach as possible, while giving the freedom and
784 flexibility to subclass for specialization.
786 See L<Class::MOP::Attribute> for more details.
788 =item The Method protocol
790 This provides a means of manipulating and introspecting methods in
791 the Perl 5 object system. As with attributes, there are many ways to
792 approach this topic, so we try to keep it pretty basic, while still
793 making it possible to extend the system in many ways.
795 See L<Class::MOP::Method> for more details.
797 =item The Instance protocol
799 This provides a layer of abstraction for creating object instances.
800 Since the other layers use this protocol, it is relatively easy to
801 change the type of your instances from the default HASH ref to other
802 types of references. Several examples are provided in the F<examples/>
803 directory included in this distribution.
805 See L<Class::MOP::Instance> for more details.
815 =item I<IS_RUNNING_ON_5_10>
817 We set this constant depending on what version perl we are on, this
818 allows us to take advantage of new 5.10 features and stay backwards
823 Whether or not C<mro> provides C<get_isarev>, a much faster way to get all the
824 subclasses of a certain class.
828 =head2 Utility functions
832 =item B<load_class ($class_name)>
834 This will load a given C<$class_name> and if it does not have an
835 already initialized metaclass, then it will intialize one for it.
836 This function can be used in place of tricks like
837 C<eval "use $module"> or using C<require>.
839 =item B<is_class_loaded ($class_name)>
841 This will return a boolean depending on if the C<$class_name> has
844 NOTE: This does a basic check of the symbol table to try and
845 determine as best it can if the C<$class_name> is loaded, it
846 is probably correct about 99% of the time.
848 =item B<check_package_cache_flag ($pkg)>
850 This will return an integer that is managed by C<Class::MOP::Class>
851 to determine if a module's symbol table has been altered.
853 In Perl 5.10 or greater, this flag is package specific. However in
854 versions prior to 5.10, this will use the C<PL_sub_generation> variable
855 which is not package specific.
857 =item B<get_code_info ($code)>
859 This function returns two values, the name of the package the C<$code>
860 is from and the name of the C<$code> itself. This is used by several
861 elements of the MOP to detemine where a given C<$code> reference is from.
863 =item B<subname ($name, $code)>
865 B<NOTE: DO NOT USE THIS FUNCTION, IT IS FOR INTERNAL USE ONLY!>
867 If possible, we will load the L<Sub::Name> module and this will function
868 as C<Sub::Name::subname> does, otherwise it will just return the C<$code>
871 =item B<in_global_destruction>
873 If L<Devel::GlobalDestruction> is available, this returns true under global
876 Otherwise it's a constant returning false.
880 =head2 Metaclass cache functions
882 Class::MOP holds a cache of metaclasses, the following are functions
883 (B<not methods>) which can be used to access that cache. It is not
884 recommended that you mess with this, bad things could happen. But if
885 you are brave and willing to risk it, go for it.
889 =item B<get_all_metaclasses>
891 This will return an hash of all the metaclass instances that have
892 been cached by B<Class::MOP::Class> keyed by the package name.
894 =item B<get_all_metaclass_instances>
896 This will return an array of all the metaclass instances that have
897 been cached by B<Class::MOP::Class>.
899 =item B<get_all_metaclass_names>
901 This will return an array of all the metaclass names that have
902 been cached by B<Class::MOP::Class>.
904 =item B<get_metaclass_by_name ($name)>
906 This will return a cached B<Class::MOP::Class> instance of nothing
907 if no metaclass exist by that C<$name>.
909 =item B<store_metaclass_by_name ($name, $meta)>
911 This will store a metaclass in the cache at the supplied C<$key>.
913 =item B<weaken_metaclass ($name)>
915 In rare cases it is desireable to store a weakened reference in
916 the metaclass cache. This function will weaken the reference to
917 the metaclass stored in C<$name>.
919 =item B<does_metaclass_exist ($name)>
921 This will return true of there exists a metaclass stored in the
922 C<$name> key and return false otherwise.
924 =item B<remove_metaclass_by_name ($name)>
926 This will remove a the metaclass stored in the C<$name> key.
934 There are very few books out on Meta Object Protocols and Metaclasses
935 because it is such an esoteric topic. The following books are really
936 the only ones I have found. If you know of any more, B<I<please>>
937 email me and let me know, I would love to hear about them.
941 =item "The Art of the Meta Object Protocol"
943 =item "Advances in Object-Oriented Metalevel Architecture and Reflection"
945 =item "Putting MetaClasses to Work"
947 =item "Smalltalk: The Language"
955 =item Uniform and safe metaclass composition
957 An excellent paper by the people who brought us the original Traits paper.
958 This paper is on how Traits can be used to do safe metaclass composition,
959 and offers an excellent introduction section which delves into the topic of
960 metaclass compatibility.
962 L<http://www.iam.unibe.ch/~scg/Archive/Papers/Duca05ySafeMetaclassTrait.pdf>
964 =item Safe Metaclass Programming
966 This paper seems to precede the above paper, and propose a mix-in based
967 approach as opposed to the Traits based approach. Both papers have similar
968 information on the metaclass compatibility problem space.
970 L<http://citeseer.ist.psu.edu/37617.html>
978 =item The Perl 6 MetaModel work in the Pugs project
982 =item L<http://svn.openfoundry.org/pugs/perl5/Perl6-MetaModel>
984 =item L<http://svn.openfoundry.org/pugs/perl5/Perl6-ObjectSpace>
994 =item CPAN Module Review of Class::MOP
996 L<http://www.oreillynet.com/onlamp/blog/2006/06/cpan_module_review_classmop.html>
1000 =head1 SIMILAR MODULES
1002 As I have said above, this module is a class-builder-builder, so it is
1003 not the same thing as modules like L<Class::Accessor> and
1004 L<Class::MethodMaker>. That being said there are very few modules on CPAN
1005 with similar goals to this module. The one I have found which is most
1006 like this module is L<Class::Meta>, although it's philosophy and the MOP it
1007 creates are very different from this modules.
1011 All complex software has bugs lurking in it, and this module is no
1012 exception. If you find a bug please either email me, or add the bug
1015 =head1 ACKNOWLEDGEMENTS
1021 Thanks to Rob for actually getting the development of this module kick-started.
1027 Stevan Little E<lt>stevan@iinteractive.comE<gt>
1029 B<with contributions from:>
1031 Brandon (blblack) Black
1033 Guillermo (groditi) Roditi
1037 Rob (robkinyon) Kinyon
1039 Yuval (nothingmuch) Kogman
1041 Scott (konobi) McWhirter
1043 =head1 COPYRIGHT AND LICENSE
1045 Copyright 2006-2008 by Infinity Interactive, Inc.
1047 L<http://www.iinteractive.com>
1049 This library is free software; you can redistribute it and/or modify
1050 it under the same terms as Perl itself.