12 use Scalar::Util 'weaken';
18 Sub::Name->import(qw(subname));
20 } or eval 'sub subname { $_[1] }';
22 # this is either part of core or set up appropriately by MRO::Compat
23 *check_package_cache_flag = \&mro::get_pkg_gen;
26 require Devel::GlobalDestruction;
27 Devel::GlobalDestruction->import("in_global_destruction");
29 } or *in_global_destruction = sub () { !1 };
33 use Class::MOP::Class;
34 use Class::MOP::Attribute;
35 use Class::MOP::Method;
37 use Class::MOP::Immutable;
40 *IS_RUNNING_ON_5_10 = ($] < 5.009_005)
44 *HAVE_ISAREV = defined(&mro::get_isarev)
49 our $VERSION = '0.65';
50 our $XS_VERSION = $VERSION;
51 $VERSION = eval $VERSION;
52 our $AUTHORITY = 'cpan:STEVAN';
54 # after that everything is loaded, if we're allowed try to load faster XS
55 # versions of various things
56 _try_load_xs() or _load_pure_perl();
59 return if $ENV{CLASS_MOP_NO_XS};
65 # just doing this - no warnings 'redefine' - doesn't work
68 __PACKAGE__->XSLoader::load($XS_VERSION);
73 die $e if $e && $e !~ /object version|loadable object/;
79 require Sub::Identify;
80 Sub::Identify->import('get_code_info');
85 # Metaclasses are singletons, so we cache them here.
86 # there is no need to worry about destruction though
87 # because they should die only when the program dies.
88 # After all, do package definitions even get reaped?
91 # means of accessing all the metaclasses that have
92 # been initialized thus far (for mugwumps obj browser)
93 sub get_all_metaclasses { %METAS }
94 sub get_all_metaclass_instances { values %METAS }
95 sub get_all_metaclass_names { keys %METAS }
96 sub get_metaclass_by_name { $METAS{$_[0]} }
97 sub store_metaclass_by_name { $METAS{$_[0]} = $_[1] }
98 sub weaken_metaclass { weaken($METAS{$_[0]}) }
99 sub does_metaclass_exist { exists $METAS{$_[0]} && defined $METAS{$_[0]} }
100 sub remove_metaclass_by_name { $METAS{$_[0]} = undef }
103 # We only cache metaclasses, meaning instances of
104 # Class::MOP::Class. We do not cache instance of
105 # Class::MOP::Package or Class::MOP::Module. Mostly
106 # because I don't yet see a good reason to do so.
112 unless ( _is_valid_class_name($class) ) {
113 my $display = defined($class) ? $class : 'undef';
114 confess "Invalid class name ($display)";
117 # if the class is not already loaded in the symbol table..
118 unless (is_class_loaded($class)) {
120 my $e = do { local $@; eval "require $class"; $@ };
121 confess "Could not load class ($class) because : $e" if $e;
124 get_metaclass_by_name($class) || $class if defined wantarray;
127 sub _is_valid_class_name {
130 return 0 if ref($class);
131 return 0 unless defined($class);
132 return 0 unless length($class);
134 return 1 if $class =~ /^\w+(?:::\w+)*$/;
139 sub is_class_loaded {
142 return 0 if ref($class) || !defined($class) || !length($class);
144 # walk the symbol table tree to avoid autovififying
145 # \*{${main::}{"Foo::"}} == \*main::Foo::
148 foreach my $part (split('::', $class)) {
149 return 0 unless exists ${$$pack}{"${part}::"};
150 $pack = \*{${$$pack}{"${part}::"}};
153 # check for $VERSION or @ISA
154 return 1 if exists ${$$pack}{VERSION}
155 && defined *{${$$pack}{VERSION}}{SCALAR};
156 return 1 if exists ${$$pack}{ISA}
157 && defined *{${$$pack}{ISA}}{ARRAY};
159 # check for any method
160 foreach ( keys %{$$pack} ) {
161 next if substr($_, -2, 2) eq '::';
163 my $glob = ${$$pack}{$_} || next;
166 if ( IS_RUNNING_ON_5_10 ) {
167 return 1 if ref $glob eq 'SCALAR';
170 return 1 if defined *{$glob}{CODE};
178 ## ----------------------------------------------------------------------------
179 ## Setting up our environment ...
180 ## ----------------------------------------------------------------------------
181 ## Class::MOP needs to have a few things in the global perl environment so
182 ## that it can operate effectively. Those things are done here.
183 ## ----------------------------------------------------------------------------
185 # ... nothing yet actually ;)
187 ## ----------------------------------------------------------------------------
189 ## ----------------------------------------------------------------------------
190 ## The code below here is to bootstrap our MOP with itself. This is also
191 ## sometimes called "tying the knot". By doing this, we make it much easier
192 ## to extend the MOP through subclassing and such since now you can use the
193 ## MOP itself to extend itself.
195 ## Yes, I know, thats weird and insane, but it's a good thing, trust me :)
196 ## ----------------------------------------------------------------------------
198 # We need to add in the meta-attributes here so that
199 # any subclass of Class::MOP::* will be able to
200 # inherit them using &construct_instance
202 ## --------------------------------------------------------
203 ## Class::MOP::Package
205 Class::MOP::Package->meta->add_attribute(
206 Class::MOP::Attribute->new('package' => (
208 # NOTE: we need to do this in order
209 # for the instance meta-object to
210 # not fall into meta-circular death
212 # we just alias the original method
213 # rather than re-produce it here
214 'name' => \&Class::MOP::Package::name
219 Class::MOP::Package->meta->add_attribute(
220 Class::MOP::Attribute->new('namespace' => (
223 # we just alias the original method
224 # rather than re-produce it here
225 'namespace' => \&Class::MOP::Package::namespace
228 default => sub { \undef }
232 ## --------------------------------------------------------
233 ## Class::MOP::Module
236 # yeah this is kind of stretching things a bit,
237 # but truthfully the version should be an attribute
238 # of the Module, the weirdness comes from having to
239 # stick to Perl 5 convention and store it in the
240 # $VERSION package variable. Basically if you just
241 # squint at it, it will look how you want it to look.
242 # Either as a package variable, or as a attribute of
243 # the metaclass, isn't abstraction great :)
245 Class::MOP::Module->meta->add_attribute(
246 Class::MOP::Attribute->new('version' => (
249 # we just alias the original method
250 # rather than re-produce it here
251 'version' => \&Class::MOP::Module::version
254 default => sub { \undef }
259 # By following the same conventions as version here,
260 # we are opening up the possibility that people can
261 # use the $AUTHORITY in non-Class::MOP modules as
264 Class::MOP::Module->meta->add_attribute(
265 Class::MOP::Attribute->new('authority' => (
268 # we just alias the original method
269 # rather than re-produce it here
270 'authority' => \&Class::MOP::Module::authority
273 default => sub { \undef }
277 ## --------------------------------------------------------
280 Class::MOP::Class->meta->add_attribute(
281 Class::MOP::Attribute->new('attributes' => (
283 # NOTE: we need to do this in order
284 # for the instance meta-object to
285 # not fall into meta-circular death
287 # we just alias the original method
288 # rather than re-produce it here
289 'get_attribute_map' => \&Class::MOP::Class::get_attribute_map
291 default => sub { {} }
295 Class::MOP::Class->meta->add_attribute(
296 Class::MOP::Attribute->new('methods' => (
299 # we just alias the original method
300 # rather than re-produce it here
301 'get_method_map' => \&Class::MOP::Class::get_method_map
303 default => sub { {} }
307 Class::MOP::Class->meta->add_attribute(
308 Class::MOP::Attribute->new('superclasses' => (
311 # we just alias the original method
312 # rather than re-produce it here
313 'superclasses' => \&Class::MOP::Class::superclasses
316 default => sub { \undef }
320 Class::MOP::Class->meta->add_attribute(
321 Class::MOP::Attribute->new('attribute_metaclass' => (
324 # we just alias the original method
325 # rather than re-produce it here
326 'attribute_metaclass' => \&Class::MOP::Class::attribute_metaclass
328 default => 'Class::MOP::Attribute',
332 Class::MOP::Class->meta->add_attribute(
333 Class::MOP::Attribute->new('method_metaclass' => (
336 # we just alias the original method
337 # rather than re-produce it here
338 'method_metaclass' => \&Class::MOP::Class::method_metaclass
340 default => 'Class::MOP::Method',
344 Class::MOP::Class->meta->add_attribute(
345 Class::MOP::Attribute->new('instance_metaclass' => (
347 # NOTE: we need to do this in order
348 # for the instance meta-object to
349 # not fall into meta-circular death
351 # we just alias the original method
352 # rather than re-produce it here
353 'instance_metaclass' => \&Class::MOP::Class::instance_metaclass
355 default => 'Class::MOP::Instance',
360 # we don't actually need to tie the knot with
361 # Class::MOP::Class here, it is actually handled
362 # within Class::MOP::Class itself in the
363 # construct_class_instance method.
365 ## --------------------------------------------------------
366 ## Class::MOP::Attribute
368 Class::MOP::Attribute->meta->add_attribute(
369 Class::MOP::Attribute->new('name' => (
371 # NOTE: we need to do this in order
372 # for the instance meta-object to
373 # not fall into meta-circular death
375 # we just alias the original method
376 # rather than re-produce it here
377 'name' => \&Class::MOP::Attribute::name
382 Class::MOP::Attribute->meta->add_attribute(
383 Class::MOP::Attribute->new('associated_class' => (
385 # NOTE: we need to do this in order
386 # for the instance meta-object to
387 # not fall into meta-circular death
389 # we just alias the original method
390 # rather than re-produce it here
391 'associated_class' => \&Class::MOP::Attribute::associated_class
396 Class::MOP::Attribute->meta->add_attribute(
397 Class::MOP::Attribute->new('accessor' => (
398 reader => { 'accessor' => \&Class::MOP::Attribute::accessor },
399 predicate => { 'has_accessor' => \&Class::MOP::Attribute::has_accessor },
403 Class::MOP::Attribute->meta->add_attribute(
404 Class::MOP::Attribute->new('reader' => (
405 reader => { 'reader' => \&Class::MOP::Attribute::reader },
406 predicate => { 'has_reader' => \&Class::MOP::Attribute::has_reader },
410 Class::MOP::Attribute->meta->add_attribute(
411 Class::MOP::Attribute->new('initializer' => (
412 reader => { 'initializer' => \&Class::MOP::Attribute::initializer },
413 predicate => { 'has_initializer' => \&Class::MOP::Attribute::has_initializer },
417 Class::MOP::Attribute->meta->add_attribute(
418 Class::MOP::Attribute->new('writer' => (
419 reader => { 'writer' => \&Class::MOP::Attribute::writer },
420 predicate => { 'has_writer' => \&Class::MOP::Attribute::has_writer },
424 Class::MOP::Attribute->meta->add_attribute(
425 Class::MOP::Attribute->new('predicate' => (
426 reader => { 'predicate' => \&Class::MOP::Attribute::predicate },
427 predicate => { 'has_predicate' => \&Class::MOP::Attribute::has_predicate },
431 Class::MOP::Attribute->meta->add_attribute(
432 Class::MOP::Attribute->new('clearer' => (
433 reader => { 'clearer' => \&Class::MOP::Attribute::clearer },
434 predicate => { 'has_clearer' => \&Class::MOP::Attribute::has_clearer },
438 Class::MOP::Attribute->meta->add_attribute(
439 Class::MOP::Attribute->new('builder' => (
440 reader => { 'builder' => \&Class::MOP::Attribute::builder },
441 predicate => { 'has_builder' => \&Class::MOP::Attribute::has_builder },
445 Class::MOP::Attribute->meta->add_attribute(
446 Class::MOP::Attribute->new('init_arg' => (
447 reader => { 'init_arg' => \&Class::MOP::Attribute::init_arg },
448 predicate => { 'has_init_arg' => \&Class::MOP::Attribute::has_init_arg },
452 Class::MOP::Attribute->meta->add_attribute(
453 Class::MOP::Attribute->new('default' => (
454 # default has a custom 'reader' method ...
455 predicate => { 'has_default' => \&Class::MOP::Attribute::has_default },
459 Class::MOP::Attribute->meta->add_attribute(
460 Class::MOP::Attribute->new('associated_methods' => (
461 reader => { 'associated_methods' => \&Class::MOP::Attribute::associated_methods },
462 default => sub { [] }
466 Class::MOP::Attribute->meta->add_method('clone' => sub {
468 $self->meta->clone_object($self, @_);
471 ## --------------------------------------------------------
472 ## Class::MOP::Method
473 Class::MOP::Method->meta->add_attribute(
474 Class::MOP::Attribute->new('body' => (
475 reader => { 'body' => \&Class::MOP::Method::body },
479 Class::MOP::Method->meta->add_attribute(
480 Class::MOP::Attribute->new('associated_metaclass' => (
481 reader => { 'associated_metaclass' => \&Class::MOP::Method::associated_metaclass },
485 Class::MOP::Method->meta->add_attribute(
486 Class::MOP::Attribute->new('package_name' => (
487 reader => { 'package_name' => \&Class::MOP::Method::package_name },
491 Class::MOP::Method->meta->add_attribute(
492 Class::MOP::Attribute->new('name' => (
493 reader => { 'name' => \&Class::MOP::Method::name },
497 Class::MOP::Method->meta->add_method('clone' => sub {
499 $self->meta->clone_object($self, @_);
502 ## --------------------------------------------------------
503 ## Class::MOP::Method::Wrapped
506 # the way this item is initialized, this
507 # really does not follow the standard
508 # practices of attributes, but we put
509 # it here for completeness
510 Class::MOP::Method::Wrapped->meta->add_attribute(
511 Class::MOP::Attribute->new('modifier_table')
514 ## --------------------------------------------------------
515 ## Class::MOP::Method::Generated
517 Class::MOP::Method::Generated->meta->add_attribute(
518 Class::MOP::Attribute->new('is_inline' => (
519 reader => { 'is_inline' => \&Class::MOP::Method::Generated::is_inline },
524 ## --------------------------------------------------------
525 ## Class::MOP::Method::Accessor
527 Class::MOP::Method::Accessor->meta->add_attribute(
528 Class::MOP::Attribute->new('attribute' => (
530 'associated_attribute' => \&Class::MOP::Method::Accessor::associated_attribute
535 Class::MOP::Method::Accessor->meta->add_attribute(
536 Class::MOP::Attribute->new('accessor_type' => (
537 reader => { 'accessor_type' => \&Class::MOP::Method::Accessor::accessor_type },
541 ## --------------------------------------------------------
542 ## Class::MOP::Method::Constructor
544 Class::MOP::Method::Constructor->meta->add_attribute(
545 Class::MOP::Attribute->new('options' => (
547 'options' => \&Class::MOP::Method::Constructor::options
549 default => sub { +{} }
553 Class::MOP::Method::Constructor->meta->add_attribute(
554 Class::MOP::Attribute->new('associated_metaclass' => (
555 init_arg => "metaclass", # FIXME alias and rename
557 'associated_metaclass' => \&Class::MOP::Method::Constructor::associated_metaclass
562 ## --------------------------------------------------------
563 ## Class::MOP::Instance
566 # these don't yet do much of anything, but are just
567 # included for completeness
569 Class::MOP::Instance->meta->add_attribute(
570 Class::MOP::Attribute->new('associated_metaclass',
571 reader => { associated_metaclass => \&Class::MOP::Instance::associated_metaclass },
575 Class::MOP::Instance->meta->add_attribute(
576 Class::MOP::Attribute->new('_class_name',
578 reader => { _class_name => \&Class::MOP::Instance::_class_name },
579 #lazy => 1, # not yet supported by Class::MOP but out our version does it anyway
580 #default => sub { $_[0]->associated_metaclass->name },
584 Class::MOP::Instance->meta->add_attribute(
585 Class::MOP::Attribute->new('attributes',
586 reader => { attributes => \&Class::MOP::Instance::get_all_attributes },
590 Class::MOP::Instance->meta->add_attribute(
591 Class::MOP::Attribute->new('slots',
592 reader => { slots => \&Class::MOP::Instance::slots },
596 Class::MOP::Instance->meta->add_attribute(
597 Class::MOP::Attribute->new('slot_hash',
598 reader => { slot_hash => \&Class::MOP::Instance::slot_hash },
603 # we need the meta instance of the meta instance to be created now, in order
604 # for the constructor to be able to use it
605 Class::MOP::Instance->meta->get_meta_instance;
607 # pretend the add_method never happenned. it hasn't yet affected anything
608 undef Class::MOP::Instance->meta->{_package_cache_flag};
610 ## --------------------------------------------------------
611 ## Now close all the Class::MOP::* classes
614 # we don't need to inline the
615 # constructors or the accessors
616 # this only lengthens the compile
617 # time of the MOP, and gives us
618 # no actual benefits.
620 $_->meta->make_immutable(
621 inline_constructor => 1,
622 replace_constructor => 1,
623 constructor_name => "_new",
624 inline_accessors => 0,
630 Class::MOP::Attribute
636 Class::MOP::Method::Generated
638 Class::MOP::Method::Accessor
639 Class::MOP::Method::Constructor
640 Class::MOP::Method::Wrapped
651 Class::MOP - A Meta Object Protocol for Perl 5
655 This module is a fully functioning meta object protocol for the
656 Perl 5 object system. It makes no attempt to change the behavior or
657 characteristics of the Perl 5 object system, only to create a
658 protocol for its manipulation and introspection.
660 That said, it does attempt to create the tools for building a rich
661 set of extensions to the Perl 5 object system. Every attempt has been
662 made for these tools to keep to the spirit of the Perl 5 object
663 system that we all know and love.
665 This documentation is admittedly sparse on details, as time permits
666 I will try to improve them. For now, I suggest looking at the items
667 listed in the L<SEE ALSO> section for more information. In particular
668 the book "The Art of the Meta Object Protocol" was very influential
669 in the development of this system.
671 =head2 What is a Meta Object Protocol?
673 A meta object protocol is an API to an object system.
675 To be more specific, it is a set of abstractions of the components of
676 an object system (typically things like; classes, object, methods,
677 object attributes, etc.). These abstractions can then be used to both
678 inspect and manipulate the object system which they describe.
680 It can be said that there are two MOPs for any object system; the
681 implicit MOP, and the explicit MOP. The implicit MOP handles things
682 like method dispatch or inheritance, which happen automatically as
683 part of how the object system works. The explicit MOP typically
684 handles the introspection/reflection features of the object system.
685 All object systems have implicit MOPs, without one, they would not
686 work. Explict MOPs however as less common, and depending on the
687 language can vary from restrictive (Reflection in Java or C#) to
688 wide open (CLOS is a perfect example).
690 =head2 Yet Another Class Builder!! Why?
692 This is B<not> a class builder so much as it is a I<class builder
693 B<builder>>. My intent is that an end user does not use this module
694 directly, but instead this module is used by module authors to
695 build extensions and features onto the Perl 5 object system.
697 =head2 Who is this module for?
699 This module is specifically for anyone who has ever created or
700 wanted to create a module for the Class:: namespace. The tools which
701 this module will provide will hopefully make it easier to do more
702 complex things with Perl 5 classes by removing such barriers as
703 the need to hack the symbol tables, or understand the fine details
706 =head2 What changes do I have to make to use this module?
708 This module was designed to be as unintrusive as possible. Many of
709 its features are accessible without B<any> change to your existsing
710 code at all. It is meant to be a compliment to your existing code and
711 not an intrusion on your code base. Unlike many other B<Class::>
712 modules, this module B<does not> require you subclass it, or even that
713 you C<use> it in within your module's package.
715 The only features which requires additions to your code are the
716 attribute handling and instance construction features, and these are
717 both completely optional features. The only reason for this is because
718 Perl 5's object system does not actually have these features built
719 in. More information about this feature can be found below.
721 =head2 A Note about Performance?
723 It is a common misconception that explict MOPs are performance drains.
724 But this is not a universal truth at all, it is an side-effect of
725 specific implementations. For instance, using Java reflection is much
726 slower because the JVM cannot take advantage of any compiler
727 optimizations, and the JVM has to deal with much more runtime type
728 information as well. Reflection in C# is marginally better as it was
729 designed into the language and runtime (the CLR). In contrast, CLOS
730 (the Common Lisp Object System) was built to support an explicit MOP,
731 and so performance is tuned for it.
733 This library in particular does it's absolute best to avoid putting
734 B<any> drain at all upon your code's performance. In fact, by itself
735 it does nothing to affect your existing code. So you only pay for
736 what you actually use.
738 =head2 About Metaclass compatibility
740 This module makes sure that all metaclasses created are both upwards
741 and downwards compatible. The topic of metaclass compatibility is
742 highly esoteric and is something only encountered when doing deep and
743 involved metaclass hacking. There are two basic kinds of metaclass
744 incompatibility; upwards and downwards.
746 Upwards metaclass compatibility means that the metaclass of a
747 given class is either the same as (or a subclass of) all of the
750 Downward metaclass compatibility means that the metaclasses of a
751 given class's anscestors are all either the same as (or a subclass
754 Here is a diagram showing a set of two classes (C<A> and C<B>) and
755 two metaclasses (C<Meta::A> and C<Meta::B>) which have correct
756 metaclass compatibility both upwards and downwards.
758 +---------+ +---------+
759 | Meta::A |<----| Meta::B | <....... (instance of )
760 +---------+ +---------+ <------- (inherits from)
763 +---------+ +---------+
765 +---------+ +---------+
767 As I said this is a highly esoteric topic and one you will only run
768 into if you do a lot of subclassing of B<Class::MOP::Class>. If you
769 are interested in why this is an issue see the paper
770 I<Uniform and safe metaclass composition> linked to in the
771 L<SEE ALSO> section of this document.
773 =head2 Using custom metaclasses
775 Always use the metaclass pragma when using a custom metaclass, this
776 will ensure the proper initialization order and not accidentely
777 create an incorrect type of metaclass for you. This is a very rare
778 problem, and one which can only occur if you are doing deep metaclass
779 programming. So in other words, don't worry about it.
783 The protocol is divided into 4 main sub-protocols:
787 =item The Class protocol
789 This provides a means of manipulating and introspecting a Perl 5
790 class. It handles all of symbol table hacking for you, and provides
791 a rich set of methods that go beyond simple package introspection.
793 See L<Class::MOP::Class> for more details.
795 =item The Attribute protocol
797 This provides a consistent represenation for an attribute of a
798 Perl 5 class. Since there are so many ways to create and handle
799 attributes in Perl 5 OO, this attempts to provide as much of a
800 unified approach as possible, while giving the freedom and
801 flexibility to subclass for specialization.
803 See L<Class::MOP::Attribute> for more details.
805 =item The Method protocol
807 This provides a means of manipulating and introspecting methods in
808 the Perl 5 object system. As with attributes, there are many ways to
809 approach this topic, so we try to keep it pretty basic, while still
810 making it possible to extend the system in many ways.
812 See L<Class::MOP::Method> for more details.
814 =item The Instance protocol
816 This provides a layer of abstraction for creating object instances.
817 Since the other layers use this protocol, it is relatively easy to
818 change the type of your instances from the default HASH ref to other
819 types of references. Several examples are provided in the F<examples/>
820 directory included in this distribution.
822 See L<Class::MOP::Instance> for more details.
832 =item I<IS_RUNNING_ON_5_10>
834 We set this constant depending on what version perl we are on, this
835 allows us to take advantage of new 5.10 features and stay backwards
840 Whether or not C<mro> provides C<get_isarev>, a much faster way to get all the
841 subclasses of a certain class.
845 =head2 Utility functions
849 =item B<load_class ($class_name)>
851 This will load a given C<$class_name> and if it does not have an
852 already initialized metaclass, then it will intialize one for it.
853 This function can be used in place of tricks like
854 C<eval "use $module"> or using C<require>.
856 =item B<is_class_loaded ($class_name)>
858 This will return a boolean depending on if the C<$class_name> has
861 NOTE: This does a basic check of the symbol table to try and
862 determine as best it can if the C<$class_name> is loaded, it
863 is probably correct about 99% of the time.
865 =item B<check_package_cache_flag ($pkg)>
867 This will return an integer that is managed by C<Class::MOP::Class>
868 to determine if a module's symbol table has been altered.
870 In Perl 5.10 or greater, this flag is package specific. However in
871 versions prior to 5.10, this will use the C<PL_sub_generation> variable
872 which is not package specific.
874 =item B<get_code_info ($code)>
876 This function returns two values, the name of the package the C<$code>
877 is from and the name of the C<$code> itself. This is used by several
878 elements of the MOP to detemine where a given C<$code> reference is from.
880 =item B<subname ($name, $code)>
882 B<NOTE: DO NOT USE THIS FUNCTION, IT IS FOR INTERNAL USE ONLY!>
884 If possible, we will load the L<Sub::Name> module and this will function
885 as C<Sub::Name::subname> does, otherwise it will just return the C<$code>
888 =item B<in_global_destruction>
890 If L<Devel::GlobalDestruction> is available, this returns true under global
893 Otherwise it's a constant returning false.
897 =head2 Metaclass cache functions
899 Class::MOP holds a cache of metaclasses, the following are functions
900 (B<not methods>) which can be used to access that cache. It is not
901 recommended that you mess with this, bad things could happen. But if
902 you are brave and willing to risk it, go for it.
906 =item B<get_all_metaclasses>
908 This will return an hash of all the metaclass instances that have
909 been cached by B<Class::MOP::Class> keyed by the package name.
911 =item B<get_all_metaclass_instances>
913 This will return an array of all the metaclass instances that have
914 been cached by B<Class::MOP::Class>.
916 =item B<get_all_metaclass_names>
918 This will return an array of all the metaclass names that have
919 been cached by B<Class::MOP::Class>.
921 =item B<get_metaclass_by_name ($name)>
923 This will return a cached B<Class::MOP::Class> instance of nothing
924 if no metaclass exist by that C<$name>.
926 =item B<store_metaclass_by_name ($name, $meta)>
928 This will store a metaclass in the cache at the supplied C<$key>.
930 =item B<weaken_metaclass ($name)>
932 In rare cases it is desireable to store a weakened reference in
933 the metaclass cache. This function will weaken the reference to
934 the metaclass stored in C<$name>.
936 =item B<does_metaclass_exist ($name)>
938 This will return true of there exists a metaclass stored in the
939 C<$name> key and return false otherwise.
941 =item B<remove_metaclass_by_name ($name)>
943 This will remove a the metaclass stored in the C<$name> key.
951 There are very few books out on Meta Object Protocols and Metaclasses
952 because it is such an esoteric topic. The following books are really
953 the only ones I have found. If you know of any more, B<I<please>>
954 email me and let me know, I would love to hear about them.
958 =item "The Art of the Meta Object Protocol"
960 =item "Advances in Object-Oriented Metalevel Architecture and Reflection"
962 =item "Putting MetaClasses to Work"
964 =item "Smalltalk: The Language"
972 =item Uniform and safe metaclass composition
974 An excellent paper by the people who brought us the original Traits paper.
975 This paper is on how Traits can be used to do safe metaclass composition,
976 and offers an excellent introduction section which delves into the topic of
977 metaclass compatibility.
979 L<http://www.iam.unibe.ch/~scg/Archive/Papers/Duca05ySafeMetaclassTrait.pdf>
981 =item Safe Metaclass Programming
983 This paper seems to precede the above paper, and propose a mix-in based
984 approach as opposed to the Traits based approach. Both papers have similar
985 information on the metaclass compatibility problem space.
987 L<http://citeseer.ist.psu.edu/37617.html>
995 =item The Perl 6 MetaModel work in the Pugs project
999 =item L<http://svn.openfoundry.org/pugs/perl5/Perl6-MetaModel>
1001 =item L<http://svn.openfoundry.org/pugs/perl5/Perl6-ObjectSpace>
1011 =item CPAN Module Review of Class::MOP
1013 L<http://www.oreillynet.com/onlamp/blog/2006/06/cpan_module_review_classmop.html>
1017 =head1 SIMILAR MODULES
1019 As I have said above, this module is a class-builder-builder, so it is
1020 not the same thing as modules like L<Class::Accessor> and
1021 L<Class::MethodMaker>. That being said there are very few modules on CPAN
1022 with similar goals to this module. The one I have found which is most
1023 like this module is L<Class::Meta>, although it's philosophy and the MOP it
1024 creates are very different from this modules.
1028 All complex software has bugs lurking in it, and this module is no
1029 exception. If you find a bug please either email me, or add the bug
1032 =head1 ACKNOWLEDGEMENTS
1038 Thanks to Rob for actually getting the development of this module kick-started.
1044 Stevan Little E<lt>stevan@iinteractive.comE<gt>
1046 B<with contributions from:>
1048 Brandon (blblack) Black
1050 Guillermo (groditi) Roditi
1054 Rob (robkinyon) Kinyon
1056 Yuval (nothingmuch) Kogman
1058 Scott (konobi) McWhirter
1060 =head1 COPYRIGHT AND LICENSE
1062 Copyright 2006-2008 by Infinity Interactive, Inc.
1064 L<http://www.iinteractive.com>
1066 This library is free software; you can redistribute it and/or modify
1067 it under the same terms as Perl itself.