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.75';
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.
103 sub load_first_existing_class {
107 foreach my $class (@classes) {
108 unless ( _is_valid_class_name($class) ) {
109 my $display = defined($class) ? $class : 'undef';
110 confess "Invalid class name ($display)";
116 for my $class (@classes) {
117 my $e = _try_load_one_class($class);
120 $exceptions{$class} = $e;
128 return $found if $found;
134 "Could not load class (%s) because : %s", $_,
141 sub _try_load_one_class {
144 return if is_class_loaded($class);
146 my $file = $class . '.pm';
151 eval { require($file) };
157 my $class = load_first_existing_class($_[0]);
158 return get_metaclass_by_name($class) || $class;
161 sub _is_valid_class_name {
164 return 0 if ref($class);
165 return 0 unless defined($class);
166 return 0 unless length($class);
168 return 1 if $class =~ /^\w+(?:::\w+)*$/;
173 sub is_class_loaded {
176 return 0 unless _is_valid_class_name($class);
178 # walk the symbol table tree to avoid autovififying
179 # \*{${main::}{"Foo::"}} == \*main::Foo::
182 foreach my $part (split('::', $class)) {
183 return 0 unless exists ${$$pack}{"${part}::"};
184 $pack = \*{${$$pack}{"${part}::"}};
187 # check for $VERSION or @ISA
188 return 1 if exists ${$$pack}{VERSION}
189 && defined *{${$$pack}{VERSION}}{SCALAR};
190 return 1 if exists ${$$pack}{ISA}
191 && defined *{${$$pack}{ISA}}{ARRAY};
193 # check for any method
194 foreach ( keys %{$$pack} ) {
195 next if substr($_, -2, 2) eq '::';
197 my $glob = ${$$pack}{$_} || next;
200 if ( IS_RUNNING_ON_5_10 ) {
201 return 1 if ref $glob eq 'SCALAR';
204 return 1 if defined *{$glob}{CODE};
212 ## ----------------------------------------------------------------------------
213 ## Setting up our environment ...
214 ## ----------------------------------------------------------------------------
215 ## Class::MOP needs to have a few things in the global perl environment so
216 ## that it can operate effectively. Those things are done here.
217 ## ----------------------------------------------------------------------------
219 # ... nothing yet actually ;)
221 ## ----------------------------------------------------------------------------
223 ## ----------------------------------------------------------------------------
224 ## The code below here is to bootstrap our MOP with itself. This is also
225 ## sometimes called "tying the knot". By doing this, we make it much easier
226 ## to extend the MOP through subclassing and such since now you can use the
227 ## MOP itself to extend itself.
229 ## Yes, I know, thats weird and insane, but it's a good thing, trust me :)
230 ## ----------------------------------------------------------------------------
232 # We need to add in the meta-attributes here so that
233 # any subclass of Class::MOP::* will be able to
234 # inherit them using &construct_instance
236 ## --------------------------------------------------------
237 ## Class::MOP::Package
239 Class::MOP::Package->meta->add_attribute(
240 Class::MOP::Attribute->new('package' => (
242 # NOTE: we need to do this in order
243 # for the instance meta-object to
244 # not fall into meta-circular death
246 # we just alias the original method
247 # rather than re-produce it here
248 'name' => \&Class::MOP::Package::name
253 Class::MOP::Package->meta->add_attribute(
254 Class::MOP::Attribute->new('namespace' => (
257 # we just alias the original method
258 # rather than re-produce it here
259 'namespace' => \&Class::MOP::Package::namespace
262 default => sub { \undef }
266 ## --------------------------------------------------------
267 ## Class::MOP::Module
270 # yeah this is kind of stretching things a bit,
271 # but truthfully the version should be an attribute
272 # of the Module, the weirdness comes from having to
273 # stick to Perl 5 convention and store it in the
274 # $VERSION package variable. Basically if you just
275 # squint at it, it will look how you want it to look.
276 # Either as a package variable, or as a attribute of
277 # the metaclass, isn't abstraction great :)
279 Class::MOP::Module->meta->add_attribute(
280 Class::MOP::Attribute->new('version' => (
283 # we just alias the original method
284 # rather than re-produce it here
285 'version' => \&Class::MOP::Module::version
288 default => sub { \undef }
293 # By following the same conventions as version here,
294 # we are opening up the possibility that people can
295 # use the $AUTHORITY in non-Class::MOP modules as
298 Class::MOP::Module->meta->add_attribute(
299 Class::MOP::Attribute->new('authority' => (
302 # we just alias the original method
303 # rather than re-produce it here
304 'authority' => \&Class::MOP::Module::authority
307 default => sub { \undef }
311 ## --------------------------------------------------------
314 Class::MOP::Class->meta->add_attribute(
315 Class::MOP::Attribute->new('attributes' => (
317 # NOTE: we need to do this in order
318 # for the instance meta-object to
319 # not fall into meta-circular death
321 # we just alias the original method
322 # rather than re-produce it here
323 'get_attribute_map' => \&Class::MOP::Class::get_attribute_map
325 default => sub { {} }
329 Class::MOP::Class->meta->add_attribute(
330 Class::MOP::Attribute->new('methods' => (
333 # we just alias the original method
334 # rather than re-produce it here
335 'get_method_map' => \&Class::MOP::Class::get_method_map
337 default => sub { {} }
341 Class::MOP::Class->meta->add_attribute(
342 Class::MOP::Attribute->new('superclasses' => (
345 # we just alias the original method
346 # rather than re-produce it here
347 'superclasses' => \&Class::MOP::Class::superclasses
350 default => sub { \undef }
354 Class::MOP::Class->meta->add_attribute(
355 Class::MOP::Attribute->new('attribute_metaclass' => (
358 # we just alias the original method
359 # rather than re-produce it here
360 'attribute_metaclass' => \&Class::MOP::Class::attribute_metaclass
362 default => 'Class::MOP::Attribute',
366 Class::MOP::Class->meta->add_attribute(
367 Class::MOP::Attribute->new('method_metaclass' => (
370 # we just alias the original method
371 # rather than re-produce it here
372 'method_metaclass' => \&Class::MOP::Class::method_metaclass
374 default => 'Class::MOP::Method',
378 Class::MOP::Class->meta->add_attribute(
379 Class::MOP::Attribute->new('instance_metaclass' => (
381 # NOTE: we need to do this in order
382 # for the instance meta-object to
383 # not fall into meta-circular death
385 # we just alias the original method
386 # rather than re-produce it here
387 'instance_metaclass' => \&Class::MOP::Class::instance_metaclass
389 default => 'Class::MOP::Instance',
394 # we don't actually need to tie the knot with
395 # Class::MOP::Class here, it is actually handled
396 # within Class::MOP::Class itself in the
397 # construct_class_instance method.
399 ## --------------------------------------------------------
400 ## Class::MOP::Attribute
402 Class::MOP::Attribute->meta->add_attribute(
403 Class::MOP::Attribute->new('name' => (
405 # NOTE: we need to do this in order
406 # for the instance meta-object to
407 # not fall into meta-circular death
409 # we just alias the original method
410 # rather than re-produce it here
411 'name' => \&Class::MOP::Attribute::name
416 Class::MOP::Attribute->meta->add_attribute(
417 Class::MOP::Attribute->new('associated_class' => (
419 # NOTE: we need to do this in order
420 # for the instance meta-object to
421 # not fall into meta-circular death
423 # we just alias the original method
424 # rather than re-produce it here
425 'associated_class' => \&Class::MOP::Attribute::associated_class
430 Class::MOP::Attribute->meta->add_attribute(
431 Class::MOP::Attribute->new('accessor' => (
432 reader => { 'accessor' => \&Class::MOP::Attribute::accessor },
433 predicate => { 'has_accessor' => \&Class::MOP::Attribute::has_accessor },
437 Class::MOP::Attribute->meta->add_attribute(
438 Class::MOP::Attribute->new('reader' => (
439 reader => { 'reader' => \&Class::MOP::Attribute::reader },
440 predicate => { 'has_reader' => \&Class::MOP::Attribute::has_reader },
444 Class::MOP::Attribute->meta->add_attribute(
445 Class::MOP::Attribute->new('initializer' => (
446 reader => { 'initializer' => \&Class::MOP::Attribute::initializer },
447 predicate => { 'has_initializer' => \&Class::MOP::Attribute::has_initializer },
451 Class::MOP::Attribute->meta->add_attribute(
452 Class::MOP::Attribute->new('definition_context' => (
453 reader => { 'definition_context' => \&Class::MOP::Attribute::definition_context },
457 Class::MOP::Attribute->meta->add_attribute(
458 Class::MOP::Attribute->new('writer' => (
459 reader => { 'writer' => \&Class::MOP::Attribute::writer },
460 predicate => { 'has_writer' => \&Class::MOP::Attribute::has_writer },
464 Class::MOP::Attribute->meta->add_attribute(
465 Class::MOP::Attribute->new('predicate' => (
466 reader => { 'predicate' => \&Class::MOP::Attribute::predicate },
467 predicate => { 'has_predicate' => \&Class::MOP::Attribute::has_predicate },
471 Class::MOP::Attribute->meta->add_attribute(
472 Class::MOP::Attribute->new('clearer' => (
473 reader => { 'clearer' => \&Class::MOP::Attribute::clearer },
474 predicate => { 'has_clearer' => \&Class::MOP::Attribute::has_clearer },
478 Class::MOP::Attribute->meta->add_attribute(
479 Class::MOP::Attribute->new('builder' => (
480 reader => { 'builder' => \&Class::MOP::Attribute::builder },
481 predicate => { 'has_builder' => \&Class::MOP::Attribute::has_builder },
485 Class::MOP::Attribute->meta->add_attribute(
486 Class::MOP::Attribute->new('init_arg' => (
487 reader => { 'init_arg' => \&Class::MOP::Attribute::init_arg },
488 predicate => { 'has_init_arg' => \&Class::MOP::Attribute::has_init_arg },
492 Class::MOP::Attribute->meta->add_attribute(
493 Class::MOP::Attribute->new('default' => (
494 # default has a custom 'reader' method ...
495 predicate => { 'has_default' => \&Class::MOP::Attribute::has_default },
499 Class::MOP::Attribute->meta->add_attribute(
500 Class::MOP::Attribute->new('associated_methods' => (
501 reader => { 'associated_methods' => \&Class::MOP::Attribute::associated_methods },
502 default => sub { [] }
506 Class::MOP::Attribute->meta->add_method('clone' => sub {
508 $self->meta->clone_object($self, @_);
511 ## --------------------------------------------------------
512 ## Class::MOP::Method
513 Class::MOP::Method->meta->add_attribute(
514 Class::MOP::Attribute->new('body' => (
515 reader => { 'body' => \&Class::MOP::Method::body },
519 Class::MOP::Method->meta->add_attribute(
520 Class::MOP::Attribute->new('associated_metaclass' => (
521 reader => { 'associated_metaclass' => \&Class::MOP::Method::associated_metaclass },
525 Class::MOP::Method->meta->add_attribute(
526 Class::MOP::Attribute->new('package_name' => (
527 reader => { 'package_name' => \&Class::MOP::Method::package_name },
531 Class::MOP::Method->meta->add_attribute(
532 Class::MOP::Attribute->new('name' => (
533 reader => { 'name' => \&Class::MOP::Method::name },
537 Class::MOP::Method->meta->add_attribute(
538 Class::MOP::Attribute->new('original_method' => (
539 reader => { 'original_method' => \&Class::MOP::Method::original_method },
540 writer => { '_set_original_method' => \&Class::MOP::Method::_set_original_method },
544 Class::MOP::Method->meta->add_method('clone' => sub {
546 my $clone = $self->meta->clone_object($self, @_);
547 $clone->_set_original_method($self);
551 ## --------------------------------------------------------
552 ## Class::MOP::Method::Wrapped
555 # the way this item is initialized, this
556 # really does not follow the standard
557 # practices of attributes, but we put
558 # it here for completeness
559 Class::MOP::Method::Wrapped->meta->add_attribute(
560 Class::MOP::Attribute->new('modifier_table')
563 ## --------------------------------------------------------
564 ## Class::MOP::Method::Generated
566 Class::MOP::Method::Generated->meta->add_attribute(
567 Class::MOP::Attribute->new('is_inline' => (
568 reader => { 'is_inline' => \&Class::MOP::Method::Generated::is_inline },
573 Class::MOP::Method::Generated->meta->add_attribute(
574 Class::MOP::Attribute->new('definition_context' => (
575 reader => { 'definition_context' => \&Class::MOP::Method::Generated::definition_context },
579 ## --------------------------------------------------------
580 ## Class::MOP::Method::Accessor
582 Class::MOP::Method::Accessor->meta->add_attribute(
583 Class::MOP::Attribute->new('attribute' => (
585 'associated_attribute' => \&Class::MOP::Method::Accessor::associated_attribute
590 Class::MOP::Method::Accessor->meta->add_attribute(
591 Class::MOP::Attribute->new('accessor_type' => (
592 reader => { 'accessor_type' => \&Class::MOP::Method::Accessor::accessor_type },
596 ## --------------------------------------------------------
597 ## Class::MOP::Method::Constructor
599 Class::MOP::Method::Constructor->meta->add_attribute(
600 Class::MOP::Attribute->new('options' => (
602 'options' => \&Class::MOP::Method::Constructor::options
604 default => sub { +{} }
608 Class::MOP::Method::Constructor->meta->add_attribute(
609 Class::MOP::Attribute->new('associated_metaclass' => (
610 init_arg => "metaclass", # FIXME alias and rename
612 'associated_metaclass' => \&Class::MOP::Method::Constructor::associated_metaclass
617 ## --------------------------------------------------------
618 ## Class::MOP::Instance
621 # these don't yet do much of anything, but are just
622 # included for completeness
624 Class::MOP::Instance->meta->add_attribute(
625 Class::MOP::Attribute->new('associated_metaclass',
626 reader => { associated_metaclass => \&Class::MOP::Instance::associated_metaclass },
630 Class::MOP::Instance->meta->add_attribute(
631 Class::MOP::Attribute->new('_class_name',
633 reader => { _class_name => \&Class::MOP::Instance::_class_name },
634 #lazy => 1, # not yet supported by Class::MOP but out our version does it anyway
635 #default => sub { $_[0]->associated_metaclass->name },
639 Class::MOP::Instance->meta->add_attribute(
640 Class::MOP::Attribute->new('attributes',
641 reader => { attributes => \&Class::MOP::Instance::get_all_attributes },
645 Class::MOP::Instance->meta->add_attribute(
646 Class::MOP::Attribute->new('slots',
647 reader => { slots => \&Class::MOP::Instance::slots },
651 Class::MOP::Instance->meta->add_attribute(
652 Class::MOP::Attribute->new('slot_hash',
653 reader => { slot_hash => \&Class::MOP::Instance::slot_hash },
658 # we need the meta instance of the meta instance to be created now, in order
659 # for the constructor to be able to use it
660 Class::MOP::Instance->meta->get_meta_instance;
662 # pretend the add_method never happenned. it hasn't yet affected anything
663 undef Class::MOP::Instance->meta->{_package_cache_flag};
665 ## --------------------------------------------------------
666 ## Now close all the Class::MOP::* classes
668 # NOTE: we don't need to inline the the accessors this only lengthens
669 # the compile time of the MOP, and gives us no actual benefits.
671 $_->meta->make_immutable(
672 inline_constructor => 1,
673 replace_constructor => 1,
674 constructor_name => "_new",
675 inline_accessors => 0,
681 Class::MOP::Attribute
687 Class::MOP::Method::Generated
689 Class::MOP::Method::Accessor
690 Class::MOP::Method::Constructor
691 Class::MOP::Method::Wrapped
702 Class::MOP - A Meta Object Protocol for Perl 5
706 This module is a fully functioning meta object protocol for the
707 Perl 5 object system. It makes no attempt to change the behavior or
708 characteristics of the Perl 5 object system, only to create a
709 protocol for its manipulation and introspection.
711 That said, it does attempt to create the tools for building a rich
712 set of extensions to the Perl 5 object system. Every attempt has been
713 made for these tools to keep to the spirit of the Perl 5 object
714 system that we all know and love.
716 This documentation is admittedly sparse on details, as time permits
717 I will try to improve them. For now, I suggest looking at the items
718 listed in the L<SEE ALSO> section for more information. In particular
719 the book "The Art of the Meta Object Protocol" was very influential
720 in the development of this system.
722 =head2 What is a Meta Object Protocol?
724 A meta object protocol is an API to an object system.
726 To be more specific, it is a set of abstractions of the components of
727 an object system (typically things like; classes, object, methods,
728 object attributes, etc.). These abstractions can then be used to both
729 inspect and manipulate the object system which they describe.
731 It can be said that there are two MOPs for any object system; the
732 implicit MOP, and the explicit MOP. The implicit MOP handles things
733 like method dispatch or inheritance, which happen automatically as
734 part of how the object system works. The explicit MOP typically
735 handles the introspection/reflection features of the object system.
736 All object systems have implicit MOPs, without one, they would not
737 work. Explict MOPs however as less common, and depending on the
738 language can vary from restrictive (Reflection in Java or C#) to
739 wide open (CLOS is a perfect example).
741 =head2 Yet Another Class Builder!! Why?
743 This is B<not> a class builder so much as it is a I<class builder
744 B<builder>>. My intent is that an end user does not use this module
745 directly, but instead this module is used by module authors to
746 build extensions and features onto the Perl 5 object system.
748 =head2 Who is this module for?
750 This module is specifically for anyone who has ever created or
751 wanted to create a module for the Class:: namespace. The tools which
752 this module will provide will hopefully make it easier to do more
753 complex things with Perl 5 classes by removing such barriers as
754 the need to hack the symbol tables, or understand the fine details
757 =head2 What changes do I have to make to use this module?
759 This module was designed to be as unintrusive as possible. Many of
760 its features are accessible without B<any> change to your existsing
761 code at all. It is meant to be a compliment to your existing code and
762 not an intrusion on your code base. Unlike many other B<Class::>
763 modules, this module B<does not> require you subclass it, or even that
764 you C<use> it in within your module's package.
766 The only features which requires additions to your code are the
767 attribute handling and instance construction features, and these are
768 both completely optional features. The only reason for this is because
769 Perl 5's object system does not actually have these features built
770 in. More information about this feature can be found below.
772 =head2 A Note about Performance?
774 It is a common misconception that explict MOPs are performance drains.
775 But this is not a universal truth at all, it is an side-effect of
776 specific implementations. For instance, using Java reflection is much
777 slower because the JVM cannot take advantage of any compiler
778 optimizations, and the JVM has to deal with much more runtime type
779 information as well. Reflection in C# is marginally better as it was
780 designed into the language and runtime (the CLR). In contrast, CLOS
781 (the Common Lisp Object System) was built to support an explicit MOP,
782 and so performance is tuned for it.
784 This library in particular does it's absolute best to avoid putting
785 B<any> drain at all upon your code's performance. In fact, by itself
786 it does nothing to affect your existing code. So you only pay for
787 what you actually use.
789 =head2 About Metaclass compatibility
791 This module makes sure that all metaclasses created are both upwards
792 and downwards compatible. The topic of metaclass compatibility is
793 highly esoteric and is something only encountered when doing deep and
794 involved metaclass hacking. There are two basic kinds of metaclass
795 incompatibility; upwards and downwards.
797 Upwards metaclass compatibility means that the metaclass of a
798 given class is either the same as (or a subclass of) all of the
801 Downward metaclass compatibility means that the metaclasses of a
802 given class's anscestors are all either the same as (or a subclass
805 Here is a diagram showing a set of two classes (C<A> and C<B>) and
806 two metaclasses (C<Meta::A> and C<Meta::B>) which have correct
807 metaclass compatibility both upwards and downwards.
809 +---------+ +---------+
810 | Meta::A |<----| Meta::B | <....... (instance of )
811 +---------+ +---------+ <------- (inherits from)
814 +---------+ +---------+
816 +---------+ +---------+
818 As I said this is a highly esoteric topic and one you will only run
819 into if you do a lot of subclassing of B<Class::MOP::Class>. If you
820 are interested in why this is an issue see the paper
821 I<Uniform and safe metaclass composition> linked to in the
822 L<SEE ALSO> section of this document.
824 =head2 Using custom metaclasses
826 Always use the metaclass pragma when using a custom metaclass, this
827 will ensure the proper initialization order and not accidentely
828 create an incorrect type of metaclass for you. This is a very rare
829 problem, and one which can only occur if you are doing deep metaclass
830 programming. So in other words, don't worry about it.
834 The protocol is divided into 4 main sub-protocols:
838 =item The Class protocol
840 This provides a means of manipulating and introspecting a Perl 5
841 class. It handles all of symbol table hacking for you, and provides
842 a rich set of methods that go beyond simple package introspection.
844 See L<Class::MOP::Class> for more details.
846 =item The Attribute protocol
848 This provides a consistent represenation for an attribute of a
849 Perl 5 class. Since there are so many ways to create and handle
850 attributes in Perl 5 OO, this attempts to provide as much of a
851 unified approach as possible, while giving the freedom and
852 flexibility to subclass for specialization.
854 See L<Class::MOP::Attribute> for more details.
856 =item The Method protocol
858 This provides a means of manipulating and introspecting methods in
859 the Perl 5 object system. As with attributes, there are many ways to
860 approach this topic, so we try to keep it pretty basic, while still
861 making it possible to extend the system in many ways.
863 See L<Class::MOP::Method> for more details.
865 =item The Instance protocol
867 This provides a layer of abstraction for creating object instances.
868 Since the other layers use this protocol, it is relatively easy to
869 change the type of your instances from the default HASH ref to other
870 types of references. Several examples are provided in the F<examples/>
871 directory included in this distribution.
873 See L<Class::MOP::Instance> for more details.
883 =item I<IS_RUNNING_ON_5_10>
885 We set this constant depending on what version perl we are on, this
886 allows us to take advantage of new 5.10 features and stay backwards
891 Whether or not C<mro> provides C<get_isarev>, a much faster way to get all the
892 subclasses of a certain class.
896 =head2 Utility functions
898 Note that these are all called as B<functions, not methods>.
902 =item B<load_class ($class_name)>
904 This will load a given C<$class_name> and if it does not have an
905 already initialized metaclass, then it will intialize one for it.
906 This function can be used in place of tricks like
907 C<eval "use $module"> or using C<require>.
909 =item B<is_class_loaded ($class_name)>
911 This will return a boolean depending on if the C<$class_name> has
914 NOTE: This does a basic check of the symbol table to try and
915 determine as best it can if the C<$class_name> is loaded, it
916 is probably correct about 99% of the time.
918 =item B<check_package_cache_flag ($pkg)>
920 B<NOTE: DO NOT USE THIS FUNCTION, IT IS FOR INTERNAL USE ONLY!>
922 This will return an integer that is managed by C<Class::MOP::Class>
923 to determine if a module's symbol table has been altered.
925 In Perl 5.10 or greater, this flag is package specific. However in
926 versions prior to 5.10, this will use the C<PL_sub_generation> variable
927 which is not package specific.
929 =item B<get_code_info ($code)>
931 B<NOTE: DO NOT USE THIS FUNCTION, IT IS FOR INTERNAL USE ONLY!>
933 This function returns two values, the name of the package the C<$code>
934 is from and the name of the C<$code> itself. This is used by several
935 elements of the MOP to detemine where a given C<$code> reference is from.
937 =item B<subname ($name, $code)>
939 B<NOTE: DO NOT USE THIS FUNCTION, IT IS FOR INTERNAL USE ONLY!>
941 If possible, we will load the L<Sub::Name> module and this will function
942 as C<Sub::Name::subname> does, otherwise it will just return the C<$code>
945 =item B<in_global_destruction>
947 B<NOTE: DO NOT USE THIS FUNCTION, IT IS FOR INTERNAL USE ONLY!>
949 If L<Devel::GlobalDestruction> is available, this returns true under global
952 Otherwise it's a constant returning false.
954 =item B<load_first_existing_class ($class_name, [$class_name, ...])>
956 B<NOTE: DO NOT USE THIS FUNCTION, IT IS FOR INTERNAL USE ONLY!>
958 Given a list of class names, this function will attempt to load each
961 If it finds a class it can load, it will return that class' name.
962 If none of the classes can be loaded, it will throw an exception.
966 =head2 Metaclass cache functions
968 Class::MOP holds a cache of metaclasses. The following are functions
969 (B<not methods>) which can be used to access that cache. It is not
970 recommended that you mess with these. Bad things could happen, but if
971 you are brave and willing to risk it: go for it!
975 =item B<get_all_metaclasses>
977 This will return a hash of all the metaclass instances that have
978 been cached by B<Class::MOP::Class>, keyed by the package name.
980 =item B<get_all_metaclass_instances>
982 This will return a list of all the metaclass instances that have
983 been cached by B<Class::MOP::Class>.
985 =item B<get_all_metaclass_names>
987 This will return a list of all the metaclass names that have
988 been cached by B<Class::MOP::Class>.
990 =item B<get_metaclass_by_name ($name)>
992 This will return a cached B<Class::MOP::Class> instance, or nothing
993 if no metaclass exists with that C<$name>.
995 =item B<store_metaclass_by_name ($name, $meta)>
997 This will store a metaclass in the cache at the supplied C<$key>.
999 =item B<weaken_metaclass ($name)>
1001 In rare cases (e.g. anonymous metaclasses) it is desirable to
1002 store a weakened reference in the metaclass cache. This
1003 function will weaken the reference to the metaclass stored
1006 =item B<does_metaclass_exist ($name)>
1008 This will return true of there exists a metaclass stored in the
1009 C<$name> key, and return false otherwise.
1011 =item B<remove_metaclass_by_name ($name)>
1013 This will remove the metaclass stored in the C<$name> key.
1021 There are very few books out on Meta Object Protocols and Metaclasses
1022 because it is such an esoteric topic. The following books are really
1023 the only ones I have found. If you know of any more, B<I<please>>
1024 email me and let me know, I would love to hear about them.
1028 =item "The Art of the Meta Object Protocol"
1030 =item "Advances in Object-Oriented Metalevel Architecture and Reflection"
1032 =item "Putting MetaClasses to Work"
1034 =item "Smalltalk: The Language"
1042 =item Uniform and safe metaclass composition
1044 An excellent paper by the people who brought us the original Traits paper.
1045 This paper is on how Traits can be used to do safe metaclass composition,
1046 and offers an excellent introduction section which delves into the topic of
1047 metaclass compatibility.
1049 L<http://www.iam.unibe.ch/~scg/Archive/Papers/Duca05ySafeMetaclassTrait.pdf>
1051 =item Safe Metaclass Programming
1053 This paper seems to precede the above paper, and propose a mix-in based
1054 approach as opposed to the Traits based approach. Both papers have similar
1055 information on the metaclass compatibility problem space.
1057 L<http://citeseer.ist.psu.edu/37617.html>
1065 =item The Perl 6 MetaModel work in the Pugs project
1069 =item L<http://svn.openfoundry.org/pugs/perl5/Perl6-MetaModel>
1071 =item L<http://svn.openfoundry.org/pugs/perl5/Perl6-ObjectSpace>
1081 =item CPAN Module Review of Class::MOP
1083 L<http://www.oreillynet.com/onlamp/blog/2006/06/cpan_module_review_classmop.html>
1087 =head1 SIMILAR MODULES
1089 As I have said above, this module is a class-builder-builder, so it is
1090 not the same thing as modules like L<Class::Accessor> and
1091 L<Class::MethodMaker>. That being said there are very few modules on CPAN
1092 with similar goals to this module. The one I have found which is most
1093 like this module is L<Class::Meta>, although it's philosophy and the MOP it
1094 creates are very different from this modules.
1098 All complex software has bugs lurking in it, and this module is no
1099 exception. If you find a bug please either email me, or add the bug
1102 =head1 ACKNOWLEDGEMENTS
1108 Thanks to Rob for actually getting the development of this module kick-started.
1114 Stevan Little E<lt>stevan@iinteractive.comE<gt>
1116 B<with contributions from:>
1118 Brandon (blblack) Black
1120 Florian (rafl) Ragwitz
1122 Guillermo (groditi) Roditi
1126 Rob (robkinyon) Kinyon
1128 Yuval (nothingmuch) Kogman
1130 Scott (konobi) McWhirter
1132 =head1 COPYRIGHT AND LICENSE
1134 Copyright 2006-2008 by Infinity Interactive, Inc.
1136 L<http://www.iinteractive.com>
1138 This library is free software; you can redistribute it and/or modify
1139 it under the same terms as Perl itself.