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