Commit | Line | Data |
94b19069 |
1 | |
2 | package Class::MOP; |
3 | |
4 | use strict; |
5 | use warnings; |
6 | |
727919c5 |
7 | use Carp 'confess'; |
be7677c7 |
8 | use Scalar::Util 'weaken'; |
8b978dd5 |
9 | |
2eb717d5 |
10 | use Class::MOP::Class; |
11 | use Class::MOP::Attribute; |
12 | use Class::MOP::Method; |
13 | |
857f87a7 |
14 | use Class::MOP::Class::Immutable; |
15 | |
b1897d4d |
16 | our $VERSION = '0.35'; |
f0480c45 |
17 | our $AUTHORITY = 'cpan:STEVAN'; |
94b19069 |
18 | |
be7677c7 |
19 | { |
20 | # Metaclasses are singletons, so we cache them here. |
21 | # there is no need to worry about destruction though |
22 | # because they should die only when the program dies. |
23 | # After all, do package definitions even get reaped? |
24 | my %METAS; |
25 | |
26 | # means of accessing all the metaclasses that have |
27 | # been initialized thus far (for mugwumps obj browser) |
28 | sub get_all_metaclasses { %METAS } |
29 | sub get_all_metaclass_instances { values %METAS } |
30 | sub get_all_metaclass_names { keys %METAS } |
31 | sub get_metaclass_by_name { $METAS{$_[0]} } |
32 | sub store_metaclass_by_name { $METAS{$_[0]} = $_[1] } |
33 | sub weaken_metaclass { weaken($METAS{$_[0]}) } |
34 | sub does_metaclass_exist { exists $METAS{$_[0]} && defined $METAS{$_[0]} } |
35 | sub remove_metaclass_by_name { $METAS{$_[0]} = undef } |
36 | |
37 | # NOTE: |
38 | # We only cache metaclasses, meaning instances of |
39 | # Class::MOP::Class. We do not cache instance of |
40 | # Class::MOP::Package or Class::MOP::Module. Mostly |
41 | # because I don't yet see a good reason to do so. |
42 | } |
43 | |
aa448b16 |
44 | ## ---------------------------------------------------------------------------- |
45 | ## Setting up our environment ... |
46 | ## ---------------------------------------------------------------------------- |
47 | ## Class::MOP needs to have a few things in the global perl environment so |
48 | ## that it can operate effectively. Those things are done here. |
49 | ## ---------------------------------------------------------------------------- |
50 | |
3bf7644b |
51 | # ... nothing yet actually ;) |
8b978dd5 |
52 | |
b51af7f9 |
53 | ## ---------------------------------------------------------------------------- |
54 | ## Bootstrapping |
55 | ## ---------------------------------------------------------------------------- |
56 | ## The code below here is to bootstrap our MOP with itself. This is also |
57 | ## sometimes called "tying the knot". By doing this, we make it much easier |
58 | ## to extend the MOP through subclassing and such since now you can use the |
59 | ## MOP itself to extend itself. |
60 | ## |
61 | ## Yes, I know, thats weird and insane, but it's a good thing, trust me :) |
62 | ## ---------------------------------------------------------------------------- |
727919c5 |
63 | |
64 | # We need to add in the meta-attributes here so that |
65 | # any subclass of Class::MOP::* will be able to |
66 | # inherit them using &construct_instance |
67 | |
f0480c45 |
68 | ## -------------------------------------------------------- |
6d5355c3 |
69 | ## Class::MOP::Package |
727919c5 |
70 | |
6d5355c3 |
71 | Class::MOP::Package->meta->add_attribute( |
351bd7d4 |
72 | Class::MOP::Attribute->new('$:package' => ( |
b880e0de |
73 | reader => { |
74 | # NOTE: we need to do this in order |
75 | # for the instance meta-object to |
76 | # not fall into meta-circular death |
ce2ae40f |
77 | # |
78 | # we just alias the original method |
79 | # rather than re-produce it here |
80 | 'name' => \&Class::MOP::Package::name |
b880e0de |
81 | }, |
7b31baf4 |
82 | init_arg => ':package', |
727919c5 |
83 | )) |
84 | ); |
85 | |
a5e51f0b |
86 | Class::MOP::Package->meta->add_attribute( |
87 | Class::MOP::Attribute->new('%:namespace' => ( |
88 | reader => { |
56dcfc1a |
89 | # NOTE: |
ce2ae40f |
90 | # we just alias the original method |
91 | # rather than re-produce it here |
92 | 'namespace' => \&Class::MOP::Package::namespace |
a5e51f0b |
93 | }, |
94 | # NOTE: |
95 | # protect this from silliness |
a2ee6c61 |
96 | init_arg => '!............( DO NOT DO THIS )............!', |
c4260b45 |
97 | default => sub { \undef } |
a5e51f0b |
98 | )) |
99 | ); |
100 | |
9d6dce77 |
101 | # NOTE: |
102 | # use the metaclass to construct the meta-package |
103 | # which is a superclass of the metaclass itself :P |
104 | Class::MOP::Package->meta->add_method('initialize' => sub { |
105 | my $class = shift; |
106 | my $package_name = shift; |
107 | $class->meta->new_object(':package' => $package_name, @_); |
108 | }); |
109 | |
f0480c45 |
110 | ## -------------------------------------------------------- |
111 | ## Class::MOP::Module |
112 | |
113 | # NOTE: |
114 | # yeah this is kind of stretching things a bit, |
115 | # but truthfully the version should be an attribute |
116 | # of the Module, the weirdness comes from having to |
117 | # stick to Perl 5 convention and store it in the |
118 | # $VERSION package variable. Basically if you just |
119 | # squint at it, it will look how you want it to look. |
120 | # Either as a package variable, or as a attribute of |
121 | # the metaclass, isn't abstraction great :) |
122 | |
123 | Class::MOP::Module->meta->add_attribute( |
124 | Class::MOP::Attribute->new('$:version' => ( |
125 | reader => { |
ce2ae40f |
126 | # NOTE: |
127 | # we just alias the original method |
128 | # rather than re-produce it here |
129 | 'version' => \&Class::MOP::Module::version |
f0480c45 |
130 | }, |
131 | # NOTE: |
132 | # protect this from silliness |
133 | init_arg => '!............( DO NOT DO THIS )............!', |
c4260b45 |
134 | default => sub { \undef } |
f0480c45 |
135 | )) |
136 | ); |
137 | |
138 | # NOTE: |
139 | # By following the same conventions as version here, |
140 | # we are opening up the possibility that people can |
141 | # use the $AUTHORITY in non-Class::MOP modules as |
142 | # well. |
143 | |
144 | Class::MOP::Module->meta->add_attribute( |
145 | Class::MOP::Attribute->new('$:authority' => ( |
146 | reader => { |
ce2ae40f |
147 | # NOTE: |
148 | # we just alias the original method |
149 | # rather than re-produce it here |
150 | 'authority' => \&Class::MOP::Module::authority |
f0480c45 |
151 | }, |
152 | # NOTE: |
153 | # protect this from silliness |
154 | init_arg => '!............( DO NOT DO THIS )............!', |
c4260b45 |
155 | default => sub { \undef } |
f0480c45 |
156 | )) |
157 | ); |
158 | |
159 | ## -------------------------------------------------------- |
6d5355c3 |
160 | ## Class::MOP::Class |
161 | |
727919c5 |
162 | Class::MOP::Class->meta->add_attribute( |
351bd7d4 |
163 | Class::MOP::Attribute->new('%:attributes' => ( |
f7259199 |
164 | reader => { |
165 | # NOTE: we need to do this in order |
166 | # for the instance meta-object to |
ce2ae40f |
167 | # not fall into meta-circular death |
168 | # |
169 | # we just alias the original method |
170 | # rather than re-produce it here |
171 | 'get_attribute_map' => \&Class::MOP::Class::get_attribute_map |
f7259199 |
172 | }, |
351bd7d4 |
173 | init_arg => ':attributes', |
727919c5 |
174 | default => sub { {} } |
175 | )) |
176 | ); |
177 | |
351bd7d4 |
178 | Class::MOP::Class->meta->add_attribute( |
c4260b45 |
179 | Class::MOP::Attribute->new('%:methods' => ( |
92330ee2 |
180 | reader => { |
ce2ae40f |
181 | # NOTE: |
182 | # we just alias the original method |
183 | # rather than re-produce it here |
184 | 'get_method_map' => \&Class::MOP::Class::get_method_map |
92330ee2 |
185 | }, |
7855ddba |
186 | default => sub { {} } |
c4260b45 |
187 | )) |
188 | ); |
189 | |
190 | Class::MOP::Class->meta->add_attribute( |
351bd7d4 |
191 | Class::MOP::Attribute->new('$:attribute_metaclass' => ( |
7b31baf4 |
192 | reader => 'attribute_metaclass', |
351bd7d4 |
193 | init_arg => ':attribute_metaclass', |
194 | default => 'Class::MOP::Attribute', |
195 | )) |
196 | ); |
197 | |
198 | Class::MOP::Class->meta->add_attribute( |
199 | Class::MOP::Attribute->new('$:method_metaclass' => ( |
7b31baf4 |
200 | reader => 'method_metaclass', |
351bd7d4 |
201 | init_arg => ':method_metaclass', |
202 | default => 'Class::MOP::Method', |
203 | )) |
204 | ); |
205 | |
2bab2be6 |
206 | Class::MOP::Class->meta->add_attribute( |
207 | Class::MOP::Attribute->new('$:instance_metaclass' => ( |
b880e0de |
208 | reader => { |
209 | # NOTE: we need to do this in order |
210 | # for the instance meta-object to |
ce2ae40f |
211 | # not fall into meta-circular death |
212 | # |
213 | # we just alias the original method |
214 | # rather than re-produce it here |
215 | 'instance_metaclass' => \&Class::MOP::Class::instance_metaclass |
b880e0de |
216 | }, |
2bab2be6 |
217 | init_arg => ':instance_metaclass', |
218 | default => 'Class::MOP::Instance', |
219 | )) |
220 | ); |
221 | |
9d6dce77 |
222 | # NOTE: |
223 | # we don't actually need to tie the knot with |
224 | # Class::MOP::Class here, it is actually handled |
225 | # within Class::MOP::Class itself in the |
226 | # construct_class_instance method. |
227 | |
f0480c45 |
228 | ## -------------------------------------------------------- |
727919c5 |
229 | ## Class::MOP::Attribute |
230 | |
7b31baf4 |
231 | Class::MOP::Attribute->meta->add_attribute( |
232 | Class::MOP::Attribute->new('name' => ( |
b880e0de |
233 | reader => { |
234 | # NOTE: we need to do this in order |
235 | # for the instance meta-object to |
ce2ae40f |
236 | # not fall into meta-circular death |
237 | # |
238 | # we just alias the original method |
239 | # rather than re-produce it here |
240 | 'name' => \&Class::MOP::Attribute::name |
b880e0de |
241 | } |
7b31baf4 |
242 | )) |
243 | ); |
244 | |
245 | Class::MOP::Attribute->meta->add_attribute( |
246 | Class::MOP::Attribute->new('associated_class' => ( |
b880e0de |
247 | reader => { |
248 | # NOTE: we need to do this in order |
249 | # for the instance meta-object to |
ce2ae40f |
250 | # not fall into meta-circular death |
251 | # |
252 | # we just alias the original method |
253 | # rather than re-produce it here |
254 | 'associated_class' => \&Class::MOP::Attribute::associated_class |
b880e0de |
255 | } |
7b31baf4 |
256 | )) |
257 | ); |
258 | |
259 | Class::MOP::Attribute->meta->add_attribute( |
260 | Class::MOP::Attribute->new('accessor' => ( |
261 | reader => 'accessor', |
262 | predicate => 'has_accessor', |
263 | )) |
264 | ); |
265 | |
266 | Class::MOP::Attribute->meta->add_attribute( |
267 | Class::MOP::Attribute->new('reader' => ( |
268 | reader => 'reader', |
269 | predicate => 'has_reader', |
270 | )) |
271 | ); |
272 | |
273 | Class::MOP::Attribute->meta->add_attribute( |
274 | Class::MOP::Attribute->new('writer' => ( |
275 | reader => 'writer', |
276 | predicate => 'has_writer', |
277 | )) |
278 | ); |
279 | |
280 | Class::MOP::Attribute->meta->add_attribute( |
281 | Class::MOP::Attribute->new('predicate' => ( |
282 | reader => 'predicate', |
283 | predicate => 'has_predicate', |
284 | )) |
285 | ); |
286 | |
287 | Class::MOP::Attribute->meta->add_attribute( |
7d28758b |
288 | Class::MOP::Attribute->new('clearer' => ( |
289 | reader => 'clearer', |
290 | predicate => 'has_clearer', |
291 | )) |
292 | ); |
293 | |
294 | Class::MOP::Attribute->meta->add_attribute( |
7b31baf4 |
295 | Class::MOP::Attribute->new('init_arg' => ( |
296 | reader => 'init_arg', |
297 | predicate => 'has_init_arg', |
298 | )) |
299 | ); |
300 | |
301 | Class::MOP::Attribute->meta->add_attribute( |
302 | Class::MOP::Attribute->new('default' => ( |
303 | # default has a custom 'reader' method ... |
304 | predicate => 'has_default', |
305 | )) |
306 | ); |
307 | |
727919c5 |
308 | |
309 | # NOTE: (meta-circularity) |
310 | # This should be one of the last things done |
311 | # it will "tie the knot" with Class::MOP::Attribute |
312 | # so that it uses the attributes meta-objects |
313 | # to construct itself. |
314 | Class::MOP::Attribute->meta->add_method('new' => sub { |
315 | my $class = shift; |
316 | my $name = shift; |
317 | my %options = @_; |
318 | |
319 | (defined $name && $name) |
320 | || confess "You must provide a name for the attribute"; |
5659d76e |
321 | $options{init_arg} = $name |
322 | if not exists $options{init_arg}; |
148b4697 |
323 | |
324 | (Class::MOP::Attribute::is_default_a_coderef(\%options)) |
325 | || confess("References are not allowed as default values, you must ". |
326 | "wrap then in a CODE reference (ex: sub { [] } and not [])") |
327 | if exists $options{default} && ref $options{default}; |
651955fb |
328 | |
5659d76e |
329 | # return the new object |
330 | $class->meta->new_object(name => $name, %options); |
331 | }); |
332 | |
333 | Class::MOP::Attribute->meta->add_method('clone' => sub { |
a740253a |
334 | my $self = shift; |
a27ae83f |
335 | $self->meta->clone_object($self, @_); |
727919c5 |
336 | }); |
337 | |
f0480c45 |
338 | ## -------------------------------------------------------- |
b6164407 |
339 | ## Class::MOP::Method |
340 | |
341 | Class::MOP::Method->meta->add_attribute( |
342 | Class::MOP::Attribute->new('body' => ( |
343 | reader => 'body' |
344 | )) |
345 | ); |
346 | |
347 | ## -------------------------------------------------------- |
348 | ## Class::MOP::Method::Wrapped |
349 | |
350 | # NOTE: |
351 | # the way this item is initialized, this |
352 | # really does not follow the standard |
353 | # practices of attributes, but we put |
354 | # it here for completeness |
355 | Class::MOP::Method::Wrapped->meta->add_attribute( |
356 | Class::MOP::Attribute->new('modifier_table') |
357 | ); |
358 | |
359 | ## -------------------------------------------------------- |
86482605 |
360 | ## Class::MOP::Instance |
361 | |
362 | # NOTE: |
363 | # these don't yet do much of anything, but are just |
364 | # included for completeness |
365 | |
366 | Class::MOP::Instance->meta->add_attribute( |
367 | Class::MOP::Attribute->new('meta') |
368 | ); |
369 | |
370 | Class::MOP::Instance->meta->add_attribute( |
371 | Class::MOP::Attribute->new('slots') |
372 | ); |
373 | |
374 | ## -------------------------------------------------------- |
f0480c45 |
375 | ## Now close all the Class::MOP::* classes |
4d47b77f |
376 | |
0b9372a2 |
377 | # NOTE: |
378 | # we don't need to inline the |
379 | # constructors or the accessors |
380 | # this only lengthens the compile |
381 | # time of the MOP, and gives us |
382 | # no actual benefits. |
383 | |
384 | $_->meta->make_immutable( |
385 | inline_constructor => 0, |
386 | inline_accessors => 0, |
387 | ) for qw/ |
388 | Class::MOP::Package |
389 | Class::MOP::Module |
390 | Class::MOP::Class |
86482605 |
391 | |
0b9372a2 |
392 | Class::MOP::Attribute |
393 | Class::MOP::Method |
394 | Class::MOP::Instance |
86482605 |
395 | |
0b9372a2 |
396 | Class::MOP::Object |
397 | |
398 | Class::MOP::Attribute::Accessor |
399 | Class::MOP::Method::Wrapped |
400 | /; |
b6164407 |
401 | |
94b19069 |
402 | 1; |
403 | |
404 | __END__ |
405 | |
406 | =pod |
407 | |
408 | =head1 NAME |
409 | |
410 | Class::MOP - A Meta Object Protocol for Perl 5 |
411 | |
412 | =head1 SYNOPSIS |
413 | |
a2e85e6c |
414 | # ... This will come later, for now see |
415 | # the other SYNOPSIS for more information |
94b19069 |
416 | |
417 | =head1 DESCRIPTON |
418 | |
419 | This module is an attempt to create a meta object protocol for the |
420 | Perl 5 object system. It makes no attempt to change the behavior or |
421 | characteristics of the Perl 5 object system, only to create a |
27e31eaf |
422 | protocol for its manipulation and introspection. |
94b19069 |
423 | |
424 | That said, it does attempt to create the tools for building a rich |
425 | set of extensions to the Perl 5 object system. Every attempt has been |
426 | made for these tools to keep to the spirit of the Perl 5 object |
427 | system that we all know and love. |
428 | |
40483095 |
429 | This documentation is admittedly sparse on details, as time permits |
430 | I will try to improve them. For now, I suggest looking at the items |
431 | listed in the L<SEE ALSO> section for more information. In particular |
432 | the book "The Art of the Meta Object Protocol" was very influential |
433 | in the development of this system. |
434 | |
bfe4d0fc |
435 | =head2 What is a Meta Object Protocol? |
436 | |
437 | A meta object protocol is an API to an object system. |
438 | |
439 | To be more specific, it is a set of abstractions of the components of |
440 | an object system (typically things like; classes, object, methods, |
441 | object attributes, etc.). These abstractions can then be used to both |
442 | inspect and manipulate the object system which they describe. |
443 | |
444 | It can be said that there are two MOPs for any object system; the |
445 | implicit MOP, and the explicit MOP. The implicit MOP handles things |
446 | like method dispatch or inheritance, which happen automatically as |
447 | part of how the object system works. The explicit MOP typically |
448 | handles the introspection/reflection features of the object system. |
449 | All object systems have implicit MOPs, without one, they would not |
450 | work. Explict MOPs however as less common, and depending on the |
451 | language can vary from restrictive (Reflection in Java or C#) to |
452 | wide open (CLOS is a perfect example). |
453 | |
e16da3e6 |
454 | =head2 Yet Another Class Builder!! Why? |
455 | |
456 | This is B<not> a class builder so much as it is a I<class builder |
457 | B<builder>>. My intent is that an end user does not use this module |
458 | directly, but instead this module is used by module authors to |
459 | build extensions and features onto the Perl 5 object system. |
460 | |
94b19069 |
461 | =head2 Who is this module for? |
462 | |
463 | This module is specifically for anyone who has ever created or |
464 | wanted to create a module for the Class:: namespace. The tools which |
465 | this module will provide will hopefully make it easier to do more |
466 | complex things with Perl 5 classes by removing such barriers as |
467 | the need to hack the symbol tables, or understand the fine details |
468 | of method dispatch. |
469 | |
bfe4d0fc |
470 | =head2 What changes do I have to make to use this module? |
471 | |
2eb717d5 |
472 | This module was designed to be as unintrusive as possible. Many of |
343203ee |
473 | its features are accessible without B<any> change to your existsing |
bfe4d0fc |
474 | code at all. It is meant to be a compliment to your existing code and |
2eb717d5 |
475 | not an intrusion on your code base. Unlike many other B<Class::> |
a2e85e6c |
476 | modules, this module B<does not> require you subclass it, or even that |
477 | you C<use> it in within your module's package. |
bfe4d0fc |
478 | |
2eb717d5 |
479 | The only features which requires additions to your code are the |
480 | attribute handling and instance construction features, and these are |
a2e85e6c |
481 | both completely optional features. The only reason for this is because |
2eb717d5 |
482 | Perl 5's object system does not actually have these features built |
483 | in. More information about this feature can be found below. |
bfe4d0fc |
484 | |
485 | =head2 A Note about Performance? |
486 | |
487 | It is a common misconception that explict MOPs are performance drains. |
488 | But this is not a universal truth at all, it is an side-effect of |
489 | specific implementations. For instance, using Java reflection is much |
490 | slower because the JVM cannot take advantage of any compiler |
491 | optimizations, and the JVM has to deal with much more runtime type |
492 | information as well. Reflection in C# is marginally better as it was |
493 | designed into the language and runtime (the CLR). In contrast, CLOS |
494 | (the Common Lisp Object System) was built to support an explicit MOP, |
495 | and so performance is tuned for it. |
496 | |
497 | This library in particular does it's absolute best to avoid putting |
2eb717d5 |
498 | B<any> drain at all upon your code's performance. In fact, by itself |
499 | it does nothing to affect your existing code. So you only pay for |
500 | what you actually use. |
bfe4d0fc |
501 | |
550d56db |
502 | =head2 About Metaclass compatibility |
503 | |
504 | This module makes sure that all metaclasses created are both upwards |
505 | and downwards compatible. The topic of metaclass compatibility is |
506 | highly esoteric and is something only encountered when doing deep and |
507 | involved metaclass hacking. There are two basic kinds of metaclass |
508 | incompatibility; upwards and downwards. |
509 | |
510 | Upwards metaclass compatibility means that the metaclass of a |
511 | given class is either the same as (or a subclass of) all of the |
512 | class's ancestors. |
513 | |
514 | Downward metaclass compatibility means that the metaclasses of a |
515 | given class's anscestors are all either the same as (or a subclass |
516 | of) that metaclass. |
517 | |
518 | Here is a diagram showing a set of two classes (C<A> and C<B>) and |
519 | two metaclasses (C<Meta::A> and C<Meta::B>) which have correct |
520 | metaclass compatibility both upwards and downwards. |
521 | |
522 | +---------+ +---------+ |
523 | | Meta::A |<----| Meta::B | <....... (instance of ) |
524 | +---------+ +---------+ <------- (inherits from) |
525 | ^ ^ |
526 | : : |
527 | +---------+ +---------+ |
528 | | A |<----| B | |
529 | +---------+ +---------+ |
530 | |
531 | As I said this is a highly esoteric topic and one you will only run |
532 | into if you do a lot of subclassing of B<Class::MOP::Class>. If you |
533 | are interested in why this is an issue see the paper |
534 | I<Uniform and safe metaclass composition> linked to in the |
535 | L<SEE ALSO> section of this document. |
536 | |
aa448b16 |
537 | =head2 Using custom metaclasses |
538 | |
539 | Always use the metaclass pragma when using a custom metaclass, this |
540 | will ensure the proper initialization order and not accidentely |
541 | create an incorrect type of metaclass for you. This is a very rare |
542 | problem, and one which can only occur if you are doing deep metaclass |
543 | programming. So in other words, don't worry about it. |
544 | |
94b19069 |
545 | =head1 PROTOCOLS |
546 | |
547 | The protocol is divided into 3 main sub-protocols: |
548 | |
549 | =over 4 |
550 | |
551 | =item The Class protocol |
552 | |
553 | This provides a means of manipulating and introspecting a Perl 5 |
554 | class. It handles all of symbol table hacking for you, and provides |
555 | a rich set of methods that go beyond simple package introspection. |
556 | |
552e3d24 |
557 | See L<Class::MOP::Class> for more details. |
558 | |
94b19069 |
559 | =item The Attribute protocol |
560 | |
561 | This provides a consistent represenation for an attribute of a |
562 | Perl 5 class. Since there are so many ways to create and handle |
563 | atttributes in Perl 5 OO, this attempts to provide as much of a |
564 | unified approach as possible, while giving the freedom and |
565 | flexibility to subclass for specialization. |
566 | |
552e3d24 |
567 | See L<Class::MOP::Attribute> for more details. |
568 | |
94b19069 |
569 | =item The Method protocol |
570 | |
571 | This provides a means of manipulating and introspecting methods in |
572 | the Perl 5 object system. As with attributes, there are many ways to |
573 | approach this topic, so we try to keep it pretty basic, while still |
574 | making it possible to extend the system in many ways. |
575 | |
552e3d24 |
576 | See L<Class::MOP::Method> for more details. |
94b19069 |
577 | |
578 | =back |
579 | |
be7677c7 |
580 | =head1 FUNCTIONS |
581 | |
582 | Class::MOP holds a cache of metaclasses, the following are functions |
583 | (B<not methods>) which can be used to access that cache. It is not |
584 | recommended that you mess with this, bad things could happen. But if |
585 | you are brave and willing to risk it, go for it. |
586 | |
587 | =over 4 |
588 | |
589 | =item B<get_all_metaclasses> |
590 | |
b9d9fc0b |
591 | This will return an hash of all the metaclass instances that have |
592 | been cached by B<Class::MOP::Class> keyed by the package name. |
593 | |
be7677c7 |
594 | =item B<get_all_metaclass_instances> |
595 | |
b9d9fc0b |
596 | This will return an array of all the metaclass instances that have |
597 | been cached by B<Class::MOP::Class>. |
598 | |
be7677c7 |
599 | =item B<get_all_metaclass_names> |
600 | |
b9d9fc0b |
601 | This will return an array of all the metaclass names that have |
602 | been cached by B<Class::MOP::Class>. |
603 | |
be7677c7 |
604 | =item B<get_metaclass_by_name ($name)> |
605 | |
606 | =item B<store_metaclass_by_name ($name, $meta)> |
607 | |
608 | =item B<weaken_metaclass ($name)> |
609 | |
610 | =item B<does_metaclass_exist ($name)> |
611 | |
612 | =item B<remove_metaclass_by_name ($name)> |
613 | |
614 | =back |
615 | |
552e3d24 |
616 | =head1 SEE ALSO |
8b978dd5 |
617 | |
552e3d24 |
618 | =head2 Books |
8b978dd5 |
619 | |
a2e85e6c |
620 | There are very few books out on Meta Object Protocols and Metaclasses |
621 | because it is such an esoteric topic. The following books are really |
622 | the only ones I have found. If you know of any more, B<I<please>> |
623 | email me and let me know, I would love to hear about them. |
624 | |
8b978dd5 |
625 | =over 4 |
626 | |
552e3d24 |
627 | =item "The Art of the Meta Object Protocol" |
8b978dd5 |
628 | |
552e3d24 |
629 | =item "Advances in Object-Oriented Metalevel Architecture and Reflection" |
8b978dd5 |
630 | |
b51af7f9 |
631 | =item "Putting MetaClasses to Work" |
632 | |
a2e85e6c |
633 | =item "Smalltalk: The Language" |
634 | |
94b19069 |
635 | =back |
636 | |
550d56db |
637 | =head2 Papers |
638 | |
639 | =over 4 |
640 | |
641 | =item Uniform and safe metaclass composition |
642 | |
643 | An excellent paper by the people who brought us the original Traits paper. |
644 | This paper is on how Traits can be used to do safe metaclass composition, |
645 | and offers an excellent introduction section which delves into the topic of |
646 | metaclass compatibility. |
647 | |
648 | L<http://www.iam.unibe.ch/~scg/Archive/Papers/Duca05ySafeMetaclassTrait.pdf> |
649 | |
650 | =item Safe Metaclass Programming |
651 | |
652 | This paper seems to precede the above paper, and propose a mix-in based |
653 | approach as opposed to the Traits based approach. Both papers have similar |
654 | information on the metaclass compatibility problem space. |
655 | |
656 | L<http://citeseer.ist.psu.edu/37617.html> |
657 | |
658 | =back |
659 | |
552e3d24 |
660 | =head2 Prior Art |
8b978dd5 |
661 | |
662 | =over 4 |
663 | |
7184ca14 |
664 | =item The Perl 6 MetaModel work in the Pugs project |
8b978dd5 |
665 | |
666 | =over 4 |
667 | |
552e3d24 |
668 | =item L<http://svn.openfoundry.org/pugs/perl5/Perl6-MetaModel> |
8b978dd5 |
669 | |
552e3d24 |
670 | =item L<http://svn.openfoundry.org/pugs/perl5/Perl6-ObjectSpace> |
8b978dd5 |
671 | |
672 | =back |
673 | |
94b19069 |
674 | =back |
675 | |
a2e85e6c |
676 | =head1 SIMILAR MODULES |
677 | |
678 | As I have said above, this module is a class-builder-builder, so it is |
679 | not the same thing as modules like L<Class::Accessor> and |
680 | L<Class::MethodMaker>. That being said there are very few modules on CPAN |
681 | with similar goals to this module. The one I have found which is most |
550d56db |
682 | like this module is L<Class::Meta>, although it's philosophy and the MOP it |
683 | creates are very different from this modules. |
94b19069 |
684 | |
a2e85e6c |
685 | =head1 BUGS |
686 | |
687 | All complex software has bugs lurking in it, and this module is no |
688 | exception. If you find a bug please either email me, or add the bug |
689 | to cpan-RT. |
690 | |
22286063 |
691 | =head1 CODE COVERAGE |
692 | |
693 | I use L<Devel::Cover> to test the code coverage of my tests, below is the |
694 | L<Devel::Cover> report on this module's test suite. |
695 | |
696 | ---------------------------- ------ ------ ------ ------ ------ ------ ------ |
697 | File stmt bran cond sub pod time total |
698 | ---------------------------- ------ ------ ------ ------ ------ ------ ------ |
b9d9fc0b |
699 | Class/MOP.pm 78.0 87.5 55.6 71.4 100.0 12.4 76.8 |
700 | Class/MOP/Attribute.pm 83.4 75.6 86.7 94.4 100.0 8.9 85.2 |
701 | Class/MOP/Class.pm 96.9 75.8 43.2 98.0 100.0 55.3 83.6 |
702 | Class/MOP/Class/Immutable.pm 88.5 53.8 n/a 95.8 100.0 1.1 84.7 |
703 | Class/MOP/Instance.pm 87.9 75.0 33.3 89.7 100.0 10.1 89.1 |
704 | Class/MOP/Method.pm 97.6 60.0 57.9 76.9 100.0 1.5 82.8 |
705 | Class/MOP/Module.pm 87.5 n/a 11.1 83.3 100.0 0.3 66.7 |
706 | Class/MOP/Object.pm 100.0 n/a 33.3 100.0 100.0 0.1 89.5 |
707 | Class/MOP/Package.pm 95.1 69.0 33.3 100.0 100.0 9.9 85.5 |
708 | metaclass.pm 100.0 100.0 83.3 100.0 n/a 0.5 97.7 |
22286063 |
709 | ---------------------------- ------ ------ ------ ------ ------ ------ ------ |
b9d9fc0b |
710 | Total 91.5 72.1 48.8 90.7 100.0 100.0 84.2 |
22286063 |
711 | ---------------------------- ------ ------ ------ ------ ------ ------ ------ |
712 | |
a2e85e6c |
713 | =head1 ACKNOWLEDGEMENTS |
714 | |
715 | =over 4 |
716 | |
b9d9fc0b |
717 | =item Rob Kinyon |
a2e85e6c |
718 | |
719 | Thanks to Rob for actually getting the development of this module kick-started. |
720 | |
721 | =back |
722 | |
1a09d9cc |
723 | =head1 AUTHORS |
94b19069 |
724 | |
a2e85e6c |
725 | Stevan Little E<lt>stevan@iinteractive.comE<gt> |
552e3d24 |
726 | |
1a09d9cc |
727 | Yuval Kogman E<lt>nothingmuch@woobling.comE<gt> |
728 | |
94b19069 |
729 | =head1 COPYRIGHT AND LICENSE |
730 | |
731 | Copyright 2006 by Infinity Interactive, Inc. |
732 | |
733 | L<http://www.iinteractive.com> |
734 | |
735 | This library is free software; you can redistribute it and/or modify |
736 | it under the same terms as Perl itself. |
737 | |
738 | =cut |