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 | |
50 | # is this going to be an issue? it's currently used for coercions |
51 | # and the tc message, is there a way to inline those too? |
52 | $env->{'$type_constraint_obj'} = \$tc_obj; |
53 | $env->{'$type_constraint'} = \($tc_obj->_compiled_type_constraint) |
54 | unless $tc_obj->can_be_inlined; |
55 | |
56 | $env = { %$env, %{ $tc_obj->inline_environment } }; |
57 | } |
58 | |
59 | # XXX ugh, fix these |
60 | $env->{'$attr'} = \$attr |
61 | if $attr->has_initializer; |
62 | $env->{'$meta'} = \$self; |
63 | |
64 | return $env; |
f5f08b5f |
65 | } |
66 | |
f001c60f |
67 | sub _instance_is_inlinable { |
68 | my $self = shift; |
69 | return $self->associated_attribute->associated_class->instance_metaclass->is_inlinable; |
70 | } |
71 | |
72 | sub _generate_reader_method { |
73 | my $self = shift; |
74 | $self->_instance_is_inlinable ? $self->_generate_reader_method_inline(@_) |
75 | : $self->SUPER::_generate_reader_method(@_); |
76 | } |
77 | |
78 | sub _generate_writer_method { |
79 | my $self = shift; |
80 | $self->_instance_is_inlinable ? $self->_generate_writer_method_inline(@_) |
81 | : $self->SUPER::_generate_writer_method(@_); |
82 | } |
83 | |
84 | sub _generate_accessor_method { |
85 | my $self = shift; |
86 | $self->_instance_is_inlinable ? $self->_generate_accessor_method_inline(@_) |
87 | : $self->SUPER::_generate_accessor_method(@_); |
88 | } |
89 | |
90 | sub _generate_predicate_method { |
91 | my $self = shift; |
92 | $self->_instance_is_inlinable ? $self->_generate_predicate_method_inline(@_) |
93 | : $self->SUPER::_generate_predicate_method(@_); |
94 | } |
95 | |
96 | sub _generate_clearer_method { |
97 | my $self = shift; |
98 | $self->_instance_is_inlinable ? $self->_generate_clearer_method_inline(@_) |
99 | : $self->SUPER::_generate_clearer_method(@_); |
100 | } |
8ecb1fa0 |
101 | |
6e50f7e9 |
102 | sub _writer_value_needs_copy { |
103 | shift->associated_attribute->_writer_value_needs_copy(@_); |
104 | } |
c350159f |
105 | |
1e2c801e |
106 | sub _inline_tc_code { |
6e50f7e9 |
107 | shift->associated_attribute->_inline_tc_code(@_); |
1e2c801e |
108 | } |
109 | |
0f4afc62 |
110 | sub _inline_check_coercion { |
111 | shift->associated_attribute->_inline_check_coercion(@_); |
112 | } |
113 | |
d617b644 |
114 | sub _inline_check_constraint { |
6e50f7e9 |
115 | shift->associated_attribute->_inline_check_constraint(@_); |
d617b644 |
116 | } |
117 | |
118 | sub _inline_check_lazy { |
6e50f7e9 |
119 | shift->associated_attribute->_inline_check_lazy(@_); |
9df136d0 |
120 | } |
d617b644 |
121 | |
1e2c801e |
122 | sub _inline_store_value { |
6e50f7e9 |
123 | shift->associated_attribute->_inline_instance_set(@_) . ';'; |
d617b644 |
124 | } |
125 | |
3dda07f5 |
126 | sub _inline_get_old_value_for_trigger { |
6e50f7e9 |
127 | shift->associated_attribute->_inline_get_old_value_for_trigger(@_); |
3dda07f5 |
128 | } |
129 | |
d617b644 |
130 | sub _inline_trigger { |
6e50f7e9 |
131 | shift->associated_attribute->_inline_trigger(@_); |
d617b644 |
132 | } |
133 | |
1e2c801e |
134 | sub _get_value { |
6e50f7e9 |
135 | shift->associated_attribute->_inline_instance_get(@_); |
d617b644 |
136 | } |
137 | |
1e2c801e |
138 | sub _has_value { |
6e50f7e9 |
139 | shift->associated_attribute->_inline_instance_has(@_); |
d617b644 |
140 | } |
8ee73eeb |
141 | |
142 | 1; |
143 | |
ad46f524 |
144 | # ABSTRACT: A Moose Method metaclass for accessors |
145 | |
8ee73eeb |
146 | __END__ |
147 | |
148 | =pod |
149 | |
39b3bc94 |
150 | =head1 DESCRIPTION |
151 | |
ba4dfb8e |
152 | This class is a subclass of L<Class::MOP::Method::Accessor> that |
73f769fc |
153 | provides additional Moose-specific functionality, all of which is |
154 | private. |
ecb59493 |
155 | |
73f769fc |
156 | To understand this class, you should read the the |
ba4dfb8e |
157 | L<Class::MOP::Method::Accessor> documentation. |
39b3bc94 |
158 | |
159 | =head1 BUGS |
160 | |
d4048ef3 |
161 | See L<Moose/BUGS> for details on reporting bugs. |
39b3bc94 |
162 | |
51308c23 |
163 | =cut |