12 use Scalar::Util 'weaken';
15 use Class::MOP::Class;
16 use Class::MOP::Attribute;
17 use Class::MOP::Method;
19 use Class::MOP::Immutable;
22 *IS_RUNNING_ON_5_10 = ($] < 5.009_005)
26 *HAVE_ISAREV = defined(&mro::get_isarev)
30 # this is either part of core or set up appropriately by MRO::Compat
31 *check_package_cache_flag = \&mro::get_pkg_gen;
34 our $VERSION = '0.65';
35 our $XS_VERSION = $VERSION;
36 $VERSION = eval $VERSION;
37 our $AUTHORITY = 'cpan:STEVAN';
39 # after that everything is loaded, if we're allowed try to load faster XS
40 # versions of various things
41 _try_load_xs() or _load_pure_perl();
44 return if $ENV{CLASS_MOP_NO_XS};
50 # just doing this - no warnings 'redefine' - doesn't work
53 __PACKAGE__->XSLoader::load($XS_VERSION);
56 Sub::Name->import(qw(subname));
58 require Devel::GlobalDestruction;
59 Devel::GlobalDestruction->import("in_global_destruction");
64 die $e if $e && $e !~ /object version|loadable object/;
70 require Sub::Identify;
71 Sub::Identify->import('get_code_info');
73 *subname = sub { $_[1] };
74 *in_global_destruction = sub () { !1 }
79 # Metaclasses are singletons, so we cache them here.
80 # there is no need to worry about destruction though
81 # because they should die only when the program dies.
82 # After all, do package definitions even get reaped?
85 # means of accessing all the metaclasses that have
86 # been initialized thus far (for mugwumps obj browser)
87 sub get_all_metaclasses { %METAS }
88 sub get_all_metaclass_instances { values %METAS }
89 sub get_all_metaclass_names { keys %METAS }
90 sub get_metaclass_by_name { $METAS{$_[0]} }
91 sub store_metaclass_by_name { $METAS{$_[0]} = $_[1] }
92 sub weaken_metaclass { weaken($METAS{$_[0]}) }
93 sub does_metaclass_exist { exists $METAS{$_[0]} && defined $METAS{$_[0]} }
94 sub remove_metaclass_by_name { $METAS{$_[0]} = undef }
97 # We only cache metaclasses, meaning instances of
98 # Class::MOP::Class. We do not cache instance of
99 # Class::MOP::Package or Class::MOP::Module. Mostly
100 # because I don't yet see a good reason to do so.
106 unless ( _is_valid_class_name($class) ) {
107 my $display = defined($class) ? $class : 'undef';
108 confess "Invalid class name ($display)";
111 # if the class is not already loaded in the symbol table..
112 unless (is_class_loaded($class)) {
114 my $e = do { local $@; eval "require $class"; $@ };
115 confess "Could not load class ($class) because : $e" if $e;
118 get_metaclass_by_name($class) || $class if defined wantarray;
121 sub _is_valid_class_name {
124 return 0 if ref($class);
125 return 0 unless defined($class);
126 return 0 unless length($class);
128 return 1 if $class =~ /^\w+(?:::\w+)*$/;
133 sub is_class_loaded {
136 return 0 if ref($class) || !defined($class) || !length($class);
138 # walk the symbol table tree to avoid autovififying
139 # \*{${main::}{"Foo::"}} == \*main::Foo::
142 foreach my $part (split('::', $class)) {
143 return 0 unless exists ${$$pack}{"${part}::"};
144 $pack = \*{${$$pack}{"${part}::"}};
147 # check for $VERSION or @ISA
148 return 1 if exists ${$$pack}{VERSION}
149 && defined *{${$$pack}{VERSION}}{SCALAR};
150 return 1 if exists ${$$pack}{ISA}
151 && defined *{${$$pack}{ISA}}{ARRAY};
153 # check for any method
154 foreach ( keys %{$$pack} ) {
155 next if substr($_, -2, 2) eq '::';
157 my $glob = ${$$pack}{$_} || next;
160 if ( IS_RUNNING_ON_5_10 ) {
161 return 1 if ref $glob eq 'SCALAR';
164 return 1 if defined *{$glob}{CODE};
172 ## ----------------------------------------------------------------------------
173 ## Setting up our environment ...
174 ## ----------------------------------------------------------------------------
175 ## Class::MOP needs to have a few things in the global perl environment so
176 ## that it can operate effectively. Those things are done here.
177 ## ----------------------------------------------------------------------------
179 # ... nothing yet actually ;)
181 ## ----------------------------------------------------------------------------
183 ## ----------------------------------------------------------------------------
184 ## The code below here is to bootstrap our MOP with itself. This is also
185 ## sometimes called "tying the knot". By doing this, we make it much easier
186 ## to extend the MOP through subclassing and such since now you can use the
187 ## MOP itself to extend itself.
189 ## Yes, I know, thats weird and insane, but it's a good thing, trust me :)
190 ## ----------------------------------------------------------------------------
192 # We need to add in the meta-attributes here so that
193 # any subclass of Class::MOP::* will be able to
194 # inherit them using &construct_instance
196 ## --------------------------------------------------------
197 ## Class::MOP::Package
199 Class::MOP::Package->meta->add_attribute(
200 Class::MOP::Attribute->new('package' => (
202 # NOTE: we need to do this in order
203 # for the instance meta-object to
204 # not fall into meta-circular death
206 # we just alias the original method
207 # rather than re-produce it here
208 'name' => \&Class::MOP::Package::name
213 Class::MOP::Package->meta->add_attribute(
214 Class::MOP::Attribute->new('namespace' => (
217 # we just alias the original method
218 # rather than re-produce it here
219 'namespace' => \&Class::MOP::Package::namespace
222 default => sub { \undef }
226 ## --------------------------------------------------------
227 ## Class::MOP::Module
230 # yeah this is kind of stretching things a bit,
231 # but truthfully the version should be an attribute
232 # of the Module, the weirdness comes from having to
233 # stick to Perl 5 convention and store it in the
234 # $VERSION package variable. Basically if you just
235 # squint at it, it will look how you want it to look.
236 # Either as a package variable, or as a attribute of
237 # the metaclass, isn't abstraction great :)
239 Class::MOP::Module->meta->add_attribute(
240 Class::MOP::Attribute->new('version' => (
243 # we just alias the original method
244 # rather than re-produce it here
245 'version' => \&Class::MOP::Module::version
248 default => sub { \undef }
253 # By following the same conventions as version here,
254 # we are opening up the possibility that people can
255 # use the $AUTHORITY in non-Class::MOP modules as
258 Class::MOP::Module->meta->add_attribute(
259 Class::MOP::Attribute->new('authority' => (
262 # we just alias the original method
263 # rather than re-produce it here
264 'authority' => \&Class::MOP::Module::authority
267 default => sub { \undef }
271 ## --------------------------------------------------------
274 Class::MOP::Class->meta->add_attribute(
275 Class::MOP::Attribute->new('attributes' => (
277 # NOTE: we need to do this in order
278 # for the instance meta-object to
279 # not fall into meta-circular death
281 # we just alias the original method
282 # rather than re-produce it here
283 'get_attribute_map' => \&Class::MOP::Class::get_attribute_map
285 default => sub { {} }
289 Class::MOP::Class->meta->add_attribute(
290 Class::MOP::Attribute->new('methods' => (
293 # we just alias the original method
294 # rather than re-produce it here
295 'get_method_map' => \&Class::MOP::Class::get_method_map
297 default => sub { {} }
301 Class::MOP::Class->meta->add_attribute(
302 Class::MOP::Attribute->new('superclasses' => (
305 # we just alias the original method
306 # rather than re-produce it here
307 'superclasses' => \&Class::MOP::Class::superclasses
310 default => sub { \undef }
314 Class::MOP::Class->meta->add_attribute(
315 Class::MOP::Attribute->new('attribute_metaclass' => (
318 # we just alias the original method
319 # rather than re-produce it here
320 'attribute_metaclass' => \&Class::MOP::Class::attribute_metaclass
322 default => 'Class::MOP::Attribute',
326 Class::MOP::Class->meta->add_attribute(
327 Class::MOP::Attribute->new('method_metaclass' => (
330 # we just alias the original method
331 # rather than re-produce it here
332 'method_metaclass' => \&Class::MOP::Class::method_metaclass
334 default => 'Class::MOP::Method',
338 Class::MOP::Class->meta->add_attribute(
339 Class::MOP::Attribute->new('instance_metaclass' => (
341 # NOTE: we need to do this in order
342 # for the instance meta-object to
343 # not fall into meta-circular death
345 # we just alias the original method
346 # rather than re-produce it here
347 'instance_metaclass' => \&Class::MOP::Class::instance_metaclass
349 default => 'Class::MOP::Instance',
354 # we don't actually need to tie the knot with
355 # Class::MOP::Class here, it is actually handled
356 # within Class::MOP::Class itself in the
357 # construct_class_instance method.
359 ## --------------------------------------------------------
360 ## Class::MOP::Attribute
362 Class::MOP::Attribute->meta->add_attribute(
363 Class::MOP::Attribute->new('name' => (
365 # NOTE: we need to do this in order
366 # for the instance meta-object to
367 # not fall into meta-circular death
369 # we just alias the original method
370 # rather than re-produce it here
371 'name' => \&Class::MOP::Attribute::name
376 Class::MOP::Attribute->meta->add_attribute(
377 Class::MOP::Attribute->new('associated_class' => (
379 # NOTE: we need to do this in order
380 # for the instance meta-object to
381 # not fall into meta-circular death
383 # we just alias the original method
384 # rather than re-produce it here
385 'associated_class' => \&Class::MOP::Attribute::associated_class
390 Class::MOP::Attribute->meta->add_attribute(
391 Class::MOP::Attribute->new('accessor' => (
392 reader => { 'accessor' => \&Class::MOP::Attribute::accessor },
393 predicate => { 'has_accessor' => \&Class::MOP::Attribute::has_accessor },
397 Class::MOP::Attribute->meta->add_attribute(
398 Class::MOP::Attribute->new('reader' => (
399 reader => { 'reader' => \&Class::MOP::Attribute::reader },
400 predicate => { 'has_reader' => \&Class::MOP::Attribute::has_reader },
404 Class::MOP::Attribute->meta->add_attribute(
405 Class::MOP::Attribute->new('initializer' => (
406 reader => { 'initializer' => \&Class::MOP::Attribute::initializer },
407 predicate => { 'has_initializer' => \&Class::MOP::Attribute::has_initializer },
411 Class::MOP::Attribute->meta->add_attribute(
412 Class::MOP::Attribute->new('writer' => (
413 reader => { 'writer' => \&Class::MOP::Attribute::writer },
414 predicate => { 'has_writer' => \&Class::MOP::Attribute::has_writer },
418 Class::MOP::Attribute->meta->add_attribute(
419 Class::MOP::Attribute->new('predicate' => (
420 reader => { 'predicate' => \&Class::MOP::Attribute::predicate },
421 predicate => { 'has_predicate' => \&Class::MOP::Attribute::has_predicate },
425 Class::MOP::Attribute->meta->add_attribute(
426 Class::MOP::Attribute->new('clearer' => (
427 reader => { 'clearer' => \&Class::MOP::Attribute::clearer },
428 predicate => { 'has_clearer' => \&Class::MOP::Attribute::has_clearer },
432 Class::MOP::Attribute->meta->add_attribute(
433 Class::MOP::Attribute->new('builder' => (
434 reader => { 'builder' => \&Class::MOP::Attribute::builder },
435 predicate => { 'has_builder' => \&Class::MOP::Attribute::has_builder },
439 Class::MOP::Attribute->meta->add_attribute(
440 Class::MOP::Attribute->new('init_arg' => (
441 reader => { 'init_arg' => \&Class::MOP::Attribute::init_arg },
442 predicate => { 'has_init_arg' => \&Class::MOP::Attribute::has_init_arg },
446 Class::MOP::Attribute->meta->add_attribute(
447 Class::MOP::Attribute->new('default' => (
448 # default has a custom 'reader' method ...
449 predicate => { 'has_default' => \&Class::MOP::Attribute::has_default },
453 Class::MOP::Attribute->meta->add_attribute(
454 Class::MOP::Attribute->new('associated_methods' => (
455 reader => { 'associated_methods' => \&Class::MOP::Attribute::associated_methods },
456 default => sub { [] }
460 Class::MOP::Attribute->meta->add_method('clone' => sub {
462 $self->meta->clone_object($self, @_);
465 ## --------------------------------------------------------
466 ## Class::MOP::Method
467 Class::MOP::Method->meta->add_attribute(
468 Class::MOP::Attribute->new('body' => (
469 reader => { 'body' => \&Class::MOP::Method::body },
473 Class::MOP::Method->meta->add_attribute(
474 Class::MOP::Attribute->new('associated_metaclass' => (
475 reader => { 'associated_metaclass' => \&Class::MOP::Method::associated_metaclass },
479 Class::MOP::Method->meta->add_attribute(
480 Class::MOP::Attribute->new('package_name' => (
481 reader => { 'package_name' => \&Class::MOP::Method::package_name },
485 Class::MOP::Method->meta->add_attribute(
486 Class::MOP::Attribute->new('name' => (
487 reader => { 'name' => \&Class::MOP::Method::name },
491 Class::MOP::Method->meta->add_method('clone' => sub {
493 $self->meta->clone_object($self, @_);
496 ## --------------------------------------------------------
497 ## Class::MOP::Method::Wrapped
500 # the way this item is initialized, this
501 # really does not follow the standard
502 # practices of attributes, but we put
503 # it here for completeness
504 Class::MOP::Method::Wrapped->meta->add_attribute(
505 Class::MOP::Attribute->new('modifier_table')
508 ## --------------------------------------------------------
509 ## Class::MOP::Method::Generated
511 Class::MOP::Method::Generated->meta->add_attribute(
512 Class::MOP::Attribute->new('is_inline' => (
513 reader => { 'is_inline' => \&Class::MOP::Method::Generated::is_inline },
518 ## --------------------------------------------------------
519 ## Class::MOP::Method::Accessor
521 Class::MOP::Method::Accessor->meta->add_attribute(
522 Class::MOP::Attribute->new('attribute' => (
524 'associated_attribute' => \&Class::MOP::Method::Accessor::associated_attribute
529 Class::MOP::Method::Accessor->meta->add_attribute(
530 Class::MOP::Attribute->new('accessor_type' => (
531 reader => { 'accessor_type' => \&Class::MOP::Method::Accessor::accessor_type },
535 ## --------------------------------------------------------
536 ## Class::MOP::Method::Constructor
538 Class::MOP::Method::Constructor->meta->add_attribute(
539 Class::MOP::Attribute->new('options' => (
541 'options' => \&Class::MOP::Method::Constructor::options
543 default => sub { +{} }
547 Class::MOP::Method::Constructor->meta->add_attribute(
548 Class::MOP::Attribute->new('associated_metaclass' => (
549 init_arg => "metaclass", # FIXME alias and rename
551 'associated_metaclass' => \&Class::MOP::Method::Constructor::associated_metaclass
556 ## --------------------------------------------------------
557 ## Class::MOP::Instance
560 # these don't yet do much of anything, but are just
561 # included for completeness
563 Class::MOP::Instance->meta->add_attribute(
564 Class::MOP::Attribute->new('associated_metaclass',
565 reader => { associated_metaclass => \&Class::MOP::Instance::associated_metaclass },
569 Class::MOP::Instance->meta->add_attribute(
570 Class::MOP::Attribute->new('_class_name',
572 reader => { _class_name => \&Class::MOP::Instance::_class_name },
573 #lazy => 1, # not yet supported by Class::MOP but out our version does it anyway
574 #default => sub { $_[0]->associated_metaclass->name },
578 Class::MOP::Instance->meta->add_attribute(
579 Class::MOP::Attribute->new('attributes',
580 reader => { attributes => \&Class::MOP::Instance::get_all_attributes },
584 Class::MOP::Instance->meta->add_attribute(
585 Class::MOP::Attribute->new('slots',
586 reader => { slots => \&Class::MOP::Instance::slots },
590 Class::MOP::Instance->meta->add_attribute(
591 Class::MOP::Attribute->new('slot_hash',
592 reader => { slot_hash => \&Class::MOP::Instance::slot_hash },
597 # we need the meta instance of the meta instance to be created now, in order
598 # for the constructor to be able to use it
599 Class::MOP::Instance->meta->get_meta_instance;
601 # pretend the add_method never happenned. it hasn't yet affected anything
602 undef Class::MOP::Instance->meta->{_package_cache_flag};
604 ## --------------------------------------------------------
605 ## Now close all the Class::MOP::* classes
608 # we don't need to inline the
609 # constructors or the accessors
610 # this only lengthens the compile
611 # time of the MOP, and gives us
612 # no actual benefits.
614 $_->meta->make_immutable(
615 inline_constructor => 1,
616 replace_constructor => 1,
617 constructor_name => "_new",
618 inline_accessors => 0,
624 Class::MOP::Attribute
630 Class::MOP::Method::Generated
632 Class::MOP::Method::Accessor
633 Class::MOP::Method::Constructor
634 Class::MOP::Method::Wrapped
645 Class::MOP - A Meta Object Protocol for Perl 5
649 This module is a fully functioning meta object protocol for the
650 Perl 5 object system. It makes no attempt to change the behavior or
651 characteristics of the Perl 5 object system, only to create a
652 protocol for its manipulation and introspection.
654 That said, it does attempt to create the tools for building a rich
655 set of extensions to the Perl 5 object system. Every attempt has been
656 made for these tools to keep to the spirit of the Perl 5 object
657 system that we all know and love.
659 This documentation is admittedly sparse on details, as time permits
660 I will try to improve them. For now, I suggest looking at the items
661 listed in the L<SEE ALSO> section for more information. In particular
662 the book "The Art of the Meta Object Protocol" was very influential
663 in the development of this system.
665 =head2 What is a Meta Object Protocol?
667 A meta object protocol is an API to an object system.
669 To be more specific, it is a set of abstractions of the components of
670 an object system (typically things like; classes, object, methods,
671 object attributes, etc.). These abstractions can then be used to both
672 inspect and manipulate the object system which they describe.
674 It can be said that there are two MOPs for any object system; the
675 implicit MOP, and the explicit MOP. The implicit MOP handles things
676 like method dispatch or inheritance, which happen automatically as
677 part of how the object system works. The explicit MOP typically
678 handles the introspection/reflection features of the object system.
679 All object systems have implicit MOPs, without one, they would not
680 work. Explict MOPs however as less common, and depending on the
681 language can vary from restrictive (Reflection in Java or C#) to
682 wide open (CLOS is a perfect example).
684 =head2 Yet Another Class Builder!! Why?
686 This is B<not> a class builder so much as it is a I<class builder
687 B<builder>>. My intent is that an end user does not use this module
688 directly, but instead this module is used by module authors to
689 build extensions and features onto the Perl 5 object system.
691 =head2 Who is this module for?
693 This module is specifically for anyone who has ever created or
694 wanted to create a module for the Class:: namespace. The tools which
695 this module will provide will hopefully make it easier to do more
696 complex things with Perl 5 classes by removing such barriers as
697 the need to hack the symbol tables, or understand the fine details
700 =head2 What changes do I have to make to use this module?
702 This module was designed to be as unintrusive as possible. Many of
703 its features are accessible without B<any> change to your existsing
704 code at all. It is meant to be a compliment to your existing code and
705 not an intrusion on your code base. Unlike many other B<Class::>
706 modules, this module B<does not> require you subclass it, or even that
707 you C<use> it in within your module's package.
709 The only features which requires additions to your code are the
710 attribute handling and instance construction features, and these are
711 both completely optional features. The only reason for this is because
712 Perl 5's object system does not actually have these features built
713 in. More information about this feature can be found below.
715 =head2 A Note about Performance?
717 It is a common misconception that explict MOPs are performance drains.
718 But this is not a universal truth at all, it is an side-effect of
719 specific implementations. For instance, using Java reflection is much
720 slower because the JVM cannot take advantage of any compiler
721 optimizations, and the JVM has to deal with much more runtime type
722 information as well. Reflection in C# is marginally better as it was
723 designed into the language and runtime (the CLR). In contrast, CLOS
724 (the Common Lisp Object System) was built to support an explicit MOP,
725 and so performance is tuned for it.
727 This library in particular does it's absolute best to avoid putting
728 B<any> drain at all upon your code's performance. In fact, by itself
729 it does nothing to affect your existing code. So you only pay for
730 what you actually use.
732 =head2 About Metaclass compatibility
734 This module makes sure that all metaclasses created are both upwards
735 and downwards compatible. The topic of metaclass compatibility is
736 highly esoteric and is something only encountered when doing deep and
737 involved metaclass hacking. There are two basic kinds of metaclass
738 incompatibility; upwards and downwards.
740 Upwards metaclass compatibility means that the metaclass of a
741 given class is either the same as (or a subclass of) all of the
744 Downward metaclass compatibility means that the metaclasses of a
745 given class's anscestors are all either the same as (or a subclass
748 Here is a diagram showing a set of two classes (C<A> and C<B>) and
749 two metaclasses (C<Meta::A> and C<Meta::B>) which have correct
750 metaclass compatibility both upwards and downwards.
752 +---------+ +---------+
753 | Meta::A |<----| Meta::B | <....... (instance of )
754 +---------+ +---------+ <------- (inherits from)
757 +---------+ +---------+
759 +---------+ +---------+
761 As I said this is a highly esoteric topic and one you will only run
762 into if you do a lot of subclassing of B<Class::MOP::Class>. If you
763 are interested in why this is an issue see the paper
764 I<Uniform and safe metaclass composition> linked to in the
765 L<SEE ALSO> section of this document.
767 =head2 Using custom metaclasses
769 Always use the metaclass pragma when using a custom metaclass, this
770 will ensure the proper initialization order and not accidentely
771 create an incorrect type of metaclass for you. This is a very rare
772 problem, and one which can only occur if you are doing deep metaclass
773 programming. So in other words, don't worry about it.
777 The protocol is divided into 4 main sub-protocols:
781 =item The Class protocol
783 This provides a means of manipulating and introspecting a Perl 5
784 class. It handles all of symbol table hacking for you, and provides
785 a rich set of methods that go beyond simple package introspection.
787 See L<Class::MOP::Class> for more details.
789 =item The Attribute protocol
791 This provides a consistent represenation for an attribute of a
792 Perl 5 class. Since there are so many ways to create and handle
793 attributes in Perl 5 OO, this attempts to provide as much of a
794 unified approach as possible, while giving the freedom and
795 flexibility to subclass for specialization.
797 See L<Class::MOP::Attribute> for more details.
799 =item The Method protocol
801 This provides a means of manipulating and introspecting methods in
802 the Perl 5 object system. As with attributes, there are many ways to
803 approach this topic, so we try to keep it pretty basic, while still
804 making it possible to extend the system in many ways.
806 See L<Class::MOP::Method> for more details.
808 =item The Instance protocol
810 This provides a layer of abstraction for creating object instances.
811 Since the other layers use this protocol, it is relatively easy to
812 change the type of your instances from the default HASH ref to other
813 types of references. Several examples are provided in the F<examples/>
814 directory included in this distribution.
816 See L<Class::MOP::Instance> for more details.
826 =item I<IS_RUNNING_ON_5_10>
828 We set this constant depending on what version perl we are on, this
829 allows us to take advantage of new 5.10 features and stay backwards
834 Whether or not C<mro> provides C<get_isarev>, a much faster way to get all the
835 subclasses of a certain class.
839 =head2 Utility functions
841 Note that these are all called as B<functions, not methods>.
845 =item B<load_class ($class_name)>
847 This will load a given C<$class_name> and if it does not have an
848 already initialized metaclass, then it will intialize one for it.
849 This function can be used in place of tricks like
850 C<eval "use $module"> or using C<require>.
852 =item B<is_class_loaded ($class_name)>
854 This will return a boolean depending on if the C<$class_name> has
857 NOTE: This does a basic check of the symbol table to try and
858 determine as best it can if the C<$class_name> is loaded, it
859 is probably correct about 99% of the time.
861 =item B<check_package_cache_flag ($pkg)>
863 B<NOTE: DO NOT USE THIS FUNCTION, IT IS FOR INTERNAL USE ONLY!>
865 This will return an integer that is managed by C<Class::MOP::Class>
866 to determine if a module's symbol table has been altered.
868 In Perl 5.10 or greater, this flag is package specific. However in
869 versions prior to 5.10, this will use the C<PL_sub_generation> variable
870 which is not package specific.
872 =item B<get_code_info ($code)>
874 B<NOTE: DO NOT USE THIS FUNCTION, IT IS FOR INTERNAL USE ONLY!>
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 B<NOTE: DO NOT USE THIS FUNCTION, IT IS FOR INTERNAL USE ONLY!>
892 If L<Devel::GlobalDestruction> is available, this returns true under global
895 Otherwise it's a constant returning false.
899 =head2 Metaclass cache functions
901 Class::MOP holds a cache of metaclasses, the following are functions
902 (B<not methods>) which can be used to access that cache. It is not
903 recommended that you mess with this, bad things could happen. But if
904 you are brave and willing to risk it, go for it.
908 =item B<get_all_metaclasses>
910 This will return an hash of all the metaclass instances that have
911 been cached by B<Class::MOP::Class> keyed by the package name.
913 =item B<get_all_metaclass_instances>
915 This will return an array of all the metaclass instances that have
916 been cached by B<Class::MOP::Class>.
918 =item B<get_all_metaclass_names>
920 This will return an array of all the metaclass names that have
921 been cached by B<Class::MOP::Class>.
923 =item B<get_metaclass_by_name ($name)>
925 This will return a cached B<Class::MOP::Class> instance of nothing
926 if no metaclass exist by that C<$name>.
928 =item B<store_metaclass_by_name ($name, $meta)>
930 This will store a metaclass in the cache at the supplied C<$key>.
932 =item B<weaken_metaclass ($name)>
934 In rare cases it is desireable to store a weakened reference in
935 the metaclass cache. This function will weaken the reference to
936 the metaclass stored in C<$name>.
938 =item B<does_metaclass_exist ($name)>
940 This will return true of there exists a metaclass stored in the
941 C<$name> key and return false otherwise.
943 =item B<remove_metaclass_by_name ($name)>
945 This will remove a the metaclass stored in the C<$name> key.
953 There are very few books out on Meta Object Protocols and Metaclasses
954 because it is such an esoteric topic. The following books are really
955 the only ones I have found. If you know of any more, B<I<please>>
956 email me and let me know, I would love to hear about them.
960 =item "The Art of the Meta Object Protocol"
962 =item "Advances in Object-Oriented Metalevel Architecture and Reflection"
964 =item "Putting MetaClasses to Work"
966 =item "Smalltalk: The Language"
974 =item Uniform and safe metaclass composition
976 An excellent paper by the people who brought us the original Traits paper.
977 This paper is on how Traits can be used to do safe metaclass composition,
978 and offers an excellent introduction section which delves into the topic of
979 metaclass compatibility.
981 L<http://www.iam.unibe.ch/~scg/Archive/Papers/Duca05ySafeMetaclassTrait.pdf>
983 =item Safe Metaclass Programming
985 This paper seems to precede the above paper, and propose a mix-in based
986 approach as opposed to the Traits based approach. Both papers have similar
987 information on the metaclass compatibility problem space.
989 L<http://citeseer.ist.psu.edu/37617.html>
997 =item The Perl 6 MetaModel work in the Pugs project
1001 =item L<http://svn.openfoundry.org/pugs/perl5/Perl6-MetaModel>
1003 =item L<http://svn.openfoundry.org/pugs/perl5/Perl6-ObjectSpace>
1013 =item CPAN Module Review of Class::MOP
1015 L<http://www.oreillynet.com/onlamp/blog/2006/06/cpan_module_review_classmop.html>
1019 =head1 SIMILAR MODULES
1021 As I have said above, this module is a class-builder-builder, so it is
1022 not the same thing as modules like L<Class::Accessor> and
1023 L<Class::MethodMaker>. That being said there are very few modules on CPAN
1024 with similar goals to this module. The one I have found which is most
1025 like this module is L<Class::Meta>, although it's philosophy and the MOP it
1026 creates are very different from this modules.
1030 All complex software has bugs lurking in it, and this module is no
1031 exception. If you find a bug please either email me, or add the bug
1034 =head1 ACKNOWLEDGEMENTS
1040 Thanks to Rob for actually getting the development of this module kick-started.
1046 Stevan Little E<lt>stevan@iinteractive.comE<gt>
1048 B<with contributions from:>
1050 Brandon (blblack) Black
1052 Guillermo (groditi) Roditi
1056 Rob (robkinyon) Kinyon
1058 Yuval (nothingmuch) Kogman
1060 Scott (konobi) McWhirter
1062 =head1 COPYRIGHT AND LICENSE
1064 Copyright 2006-2008 by Infinity Interactive, Inc.
1066 L<http://www.iinteractive.com>
1068 This library is free software; you can redistribute it and/or modify
1069 it under the same terms as Perl itself.