2 package Class::MOP::Method::Attribute;
8 use Scalar::Util 'blessed', 'weaken';
10 our $VERSION = '0.88';
11 $VERSION = eval $VERSION;
12 our $AUTHORITY = 'cpan:STEVAN';
14 use base 'Class::MOP::Method::Generated';
20 (exists $options{attribute})
21 || confess "You must supply an attribute to construct with";
23 (blessed($options{attribute}) && $options{attribute}->isa('Class::MOP::Attribute'))
24 || confess "You must supply an attribute which is a 'Class::MOP::Attribute' instance";
26 ($options{package_name} && $options{name})
27 || confess "You must supply the package_name and name parameters $Class::MOP::Method::UPGRADE_ERROR_TEXT";
29 my $self = $class->_new(\%options);
31 # we don't want this creating
32 # a cycle in the code, if not
34 weaken($self->{'attribute'});
41 my $options = @_ == 1 ? $_[0] : {@_};
43 $options->{is_inline} ||= 0;
45 return bless $options, $class;
50 sub associated_attribute { (shift)->{'attribute'} }
51 sub accessor_type { (shift)->{'accessor_type'} }
56 Carp::cluck('The initialize_body method has been made private.'
57 . " The public version is deprecated and will be removed in a future release.\n");
58 shift->_initialize_body;
70 Class::MOP::Method::Attribute - Method Meta Object for accessors
74 use Class::MOP::Method::Accessor;
76 my $reader = Class::MOP::Method::Accessor->new(
77 attribute => $attribute,
79 accessor_type => 'reader',
82 $reader->body->execute($instance); # call the reader method
86 This is a subclass of <Class::MOP::Method> which is used by
87 C<Class::MOP::Attribute> to generate accessor code. It handles
88 generation of readers, writers, predicates and clearers. For each type
89 of method, it can either create a subroutine reference, or actually
90 inline code by generating a string and C<eval>'ing it.
96 =item B<< Class::MOP::Method::Accessor->new(%options) >>
98 This returns a new C<Class::MOP::Method::Accessor> based on the
105 This is the C<Class::MOP::Attribute> for which accessors are being
106 generated. This option is required.
108 =item * accessor_type
110 This is a string which should be one of "reader", "writer",
111 "accessor", "predicate", or "clearer". This is the type of method
112 being generated. This option is required.
116 This indicates whether or not the accessor should be inlined. This
121 The method name (without a package name). This is required.
125 The package name for the method. This is required.
129 =item B<< $metamethod->accessor_type >>
131 Returns the accessor type which was passed to C<new>.
133 =item B<< $metamethod->is_inline >>
135 Returns a boolean indicating whether or not the accessor is inlined.
137 =item B<< $metamethod->associated_attribute >>
139 This returns the L<Class::MOP::Attribute> object which was passed to
142 =item B<< $metamethod->body >>
144 The method itself is I<generated> when the accessor object is
151 Stevan Little E<lt>stevan@iinteractive.comE<gt>
153 =head1 COPYRIGHT AND LICENSE
155 Copyright 2006-2009 by Infinity Interactive, Inc.
157 L<http://www.iinteractive.com>
159 This library is free software; you can redistribute it and/or modify
160 it under the same terms as Perl itself.