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