← Index
Performance Profile   « block view • line view • sub view »
For t/test-parsing
  Run on Sun Nov 14 09:49:57 2010
Reported on Sun Nov 14 09:50:09 2010

File /usr/local/lib/perl/5.10.0/Moose/Meta/Method/Accessor.pm
Statements Executed 503
Total Time 0.0052638 seconds
Subroutines — ordered by exclusive time
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
711260µs6.00msMoose::Meta::Method::Accessor::::_generate_accessor_method_inlineMoose::Meta::Method::Accessor::_generate_accessor_method_inline
1111173µs400µsMoose::Meta::Method::Accessor::::_eval_environmentMoose::Meta::Method::Accessor::_eval_environment
1131164µs3.56msMoose::Meta::Method::Accessor::::_eval_codeMoose::Meta::Method::Accessor::_eval_code
1021120µs325µsMoose::Meta::Method::Accessor::::_inline_check_lazyMoose::Meta::Method::Accessor::_inline_check_lazy
1031119µs308µsMoose::Meta::Method::Accessor::::_instance_is_inlinableMoose::Meta::Method::Accessor::_instance_is_inlinable
821114µs270µsMoose::Meta::Method::Accessor::::_inline_check_constraintMoose::Meta::Method::Accessor::_inline_check_constraint
1021109µs288µsMoose::Meta::Method::Accessor::::_inline_auto_derefMoose::Meta::Method::Accessor::_inline_auto_deref
1131107µs878µsMoose::Meta::Method::Accessor::::_inline_getMoose::Meta::Method::Accessor::_inline_get
1631104µs250µsMoose::Meta::Method::Accessor::::_value_needs_copyMoose::Meta::Method::Accessor::_value_needs_copy
82185µs146µsMoose::Meta::Method::Accessor::::_inline_check_coercionMoose::Meta::Method::Accessor::_inline_check_coercion
82181µs149µsMoose::Meta::Method::Accessor::::_inline_triggerMoose::Meta::Method::Accessor::_inline_trigger
82180µs173µsMoose::Meta::Method::Accessor::::_inline_check_requiredMoose::Meta::Method::Accessor::_inline_check_required
82178µs153µsMoose::Meta::Method::Accessor::::_inline_get_old_value_for_triggerMoose::Meta::Method::Accessor::_inline_get_old_value_for_trigger
82176µs1.91msMoose::Meta::Method::Accessor::::_inline_storeMoose::Meta::Method::Accessor::_inline_store
32271µs1.98msMoose::Meta::Method::Accessor::::_generate_reader_method_inlineMoose::Meta::Method::Accessor::_generate_reader_method_inline
71165µs6.26msMoose::Meta::Method::Accessor::::_generate_accessor_methodMoose::Meta::Method::Accessor::_generate_accessor_method
113156µs56µsMoose::Meta::Method::Accessor::::_inline_pre_bodyMoose::Meta::Method::Accessor::_inline_pre_body
82153µs162µsMoose::Meta::Method::Accessor::::_inline_copy_valueMoose::Meta::Method::Accessor::_inline_copy_value
113148µs48µsMoose::Meta::Method::Accessor::::_inline_post_bodyMoose::Meta::Method::Accessor::_inline_post_body
11135µs724µsMoose::Meta::Method::Accessor::::_generate_writer_method_inlineMoose::Meta::Method::Accessor::_generate_writer_method_inline
21117µs1.52msMoose::Meta::Method::Accessor::::_generate_reader_methodMoose::Meta::Method::Accessor::_generate_reader_method
11115µs767µsMoose::Meta::Method::Accessor::::_generate_writer_methodMoose::Meta::Method::Accessor::_generate_writer_method
0000s0sMoose::Meta::Method::Accessor::::BEGINMoose::Meta::Method::Accessor::BEGIN
0000s0sMoose::Meta::Method::Accessor::::_error_throwerMoose::Meta::Method::Accessor::_error_thrower
0000s0sMoose::Meta::Method::Accessor::::_generate_clearer_methodMoose::Meta::Method::Accessor::_generate_clearer_method
0000s0sMoose::Meta::Method::Accessor::::_generate_predicate_methodMoose::Meta::Method::Accessor::_generate_predicate_method
0000s0sMoose::Meta::Method::Accessor::::_inline_hasMoose::Meta::Method::Accessor::_inline_has
0000s0sMoose::Meta::Method::Accessor::::_inline_init_slotMoose::Meta::Method::Accessor::_inline_init_slot
LineStmts.Exclusive
Time
Avg.Code
1
2package Moose::Meta::Method::Accessor;
3
4323µs8µsuse strict;
# spent 8µs making 1 call to strict::import
5370µs23µsuse warnings;
# spent 30µs making 1 call to warnings::import
6
71900ns900nsour $VERSION = '1.15';
8127µs27µs$VERSION = eval $VERSION;
91600ns600nsour $AUTHORITY = 'cpan:STEVAN';
10
11use base 'Moose::Meta::Method',
# spent 135µs making 1 call to base::import
1232.34ms781µs 'Class::MOP::Method::Accessor';
13
14sub _error_thrower {
15 my $self = shift;
16 ( ref $self && $self->associated_attribute ) || $self->SUPER::_error_thrower();
17}
18
19
# spent 3.56ms (164µs+3.39) within Moose::Meta::Method::Accessor::_eval_code which was called 11 times, avg 323µs/call: # 7 times (92µs+2.16ms) by Moose::Meta::Method::Accessor::_generate_accessor_method_inline at line 58, avg 322µs/call # 3 times (51µs+930µs) by Moose::Meta::Method::Accessor::_generate_reader_method_inline at line 101, avg 327µs/call # once (21µs+302µs) by Moose::Meta::Method::Accessor::_generate_writer_method_inline at line 82
sub _eval_code {
2055190µs3µs my ( $self, $source ) = @_;
21
22 my $environment = $self->_eval_environment;
# spent 400µs making 11 calls to Moose::Meta::Method::Accessor::_eval_environment, avg 36µs/call
23
24 my ( $code, $e ) = $self->_compile_code( environment => $environment, code => $source );
# spent 2.99ms making 11 calls to Class::MOP::Method::Generated::_compile_code, avg 272µs/call
25
26 $self->throw_error(
27 "Could not create writer for '${\$self->associated_attribute->name}' because $e \n code: $source",
28 error => $e, data => $source )
29 if $e;
30
31 return $code;
32}
33
34
# spent 400µs (173+228) within Moose::Meta::Method::Accessor::_eval_environment which was called 11 times, avg 36µs/call: # 11 times (173µs+228µs) by Moose::Meta::Method::Accessor::_eval_code at line 22, avg 36µs/call
sub _eval_environment {
3544188µs4µs my $self = shift;
36
37 my $attr = $self->associated_attribute;
# spent 41µs making 11 calls to Class::MOP::Method::Accessor::associated_attribute, avg 4µs/call
38 my $type_constraint_obj = $attr->type_constraint;
# spent 139µs making 11 calls to Moose::Meta::Mixin::AttributeCore::type_constraint, avg 13µs/call
39
40 return {
41139µs39µs '$attr' => \$attr,
# spent 48µs making 7 calls to Moose::Meta::TypeConstraint::_compiled_type_constraint, avg 7µs/call
42 '$meta' => \$self,
43 '$type_constraint_obj' => \$type_constraint_obj,
44 '$type_constraint' => \(
45 $type_constraint_obj
46 ? $type_constraint_obj->_compiled_type_constraint
47 : undef
48 ),
49 };
50}
51
52
# spent 6.00ms (260µs+5.74) within Moose::Meta::Method::Accessor::_generate_accessor_method_inline which was called 7 times, avg 857µs/call: # 7 times (260µs+5.74ms) by Moose::Meta::Method::Accessor::_generate_accessor_method at line 139, avg 857µs/call
sub _generate_accessor_method_inline {
5335562µs16µs my $self = $_[0];
54 my $attr = $self->associated_attribute;
# spent 29µs making 7 calls to Class::MOP::Method::Accessor::associated_attribute, avg 4µs/call
55 my $inv = '$_[0]';
56 my $value_name = $self->_value_needs_copy ? '$val' : '$_[1]';
# spent 111µs making 7 calls to Moose::Meta::Method::Accessor::_value_needs_copy, avg 16µs/call
57
58 $self->_eval_code('sub { ' . "\n"
# spent 2.26ms making 7 calls to Moose::Meta::Method::Accessor::_eval_code, avg 322µs/call # spent 1.83ms making 7 calls to Moose::Meta::Method::Accessor::_inline_store, avg 261µs/call # spent 320µs making 7 calls to Moose::Meta::Method::Accessor::_inline_get, avg 46µs/call # spent 212µs making 7 calls to Moose::Meta::Method::Accessor::_inline_check_constraint, avg 30µs/call # spent 145µs making 7 calls to Moose::Meta::Method::Accessor::_inline_check_required, avg 21µs/call # spent 138µs making 7 calls to Moose::Meta::Method::Accessor::_inline_copy_value, avg 20µs/call # spent 133µs making 7 calls to Moose::Meta::Method::Accessor::_inline_check_lazy, avg 19µs/call # spent 130µs making 7 calls to Moose::Meta::Method::Accessor::_inline_auto_deref, avg 19µs/call # spent 128µs making 7 calls to Moose::Meta::Method::Accessor::_inline_trigger, avg 18µs/call # spent 123µs making 7 calls to Moose::Meta::Method::Accessor::_inline_get_old_value_for_trigger, avg 18µs/call # spent 123µs making 7 calls to Moose::Meta::Method::Accessor::_inline_check_coercion, avg 18µs/call # spent 35µs making 7 calls to Moose::Meta::Method::Accessor::_inline_pre_body, avg 5µs/call # spent 28µs making 7 calls to Moose::Meta::Method::Accessor::_inline_post_body, avg 4µs/call
59 . $self->_inline_pre_body(@_) . "\n"
60 . 'if (scalar(@_) >= 2) {' . "\n"
61 . $self->_inline_copy_value . "\n"
62 . $self->_inline_check_required . "\n"
63 . $self->_inline_check_coercion($value_name) . "\n"
64 . $self->_inline_check_constraint($value_name) . "\n"
65 . $self->_inline_get_old_value_for_trigger($inv, $value_name) . "\n"
66 . $self->_inline_store($inv, $value_name) . "\n"
67 . $self->_inline_trigger($inv, $value_name, '@old') . "\n"
68 . ' }' . "\n"
69 . $self->_inline_check_lazy($inv) . "\n"
70 . $self->_inline_post_body(@_) . "\n"
71 . 'return ' . $self->_inline_auto_deref($self->_inline_get($inv)) . "\n"
72 . ' }');
73}
74
75
# spent 724µs (35+690) within Moose::Meta::Method::Accessor::_generate_writer_method_inline which was called # once (35µs+690µs) by Moose::Meta::Method::Accessor::_generate_writer_method at line 133
sub _generate_writer_method_inline {
76687µs15µs my $self = $_[0];
77 my $attr = $self->associated_attribute;
78 my $inv = '$_[0]';
79 my $slot_access = $self->_inline_get($inv);
# spent 57µs making 1 call to Moose::Meta::Method::Accessor::_inline_get
80 my $value_name = $self->_value_needs_copy ? '$val' : '$_[1]';
# spent 30µs making 1 call to Moose::Meta::Method::Accessor::_value_needs_copy
81
82 $self->_eval_code('sub { '
83 . $self->_inline_pre_body(@_)
84 . $self->_inline_copy_value
85 . $self->_inline_check_required
86 . $self->_inline_check_coercion($value_name)
87 . $self->_inline_check_constraint($value_name)
88 . $self->_inline_get_old_value_for_trigger($inv, $value_name) . "\n"
89 . $self->_inline_store($inv, $value_name)
90 . $self->_inline_post_body(@_)
91 . $self->_inline_trigger($inv, $value_name, '@old')
92 . ' }');
93}
94
95
# spent 1.98ms (71µs+1.90) within Moose::Meta::Method::Accessor::_generate_reader_method_inline which was called 3 times, avg 658µs/call: # 2 times (49µs+1.37ms) by Moose::Meta::Method::Accessor::_generate_reader_method at line 127, avg 710µs/call # once (23µs+533µs) by Class::MOP::Method::Accessor::_initialize_body at line 87 of /usr/local/lib/perl/5.10.0/Class/MOP/Method/Accessor.pm
sub _generate_reader_method_inline {
9615139µs9µs my $self = $_[0];
97 my $attr = $self->associated_attribute;
# spent 12µs making 3 calls to Class::MOP::Method::Accessor::associated_attribute, avg 4µs/call
98 my $inv = '$_[0]';
99 my $slot_access = $self->_inline_get($inv);
# spent 502µs making 3 calls to Moose::Meta::Method::Accessor::_inline_get, avg 167µs/call
100
101 $self->_eval_code('sub {'
# spent 981µs making 3 calls to Moose::Meta::Method::Accessor::_eval_code, avg 327µs/call # spent 192µs making 3 calls to Moose::Meta::Method::Accessor::_inline_check_lazy, avg 64µs/call # spent 158µs making 3 calls to Moose::Meta::Method::Accessor::_inline_auto_deref, avg 53µs/call # spent 28µs making 3 calls to Moose::Meta::Method::_inline_throw_error, avg 10µs/call # spent 17µs making 3 calls to Moose::Meta::Method::Accessor::_inline_pre_body, avg 6µs/call # spent 15µs making 3 calls to Moose::Meta::Method::Accessor::_inline_post_body, avg 5µs/call
102 . $self->_inline_pre_body(@_)
103 . $self->_inline_throw_error('"Cannot assign a value to a read-only accessor"', 'data => \@_') . ' if @_ > 1;'
104 . $self->_inline_check_lazy($inv)
105 . $self->_inline_post_body(@_)
106 . 'return ' . $self->_inline_auto_deref( $slot_access ) . ';'
107 . '}');
108}
109
110
# spent 162µs (53+109) within Moose::Meta::Method::Accessor::_inline_copy_value which was called 8 times, avg 20µs/call: # 7 times (42µs+96µs) by Moose::Meta::Method::Accessor::_generate_accessor_method_inline at line 58, avg 20µs/call # once (12µs+13µs) by Moose::Meta::Method::Accessor::_generate_writer_method_inline at line 82
sub _inline_copy_value {
111841µs5µs return '' unless shift->_value_needs_copy;
# spent 109µs making 8 calls to Moose::Meta::Method::Accessor::_value_needs_copy, avg 14µs/call
112 return 'my $val = $_[1];'
113}
114
115
# spent 250µs (104+146) within Moose::Meta::Method::Accessor::_value_needs_copy which was called 16 times, avg 16µs/call: # 8 times (43µs+66µs) by Moose::Meta::Method::Accessor::_inline_copy_value at line 111, avg 14µs/call # 7 times (45µs+66µs) by Moose::Meta::Method::Accessor::_generate_accessor_method_inline at line 56, avg 16µs/call # once (17µs+13µs) by Moose::Meta::Method::Accessor::_generate_writer_method_inline at line 80
sub _value_needs_copy {
11632155µs5µs my $attr = (shift)->associated_attribute;
# spent 52µs making 16 calls to Class::MOP::Method::Accessor::associated_attribute, avg 3µs/call
117 return $attr->should_coerce;
# spent 94µs making 16 calls to Moose::Meta::Mixin::AttributeCore::should_coerce, avg 6µs/call
118}
119
120
# spent 308µs (119+189) within Moose::Meta::Method::Accessor::_instance_is_inlinable which was called 10 times, avg 31µs/call: # 7 times (71µs+131µs) by Moose::Meta::Method::Accessor::_generate_accessor_method at line 139, avg 29µs/call # 2 times (39µs+39µs) by Moose::Meta::Method::Accessor::_generate_reader_method at line 127, avg 39µs/call # once (9µs+19µs) by Moose::Meta::Method::Accessor::_generate_writer_method at line 133
sub _instance_is_inlinable {
12120193µs10µs my $self = shift;
122 return $self->associated_attribute->associated_class->instance_metaclass->is_inlinable;
# spent 58µs making 10 calls to Class::MOP::Class::instance_metaclass, avg 6µs/call # spent 49µs making 10 calls to Class::MOP::Method::Accessor::associated_attribute, avg 5µs/call # spent 42µs making 10 calls to Class::MOP::Instance::is_inlinable, avg 4µs/call # spent 41µs making 10 calls to Class::MOP::Attribute::associated_class, avg 4µs/call
123}
124
125
# spent 1.52ms (17µs+1.50) within Moose::Meta::Method::Accessor::_generate_reader_method which was called 2 times, avg 758µs/call: # 2 times (17µs+1.50ms) by Class::MOP::Method::Accessor::_initialize_body at line 87 of /usr/local/lib/perl/5.10.0/Class/MOP/Method/Accessor.pm, avg 758µs/call
sub _generate_reader_method {
126425µs6µs my $self = shift;
127 $self->_instance_is_inlinable ? $self->_generate_reader_method_inline(@_)
# spent 1.42ms making 2 calls to Moose::Meta::Method::Accessor::_generate_reader_method_inline, avg 710µs/call # spent 78µs making 2 calls to Moose::Meta::Method::Accessor::_instance_is_inlinable, avg 39µs/call
128 : $self->SUPER::_generate_reader_method(@_);
129}
130
131
# spent 767µs (15+752) within Moose::Meta::Method::Accessor::_generate_writer_method which was called # once (15µs+752µs) by Class::MOP::Method::Accessor::_initialize_body at line 87 of /usr/local/lib/perl/5.10.0/Class/MOP/Method/Accessor.pm
sub _generate_writer_method {
132219µs9µs my $self = shift;
133 $self->_instance_is_inlinable ? $self->_generate_writer_method_inline(@_)
134 : $self->SUPER::_generate_writer_method(@_);
135}
136
137
# spent 6.26ms (65µs+6.20) within Moose::Meta::Method::Accessor::_generate_accessor_method which was called 7 times, avg 895µs/call: # 7 times (65µs+6.20ms) by Class::MOP::Method::Accessor::_initialize_body at line 87 of /usr/local/lib/perl/5.10.0/Class/MOP/Method/Accessor.pm, avg 895µs/call
sub _generate_accessor_method {
1381485µs6µs my $self = shift;
139 $self->_instance_is_inlinable ? $self->_generate_accessor_method_inline(@_)
# spent 6.00ms making 7 calls to Moose::Meta::Method::Accessor::_generate_accessor_method_inline, avg 857µs/call # spent 202µs making 7 calls to Moose::Meta::Method::Accessor::_instance_is_inlinable, avg 29µs/call
140 : $self->SUPER::_generate_accessor_method(@_);
141}
142
143sub _generate_predicate_method {
144 my $self = shift;
145 $self->_instance_is_inlinable ? $self->_generate_predicate_method_inline(@_)
146 : $self->SUPER::_generate_predicate_method(@_);
147}
148
149sub _generate_clearer_method {
150 my $self = shift;
151 $self->_instance_is_inlinable ? $self->_generate_clearer_method_inline(@_)
152 : $self->SUPER::_generate_clearer_method(@_);
153}
154
1551116µs1µs
# spent 56µs within Moose::Meta::Method::Accessor::_inline_pre_body which was called 11 times, avg 5µs/call: # 7 times (35µs+0s) by Moose::Meta::Method::Accessor::_generate_accessor_method_inline at line 58, avg 5µs/call # 3 times (17µs+0s) by Moose::Meta::Method::Accessor::_generate_reader_method_inline at line 101, avg 6µs/call # once (5µs+0s) by Moose::Meta::Method::Accessor::_generate_writer_method_inline at line 82
sub _inline_pre_body { '' }
1561115µs1µs
# spent 48µs within Moose::Meta::Method::Accessor::_inline_post_body which was called 11 times, avg 4µs/call: # 7 times (28µs+0s) by Moose::Meta::Method::Accessor::_generate_accessor_method_inline at line 58, avg 4µs/call # 3 times (15µs+0s) by Moose::Meta::Method::Accessor::_generate_reader_method_inline at line 101, avg 5µs/call # once (4µs+0s) by Moose::Meta::Method::Accessor::_generate_writer_method_inline at line 82
sub _inline_post_body { '' }
157
158
# spent 270µs (114+157) within Moose::Meta::Method::Accessor::_inline_check_constraint which was called 8 times, avg 34µs/call: # 7 times (89µs+123µs) by Moose::Meta::Method::Accessor::_generate_accessor_method_inline at line 58, avg 30µs/call # once (25µs+33µs) by Moose::Meta::Method::Accessor::_generate_writer_method_inline at line 82
sub _inline_check_constraint {
15936178µs5µs my ($self, $value) = @_;
160
161 my $attr = $self->associated_attribute;
# spent 35µs making 8 calls to Class::MOP::Method::Accessor::associated_attribute, avg 4µs/call
162
163 return '' unless $attr->has_type_constraint;
# spent 40µs making 8 calls to Moose::Meta::Mixin::AttributeCore::has_type_constraint, avg 5µs/call
164
165 my $attr_name = quotemeta( $attr->name );
# spent 27µs making 6 calls to Class::MOP::Mixin::AttributeCore::name, avg 4µs/call
166
167 qq{\$type_constraint->($value) || } . $self->_inline_throw_error(qq{"Attribute ($attr_name) does not pass the type constraint because: " . \$type_constraint_obj->get_message($value)}, "data => $value") . ";";
# spent 55µs making 6 calls to Moose::Meta::Method::_inline_throw_error, avg 9µs/call
168}
169
170
# spent 146µs (85+61) within Moose::Meta::Method::Accessor::_inline_check_coercion which was called 8 times, avg 18µs/call: # 7 times (71µs+51µs) by Moose::Meta::Method::Accessor::_generate_accessor_method_inline at line 58, avg 18µs/call # once (13µs+10µs) by Moose::Meta::Method::Accessor::_generate_writer_method_inline at line 82
sub _inline_check_coercion {
1712491µs4µs my ($self, $value) = @_;
172
173 my $attr = $self->associated_attribute;
# spent 30µs making 8 calls to Class::MOP::Method::Accessor::associated_attribute, avg 4µs/call
174
175 return '' unless $attr->should_coerce && $attr->type_constraint->has_coercion;
# spent 32µs making 8 calls to Moose::Meta::Mixin::AttributeCore::should_coerce, avg 4µs/call
176 return "$value = \$attr->type_constraint->coerce($value);";
177}
178
179
# spent 173µs (80+93) within Moose::Meta::Method::Accessor::_inline_check_required which was called 8 times, avg 22µs/call: # 7 times (64µs+81µs) by Moose::Meta::Method::Accessor::_generate_accessor_method_inline at line 58, avg 21µs/call # once (15µs+12µs) by Moose::Meta::Method::Accessor::_generate_writer_method_inline at line 82
sub _inline_check_required {
18026108µs4µs my $self = shift;
181 my $attr = $self->associated_attribute;
# spent 27µs making 8 calls to Class::MOP::Method::Accessor::associated_attribute, avg 3µs/call
182
183 return '' unless $attr->is_required;
# spent 51µs making 8 calls to Moose::Meta::Mixin::AttributeCore::is_required, avg 6µs/call
184
185 my $attr_name = quotemeta( $attr->name );
# spent 5µs making 1 call to Class::MOP::Mixin::AttributeCore::name
186
187 return qq{(\@_ >= 2) || } . $self->_inline_throw_error(qq{"Attribute ($attr_name) is required, so cannot be set to undef"}) . ';' # defined $_[1] is not good enough
# spent 10µs making 1 call to Moose::Meta::Method::_inline_throw_error
188}
189
190
# spent 325µs (120+205) within Moose::Meta::Method::Accessor::_inline_check_lazy which was called 10 times, avg 32µs/call: # 7 times (77µs+56µs) by Moose::Meta::Method::Accessor::_generate_accessor_method_inline at line 58, avg 19µs/call # 3 times (43µs+149µs) by Moose::Meta::Method::Accessor::_generate_reader_method_inline at line 101, avg 64µs/call
sub _inline_check_lazy {
19130129µs4µs my ($self, $instance) = @_;
192
193 my $attr = $self->associated_attribute;
# spent 35µs making 10 calls to Class::MOP::Method::Accessor::associated_attribute, avg 3µs/call
194
195 return '' unless $attr->is_lazy;
# spent 170µs making 10 calls to Moose::Meta::Mixin::AttributeCore::is_lazy, avg 17µs/call
196
197 my $slot_exists = $self->_inline_has($instance);
198
199 my $code = 'unless (' . $slot_exists . ') {' . "\n";
200 if ($attr->has_type_constraint) {
201 if ($attr->has_default || $attr->has_builder) {
202 if ($attr->has_default) {
203 $code .= ' my $default = $attr->default(' . $instance . ');'."\n";
204 }
205 elsif ($attr->has_builder) {
206 $code .= ' my $default;'."\n".
207 ' if(my $builder = '.$instance.'->can($attr->builder)){ '."\n".
208 ' $default = '.$instance.'->$builder; '. "\n } else {\n" .
209 ' ' . $self->_inline_throw_error(q{sprintf "%s does not support builder method '%s' for attribute '%s'", ref(} . $instance . ') || '.$instance.', $attr->builder, $attr->name') .
210 ';'. "\n }";
211 }
212 $code .= $self->_inline_check_coercion('$default') . "\n";
213 $code .= $self->_inline_check_constraint('$default') . "\n";
214 $code .= ' ' . $self->_inline_init_slot($attr, $instance, '$default') . "\n";
215 }
216 else {
217 $code .= ' ' . $self->_inline_init_slot($attr, $instance, 'undef') . "\n";
218 }
219
220 } else {
221 if ($attr->has_default) {
222 $code .= ' ' . $self->_inline_init_slot($attr, $instance, ('$attr->default(' . $instance . ')')) . "\n";
223 }
224 elsif ($attr->has_builder) {
225 $code .= ' if (my $builder = '.$instance.'->can($attr->builder)) { ' . "\n"
226 . ' ' . $self->_inline_init_slot($attr, $instance, ($instance . '->$builder'))
227 . "\n } else {\n"
228 . ' ' . $self->_inline_throw_error(q{sprintf "%s does not support builder method '%s' for attribute '%s'", ref(} . $instance . ') || '.$instance.', $attr->builder, $attr->name')
229 . ';'. "\n }";
230 }
231 else {
232 $code .= ' ' . $self->_inline_init_slot($attr, $instance, 'undef') . "\n";
233 }
234 }
235 $code .= "}\n";
236 return $code;
237}
238
239sub _inline_init_slot {
240 my ($self, $attr, $inv, $value) = @_;
241 if ($attr->has_initializer) {
242 return ('$attr->set_initial_value(' . $inv . ', ' . $value . ');');
243 }
244 else {
245 return $self->_inline_store($inv, $value);
246 }
247}
248
249
# spent 1.91ms (76µs+1.83) within Moose::Meta::Method::Accessor::_inline_store which was called 8 times, avg 239µs/call: # 7 times (61µs+1.76ms) by Moose::Meta::Method::Accessor::_generate_accessor_method_inline at line 58, avg 261µs/call # once (15µs+68µs) by Moose::Meta::Method::Accessor::_generate_writer_method_inline at line 82
sub _inline_store {
2501694µs6µs my ( $self, $instance, $value ) = @_;
251
252 return $self->associated_attribute->inline_set( $instance, $value );
# spent 1.81ms making 8 calls to Moose::Meta::Attribute::inline_set, avg 226µs/call # spent 27µs making 8 calls to Class::MOP::Method::Accessor::associated_attribute, avg 3µs/call
253}
254
255
# spent 153µs (78+75) within Moose::Meta::Method::Accessor::_inline_get_old_value_for_trigger which was called 8 times, avg 19µs/call: # 7 times (60µs+63µs) by Moose::Meta::Method::Accessor::_generate_accessor_method_inline at line 58, avg 18µs/call # once (17µs+12µs) by Moose::Meta::Method::Accessor::_generate_writer_method_inline at line 82
sub _inline_get_old_value_for_trigger {
2562499µs4µs my ( $self, $instance ) = @_;
257
258 my $attr = $self->associated_attribute;
# spent 29µs making 8 calls to Class::MOP::Method::Accessor::associated_attribute, avg 4µs/call
259 return '' unless $attr->has_trigger;
# spent 46µs making 8 calls to Moose::Meta::Mixin::AttributeCore::has_trigger, avg 6µs/call
260
261 return
262 'my @old = '
263 . $self->_inline_has($instance) . q{ ? }
264 . $self->_inline_get($instance) . q{ : ()} . ";\n";
265}
266
267
# spent 149µs (81+68) within Moose::Meta::Method::Accessor::_inline_trigger which was called 8 times, avg 19µs/call: # 7 times (69µs+59µs) by Moose::Meta::Method::Accessor::_generate_accessor_method_inline at line 58, avg 18µs/call # once (11µs+9µs) by Moose::Meta::Method::Accessor::_generate_writer_method_inline at line 82
sub _inline_trigger {
2682493µs4µs my ($self, $instance, $value, $old_value) = @_;
269 my $attr = $self->associated_attribute;
# spent 39µs making 8 calls to Class::MOP::Method::Accessor::associated_attribute, avg 5µs/call
270 return '' unless $attr->has_trigger;
# spent 29µs making 8 calls to Moose::Meta::Mixin::AttributeCore::has_trigger, avg 4µs/call
271 return sprintf('$attr->trigger->(%s, %s, %s);', $instance, $value, $old_value);
272}
273
274
# spent 878µs (107+772) within Moose::Meta::Method::Accessor::_inline_get which was called 11 times, avg 80µs/call: # 7 times (56µs+264µs) by Moose::Meta::Method::Accessor::_generate_accessor_method_inline at line 58, avg 46µs/call # 3 times (40µs+462µs) by Moose::Meta::Method::Accessor::_generate_reader_method_inline at line 99, avg 167µs/call # once (11µs+46µs) by Moose::Meta::Method::Accessor::_generate_writer_method_inline at line 79
sub _inline_get {
27522121µs6µs my ($self, $instance) = @_;
276
277 return $self->associated_attribute->inline_get($instance);
# spent 736µs making 11 calls to Class::MOP::Attribute::inline_get, avg 67µs/call # spent 36µs making 11 calls to Class::MOP::Method::Accessor::associated_attribute, avg 3µs/call
278}
279
280sub _inline_has {
281 my ($self, $instance) = @_;
282
283 return $self->associated_attribute->inline_has($instance);
284}
285
286
# spent 288µs (109+179) within Moose::Meta::Method::Accessor::_inline_auto_deref which was called 10 times, avg 29µs/call: # 7 times (64µs+66µs) by Moose::Meta::Method::Accessor::_generate_accessor_method_inline at line 58, avg 19µs/call # 3 times (44µs+113µs) by Moose::Meta::Method::Accessor::_generate_reader_method_inline at line 101, avg 53µs/call
sub _inline_auto_deref {
28730127µs4µs my ( $self, $ref_value ) = @_;
288 my $attr = $self->associated_attribute;
# spent 37µs making 10 calls to Class::MOP::Method::Accessor::associated_attribute, avg 4µs/call
289
290 return $ref_value unless $attr->should_auto_deref;
# spent 143µs making 10 calls to Moose::Meta::Mixin::AttributeCore::should_auto_deref, avg 14µs/call
291
292 my $type_constraint = $attr->type_constraint;
293
294 my $sigil;
295 if ($type_constraint->is_a_type_of('ArrayRef')) {
296 $sigil = '@';
297 }
298 elsif ($type_constraint->is_a_type_of('HashRef')) {
299 $sigil = '%';
300 }
301 else {
302 $self->throw_error( "Can not auto de-reference the type constraint '"
303 . quotemeta( $type_constraint->name )
304 . "'", type_constraint => $type_constraint );
305 }
306
307 "(wantarray() ? $sigil\{ ( $ref_value ) || return } : ( $ref_value ) )";
308}
309
31014µs4µs1;
311
312__END__
313
314=pod
315
316=head1 NAME
317
318Moose::Meta::Method::Accessor - A Moose Method metaclass for accessors
319
320=head1 DESCRIPTION
321
322This class is a subclass of L<Class::MOP::Method::Accessor> that
323provides additional Moose-specific functionality, all of which is
324private.
325
326To understand this class, you should read the the
327L<Class::MOP::Method::Accessor> documentation.
328
329=head1 BUGS
330
331See L<Moose/BUGS> for details on reporting bugs.
332
333=head1 AUTHOR
334
335Stevan Little E<lt>stevan@iinteractive.comE<gt>
336
337Yuval Kogman E<lt>nothingmuch@woobling.comE<gt>
338
339=head1 COPYRIGHT AND LICENSE
340
341Copyright 2006-2010 by Infinity Interactive, Inc.
342
343L<http://www.iinteractive.com>
344
345This library is free software; you can redistribute it and/or modify
346it under the same terms as Perl itself.
347
348=cut