2 package Moose::Meta::Method::Accessor;
9 use base 'Moose::Meta::Method',
10 'Class::MOP::Method::Accessor';
12 # multiple inheritance is terrible
14 goto &Class::MOP::Method::Accessor::new;
18 goto &Class::MOP::Method::Accessor::_new;
23 return $self->associated_attribute
24 if ref($self) && defined($self->associated_attribute);
25 return $self->SUPER::_error_thrower;
32 $self->SUPER::_compile_code(@args);
36 'Could not create writer for '
37 . "'" . $self->associated_attribute->name . "' "
44 sub _eval_environment {
49 my $attr = $self->associated_attribute;
51 $env->{'$trigger'} = \($attr->trigger)
52 if $attr->has_trigger;
53 $env->{'$attr_default'} = \($attr->default)
54 if $attr->has_default;
56 if ($attr->has_type_constraint) {
57 my $tc_obj = $attr->type_constraint;
59 $env->{'$type_constraint'} = \(
60 $tc_obj->_compiled_type_constraint
61 ) unless $tc_obj->can_be_inlined;
62 # these two could probably get inlined versions too
63 $env->{'$type_coercion'} = \(
64 $tc_obj->coercion->_compiled_type_coercion
65 ) if $tc_obj->has_coercion;
66 $env->{'$type_message'} = \(
67 $tc_obj->has_message ? $tc_obj->message : $tc_obj->_default_message
70 $env = { %$env, %{ $tc_obj->inline_environment } };
74 $env->{'$attr'} = \$attr
75 if $attr->has_initializer && $attr->is_lazy;
76 # pretty sure this is only going to be closed over if you use a custom
77 # error class at this point, but we should still get rid of this
79 $env->{'$meta'} = \($self->associated_metaclass);
84 sub _instance_is_inlinable {
86 return $self->associated_attribute->associated_class->instance_metaclass->is_inlinable;
89 sub _generate_reader_method {
91 $self->_instance_is_inlinable ? $self->_generate_reader_method_inline(@_)
92 : $self->SUPER::_generate_reader_method(@_);
95 sub _generate_writer_method {
97 $self->_instance_is_inlinable ? $self->_generate_writer_method_inline(@_)
98 : $self->SUPER::_generate_writer_method(@_);
101 sub _generate_accessor_method {
103 $self->_instance_is_inlinable ? $self->_generate_accessor_method_inline(@_)
104 : $self->SUPER::_generate_accessor_method(@_);
107 sub _generate_predicate_method {
109 $self->_instance_is_inlinable ? $self->_generate_predicate_method_inline(@_)
110 : $self->SUPER::_generate_predicate_method(@_);
113 sub _generate_clearer_method {
115 $self->_instance_is_inlinable ? $self->_generate_clearer_method_inline(@_)
116 : $self->SUPER::_generate_clearer_method(@_);
119 sub _writer_value_needs_copy {
120 shift->associated_attribute->_writer_value_needs_copy(@_);
123 sub _inline_tc_code {
124 shift->associated_attribute->_inline_tc_code(@_);
127 sub _inline_check_coercion {
128 shift->associated_attribute->_inline_check_coercion(@_);
131 sub _inline_check_constraint {
132 shift->associated_attribute->_inline_check_constraint(@_);
135 sub _inline_check_lazy {
136 shift->associated_attribute->_inline_check_lazy(@_);
139 sub _inline_store_value {
140 shift->associated_attribute->_inline_instance_set(@_) . ';';
143 sub _inline_get_old_value_for_trigger {
144 shift->associated_attribute->_inline_get_old_value_for_trigger(@_);
147 sub _inline_trigger {
148 shift->associated_attribute->_inline_trigger(@_);
152 shift->associated_attribute->_inline_instance_get(@_);
156 shift->associated_attribute->_inline_instance_has(@_);
161 # ABSTRACT: A Moose Method metaclass for accessors
169 This class is a subclass of L<Class::MOP::Method::Accessor> that
170 provides additional Moose-specific functionality, all of which is
173 To understand this class, you should read the the
174 L<Class::MOP::Method::Accessor> documentation.
178 See L<Moose/BUGS> for details on reporting bugs.