add has_read_method and has_write_method
[gitmo/Class-MOP.git] / lib / Class / MOP / Attribute.pm
1
2 package Class::MOP::Attribute;
3
4 use strict;
5 use warnings;
6
7 use Class::MOP::Method::Accessor;
8
9 use Carp         'confess';
10 use Scalar::Util 'blessed', 'reftype', 'weaken';
11
12 our $VERSION   = '0.24';
13 our $AUTHORITY = 'cpan:STEVAN';
14
15 use base 'Class::MOP::Object';
16
17 # NOTE: (meta-circularity)
18 # This method will be replaced in the
19 # boostrap section of Class::MOP, by
20 # a new version which uses the
21 # &Class::MOP::Class::construct_instance
22 # method to build an attribute meta-object
23 # which itself is described with attribute
24 # meta-objects.
25 #     - Ain't meta-circularity grand? :)
26 sub new {
27     my $class   = shift;
28     my $name    = shift;
29     my %options = @_;
30
31     (defined $name && $name)
32         || confess "You must provide a name for the attribute";
33
34     $options{init_arg} = $name
35         if not exists $options{init_arg};
36     if(exists $options{builder}){
37         confess("builder must be a defined scalar value which is a method name")
38             if ref $options{builder} || !(defined $options{builder});
39         confess("Setting both default and builder is not allowed.")
40             if exists $options{default};
41     } else {
42         (is_default_a_coderef(\%options))
43             || confess("References are not allowed as default values, you must ".
44                        "wrap then in a CODE reference (ex: sub { [] } and not [])")
45                 if exists $options{default} && ref $options{default};
46     }
47     if( $options{required} and not( defined($options{builder}) || defined($options{init_arg}) || exists $options{default} ) ) {
48         confess("A required attribute must have either 'init_arg', 'builder', or 'default'");
49     }
50     bless {
51         '$!name'      => $name,
52         '$!accessor'  => $options{accessor},
53         '$!reader'    => $options{reader},
54         '$!writer'      => $options{writer},
55         '$!predicate'   => $options{predicate},
56         '$!clearer'     => $options{clearer},
57         '$!builder'     => $options{builder},
58         '$!init_arg'    => $options{init_arg},
59         '$!default'     => $options{default},
60         '$!initializer' => $options{initializer},        
61         # keep a weakened link to the
62         # class we are associated with
63         '$!associated_class' => undef,
64         # and a list of the methods
65         # associated with this attr
66         '@!associated_methods' => [],
67         # NOTE:
68         # protect this from silliness
69         init_arg => undef,
70     } => $class;
71 }
72
73 # NOTE:
74 # this is a primative (and kludgy) clone operation
75 # for now, it will be replaced in the Class::MOP
76 # bootstrap with a proper one, however we know
77 # that this one will work fine for now.
78 sub clone {
79     my $self    = shift;
80     my %options = @_;
81     (blessed($self))
82         || confess "Can only clone an instance";
83     return bless { %{$self}, %options } => blessed($self);
84 }
85
86 sub initialize_instance_slot {
87     my ($self, $meta_instance, $instance, $params) = @_;
88     my $init_arg = $self->{'$!init_arg'};
89     # try to fetch the init arg from the %params ...
90
91     # if nothing was in the %params, we can use the
92     # attribute's default value (if it has one)
93     if(defined $init_arg and exists $params->{$init_arg}){
94         $self->_set_initial_slot_value(
95             $meta_instance, 
96             $instance,
97             $params->{$init_arg},
98         );
99     } 
100     elsif (defined $self->{'$!default'}) {
101         $self->_set_initial_slot_value(
102             $meta_instance, 
103             $instance,
104             $self->default($instance),
105         );
106     } 
107     elsif (defined( my $builder = $self->{'$!builder'})) {
108         if ($builder = $instance->can($builder)) {
109             $self->_set_initial_slot_value(
110                 $meta_instance, 
111                 $instance,
112                 $instance->$builder,
113             );
114         } 
115         else {
116             confess(blessed($instance)." does not support builder method '". $self->{'$!builder'} ."' for attribute '" . $self->name . "'");
117         }
118     }
119 }
120
121 sub _set_initial_slot_value {
122     my ($self, $meta_instance, $instance, $value) = @_;
123
124     my $slot_name = $self->name;
125
126     return $meta_instance->set_slot_value($instance, $slot_name, $value)
127         unless $self->has_initializer;
128
129     my $callback = sub {
130         $meta_instance->set_slot_value($instance, $slot_name, $_[0]);
131     };
132     
133     my $initializer = $self->initializer;
134
135     # most things will just want to set a value, so make it first arg
136     $instance->$initializer($value, $callback, $self);
137 }
138
139 # NOTE:
140 # the next bunch of methods will get bootstrapped
141 # away in the Class::MOP bootstrapping section
142
143 sub name { $_[0]->{'$!name'} }
144
145 sub associated_class   { $_[0]->{'$!associated_class'}   }
146 sub associated_methods { $_[0]->{'@!associated_methods'} }
147
148 sub has_accessor    { defined($_[0]->{'$!accessor'})     ? 1 : 0 }
149 sub has_reader      { defined($_[0]->{'$!reader'})       ? 1 : 0 }
150 sub has_writer      { defined($_[0]->{'$!writer'})       ? 1 : 0 }
151 sub has_predicate   { defined($_[0]->{'$!predicate'})    ? 1 : 0 }
152 sub has_clearer     { defined($_[0]->{'$!clearer'})      ? 1 : 0 }
153 sub has_builder     { defined($_[0]->{'$!builder'})      ? 1 : 0 }
154 sub has_init_arg    { defined($_[0]->{'$!init_arg'})     ? 1 : 0 }
155 sub has_default     { defined($_[0]->{'$!default'})      ? 1 : 0 }
156 sub has_initializer { defined($_[0]->{'$!initializer'})  ? 1 : 0 }
157
158 sub accessor    { $_[0]->{'$!accessor'}    }
159 sub reader      { $_[0]->{'$!reader'}      }
160 sub writer      { $_[0]->{'$!writer'}      }
161 sub predicate   { $_[0]->{'$!predicate'}   }
162 sub clearer     { $_[0]->{'$!clearer'}     }
163 sub builder     { $_[0]->{'$!builder'}     }
164 sub init_arg    { $_[0]->{'$!init_arg'}    }
165 sub initializer { $_[0]->{'$!initializer'} }
166
167 # end bootstrapped away method section.
168 # (all methods below here are kept intact)
169
170 sub has_read_method  { $_[0]->has_reader || $_[0]->has_accessor }
171 sub has_write_method { $_[0]->has_writer || $_[0]->has_accessor }
172
173 sub get_read_method  { 
174     my $self   = shift;    
175     my $reader = $self->reader || $self->accessor;
176     # normal case ...
177     return $reader unless ref $reader;
178     # the HASH ref case
179     my ($name) = %$reader;
180     return $name;
181 }
182
183 sub get_write_method { 
184     my $self   = shift;
185     my $writer = $self->writer || $self->accessor; 
186     # normal case ...
187     return $writer unless ref $writer;
188     # the HASH ref case
189     my ($name) = %$writer;
190     return $name;    
191 }
192
193 sub get_read_method_ref {
194     my $self = shift;
195     if ((my $reader = $self->get_read_method) && $self->associated_class) {   
196         return $self->associated_class->get_method($reader);
197     }
198     else {
199         return sub { $self->get_value(@_) };
200     }
201 }
202
203 sub get_write_method_ref {
204     my $self = shift;    
205     if ((my $writer = $self->get_write_method) && $self->associated_class) {         
206         return $self->associated_class->get_method($writer);
207     }
208     else {
209         return sub { $self->set_value(@_) };
210     }
211 }
212
213 sub is_default_a_coderef {
214     ('CODE' eq (reftype($_[0]->{'$!default'} || $_[0]->{default}) || ''))
215 }
216
217 sub default {
218     my ($self, $instance) = @_;
219     if (defined $instance && $self->is_default_a_coderef) {
220         # if the default is a CODE ref, then
221         # we pass in the instance and default
222         # can return a value based on that
223         # instance. Somewhat crude, but works.
224         return $self->{'$!default'}->($instance);
225     }
226     $self->{'$!default'};
227 }
228
229 # slots
230
231 sub slots { (shift)->name }
232
233 # class association
234
235 sub attach_to_class {
236     my ($self, $class) = @_;
237     (blessed($class) && $class->isa('Class::MOP::Class'))
238         || confess "You must pass a Class::MOP::Class instance (or a subclass)";
239     weaken($self->{'$!associated_class'} = $class);
240 }
241
242 sub detach_from_class {
243     my $self = shift;
244     $self->{'$!associated_class'} = undef;
245 }
246
247 # method association
248
249 sub associate_method {
250     my ($self, $method) = @_;
251     push @{$self->{'@!associated_methods'}} => $method;
252 }
253
254 ## Slot management
255
256 sub set_initial_value {
257     my ($self, $instance, $value) = @_;
258     $self->_set_initial_slot_value(
259         Class::MOP::Class->initialize(blessed($instance))->get_meta_instance,
260         $instance,
261         $value
262     );
263 }
264
265 sub set_value {
266     my ($self, $instance, $value) = @_;
267
268     Class::MOP::Class->initialize(blessed($instance))
269                      ->get_meta_instance
270                      ->set_slot_value($instance, $self->name, $value);
271 }
272
273 sub get_value {
274     my ($self, $instance) = @_;
275
276     Class::MOP::Class->initialize(blessed($instance))
277                      ->get_meta_instance
278                      ->get_slot_value($instance, $self->name);
279 }
280
281 sub has_value {
282     my ($self, $instance) = @_;
283
284     Class::MOP::Class->initialize(blessed($instance))
285                      ->get_meta_instance
286                      ->is_slot_initialized($instance, $self->name);
287 }
288
289 sub clear_value {
290     my ($self, $instance) = @_;
291
292     Class::MOP::Class->initialize(blessed($instance))
293                      ->get_meta_instance
294                      ->deinitialize_slot($instance, $self->name);
295 }
296
297 ## load em up ...
298
299 sub accessor_metaclass { 'Class::MOP::Method::Accessor' }
300
301 sub process_accessors {
302     my ($self, $type, $accessor, $generate_as_inline_methods) = @_;
303     if (reftype($accessor)) {
304         (reftype($accessor) eq 'HASH')
305             || confess "bad accessor/reader/writer/predicate/clearer format, must be a HASH ref";
306         my ($name, $method) = %{$accessor};
307         $method = $self->accessor_metaclass->wrap($method);
308         $self->associate_method($method);
309         return ($name, $method);
310     }
311     else {
312         my $inline_me = ($generate_as_inline_methods && $self->associated_class->instance_metaclass->is_inlinable);
313         my $method;
314         eval {
315             $method = $self->accessor_metaclass->new(
316                 attribute     => $self,
317                 is_inline     => $inline_me,
318                 accessor_type => $type,
319             );
320         };
321         confess "Could not create the '$type' method for " . $self->name . " because : $@" if $@;
322         $self->associate_method($method);
323         return ($accessor, $method);
324     }
325 }
326
327 sub install_accessors {
328     my $self   = shift;
329     my $inline = shift;
330     my $class  = $self->associated_class;
331
332     $class->add_method(
333         $self->process_accessors('accessor' => $self->accessor(), $inline)
334     ) if $self->has_accessor();
335
336     $class->add_method(
337         $self->process_accessors('reader' => $self->reader(), $inline)
338     ) if $self->has_reader();
339
340     $class->add_method(
341         $self->process_accessors('writer' => $self->writer(), $inline)
342     ) if $self->has_writer();
343
344     $class->add_method(
345         $self->process_accessors('predicate' => $self->predicate(), $inline)
346     ) if $self->has_predicate();
347
348     $class->add_method(
349         $self->process_accessors('clearer' => $self->clearer(), $inline)
350     ) if $self->has_clearer();
351
352     return;
353 }
354
355 {
356     my $_remove_accessor = sub {
357         my ($accessor, $class) = @_;
358         if (reftype($accessor) && reftype($accessor) eq 'HASH') {
359             ($accessor) = keys %{$accessor};
360         }
361         my $method = $class->get_method($accessor);
362         $class->remove_method($accessor)
363             if (blessed($method) && $method->isa('Class::MOP::Method::Accessor'));
364     };
365
366     sub remove_accessors {
367         my $self = shift;
368         # TODO:
369         # we really need to make sure to remove from the
370         # associates methods here as well. But this is
371         # such a slimly used method, I am not worried
372         # about it right now.
373         $_remove_accessor->($self->accessor(),  $self->associated_class()) if $self->has_accessor();
374         $_remove_accessor->($self->reader(),    $self->associated_class()) if $self->has_reader();
375         $_remove_accessor->($self->writer(),    $self->associated_class()) if $self->has_writer();
376         $_remove_accessor->($self->predicate(), $self->associated_class()) if $self->has_predicate();
377         $_remove_accessor->($self->clearer(),   $self->associated_class()) if $self->has_clearer();
378         return;
379     }
380
381 }
382
383 1;
384
385 __END__
386
387 =pod
388
389 =head1 NAME
390
391 Class::MOP::Attribute - Attribute Meta Object
392
393 =head1 SYNOPSIS
394
395   Class::MOP::Attribute->new('$foo' => (
396       accessor  => 'foo',        # dual purpose get/set accessor
397       predicate => 'has_foo'     # predicate check for defined-ness
398       init_arg  => '-foo',       # class->new will look for a -foo key
399       default   => 'BAR IS BAZ!' # if no -foo key is provided, use this
400   ));
401
402   Class::MOP::Attribute->new('$.bar' => (
403       reader    => 'bar',        # getter
404       writer    => 'set_bar',    # setter
405       predicate => 'has_bar'     # predicate check for defined-ness
406       init_arg  => ':bar',       # class->new will look for a :bar key
407       # no default value means it is undef
408   ));
409
410 =head1 DESCRIPTION
411
412 The Attribute Protocol is almost entirely an invention of this module,
413 and is completely optional to this MOP. This is because Perl 5 does not
414 have consistent notion of what is an attribute of a class. There are
415 so many ways in which this is done, and very few (if any) are
416 easily discoverable by this module.
417
418 So, all that said, this module attempts to inject some order into this
419 chaos, by introducing a consistent API which can be used to create
420 object attributes.
421
422 =head1 METHODS
423
424 =head2 Creation
425
426 =over 4
427
428 =item B<new ($name, ?%options)>
429
430 An attribute must (at the very least), have a C<$name>. All other
431 C<%options> are contained added as key-value pairs. Acceptable keys
432 are as follows:
433
434 =over 4
435
436 =item I<init_arg>
437
438 This should be a string value representing the expected key in
439 an initialization hash. For instance, if we have an I<init_arg>
440 value of C<-foo>, then the following code will Just Work.
441
442   MyClass->meta->construct_instance(-foo => "Hello There");
443
444 In an init_arg is not assigned, it will automatically use the
445 value of C<$name>.  If an explicit C<undef> is given for an init_arg,
446 an attribute value can't be specified during initialization.
447
448 =item I<builder>
449
450 The value of this key is the name of the method that will be
451 called to obtain the value used to initialize the attribute.
452 This should be a method in the class associated with the attribute,
453 not a method in the attribute class itself.
454
455 =item I<default>
456
457 The value of this key is the default value which
458 C<Class::MOP::Class::construct_instance> will initialize the
459 attribute to.
460
461 B<NOTE:>
462 If the value is a simple scalar (string or number), then it can
463 be just passed as is. However, if you wish to initialize it with
464 a HASH or ARRAY ref, then you need to wrap that inside a CODE
465 reference, like so:
466
467   Class::MOP::Attribute->new('@foo' => (
468       default => sub { [] },
469   ));
470
471   # or ...
472
473   Class::MOP::Attribute->new('%foo' => (
474       default => sub { {} },
475   ));
476
477 If you wish to initialize an attribute with a CODE reference
478 itself, then you need to wrap that in a subroutine as well, like
479 so:
480
481   Class::MOP::Attribute->new('&foo' => (
482       default => sub { sub { print "Hello World" } },
483   ));
484
485 And lastly, if the value of your attribute is dependent upon
486 some other aspect of the instance structure, then you can take
487 advantage of the fact that when the I<default> value is a CODE
488 reference, it is passed the (as yet unfinished) instance structure
489 as it's only argument. So you can do things like this:
490
491   Class::MOP::Attribute->new('$object_identity' => (
492       default => sub { Scalar::Util::refaddr($_[0]) },
493   ));
494
495 This last feature is fairly limited as there is no gurantee of
496 the order of attribute initializations, so you cannot perform
497 any kind of dependent initializations. However, if this is
498 something you need, you could subclass B<Class::MOP::Class> and
499 this class to acheive it. However, this is currently left as
500 an exercise to the reader :).
501
502 =item I<initializer>
503
504 This may be a method name (referring to a method on the class with this
505 attribute) or a CODE ref.  The initializer is used to set the attribute value
506 on an instance when the attribute is set during instance initialization.  When
507 called, it is passed the instance (as the invocant), the value to set, a
508 slot-setting CODE ref, and the attribute meta-instance.  The slot-setting code
509 is provided to make it easy to set the (possibly altered) value on the instance
510 without going through several more method calls.
511
512 This contrived example shows an initializer that sets the attribute to twice
513 the given value.
514
515   Class::MOP::Attribute->new('$doubled' => (
516       initializer => sub {
517           my ($instance, $value, $set) = @_;
518           $set->($value * 2);
519       },
520   ));
521
522 As method names can be given as initializers, one can easily make
523 attribute initialization use the writer:
524
525   Class::MOP::Attribute->new('$some_attr' => (
526       writer      => 'some_attr',
527       initializer => 'some_attr',
528   ));
529
530 Your writer will simply need to examine it's C<@_> and determine under
531 which context it is being called.
532
533 =back
534
535 The I<accessor>, I<reader>, I<writer>, I<predicate> and I<clearer> keys can
536 contain either; the name of the method and an appropriate default one will be
537 generated for you, B<or> a HASH ref containing exactly one key (which will be
538 used as the name of the method) and one value, which should contain a CODE
539 reference which will be installed as the method itself.
540
541 =over 4
542
543 =item I<accessor>
544
545 The I<accessor> is a standard perl-style read/write accessor. It will
546 return the value of the attribute, and if a value is passed as an argument,
547 it will assign that value to the attribute.
548
549 B<NOTE:>
550 This method will properly handle the following code, by assigning an
551 C<undef> value to the attribute.
552
553   $object->set_something(undef);
554
555 =item I<reader>
556
557 This is a basic read-only accessor, it will just return the value of
558 the attribute.
559
560 =item I<writer>
561
562 This is a basic write accessor, it accepts a single argument, and
563 assigns that value to the attribute. This method does not intentially
564 return a value, however perl will return the result of the last
565 expression in the subroutine, which returns in this returning the
566 same value that it was passed.
567
568 B<NOTE:>
569 This method will properly handle the following code, by assigning an
570 C<undef> value to the attribute.
571
572   $object->set_something();
573
574 =item I<predicate>
575
576 This is a basic test to see if any value has been set for the 
577 attribute. It will return true (C<1>) if the attribute has been set 
578 to any value (even C<undef>), and false (C<0>) otherwise.
579
580 B<NOTE:>
581 The predicate will return true even when you set an attribute's
582 value to C<undef>. This behaviour has changed as of version 0.43. In 
583 older versions, the predicate (erroneously) checked for attribute 
584 value definedness, instead of presence as it is now.
585
586 If you really want to get rid of the value, you have to define and 
587 use a I<clearer> (see below).
588
589 =item I<clearer>
590
591 This is the a method that will uninitialize the attr, reverting lazy values
592 back to their "unfulfilled" state.
593
594 =back
595
596 =item B<clone (%options)>
597
598 This will return a clone of the attribute instance, allowing the overriding
599 of various attributes through the C<%options> supplied.
600
601 =item B<initialize_instance_slot ($instance, $params)>
602
603 This method is used internally to initialize the approriate slot for this 
604 attribute in a given C<$instance>, the C<$params> passed are those that were
605 passed to the constructor.
606
607 =back
608
609 =head2 Value management
610
611 These methods are basically "backdoors" to the instance, which can be used
612 to bypass the regular accessors, but still stay within the context of the MOP.
613
614 These methods are not for general use, and should only be used if you really
615 know what you are doing.
616
617 =over 4
618
619 =item B<set_value ($instance, $value)>
620
621 Set the value without going through the accessor. Note that this may be done to
622 even attributes with just read only accessors.
623
624 =item B<set_initial_value ($instance, $value)>
625
626 This method sets the value without going through the accessor -- but it is only
627 called when the instance data is first initialized.
628
629 =item B<get_value ($instance)>
630
631 Return the value without going through the accessor. Note that this may be done
632 even to attributes with just write only accessors.
633
634 =item B<has_value ($instance)>
635
636 Return a boolean indicating if the item in the C<$instance> has a value in it.
637 This is basically what the default C<predicate> method calls.
638
639 =item B<clear_value ($instance)>
640
641 This will clear the value in the C<$instance>. This is basically what the default
642 C<clearer> would call. Note that this may be done even if the attirbute does not
643 have any associated read, write or clear methods.
644
645 =back
646
647 =head2 Informational
648
649 These are all basic read-only value accessors for the values
650 passed into C<new>. I think they are pretty much self-explanitory.
651
652 =over 4
653
654 =item B<name>
655
656 =item B<accessor>
657
658 =item B<reader>
659
660 =item B<writer>
661
662 =item B<predicate>
663
664 =item B<clearer>
665
666 =item B<initializer>
667
668 =item B<init_arg>
669
670 =item B<is_default_a_coderef>
671
672 =item B<default (?$instance)>
673
674 Return the default value for the attribute.
675
676 If you pass in an C<$instance> argument to this accessor and the
677 I<default> is a CODE reference, then the CODE reference will be
678 executed with the C<$instance> as its argument.
679
680 =item B<slots>
681
682 Return a list of slots required by the attribute. This is usually
683 just one, which is the name of the attribute.
684
685 =item B<get_read_method>
686
687 =item B<get_write_method>
688
689 Return the name of a method name suitable for reading / writing the value 
690 of the attribute in the associated class. Suitable for use whether 
691 C<reader> and C<writer> or C<accessor> was used.
692
693 =item B<get_read_method_ref>
694
695 =item B<get_write_method_ref>
696
697 Return the CODE reference of a method suitable for reading / writing the 
698 value of the attribute in the associated class. Suitable for use whether 
699 C<reader> and C<writer> or C<accessor> was specified or not.
700
701 NOTE: If no reader/writer/accessor was specified, this will use the 
702 attribute get_value/set_value methods, which can be very inefficient.
703
704 =item B<has_read_method>
705
706 =item B<has_write_method>
707
708 Return whether a method exists suitable for reading / writing the value 
709 of the attribute in the associated class. Suitable for use whether 
710 C<reader> and C<writer> or C<accessor> was used.
711
712 =back
713
714 =head2 Informational predicates
715
716 These are all basic predicate methods for the values passed into C<new>.
717
718 =over 4
719
720 =item B<has_accessor>
721
722 =item B<has_reader>
723
724 =item B<has_writer>
725
726 =item B<has_predicate>
727
728 =item B<has_clearer>
729
730 =item B<has_initializer>
731
732 =item B<has_init_arg>
733
734 =item B<has_default>
735
736 =item B<has_builder>
737
738 =back
739
740 =head2 Class association
741
742 These methods allow you to manage the attributes association with
743 the class that contains it. These methods should not be used
744 lightly, nor are they very magical, they are mostly used internally
745 and by metaclass instances.
746
747 =over 4
748
749 =item B<associated_class>
750
751 This returns the metaclass this attribute is associated with.
752
753 =item B<attach_to_class ($class)>
754
755 This will store a weaken reference to C<$class> internally. You should
756 note that just changing the class assocation will not remove the attribute
757 from it's old class, and initialize it (and it's accessors) in the new
758 C<$class>. It is up to you to do this manually.
759
760 =item B<detach_from_class>
761
762 This will remove the weakened reference to the class. It does B<not>
763 remove the attribute itself from the class (or remove it's accessors),
764 you must do that yourself if you want too. Actually if that is what
765 you want to do, you should probably be looking at
766 L<Class::MOP::Class::remove_attribute> instead.
767
768 =back
769
770 =head2 Attribute Accessor generation
771
772 =over 4
773
774 =item B<accessor_metaclass>
775
776 Accessors are generated by an accessor metaclass, which is usually
777 a subclass of C<Class::MOP::Method::Accessor>. This method returns
778 the name of the accessor metaclass that this attribute uses.
779
780 =item B<associate_method ($method)>
781
782 This will associate a C<$method> with the given attribute which is
783 used internally by the accessor generator.
784
785 =item B<associated_methods>
786
787 This will return the list of methods which have been associated with
788 the C<associate_method> methods. This is a good way of seeing what 
789 methods are used to manage a given attribute. 
790
791 =item B<install_accessors>
792
793 This allows the attribute to generate and install code for it's own
794 I<accessor/reader/writer/predicate> methods. This is called by
795 C<Class::MOP::Class::add_attribute>.
796
797 This method will call C<process_accessors> for each of the possible
798 method types (accessor, reader, writer & predicate).
799
800 =item B<process_accessors ($type, $value)>
801
802 This takes a C<$type> (accessor, reader, writer or predicate), and
803 a C<$value> (the value passed into the constructor for each of the
804 different types). It will then either generate the method itself
805 (using the C<generate_*_method> methods listed below) or it will
806 use the custom method passed through the constructor.
807
808 =item B<remove_accessors>
809
810 This allows the attribute to remove the method for it's own
811 I<accessor/reader/writer/predicate/clearer>. This is called by
812 C<Class::MOP::Class::remove_attribute>.
813
814 NOTE: This does not currently remove methods from the list returned
815 by C<associated_methods>, that is on the TODO list.
816
817 =back
818
819 =head2 Introspection
820
821 =over 4
822
823 =item B<meta>
824
825 This will return a B<Class::MOP::Class> instance which is related
826 to this class.
827
828 It should also be noted that B<Class::MOP> will actually bootstrap
829 this module by installing a number of attribute meta-objects into
830 it's metaclass. This will allow this class to reap all the benefits
831 of the MOP when subclassing it.
832
833 =back
834
835 =head1 AUTHORS
836
837 Stevan Little E<lt>stevan@iinteractive.comE<gt>
838
839 =head1 COPYRIGHT AND LICENSE
840
841 Copyright 2006-2008 by Infinity Interactive, Inc.
842
843 L<http://www.iinteractive.com>
844
845 This library is free software; you can redistribute it and/or modify
846 it under the same terms as Perl itself.
847
848 =cut
849
850