Commit | Line | Data |
94b19069 |
1 | |
2 | package Class::MOP; |
3 | |
4 | use strict; |
5 | use warnings; |
6 | |
5a2932cf |
7 | use 5.008; |
8 | |
3cf322a0 |
9 | use MRO::Compat; |
10 | |
4c105333 |
11 | use Carp 'confess'; |
4bfa5ddb |
12 | use Devel::GlobalDestruction qw( in_global_destruction ); |
b1a46f91 |
13 | use Scalar::Util 'weaken', 'reftype', 'blessed'; |
4bfa5ddb |
14 | use Sub::Name qw( subname ); |
fc4f8f91 |
15 | |
0531f510 |
16 | use Class::MOP::Class; |
17 | use Class::MOP::Attribute; |
18 | use Class::MOP::Method; |
19 | |
b1f5f41d |
20 | BEGIN { |
c7e28c19 |
21 | *IS_RUNNING_ON_5_10 = ($] < 5.009_005) |
11b56828 |
22 | ? sub () { 0 } |
c7e28c19 |
23 | : sub () { 1 }; |
46b23b44 |
24 | |
f9bd8fe2 |
25 | sub HAVE_ISAREV () { |
c7e28c19 |
26 | Carp::cluck("Class::MOP::HAVE_ISAREV is deprecated and will be removed in a future release. It has always returned 1 anyway."); |
f9bd8fe2 |
27 | return 1; |
28 | } |
3ecd1b25 |
29 | |
30 | # this is either part of core or set up appropriately by MRO::Compat |
31 | *check_package_cache_flag = \&mro::get_pkg_gen; |
b1f5f41d |
32 | } |
e0e4674a |
33 | |
95e647f0 |
34 | our $VERSION = '0.82_01'; |
8a7085c1 |
35 | our $XS_VERSION = $VERSION; |
d519662a |
36 | $VERSION = eval $VERSION; |
c7e28c19 |
37 | our $AUTHORITY = 'cpan:STEVAN'; |
9d655b6d |
38 | |
4bfa5ddb |
39 | require XSLoader; |
40 | XSLoader::load( __PACKAGE__, $XS_VERSION ); |
d7bda114 |
41 | |
42 | |
be7677c7 |
43 | { |
44 | # Metaclasses are singletons, so we cache them here. |
45 | # there is no need to worry about destruction though |
46 | # because they should die only when the program dies. |
47 | # After all, do package definitions even get reaped? |
1d68af04 |
48 | my %METAS; |
49 | |
50 | # means of accessing all the metaclasses that have |
be7677c7 |
51 | # been initialized thus far (for mugwumps obj browser) |
1d68af04 |
52 | sub get_all_metaclasses { %METAS } |
53 | sub get_all_metaclass_instances { values %METAS } |
54 | sub get_all_metaclass_names { keys %METAS } |
be7677c7 |
55 | sub get_metaclass_by_name { $METAS{$_[0]} } |
1d68af04 |
56 | sub store_metaclass_by_name { $METAS{$_[0]} = $_[1] } |
57 | sub weaken_metaclass { weaken($METAS{$_[0]}) } |
be7677c7 |
58 | sub does_metaclass_exist { exists $METAS{$_[0]} && defined $METAS{$_[0]} } |
1d68af04 |
59 | sub remove_metaclass_by_name { $METAS{$_[0]} = undef } |
60 | |
86866fb5 |
61 | # This handles instances as well as class names |
62 | sub class_of { |
82999986 |
63 | return unless defined $_[0]; |
86866fb5 |
64 | my $class = blessed($_[0]) || $_[0]; |
65 | return $METAS{$class}; |
66 | } |
67 | |
be7677c7 |
68 | # NOTE: |
1d68af04 |
69 | # We only cache metaclasses, meaning instances of |
70 | # Class::MOP::Class. We do not cache instance of |
be7677c7 |
71 | # Class::MOP::Package or Class::MOP::Module. Mostly |
1d68af04 |
72 | # because I don't yet see a good reason to do so. |
be7677c7 |
73 | } |
74 | |
44da14be |
75 | sub _class_to_pmfile { |
76 | my $class = shift; |
77 | |
78 | my $file = $class . '.pm'; |
79 | $file =~ s{::}{/}g; |
80 | |
81 | return $file; |
82 | } |
83 | |
063ad0c5 |
84 | sub load_first_existing_class { |
f280f05c |
85 | my @classes = @_ |
86 | or return; |
5a24cf8a |
87 | |
88 | foreach my $class (@classes) { |
89 | unless ( _is_valid_class_name($class) ) { |
90 | my $display = defined($class) ? $class : 'undef'; |
91 | confess "Invalid class name ($display)"; |
92 | } |
ab5e2f48 |
93 | } |
94 | |
063ad0c5 |
95 | my $found; |
5a24cf8a |
96 | my %exceptions; |
063ad0c5 |
97 | for my $class (@classes) { |
44da14be |
98 | my $pmfile = _class_to_pmfile($class); |
063ad0c5 |
99 | my $e = _try_load_one_class($class); |
100 | |
5a24cf8a |
101 | if ($e) { |
063ad0c5 |
102 | $exceptions{$class} = $e; |
44da14be |
103 | last if $e !~ /^Can't locate \Q$pmfile\E in \@INC/; |
5a24cf8a |
104 | } |
105 | else { |
063ad0c5 |
106 | $found = $class; |
107 | last; |
5a24cf8a |
108 | } |
063ad0c5 |
109 | } |
5a24cf8a |
110 | |
1d8153bd |
111 | return $found if $found; |
07940968 |
112 | |
063ad0c5 |
113 | confess join( |
114 | "\n", |
115 | map { |
116 | sprintf( |
fea44045 |
117 | "Could not load class (%s) because : %s", $_, |
063ad0c5 |
118 | $exceptions{$_} |
119 | ) |
44da14be |
120 | } |
121 | grep { |
122 | exists $exceptions{$_} |
063ad0c5 |
123 | } @classes |
f280f05c |
124 | ); |
5a24cf8a |
125 | } |
126 | |
063ad0c5 |
127 | sub _try_load_one_class { |
128 | my $class = shift; |
129 | |
130 | return if is_class_loaded($class); |
2beec805 |
131 | |
44da14be |
132 | my $file = _class_to_pmfile($class); |
063ad0c5 |
133 | |
134 | return do { |
135 | local $@; |
136 | eval { require($file) }; |
137 | $@; |
138 | }; |
139 | } |
140 | |
5a24cf8a |
141 | sub load_class { |
1d8153bd |
142 | my $class = load_first_existing_class($_[0]); |
143 | return get_metaclass_by_name($class) || $class; |
448b6e55 |
144 | } |
145 | |
2c0fb064 |
146 | sub _is_valid_class_name { |
147 | my $class = shift; |
148 | |
149 | return 0 if ref($class); |
150 | return 0 unless defined($class); |
151 | return 0 unless length($class); |
152 | |
153 | return 1 if $class =~ /^\w+(?:::\w+)*$/; |
154 | |
155 | return 0; |
156 | } |
157 | |
aa448b16 |
158 | ## ---------------------------------------------------------------------------- |
159 | ## Setting up our environment ... |
160 | ## ---------------------------------------------------------------------------- |
1d68af04 |
161 | ## Class::MOP needs to have a few things in the global perl environment so |
aa448b16 |
162 | ## that it can operate effectively. Those things are done here. |
163 | ## ---------------------------------------------------------------------------- |
164 | |
3bf7644b |
165 | # ... nothing yet actually ;) |
8b978dd5 |
166 | |
b51af7f9 |
167 | ## ---------------------------------------------------------------------------- |
1d68af04 |
168 | ## Bootstrapping |
b51af7f9 |
169 | ## ---------------------------------------------------------------------------- |
1d68af04 |
170 | ## The code below here is to bootstrap our MOP with itself. This is also |
b51af7f9 |
171 | ## sometimes called "tying the knot". By doing this, we make it much easier |
172 | ## to extend the MOP through subclassing and such since now you can use the |
1d68af04 |
173 | ## MOP itself to extend itself. |
174 | ## |
b51af7f9 |
175 | ## Yes, I know, thats weird and insane, but it's a good thing, trust me :) |
1d68af04 |
176 | ## ---------------------------------------------------------------------------- |
727919c5 |
177 | |
1d68af04 |
178 | # We need to add in the meta-attributes here so that |
179 | # any subclass of Class::MOP::* will be able to |
c2b256bc |
180 | # inherit them using _construct_instance |
727919c5 |
181 | |
f0480c45 |
182 | ## -------------------------------------------------------- |
6d5355c3 |
183 | ## Class::MOP::Package |
727919c5 |
184 | |
6d5355c3 |
185 | Class::MOP::Package->meta->add_attribute( |
8683db0e |
186 | Class::MOP::Attribute->new('package' => ( |
b880e0de |
187 | reader => { |
1d68af04 |
188 | # NOTE: we need to do this in order |
189 | # for the instance meta-object to |
b880e0de |
190 | # not fall into meta-circular death |
1d68af04 |
191 | # |
ce2ae40f |
192 | # we just alias the original method |
1d68af04 |
193 | # rather than re-produce it here |
ce2ae40f |
194 | 'name' => \&Class::MOP::Package::name |
b880e0de |
195 | }, |
727919c5 |
196 | )) |
197 | ); |
198 | |
a5e51f0b |
199 | Class::MOP::Package->meta->add_attribute( |
8683db0e |
200 | Class::MOP::Attribute->new('namespace' => ( |
a5e51f0b |
201 | reader => { |
56dcfc1a |
202 | # NOTE: |
ce2ae40f |
203 | # we just alias the original method |
204 | # rather than re-produce it here |
205 | 'namespace' => \&Class::MOP::Package::namespace |
a5e51f0b |
206 | }, |
2e877f58 |
207 | init_arg => undef, |
c4260b45 |
208 | default => sub { \undef } |
a5e51f0b |
209 | )) |
210 | ); |
211 | |
f0480c45 |
212 | ## -------------------------------------------------------- |
213 | ## Class::MOP::Module |
214 | |
215 | # NOTE: |
1d68af04 |
216 | # yeah this is kind of stretching things a bit, |
f0480c45 |
217 | # but truthfully the version should be an attribute |
1d68af04 |
218 | # of the Module, the weirdness comes from having to |
219 | # stick to Perl 5 convention and store it in the |
220 | # $VERSION package variable. Basically if you just |
221 | # squint at it, it will look how you want it to look. |
f0480c45 |
222 | # Either as a package variable, or as a attribute of |
223 | # the metaclass, isn't abstraction great :) |
224 | |
225 | Class::MOP::Module->meta->add_attribute( |
8683db0e |
226 | Class::MOP::Attribute->new('version' => ( |
f0480c45 |
227 | reader => { |
ce2ae40f |
228 | # NOTE: |
229 | # we just alias the original method |
1d68af04 |
230 | # rather than re-produce it here |
ce2ae40f |
231 | 'version' => \&Class::MOP::Module::version |
f0480c45 |
232 | }, |
2e877f58 |
233 | init_arg => undef, |
c4260b45 |
234 | default => sub { \undef } |
f0480c45 |
235 | )) |
236 | ); |
237 | |
238 | # NOTE: |
1d68af04 |
239 | # By following the same conventions as version here, |
240 | # we are opening up the possibility that people can |
241 | # use the $AUTHORITY in non-Class::MOP modules as |
242 | # well. |
f0480c45 |
243 | |
244 | Class::MOP::Module->meta->add_attribute( |
8683db0e |
245 | Class::MOP::Attribute->new('authority' => ( |
f0480c45 |
246 | reader => { |
ce2ae40f |
247 | # NOTE: |
248 | # we just alias the original method |
1d68af04 |
249 | # rather than re-produce it here |
ce2ae40f |
250 | 'authority' => \&Class::MOP::Module::authority |
1d68af04 |
251 | }, |
2e877f58 |
252 | init_arg => undef, |
c4260b45 |
253 | default => sub { \undef } |
f0480c45 |
254 | )) |
255 | ); |
256 | |
257 | ## -------------------------------------------------------- |
6d5355c3 |
258 | ## Class::MOP::Class |
259 | |
727919c5 |
260 | Class::MOP::Class->meta->add_attribute( |
8683db0e |
261 | Class::MOP::Attribute->new('attributes' => ( |
f7259199 |
262 | reader => { |
1d68af04 |
263 | # NOTE: we need to do this in order |
264 | # for the instance meta-object to |
265 | # not fall into meta-circular death |
266 | # |
ce2ae40f |
267 | # we just alias the original method |
1d68af04 |
268 | # rather than re-produce it here |
ce2ae40f |
269 | 'get_attribute_map' => \&Class::MOP::Class::get_attribute_map |
f7259199 |
270 | }, |
727919c5 |
271 | default => sub { {} } |
272 | )) |
273 | ); |
274 | |
351bd7d4 |
275 | Class::MOP::Class->meta->add_attribute( |
8683db0e |
276 | Class::MOP::Attribute->new('methods' => ( |
1d68af04 |
277 | reader => { |
ce2ae40f |
278 | # NOTE: |
279 | # we just alias the original method |
1d68af04 |
280 | # rather than re-produce it here |
ce2ae40f |
281 | 'get_method_map' => \&Class::MOP::Class::get_method_map |
92330ee2 |
282 | }, |
7855ddba |
283 | default => sub { {} } |
c4260b45 |
284 | )) |
285 | ); |
286 | |
287 | Class::MOP::Class->meta->add_attribute( |
8683db0e |
288 | Class::MOP::Attribute->new('superclasses' => ( |
c23184fc |
289 | accessor => { |
290 | # NOTE: |
291 | # we just alias the original method |
1d68af04 |
292 | # rather than re-produce it here |
c23184fc |
293 | 'superclasses' => \&Class::MOP::Class::superclasses |
294 | }, |
2e877f58 |
295 | init_arg => undef, |
c23184fc |
296 | default => sub { \undef } |
297 | )) |
298 | ); |
299 | |
300 | Class::MOP::Class->meta->add_attribute( |
8683db0e |
301 | Class::MOP::Attribute->new('attribute_metaclass' => ( |
1d68af04 |
302 | reader => { |
6d2118a4 |
303 | # NOTE: |
304 | # we just alias the original method |
1d68af04 |
305 | # rather than re-produce it here |
6d2118a4 |
306 | 'attribute_metaclass' => \&Class::MOP::Class::attribute_metaclass |
1d68af04 |
307 | }, |
351bd7d4 |
308 | default => 'Class::MOP::Attribute', |
309 | )) |
310 | ); |
311 | |
312 | Class::MOP::Class->meta->add_attribute( |
8683db0e |
313 | Class::MOP::Attribute->new('method_metaclass' => ( |
1d68af04 |
314 | reader => { |
6d2118a4 |
315 | # NOTE: |
316 | # we just alias the original method |
1d68af04 |
317 | # rather than re-produce it here |
6d2118a4 |
318 | 'method_metaclass' => \&Class::MOP::Class::method_metaclass |
319 | }, |
1d68af04 |
320 | default => 'Class::MOP::Method', |
351bd7d4 |
321 | )) |
322 | ); |
323 | |
2bab2be6 |
324 | Class::MOP::Class->meta->add_attribute( |
77373da8 |
325 | Class::MOP::Attribute->new('wrapped_method_metaclass' => ( |
326 | reader => { |
327 | # NOTE: |
328 | # we just alias the original method |
329 | # rather than re-produce it here |
330 | 'wrapped_method_metaclass' => \&Class::MOP::Class::wrapped_method_metaclass |
331 | }, |
332 | default => 'Class::MOP::Method::Wrapped', |
333 | )) |
334 | ); |
335 | |
336 | Class::MOP::Class->meta->add_attribute( |
8683db0e |
337 | Class::MOP::Attribute->new('instance_metaclass' => ( |
b880e0de |
338 | reader => { |
1d68af04 |
339 | # NOTE: we need to do this in order |
340 | # for the instance meta-object to |
341 | # not fall into meta-circular death |
342 | # |
ce2ae40f |
343 | # we just alias the original method |
1d68af04 |
344 | # rather than re-produce it here |
ce2ae40f |
345 | 'instance_metaclass' => \&Class::MOP::Class::instance_metaclass |
b880e0de |
346 | }, |
1d68af04 |
347 | default => 'Class::MOP::Instance', |
2bab2be6 |
348 | )) |
349 | ); |
350 | |
44d6ea77 |
351 | Class::MOP::Class->meta->add_attribute( |
f5d08022 |
352 | Class::MOP::Attribute->new('immutable_trait' => ( |
353 | reader => { |
354 | 'immutable_trait' => \&Class::MOP::Class::immutable_trait |
355 | }, |
356 | default => "Class::MOP::Class::Immutable::Trait", |
357 | )) |
358 | ); |
359 | |
360 | Class::MOP::Class->meta->add_attribute( |
361 | Class::MOP::Attribute->new('constructor_name' => ( |
44d6ea77 |
362 | reader => { |
f5d08022 |
363 | 'constructor_name' => \&Class::MOP::Class::constructor_name, |
44d6ea77 |
364 | }, |
f5d08022 |
365 | default => "new", |
366 | )) |
367 | ); |
368 | |
369 | Class::MOP::Class->meta->add_attribute( |
370 | Class::MOP::Attribute->new('constructor_class' => ( |
44d6ea77 |
371 | reader => { |
f5d08022 |
372 | 'constructor_class' => \&Class::MOP::Class::constructor_class, |
44d6ea77 |
373 | }, |
f5d08022 |
374 | default => "Class::MOP::Method::Constructor", |
375 | )) |
376 | ); |
377 | |
378 | |
379 | Class::MOP::Class->meta->add_attribute( |
380 | Class::MOP::Attribute->new('destructor_class' => ( |
381 | reader => { |
382 | 'destructor_class' => \&Class::MOP::Class::destructor_class, |
44d6ea77 |
383 | }, |
384 | )) |
385 | ); |
386 | |
9d6dce77 |
387 | # NOTE: |
1d68af04 |
388 | # we don't actually need to tie the knot with |
389 | # Class::MOP::Class here, it is actually handled |
390 | # within Class::MOP::Class itself in the |
c2b256bc |
391 | # _construct_class_instance method. |
9d6dce77 |
392 | |
f0480c45 |
393 | ## -------------------------------------------------------- |
727919c5 |
394 | ## Class::MOP::Attribute |
395 | |
7b31baf4 |
396 | Class::MOP::Attribute->meta->add_attribute( |
8683db0e |
397 | Class::MOP::Attribute->new('name' => ( |
c23184fc |
398 | reader => { |
1d68af04 |
399 | # NOTE: we need to do this in order |
400 | # for the instance meta-object to |
401 | # not fall into meta-circular death |
402 | # |
ce2ae40f |
403 | # we just alias the original method |
1d68af04 |
404 | # rather than re-produce it here |
ce2ae40f |
405 | 'name' => \&Class::MOP::Attribute::name |
b880e0de |
406 | } |
7b31baf4 |
407 | )) |
408 | ); |
409 | |
410 | Class::MOP::Attribute->meta->add_attribute( |
8683db0e |
411 | Class::MOP::Attribute->new('associated_class' => ( |
c23184fc |
412 | reader => { |
1d68af04 |
413 | # NOTE: we need to do this in order |
414 | # for the instance meta-object to |
415 | # not fall into meta-circular death |
416 | # |
ce2ae40f |
417 | # we just alias the original method |
1d68af04 |
418 | # rather than re-produce it here |
ce2ae40f |
419 | 'associated_class' => \&Class::MOP::Attribute::associated_class |
b880e0de |
420 | } |
7b31baf4 |
421 | )) |
422 | ); |
423 | |
424 | Class::MOP::Attribute->meta->add_attribute( |
8683db0e |
425 | Class::MOP::Attribute->new('accessor' => ( |
6d2118a4 |
426 | reader => { 'accessor' => \&Class::MOP::Attribute::accessor }, |
427 | predicate => { 'has_accessor' => \&Class::MOP::Attribute::has_accessor }, |
7b31baf4 |
428 | )) |
429 | ); |
430 | |
431 | Class::MOP::Attribute->meta->add_attribute( |
8683db0e |
432 | Class::MOP::Attribute->new('reader' => ( |
6d2118a4 |
433 | reader => { 'reader' => \&Class::MOP::Attribute::reader }, |
434 | predicate => { 'has_reader' => \&Class::MOP::Attribute::has_reader }, |
7b31baf4 |
435 | )) |
436 | ); |
437 | |
438 | Class::MOP::Attribute->meta->add_attribute( |
8683db0e |
439 | Class::MOP::Attribute->new('initializer' => ( |
8ee74136 |
440 | reader => { 'initializer' => \&Class::MOP::Attribute::initializer }, |
441 | predicate => { 'has_initializer' => \&Class::MOP::Attribute::has_initializer }, |
0ab65f99 |
442 | )) |
443 | ); |
444 | |
445 | Class::MOP::Attribute->meta->add_attribute( |
d9d99689 |
446 | Class::MOP::Attribute->new('definition_context' => ( |
447 | reader => { 'definition_context' => \&Class::MOP::Attribute::definition_context }, |
448 | )) |
449 | ); |
450 | |
451 | Class::MOP::Attribute->meta->add_attribute( |
8683db0e |
452 | Class::MOP::Attribute->new('writer' => ( |
6d2118a4 |
453 | reader => { 'writer' => \&Class::MOP::Attribute::writer }, |
454 | predicate => { 'has_writer' => \&Class::MOP::Attribute::has_writer }, |
7b31baf4 |
455 | )) |
456 | ); |
457 | |
458 | Class::MOP::Attribute->meta->add_attribute( |
8683db0e |
459 | Class::MOP::Attribute->new('predicate' => ( |
6d2118a4 |
460 | reader => { 'predicate' => \&Class::MOP::Attribute::predicate }, |
461 | predicate => { 'has_predicate' => \&Class::MOP::Attribute::has_predicate }, |
7b31baf4 |
462 | )) |
463 | ); |
464 | |
465 | Class::MOP::Attribute->meta->add_attribute( |
8683db0e |
466 | Class::MOP::Attribute->new('clearer' => ( |
6d2118a4 |
467 | reader => { 'clearer' => \&Class::MOP::Attribute::clearer }, |
468 | predicate => { 'has_clearer' => \&Class::MOP::Attribute::has_clearer }, |
7d28758b |
469 | )) |
470 | ); |
471 | |
472 | Class::MOP::Attribute->meta->add_attribute( |
8683db0e |
473 | Class::MOP::Attribute->new('builder' => ( |
1d68af04 |
474 | reader => { 'builder' => \&Class::MOP::Attribute::builder }, |
475 | predicate => { 'has_builder' => \&Class::MOP::Attribute::has_builder }, |
476 | )) |
477 | ); |
478 | |
479 | Class::MOP::Attribute->meta->add_attribute( |
8683db0e |
480 | Class::MOP::Attribute->new('init_arg' => ( |
6d2118a4 |
481 | reader => { 'init_arg' => \&Class::MOP::Attribute::init_arg }, |
482 | predicate => { 'has_init_arg' => \&Class::MOP::Attribute::has_init_arg }, |
7b31baf4 |
483 | )) |
484 | ); |
485 | |
486 | Class::MOP::Attribute->meta->add_attribute( |
8683db0e |
487 | Class::MOP::Attribute->new('default' => ( |
7b31baf4 |
488 | # default has a custom 'reader' method ... |
1d68af04 |
489 | predicate => { 'has_default' => \&Class::MOP::Attribute::has_default }, |
7b31baf4 |
490 | )) |
491 | ); |
492 | |
3545c727 |
493 | Class::MOP::Attribute->meta->add_attribute( |
8683db0e |
494 | Class::MOP::Attribute->new('associated_methods' => ( |
c23184fc |
495 | reader => { 'associated_methods' => \&Class::MOP::Attribute::associated_methods }, |
1d68af04 |
496 | default => sub { [] } |
3545c727 |
497 | )) |
498 | ); |
727919c5 |
499 | |
5659d76e |
500 | Class::MOP::Attribute->meta->add_method('clone' => sub { |
a740253a |
501 | my $self = shift; |
1d68af04 |
502 | $self->meta->clone_object($self, @_); |
727919c5 |
503 | }); |
504 | |
f0480c45 |
505 | ## -------------------------------------------------------- |
b6164407 |
506 | ## Class::MOP::Method |
b6164407 |
507 | Class::MOP::Method->meta->add_attribute( |
8683db0e |
508 | Class::MOP::Attribute->new('body' => ( |
c23184fc |
509 | reader => { 'body' => \&Class::MOP::Method::body }, |
b6164407 |
510 | )) |
511 | ); |
512 | |
4c105333 |
513 | Class::MOP::Method->meta->add_attribute( |
5e607260 |
514 | Class::MOP::Attribute->new('associated_metaclass' => ( |
5e607260 |
515 | reader => { 'associated_metaclass' => \&Class::MOP::Method::associated_metaclass }, |
516 | )) |
517 | ); |
518 | |
519 | Class::MOP::Method->meta->add_attribute( |
8683db0e |
520 | Class::MOP::Attribute->new('package_name' => ( |
4c105333 |
521 | reader => { 'package_name' => \&Class::MOP::Method::package_name }, |
522 | )) |
523 | ); |
524 | |
525 | Class::MOP::Method->meta->add_attribute( |
8683db0e |
526 | Class::MOP::Attribute->new('name' => ( |
4c105333 |
527 | reader => { 'name' => \&Class::MOP::Method::name }, |
528 | )) |
529 | ); |
530 | |
2226a8b0 |
531 | Class::MOP::Method->meta->add_attribute( |
532 | Class::MOP::Attribute->new('original_method' => ( |
533 | reader => { 'original_method' => \&Class::MOP::Method::original_method }, |
534 | writer => { '_set_original_method' => \&Class::MOP::Method::_set_original_method }, |
535 | )) |
536 | ); |
537 | |
4c105333 |
538 | Class::MOP::Method->meta->add_method('clone' => sub { |
539 | my $self = shift; |
2226a8b0 |
540 | my $clone = $self->meta->clone_object($self, @_); |
541 | $clone->_set_original_method($self); |
542 | return $clone; |
4c105333 |
543 | }); |
544 | |
b6164407 |
545 | ## -------------------------------------------------------- |
546 | ## Class::MOP::Method::Wrapped |
547 | |
548 | # NOTE: |
1d68af04 |
549 | # the way this item is initialized, this |
550 | # really does not follow the standard |
551 | # practices of attributes, but we put |
b6164407 |
552 | # it here for completeness |
553 | Class::MOP::Method::Wrapped->meta->add_attribute( |
8683db0e |
554 | Class::MOP::Attribute->new('modifier_table') |
b6164407 |
555 | ); |
556 | |
557 | ## -------------------------------------------------------- |
565f0cbb |
558 | ## Class::MOP::Method::Generated |
559 | |
560 | Class::MOP::Method::Generated->meta->add_attribute( |
8683db0e |
561 | Class::MOP::Attribute->new('is_inline' => ( |
565f0cbb |
562 | reader => { 'is_inline' => \&Class::MOP::Method::Generated::is_inline }, |
4c105333 |
563 | default => 0, |
1d68af04 |
564 | )) |
565f0cbb |
565 | ); |
566 | |
d9d99689 |
567 | Class::MOP::Method::Generated->meta->add_attribute( |
568 | Class::MOP::Attribute->new('definition_context' => ( |
569 | reader => { 'definition_context' => \&Class::MOP::Method::Generated::definition_context }, |
570 | )) |
571 | ); |
572 | |
29d4e92a |
573 | |
574 | ## -------------------------------------------------------- |
575 | ## Class::MOP::Method::Inlined |
576 | |
577 | Class::MOP::Method::Inlined->meta->add_attribute( |
578 | Class::MOP::Attribute->new('_expected_method_class' => ( |
579 | reader => { '_expected_method_class' => \&Class::MOP::Method::Inlined::_expected_method_class }, |
580 | )) |
581 | ); |
582 | |
565f0cbb |
583 | ## -------------------------------------------------------- |
d90b42a6 |
584 | ## Class::MOP::Method::Accessor |
585 | |
586 | Class::MOP::Method::Accessor->meta->add_attribute( |
8683db0e |
587 | Class::MOP::Attribute->new('attribute' => ( |
1d68af04 |
588 | reader => { |
589 | 'associated_attribute' => \&Class::MOP::Method::Accessor::associated_attribute |
d90b42a6 |
590 | }, |
1d68af04 |
591 | )) |
d90b42a6 |
592 | ); |
593 | |
594 | Class::MOP::Method::Accessor->meta->add_attribute( |
8683db0e |
595 | Class::MOP::Attribute->new('accessor_type' => ( |
c23184fc |
596 | reader => { 'accessor_type' => \&Class::MOP::Method::Accessor::accessor_type }, |
1d68af04 |
597 | )) |
d90b42a6 |
598 | ); |
599 | |
d90b42a6 |
600 | ## -------------------------------------------------------- |
601 | ## Class::MOP::Method::Constructor |
602 | |
603 | Class::MOP::Method::Constructor->meta->add_attribute( |
8683db0e |
604 | Class::MOP::Attribute->new('options' => ( |
1d68af04 |
605 | reader => { |
606 | 'options' => \&Class::MOP::Method::Constructor::options |
d90b42a6 |
607 | }, |
4c105333 |
608 | default => sub { +{} } |
1d68af04 |
609 | )) |
d90b42a6 |
610 | ); |
611 | |
612 | Class::MOP::Method::Constructor->meta->add_attribute( |
8683db0e |
613 | Class::MOP::Attribute->new('associated_metaclass' => ( |
e8a38403 |
614 | init_arg => "metaclass", # FIXME alias and rename |
1d68af04 |
615 | reader => { |
616 | 'associated_metaclass' => \&Class::MOP::Method::Constructor::associated_metaclass |
617 | }, |
618 | )) |
d90b42a6 |
619 | ); |
620 | |
621 | ## -------------------------------------------------------- |
86482605 |
622 | ## Class::MOP::Instance |
623 | |
624 | # NOTE: |
1d68af04 |
625 | # these don't yet do much of anything, but are just |
86482605 |
626 | # included for completeness |
627 | |
628 | Class::MOP::Instance->meta->add_attribute( |
74890687 |
629 | Class::MOP::Attribute->new('associated_metaclass', |
630 | reader => { associated_metaclass => \&Class::MOP::Instance::associated_metaclass }, |
631 | ), |
86482605 |
632 | ); |
633 | |
634 | Class::MOP::Instance->meta->add_attribute( |
74890687 |
635 | Class::MOP::Attribute->new('_class_name', |
636 | init_arg => undef, |
637 | reader => { _class_name => \&Class::MOP::Instance::_class_name }, |
638 | #lazy => 1, # not yet supported by Class::MOP but out our version does it anyway |
639 | #default => sub { $_[0]->associated_metaclass->name }, |
640 | ), |
641 | ); |
642 | |
643 | Class::MOP::Instance->meta->add_attribute( |
644 | Class::MOP::Attribute->new('attributes', |
0b5d46da |
645 | reader => { attributes => \&Class::MOP::Instance::get_all_attributes }, |
74890687 |
646 | ), |
32bfc810 |
647 | ); |
648 | |
649 | Class::MOP::Instance->meta->add_attribute( |
74890687 |
650 | Class::MOP::Attribute->new('slots', |
651 | reader => { slots => \&Class::MOP::Instance::slots }, |
652 | ), |
86482605 |
653 | ); |
654 | |
63d08a9e |
655 | Class::MOP::Instance->meta->add_attribute( |
74890687 |
656 | Class::MOP::Attribute->new('slot_hash', |
657 | reader => { slot_hash => \&Class::MOP::Instance::slot_hash }, |
658 | ), |
63d08a9e |
659 | ); |
660 | |
661 | |
caa051fa |
662 | # we need the meta instance of the meta instance to be created now, in order |
663 | # for the constructor to be able to use it |
664 | Class::MOP::Instance->meta->get_meta_instance; |
665 | |
caa051fa |
666 | # pretend the add_method never happenned. it hasn't yet affected anything |
667 | undef Class::MOP::Instance->meta->{_package_cache_flag}; |
668 | |
86482605 |
669 | ## -------------------------------------------------------- |
f0480c45 |
670 | ## Now close all the Class::MOP::* classes |
4d47b77f |
671 | |
1aa13cf4 |
672 | # NOTE: we don't need to inline the the accessors this only lengthens |
673 | # the compile time of the MOP, and gives us no actual benefits. |
0b9372a2 |
674 | |
a7b17d6f |
675 | # this is just nitpicking to ensure Class::MOP::Class->meta == ->meta->meta |
676 | Class::MOP::Class->meta->immutable_metaclass; |
677 | $Class::MOP::Class::immutable_metaclass_cache{"Class::MOP::Class"}{"Class::MOP::Class::Immutable::Trait"} = Class::MOP::Class::Immutable::Class::MOP::Class->meta; |
678 | |
0b9372a2 |
679 | $_->meta->make_immutable( |
6c2f6b5c |
680 | inline_constructor => 1, |
681 | replace_constructor => 1, |
682 | constructor_name => "_new", |
45582002 |
683 | inline_accessors => 0, |
0b9372a2 |
684 | ) for qw/ |
1d68af04 |
685 | Class::MOP::Package |
686 | Class::MOP::Module |
687 | Class::MOP::Class |
f5d08022 |
688 | Class::MOP::Class::Immutable::Trait |
a7b17d6f |
689 | Class::MOP::Class::Immutable::Class::MOP::Class |
1d68af04 |
690 | |
0b9372a2 |
691 | Class::MOP::Attribute |
1d68af04 |
692 | Class::MOP::Method |
693 | Class::MOP::Instance |
694 | |
695 | Class::MOP::Object |
0b9372a2 |
696 | |
565f0cbb |
697 | Class::MOP::Method::Generated |
29d4e92a |
698 | Class::MOP::Method::Inlined |
1d68af04 |
699 | |
ba38bf08 |
700 | Class::MOP::Method::Accessor |
1d68af04 |
701 | Class::MOP::Method::Constructor |
702 | Class::MOP::Method::Wrapped |
0b9372a2 |
703 | /; |
b6164407 |
704 | |
94b19069 |
705 | 1; |
706 | |
707 | __END__ |
708 | |
709 | =pod |
710 | |
1d68af04 |
711 | =head1 NAME |
94b19069 |
712 | |
713 | Class::MOP - A Meta Object Protocol for Perl 5 |
714 | |
5b60bf98 |
715 | =head1 DESCRIPTION |
94b19069 |
716 | |
127d39a7 |
717 | This module is a fully functioning meta object protocol for the |
1d68af04 |
718 | Perl 5 object system. It makes no attempt to change the behavior or |
719 | characteristics of the Perl 5 object system, only to create a |
27e31eaf |
720 | protocol for its manipulation and introspection. |
94b19069 |
721 | |
828ecf13 |
722 | That said, it does attempt to create the tools for building a rich set |
723 | of extensions to the Perl 5 object system. Every attempt has been made |
724 | to abide by the spirit of the Perl 5 object system that we all know |
725 | and love. |
94b19069 |
726 | |
828ecf13 |
727 | This documentation is sparse on conceptual details. We suggest looking |
728 | at the items listed in the L<SEE ALSO> section for more |
729 | information. In particular the book "The Art of the Meta Object |
730 | Protocol" was very influential in the development of this system. |
40483095 |
731 | |
bfe4d0fc |
732 | =head2 What is a Meta Object Protocol? |
733 | |
1d68af04 |
734 | A meta object protocol is an API to an object system. |
bfe4d0fc |
735 | |
828ecf13 |
736 | To be more specific, it abstracts the components of an object system |
737 | (classes, object, methods, object attributes, etc.). These |
738 | abstractions can then be used to inspect and manipulate the object |
739 | system which they describe. |
bfe4d0fc |
740 | |
1d68af04 |
741 | It can be said that there are two MOPs for any object system; the |
828ecf13 |
742 | implicit MOP and the explicit MOP. The implicit MOP handles things |
1d68af04 |
743 | like method dispatch or inheritance, which happen automatically as |
744 | part of how the object system works. The explicit MOP typically |
745 | handles the introspection/reflection features of the object system. |
bfe4d0fc |
746 | |
828ecf13 |
747 | All object systems have implicit MOPs. Without one, they would not |
5b60bf98 |
748 | work. Explicit MOPs are much less common, and depending on the |
749 | language can vary from restrictive (Reflection in Java or C#) to wide |
750 | open (CLOS is a perfect example). |
e16da3e6 |
751 | |
828ecf13 |
752 | =head2 Yet Another Class Builder! Why? |
753 | |
754 | This is B<not> a class builder so much as a I<class builder |
755 | B<builder>>. The intent is that an end user will not use this module |
756 | directly, but instead this module is used by module authors to build |
757 | extensions and features onto the Perl 5 object system. |
758 | |
759 | This system is used by L<Moose>, which supplies a powerful class |
760 | builder system built entirely on top of C<Class::MOP>. |
e16da3e6 |
761 | |
94b19069 |
762 | =head2 Who is this module for? |
763 | |
828ecf13 |
764 | This module is for anyone who has ever created or wanted to create a |
765 | module for the Class:: namespace. The tools which this module provides |
766 | make doing complex Perl 5 wizardry simpler, by removing such barriers |
767 | as the need to hack symbol tables, or understand the fine details of |
768 | method dispatch. |
94b19069 |
769 | |
bfe4d0fc |
770 | =head2 What changes do I have to make to use this module? |
771 | |
828ecf13 |
772 | This module was designed to be as unintrusive as possible. Many of its |
5b60bf98 |
773 | features are accessible without B<any> change to your existing |
828ecf13 |
774 | code. It is meant to be a compliment to your existing code and not an |
775 | intrusion on your code base. Unlike many other B<Class::> modules, |
776 | this module B<does not> require you subclass it, or even that you |
777 | C<use> it in within your module's package. |
bfe4d0fc |
778 | |
1d68af04 |
779 | The only features which requires additions to your code are the |
2eb717d5 |
780 | attribute handling and instance construction features, and these are |
1d68af04 |
781 | both completely optional features. The only reason for this is because |
782 | Perl 5's object system does not actually have these features built |
2eb717d5 |
783 | in. More information about this feature can be found below. |
bfe4d0fc |
784 | |
828ecf13 |
785 | =head2 About Performance |
786 | |
5b60bf98 |
787 | It is a common misconception that explicit MOPs are a performance hit. |
828ecf13 |
788 | This is not a universal truth, it is a side-effect of some specific |
789 | implementations. For instance, using Java reflection is slow because |
790 | the JVM cannot take advantage of any compiler optimizations, and the |
791 | JVM has to deal with much more runtime type information as well. |
bfe4d0fc |
792 | |
828ecf13 |
793 | Reflection in C# is marginally better as it was designed into the |
794 | language and runtime (the CLR). In contrast, CLOS (the Common Lisp |
795 | Object System) was built to support an explicit MOP, and so |
796 | performance is tuned for it. |
1d68af04 |
797 | |
828ecf13 |
798 | This library in particular does its absolute best to avoid putting |
1d68af04 |
799 | B<any> drain at all upon your code's performance. In fact, by itself |
828ecf13 |
800 | it does nothing to affect your existing code. So you only pay for what |
801 | you actually use. |
bfe4d0fc |
802 | |
550d56db |
803 | =head2 About Metaclass compatibility |
804 | |
1d68af04 |
805 | This module makes sure that all metaclasses created are both upwards |
806 | and downwards compatible. The topic of metaclass compatibility is |
807 | highly esoteric and is something only encountered when doing deep and |
808 | involved metaclass hacking. There are two basic kinds of metaclass |
809 | incompatibility; upwards and downwards. |
550d56db |
810 | |
1d68af04 |
811 | Upwards metaclass compatibility means that the metaclass of a |
812 | given class is either the same as (or a subclass of) all of the |
550d56db |
813 | class's ancestors. |
814 | |
1d68af04 |
815 | Downward metaclass compatibility means that the metaclasses of a |
828ecf13 |
816 | given class's ancestors are all either the same as (or a subclass |
550d56db |
817 | of) that metaclass. |
818 | |
1d68af04 |
819 | Here is a diagram showing a set of two classes (C<A> and C<B>) and |
820 | two metaclasses (C<Meta::A> and C<Meta::B>) which have correct |
550d56db |
821 | metaclass compatibility both upwards and downwards. |
822 | |
823 | +---------+ +---------+ |
824 | | Meta::A |<----| Meta::B | <....... (instance of ) |
1d68af04 |
825 | +---------+ +---------+ <------- (inherits from) |
550d56db |
826 | ^ ^ |
827 | : : |
828 | +---------+ +---------+ |
829 | | A |<----| B | |
830 | +---------+ +---------+ |
831 | |
1d68af04 |
832 | As I said this is a highly esoteric topic and one you will only run |
828ecf13 |
833 | into if you do a lot of subclassing of L<Class::MOP::Class>. If you |
834 | are interested in why this is an issue see the paper I<Uniform and |
835 | safe metaclass composition> linked to in the L<SEE ALSO> section of |
836 | this document. |
550d56db |
837 | |
aa448b16 |
838 | =head2 Using custom metaclasses |
839 | |
828ecf13 |
840 | Always use the L<metaclass> pragma when using a custom metaclass, this |
5b60bf98 |
841 | will ensure the proper initialization order and not accidentally |
842 | create an incorrect type of metaclass for you. This is a very rare |
843 | problem, and one which can only occur if you are doing deep metaclass |
aa448b16 |
844 | programming. So in other words, don't worry about it. |
845 | |
828ecf13 |
846 | Note that if you're using L<Moose> we encourage you to I<not> use |
847 | L<metaclass> pragma, and instead use L<Moose::Util::MetaRole> to apply |
848 | roles to a class's metaclasses. This topic is covered at length in |
849 | various L<Moose::Cookbook> recipes. |
850 | |
94b19069 |
851 | =head1 PROTOCOLS |
852 | |
828ecf13 |
853 | The meta-object protocol is divided into 4 main sub-protocols: |
94b19069 |
854 | |
828ecf13 |
855 | =head2 The Class protocol |
94b19069 |
856 | |
1d68af04 |
857 | This provides a means of manipulating and introspecting a Perl 5 |
828ecf13 |
858 | class. It handles symbol table hacking for you, and provides a rich |
859 | set of methods that go beyond simple package introspection. |
94b19069 |
860 | |
552e3d24 |
861 | See L<Class::MOP::Class> for more details. |
862 | |
828ecf13 |
863 | =head2 The Attribute protocol |
94b19069 |
864 | |
828ecf13 |
865 | This provides a consistent representation for an attribute of a Perl 5 |
866 | class. Since there are so many ways to create and handle attributes in |
867 | Perl 5 OO, the Attribute protocol provide as much of a unified |
868 | approach as possible. Of course, you are always free to extend this |
869 | protocol by subclassing the appropriate classes. |
94b19069 |
870 | |
552e3d24 |
871 | See L<Class::MOP::Attribute> for more details. |
872 | |
828ecf13 |
873 | =head2 The Method protocol |
94b19069 |
874 | |
828ecf13 |
875 | This provides a means of manipulating and introspecting methods in the |
876 | Perl 5 object system. As with attributes, there are many ways to |
1d68af04 |
877 | approach this topic, so we try to keep it pretty basic, while still |
94b19069 |
878 | making it possible to extend the system in many ways. |
879 | |
552e3d24 |
880 | See L<Class::MOP::Method> for more details. |
94b19069 |
881 | |
828ecf13 |
882 | =head2 The Instance protocol |
127d39a7 |
883 | |
828ecf13 |
884 | This provides a layer of abstraction for creating object instances. |
885 | Since the other layers use this protocol, it is relatively easy to |
886 | change the type of your instances from the default hash reference to |
887 | some other type of reference. Several examples are provided in the |
888 | F<examples/> directory included in this distribution. |
127d39a7 |
889 | |
890 | See L<Class::MOP::Instance> for more details. |
891 | |
be7677c7 |
892 | =head1 FUNCTIONS |
893 | |
828ecf13 |
894 | Note that this module does not export any constants or functions. |
895 | |
c1d5345a |
896 | =head2 Constants |
897 | |
898 | =over 4 |
899 | |
828ecf13 |
900 | =item I<Class::MOP::IS_RUNNING_ON_5_10> |
c1d5345a |
901 | |
828ecf13 |
902 | We set this constant depending on what version perl we are on, this |
903 | allows us to take advantage of new 5.10 features and stay backwards |
5b60bf98 |
904 | compatible. |
c1d5345a |
905 | |
906 | =back |
907 | |
448b6e55 |
908 | =head2 Utility functions |
909 | |
bd07fbdb |
910 | Note that these are all called as B<functions, not methods>. |
081a927b |
911 | |
448b6e55 |
912 | =over 4 |
913 | |
828ecf13 |
914 | =item B<Class::MOP::load_class($class_name)> |
448b6e55 |
915 | |
828ecf13 |
916 | This will load the specified C<$class_name>. This function can be used |
917 | in place of tricks like C<eval "use $module"> or using C<require> |
01f3a099 |
918 | unconditionally. This will return the metaclass of C<$class_name>. |
448b6e55 |
919 | |
828ecf13 |
920 | =item B<Class::MOP::is_class_loaded($class_name)> |
448b6e55 |
921 | |
15ab5451 |
922 | Returns a boolean indicating whether or not C<$class_name> has been |
923 | loaded. |
448b6e55 |
924 | |
828ecf13 |
925 | This does a basic check of the symbol table to try and determine as |
926 | best it can if the C<$class_name> is loaded, it is probably correct |
927 | about 99% of the time, but it can be fooled into reporting false |
928 | positives. |
448b6e55 |
929 | |
cdac22cc |
930 | =item B<Class::MOP::get_code_info($code)> |
931 | |
932 | This function returns two values, the name of the package the C<$code> |
933 | is from and the name of the C<$code> itself. This is used by several |
5b60bf98 |
934 | elements of the MOP to determine where a given C<$code> reference is |
cdac22cc |
935 | from. |
936 | |
44ba77a3 |
937 | =item B<Class::MOP::class_of($instance_or_class_name)> |
938 | |
939 | This will return the metaclass of the given instance or class name. |
940 | Even if the class lacks a metaclass, no metaclass will be initialized |
941 | and C<undef> will be returned. |
942 | |
828ecf13 |
943 | =item B<Class::MOP::check_package_cache_flag($pkg)> |
e0e4674a |
944 | |
bd07fbdb |
945 | B<NOTE: DO NOT USE THIS FUNCTION, IT IS FOR INTERNAL USE ONLY!> |
946 | |
828ecf13 |
947 | This will return an integer that is managed by L<Class::MOP::Class> to |
948 | determine if a module's symbol table has been altered. |
127d39a7 |
949 | |
828ecf13 |
950 | In Perl 5.10 or greater, this flag is package specific. However in |
951 | versions prior to 5.10, this will use the C<PL_sub_generation> |
952 | variable which is not package specific. |
127d39a7 |
953 | |
828ecf13 |
954 | =item B<Class::MOP::load_first_existing_class(@class_names)> |
063ad0c5 |
955 | |
956 | B<NOTE: DO NOT USE THIS FUNCTION, IT IS FOR INTERNAL USE ONLY!> |
957 | |
958 | Given a list of class names, this function will attempt to load each |
959 | one in turn. |
960 | |
828ecf13 |
961 | If it finds a class it can load, it will return that class' name. If |
962 | none of the classes can be loaded, it will throw an exception. |
063ad0c5 |
963 | |
448b6e55 |
964 | =back |
965 | |
966 | =head2 Metaclass cache functions |
967 | |
6c842677 |
968 | Class::MOP holds a cache of metaclasses. The following are functions |
1d68af04 |
969 | (B<not methods>) which can be used to access that cache. It is not |
6c842677 |
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! |
be7677c7 |
972 | |
973 | =over 4 |
974 | |
828ecf13 |
975 | =item B<Class::MOP::get_all_metaclasses> |
be7677c7 |
976 | |
6c842677 |
977 | This will return a hash of all the metaclass instances that have |
828ecf13 |
978 | been cached by L<Class::MOP::Class>, keyed by the package name. |
b9d9fc0b |
979 | |
828ecf13 |
980 | =item B<Class::MOP::get_all_metaclass_instances> |
be7677c7 |
981 | |
6c842677 |
982 | This will return a list of all the metaclass instances that have |
828ecf13 |
983 | been cached by L<Class::MOP::Class>. |
b9d9fc0b |
984 | |
828ecf13 |
985 | =item B<Class::MOP::get_all_metaclass_names> |
be7677c7 |
986 | |
6c842677 |
987 | This will return a list of all the metaclass names that have |
828ecf13 |
988 | been cached by L<Class::MOP::Class>. |
b9d9fc0b |
989 | |
828ecf13 |
990 | =item B<Class::MOP::get_metaclass_by_name($name)> |
be7677c7 |
991 | |
828ecf13 |
992 | This will return a cached L<Class::MOP::Class> instance, or nothing |
6c842677 |
993 | if no metaclass exists with that C<$name>. |
127d39a7 |
994 | |
828ecf13 |
995 | =item B<Class::MOP::store_metaclass_by_name($name, $meta)> |
be7677c7 |
996 | |
127d39a7 |
997 | This will store a metaclass in the cache at the supplied C<$key>. |
998 | |
828ecf13 |
999 | =item B<Class::MOP::weaken_metaclass($name)> |
be7677c7 |
1000 | |
6c842677 |
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 |
1004 | in C<$name>. |
127d39a7 |
1005 | |
828ecf13 |
1006 | =item B<Class::MOP::does_metaclass_exist($name)> |
be7677c7 |
1007 | |
828ecf13 |
1008 | This will return true of there exists a metaclass stored in the |
6c842677 |
1009 | C<$name> key, and return false otherwise. |
127d39a7 |
1010 | |
828ecf13 |
1011 | =item B<Class::MOP::remove_metaclass_by_name($name)> |
be7677c7 |
1012 | |
6c842677 |
1013 | This will remove the metaclass stored in the C<$name> key. |
127d39a7 |
1014 | |
be7677c7 |
1015 | =back |
1016 | |
552e3d24 |
1017 | =head1 SEE ALSO |
8b978dd5 |
1018 | |
552e3d24 |
1019 | =head2 Books |
8b978dd5 |
1020 | |
1d68af04 |
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>> |
a2e85e6c |
1024 | email me and let me know, I would love to hear about them. |
1025 | |
8b978dd5 |
1026 | =over 4 |
1027 | |
15ab5451 |
1028 | =item I<The Art of the Meta Object Protocol> |
8b978dd5 |
1029 | |
15ab5451 |
1030 | =item I<Advances in Object-Oriented Metalevel Architecture and Reflection> |
8b978dd5 |
1031 | |
15ab5451 |
1032 | =item I<Putting MetaClasses to Work> |
b51af7f9 |
1033 | |
15ab5451 |
1034 | =item I<Smalltalk: The Language> |
a2e85e6c |
1035 | |
94b19069 |
1036 | =back |
1037 | |
550d56db |
1038 | =head2 Papers |
1039 | |
1040 | =over 4 |
1041 | |
15ab5451 |
1042 | =item "Uniform and safe metaclass composition" |
550d56db |
1043 | |
1d68af04 |
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 |
550d56db |
1047 | metaclass compatibility. |
1048 | |
1049 | L<http://www.iam.unibe.ch/~scg/Archive/Papers/Duca05ySafeMetaclassTrait.pdf> |
1050 | |
15ab5451 |
1051 | =item "Safe Metaclass Programming" |
550d56db |
1052 | |
1d68af04 |
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. |
550d56db |
1056 | |
1057 | L<http://citeseer.ist.psu.edu/37617.html> |
1058 | |
1059 | =back |
1060 | |
552e3d24 |
1061 | =head2 Prior Art |
8b978dd5 |
1062 | |
1063 | =over 4 |
1064 | |
7184ca14 |
1065 | =item The Perl 6 MetaModel work in the Pugs project |
8b978dd5 |
1066 | |
1067 | =over 4 |
1068 | |
552e3d24 |
1069 | =item L<http://svn.openfoundry.org/pugs/perl5/Perl6-MetaModel> |
8b978dd5 |
1070 | |
552e3d24 |
1071 | =item L<http://svn.openfoundry.org/pugs/perl5/Perl6-ObjectSpace> |
8b978dd5 |
1072 | |
1073 | =back |
1074 | |
94b19069 |
1075 | =back |
1076 | |
1d68af04 |
1077 | =head2 Articles |
f8dfcfb7 |
1078 | |
1079 | =over 4 |
1080 | |
1d68af04 |
1081 | =item CPAN Module Review of Class::MOP |
f8dfcfb7 |
1082 | |
1083 | L<http://www.oreillynet.com/onlamp/blog/2006/06/cpan_module_review_classmop.html> |
1084 | |
1085 | =back |
1086 | |
a2e85e6c |
1087 | =head1 SIMILAR MODULES |
1088 | |
1d68af04 |
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. |
94b19069 |
1095 | |
a2e85e6c |
1096 | =head1 BUGS |
1097 | |
1d68af04 |
1098 | All complex software has bugs lurking in it, and this module is no |
a2e85e6c |
1099 | exception. If you find a bug please either email me, or add the bug |
1100 | to cpan-RT. |
1101 | |
1102 | =head1 ACKNOWLEDGEMENTS |
1103 | |
1104 | =over 4 |
1105 | |
b9d9fc0b |
1106 | =item Rob Kinyon |
a2e85e6c |
1107 | |
1d68af04 |
1108 | Thanks to Rob for actually getting the development of this module kick-started. |
a2e85e6c |
1109 | |
1110 | =back |
1111 | |
1a09d9cc |
1112 | =head1 AUTHORS |
94b19069 |
1113 | |
a2e85e6c |
1114 | Stevan Little E<lt>stevan@iinteractive.comE<gt> |
552e3d24 |
1115 | |
9c8cda90 |
1116 | B<with contributions from:> |
1117 | |
1118 | Brandon (blblack) Black |
1119 | |
4f116037 |
1120 | Florian (rafl) Ragwitz |
1121 | |
9c8cda90 |
1122 | Guillermo (groditi) Roditi |
1123 | |
9195ddff |
1124 | Matt (mst) Trout |
1125 | |
9c8cda90 |
1126 | Rob (robkinyon) Kinyon |
1127 | |
1128 | Yuval (nothingmuch) Kogman |
1a09d9cc |
1129 | |
f430cfa4 |
1130 | Scott (konobi) McWhirter |
1131 | |
94b19069 |
1132 | =head1 COPYRIGHT AND LICENSE |
1133 | |
070bb6c9 |
1134 | Copyright 2006-2009 by Infinity Interactive, Inc. |
94b19069 |
1135 | |
1136 | L<http://www.iinteractive.com> |
1137 | |
1138 | This library is free software; you can redistribute it and/or modify |
1d68af04 |
1139 | it under the same terms as Perl itself. |
94b19069 |
1140 | |
1141 | =cut |