Commit | Line | Data |
8ee73eeb |
1 | |
2 | package Moose::Meta::Method::Accessor; |
3 | |
4 | use strict; |
5 | use warnings; |
6 | |
55c361dc |
7 | use Try::Tiny; |
8 | |
39b3bc94 |
9 | use base 'Moose::Meta::Method', |
d617b644 |
10 | 'Class::MOP::Method::Accessor'; |
11 | |
18748ad6 |
12 | sub _error_thrower { |
13 | my $self = shift; |
cc743de9 |
14 | return $self->associated_attribute |
15 | if ref($self) && defined($self->associated_attribute); |
16 | return $self->SUPER::_error_thrower; |
18748ad6 |
17 | } |
d617b644 |
18 | |
55c361dc |
19 | sub _compile_code { |
20 | my $self = shift; |
21 | my @args = @_; |
22 | try { |
23 | $self->SUPER::_compile_code(@args); |
24 | } |
25 | catch { |
26 | $self->throw_error( |
27 | 'Could not create writer for ' |
28 | . "'" . $self->associated_attribute->name . "' " |
29 | . 'because ' . $_, |
30 | error => $_, |
31 | ); |
32 | }; |
c9183ffc |
33 | } |
34 | |
f5f08b5f |
35 | sub _eval_environment { |
36 | my $self = shift; |
37 | |
144a8df1 |
38 | my $env = { }; |
39 | |
40 | my $attr = $self->associated_attribute; |
41 | |
42 | $env->{'$trigger'} = \($attr->trigger) |
43 | if $attr->has_trigger; |
44 | $env->{'$default'} = \($attr->default) |
45 | if $attr->has_default; |
46 | |
47 | if ($attr->has_type_constraint) { |
48 | my $tc_obj = $attr->type_constraint; |
49 | |
c40e4359 |
50 | # is this going to be an issue? it's currently only used for the tc |
51 | # message. is there a way to inline that too? |
144a8df1 |
52 | $env->{'$type_constraint_obj'} = \$tc_obj; |
c40e4359 |
53 | |
54 | $env->{'$type_constraint'} = \( |
55 | $tc_obj->_compiled_type_constraint |
56 | ) unless $tc_obj->can_be_inlined; |
57 | $env->{'$type_coercion'} = \( |
58 | $tc_obj->coercion->_compiled_type_coercion |
59 | ) if $tc_obj->has_coercion; |
144a8df1 |
60 | |
61 | $env = { %$env, %{ $tc_obj->inline_environment } }; |
62 | } |
63 | |
64 | # XXX ugh, fix these |
65 | $env->{'$attr'} = \$attr |
66 | if $attr->has_initializer; |
67 | $env->{'$meta'} = \$self; |
68 | |
69 | return $env; |
f5f08b5f |
70 | } |
71 | |
f001c60f |
72 | sub _instance_is_inlinable { |
73 | my $self = shift; |
74 | return $self->associated_attribute->associated_class->instance_metaclass->is_inlinable; |
75 | } |
76 | |
77 | sub _generate_reader_method { |
78 | my $self = shift; |
79 | $self->_instance_is_inlinable ? $self->_generate_reader_method_inline(@_) |
80 | : $self->SUPER::_generate_reader_method(@_); |
81 | } |
82 | |
83 | sub _generate_writer_method { |
84 | my $self = shift; |
85 | $self->_instance_is_inlinable ? $self->_generate_writer_method_inline(@_) |
86 | : $self->SUPER::_generate_writer_method(@_); |
87 | } |
88 | |
89 | sub _generate_accessor_method { |
90 | my $self = shift; |
91 | $self->_instance_is_inlinable ? $self->_generate_accessor_method_inline(@_) |
92 | : $self->SUPER::_generate_accessor_method(@_); |
93 | } |
94 | |
95 | sub _generate_predicate_method { |
96 | my $self = shift; |
97 | $self->_instance_is_inlinable ? $self->_generate_predicate_method_inline(@_) |
98 | : $self->SUPER::_generate_predicate_method(@_); |
99 | } |
100 | |
101 | sub _generate_clearer_method { |
102 | my $self = shift; |
103 | $self->_instance_is_inlinable ? $self->_generate_clearer_method_inline(@_) |
104 | : $self->SUPER::_generate_clearer_method(@_); |
105 | } |
8ecb1fa0 |
106 | |
6e50f7e9 |
107 | sub _writer_value_needs_copy { |
108 | shift->associated_attribute->_writer_value_needs_copy(@_); |
109 | } |
c350159f |
110 | |
1e2c801e |
111 | sub _inline_tc_code { |
6e50f7e9 |
112 | shift->associated_attribute->_inline_tc_code(@_); |
1e2c801e |
113 | } |
114 | |
0f4afc62 |
115 | sub _inline_check_coercion { |
116 | shift->associated_attribute->_inline_check_coercion(@_); |
117 | } |
118 | |
d617b644 |
119 | sub _inline_check_constraint { |
6e50f7e9 |
120 | shift->associated_attribute->_inline_check_constraint(@_); |
d617b644 |
121 | } |
122 | |
123 | sub _inline_check_lazy { |
6e50f7e9 |
124 | shift->associated_attribute->_inline_check_lazy(@_); |
9df136d0 |
125 | } |
d617b644 |
126 | |
1e2c801e |
127 | sub _inline_store_value { |
6e50f7e9 |
128 | shift->associated_attribute->_inline_instance_set(@_) . ';'; |
d617b644 |
129 | } |
130 | |
3dda07f5 |
131 | sub _inline_get_old_value_for_trigger { |
6e50f7e9 |
132 | shift->associated_attribute->_inline_get_old_value_for_trigger(@_); |
3dda07f5 |
133 | } |
134 | |
d617b644 |
135 | sub _inline_trigger { |
6e50f7e9 |
136 | shift->associated_attribute->_inline_trigger(@_); |
d617b644 |
137 | } |
138 | |
1e2c801e |
139 | sub _get_value { |
6e50f7e9 |
140 | shift->associated_attribute->_inline_instance_get(@_); |
d617b644 |
141 | } |
142 | |
1e2c801e |
143 | sub _has_value { |
6e50f7e9 |
144 | shift->associated_attribute->_inline_instance_has(@_); |
d617b644 |
145 | } |
8ee73eeb |
146 | |
147 | 1; |
148 | |
ad46f524 |
149 | # ABSTRACT: A Moose Method metaclass for accessors |
150 | |
8ee73eeb |
151 | __END__ |
152 | |
153 | =pod |
154 | |
39b3bc94 |
155 | =head1 DESCRIPTION |
156 | |
ba4dfb8e |
157 | This class is a subclass of L<Class::MOP::Method::Accessor> that |
73f769fc |
158 | provides additional Moose-specific functionality, all of which is |
159 | private. |
ecb59493 |
160 | |
73f769fc |
161 | To understand this class, you should read the the |
ba4dfb8e |
162 | L<Class::MOP::Method::Accessor> documentation. |
39b3bc94 |
163 | |
164 | =head1 BUGS |
165 | |
d4048ef3 |
166 | See L<Moose/BUGS> for details on reporting bugs. |
39b3bc94 |
167 | |
51308c23 |
168 | =cut |