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 | |
d44714be |
9 | our $AUTHORITY = 'cpan:STEVAN'; |
8ee73eeb |
10 | |
39b3bc94 |
11 | use base 'Moose::Meta::Method', |
d617b644 |
12 | 'Class::MOP::Method::Accessor'; |
13 | |
18748ad6 |
14 | sub _error_thrower { |
15 | my $self = shift; |
cc743de9 |
16 | return $self->associated_attribute |
17 | if ref($self) && defined($self->associated_attribute); |
18 | return $self->SUPER::_error_thrower; |
18748ad6 |
19 | } |
d617b644 |
20 | |
55c361dc |
21 | sub _compile_code { |
22 | my $self = shift; |
23 | my @args = @_; |
24 | try { |
25 | $self->SUPER::_compile_code(@args); |
26 | } |
27 | catch { |
28 | $self->throw_error( |
29 | 'Could not create writer for ' |
30 | . "'" . $self->associated_attribute->name . "' " |
31 | . 'because ' . $_, |
32 | error => $_, |
33 | ); |
34 | }; |
c9183ffc |
35 | } |
36 | |
f5f08b5f |
37 | sub _eval_environment { |
38 | my $self = shift; |
39 | |
40 | my $attr = $self->associated_attribute; |
41 | my $type_constraint_obj = $attr->type_constraint; |
42 | |
43 | return { |
44 | '$attr' => \$attr, |
45 | '$meta' => \$self, |
46 | '$type_constraint_obj' => \$type_constraint_obj, |
47 | '$type_constraint' => \( |
48 | $type_constraint_obj |
cc743de9 |
49 | ? $type_constraint_obj->_compiled_type_constraint |
50 | : undef |
f5f08b5f |
51 | ), |
52 | }; |
53 | } |
54 | |
f001c60f |
55 | sub _instance_is_inlinable { |
56 | my $self = shift; |
57 | return $self->associated_attribute->associated_class->instance_metaclass->is_inlinable; |
58 | } |
59 | |
60 | sub _generate_reader_method { |
61 | my $self = shift; |
62 | $self->_instance_is_inlinable ? $self->_generate_reader_method_inline(@_) |
63 | : $self->SUPER::_generate_reader_method(@_); |
64 | } |
65 | |
66 | sub _generate_writer_method { |
67 | my $self = shift; |
68 | $self->_instance_is_inlinable ? $self->_generate_writer_method_inline(@_) |
69 | : $self->SUPER::_generate_writer_method(@_); |
70 | } |
71 | |
72 | sub _generate_accessor_method { |
73 | my $self = shift; |
74 | $self->_instance_is_inlinable ? $self->_generate_accessor_method_inline(@_) |
75 | : $self->SUPER::_generate_accessor_method(@_); |
76 | } |
77 | |
78 | sub _generate_predicate_method { |
79 | my $self = shift; |
80 | $self->_instance_is_inlinable ? $self->_generate_predicate_method_inline(@_) |
81 | : $self->SUPER::_generate_predicate_method(@_); |
82 | } |
83 | |
84 | sub _generate_clearer_method { |
85 | my $self = shift; |
86 | $self->_instance_is_inlinable ? $self->_generate_clearer_method_inline(@_) |
87 | : $self->SUPER::_generate_clearer_method(@_); |
88 | } |
8ecb1fa0 |
89 | |
6e50f7e9 |
90 | sub _writer_value_needs_copy { |
91 | shift->associated_attribute->_writer_value_needs_copy(@_); |
92 | } |
c350159f |
93 | |
1e2c801e |
94 | sub _inline_tc_code { |
6e50f7e9 |
95 | shift->associated_attribute->_inline_tc_code(@_); |
1e2c801e |
96 | } |
97 | |
d617b644 |
98 | sub _inline_check_constraint { |
6e50f7e9 |
99 | shift->associated_attribute->_inline_check_constraint(@_); |
d617b644 |
100 | } |
101 | |
102 | sub _inline_check_lazy { |
6e50f7e9 |
103 | shift->associated_attribute->_inline_check_lazy(@_); |
9df136d0 |
104 | } |
d617b644 |
105 | |
1e2c801e |
106 | sub _inline_store_value { |
6e50f7e9 |
107 | shift->associated_attribute->_inline_instance_set(@_) . ';'; |
d617b644 |
108 | } |
109 | |
3dda07f5 |
110 | sub _inline_get_old_value_for_trigger { |
6e50f7e9 |
111 | shift->associated_attribute->_inline_get_old_value_for_trigger(@_); |
3dda07f5 |
112 | } |
113 | |
d617b644 |
114 | sub _inline_trigger { |
6e50f7e9 |
115 | shift->associated_attribute->_inline_trigger(@_); |
d617b644 |
116 | } |
117 | |
1e2c801e |
118 | sub _get_value { |
6e50f7e9 |
119 | shift->associated_attribute->_inline_instance_get(@_); |
d617b644 |
120 | } |
121 | |
1e2c801e |
122 | sub _has_value { |
6e50f7e9 |
123 | shift->associated_attribute->_inline_instance_has(@_); |
d617b644 |
124 | } |
8ee73eeb |
125 | |
126 | 1; |
127 | |
ad46f524 |
128 | # ABSTRACT: A Moose Method metaclass for accessors |
129 | |
8ee73eeb |
130 | __END__ |
131 | |
132 | =pod |
133 | |
39b3bc94 |
134 | =head1 DESCRIPTION |
135 | |
ba4dfb8e |
136 | This class is a subclass of L<Class::MOP::Method::Accessor> that |
73f769fc |
137 | provides additional Moose-specific functionality, all of which is |
138 | private. |
ecb59493 |
139 | |
73f769fc |
140 | To understand this class, you should read the the |
ba4dfb8e |
141 | L<Class::MOP::Method::Accessor> documentation. |
39b3bc94 |
142 | |
143 | =head1 BUGS |
144 | |
d4048ef3 |
145 | See L<Moose/BUGS> for details on reporting bugs. |
39b3bc94 |
146 | |
51308c23 |
147 | =cut |