2 package Class::MOP::Method::Writer;
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::Attribute';
16 sub _initialize_body {
19 my $method_name = join "_" => (
22 ($self->is_inline ? 'inline' : ())
25 $self->{'body'} = $self->$method_name();
31 Carp::cluck('The generate_writer_method method has been made private.'
32 . " The public version is deprecated and will be removed in a future release.\n");
33 shift->_generate_method;
36 sub _generate_method {
37 my $attr = (shift)->associated_attribute;
39 $attr->set_value($_[0], $_[1]);
45 sub generate_method_inline {
46 Carp::cluck('The generate_writer_method_inline method has been made private.'
47 . " The public version is deprecated and will be removed in a future release.\n");
48 shift->_generate_method_inline;
51 sub _generate_method_inline {
53 my $attr = $self->associated_attribute;
54 my $attr_name = $attr->name;
55 my $meta_instance = $attr->associated_class->instance_metaclass;
57 my ( $code, $e ) = $self->_eval_closure(
60 . $meta_instance->inline_set_slot_value('$_[0]', $attr_name, '$_[1]')
63 confess "Could not generate inline writer because : $e" if $e;
77 Class::MOP::Method::Writer - Method Meta Object for accessors
81 use Class::MOP::Method::Accessor;
83 my $reader = Class::MOP::Method::Accessor->new(
84 attribute => $attribute,
86 accessor_type => 'reader',
89 $reader->body->execute($instance); # call the reader method
93 This is a subclass of <Class::MOP::Method> which is used by
94 C<Class::MOP::Attribute> to generate accessor code. It handles
95 generation of readers, writers, predicates and clearers. For each type
96 of method, it can either create a subroutine reference, or actually
97 inline code by generating a string and C<eval>'ing it.
103 =item B<< Class::MOP::Method::Accessor->new(%options) >>
105 This returns a new C<Class::MOP::Method::Accessor> based on the
106 C<%options> provided.
112 This is the C<Class::MOP::Attribute> for which accessors are being
113 generated. This option is required.
115 =item * accessor_type
117 This is a string which should be one of "reader", "writer",
118 "accessor", "predicate", or "clearer". This is the type of method
119 being generated. This option is required.
123 This indicates whether or not the accessor should be inlined. This
128 The method name (without a package name). This is required.
132 The package name for the method. This is required.
136 =item B<< $metamethod->accessor_type >>
138 Returns the accessor type which was passed to C<new>.
140 =item B<< $metamethod->is_inline >>
142 Returns a boolean indicating whether or not the accessor is inlined.
144 =item B<< $metamethod->associated_attribute >>
146 This returns the L<Class::MOP::Attribute> object which was passed to
149 =item B<< $metamethod->body >>
151 The method itself is I<generated> when the accessor object is
158 Stevan Little E<lt>stevan@iinteractive.comE<gt>
160 =head1 COPYRIGHT AND LICENSE
162 Copyright 2006-2009 by Infinity Interactive, Inc.
164 L<http://www.iinteractive.com>
166 This library is free software; you can redistribute it and/or modify
167 it under the same terms as Perl itself.