| File | /usr/local/lib/perl/5.10.0/Moose/Meta/Method/Accessor.pm |
| Statements Executed | 503 |
| Total Time | 0.0052638 seconds |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 7 | 1 | 1 | 260µs | 6.00ms | Moose::Meta::Method::Accessor::_generate_accessor_method_inline |
| 11 | 1 | 1 | 173µs | 400µs | Moose::Meta::Method::Accessor::_eval_environment |
| 11 | 3 | 1 | 164µs | 3.56ms | Moose::Meta::Method::Accessor::_eval_code |
| 10 | 2 | 1 | 120µs | 325µs | Moose::Meta::Method::Accessor::_inline_check_lazy |
| 10 | 3 | 1 | 119µs | 308µs | Moose::Meta::Method::Accessor::_instance_is_inlinable |
| 8 | 2 | 1 | 114µs | 270µs | Moose::Meta::Method::Accessor::_inline_check_constraint |
| 10 | 2 | 1 | 109µs | 288µs | Moose::Meta::Method::Accessor::_inline_auto_deref |
| 11 | 3 | 1 | 107µs | 878µs | Moose::Meta::Method::Accessor::_inline_get |
| 16 | 3 | 1 | 104µs | 250µs | Moose::Meta::Method::Accessor::_value_needs_copy |
| 8 | 2 | 1 | 85µs | 146µs | Moose::Meta::Method::Accessor::_inline_check_coercion |
| 8 | 2 | 1 | 81µs | 149µs | Moose::Meta::Method::Accessor::_inline_trigger |
| 8 | 2 | 1 | 80µs | 173µs | Moose::Meta::Method::Accessor::_inline_check_required |
| 8 | 2 | 1 | 78µs | 153µs | Moose::Meta::Method::Accessor::_inline_get_old_value_for_trigger |
| 8 | 2 | 1 | 76µs | 1.91ms | Moose::Meta::Method::Accessor::_inline_store |
| 3 | 2 | 2 | 71µs | 1.98ms | Moose::Meta::Method::Accessor::_generate_reader_method_inline |
| 7 | 1 | 1 | 65µs | 6.26ms | Moose::Meta::Method::Accessor::_generate_accessor_method |
| 11 | 3 | 1 | 56µs | 56µs | Moose::Meta::Method::Accessor::_inline_pre_body |
| 8 | 2 | 1 | 53µs | 162µs | Moose::Meta::Method::Accessor::_inline_copy_value |
| 11 | 3 | 1 | 48µs | 48µs | Moose::Meta::Method::Accessor::_inline_post_body |
| 1 | 1 | 1 | 35µs | 724µs | Moose::Meta::Method::Accessor::_generate_writer_method_inline |
| 2 | 1 | 1 | 17µs | 1.52ms | Moose::Meta::Method::Accessor::_generate_reader_method |
| 1 | 1 | 1 | 15µs | 767µs | Moose::Meta::Method::Accessor::_generate_writer_method |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Method::Accessor::BEGIN |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Method::Accessor::_error_thrower |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Method::Accessor::_generate_clearer_method |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Method::Accessor::_generate_predicate_method |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Method::Accessor::_inline_has |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Method::Accessor::_inline_init_slot |
| Line | Stmts. | Exclusive Time | Avg. | Code |
|---|---|---|---|---|
| 1 | ||||
| 2 | package Moose::Meta::Method::Accessor; | |||
| 3 | ||||
| 4 | 3 | 23µs | 8µs | use strict; # spent 8µs making 1 call to strict::import |
| 5 | 3 | 70µs | 23µs | use warnings; # spent 30µs making 1 call to warnings::import |
| 6 | ||||
| 7 | 1 | 900ns | 900ns | our $VERSION = '1.15'; |
| 8 | 1 | 27µs | 27µs | $VERSION = eval $VERSION; |
| 9 | 1 | 600ns | 600ns | our $AUTHORITY = 'cpan:STEVAN'; |
| 10 | ||||
| 11 | use base 'Moose::Meta::Method', # spent 135µs making 1 call to base::import | |||
| 12 | 3 | 2.34ms | 781µs | 'Class::MOP::Method::Accessor'; |
| 13 | ||||
| 14 | sub _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 | |||
| 20 | 55 | 190µs | 3µ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 | |||
| 35 | 44 | 188µs | 4µ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 { | |||
| 41 | 1 | 39µs | 39µ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 | |||
| 53 | 35 | 562µs | 16µ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 | |||
| 76 | 6 | 87µs | 15µs | my $self = $_[0]; |
| 77 | my $attr = $self->associated_attribute; # spent 5µs making 1 call to Class::MOP::Method::Accessor::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 { ' # spent 322µs making 1 call to Moose::Meta::Method::Accessor::_eval_code
# spent 83µs making 1 call to Moose::Meta::Method::Accessor::_inline_store
# spent 58µs making 1 call to Moose::Meta::Method::Accessor::_inline_check_constraint
# spent 29µs making 1 call to Moose::Meta::Method::Accessor::_inline_get_old_value_for_trigger
# spent 28µs making 1 call to Moose::Meta::Method::Accessor::_inline_check_required
# spent 24µs making 1 call to Moose::Meta::Method::Accessor::_inline_copy_value
# spent 24µs making 1 call to Moose::Meta::Method::Accessor::_inline_check_coercion
# spent 21µs making 1 call to Moose::Meta::Method::Accessor::_inline_trigger
# spent 5µs making 1 call to Moose::Meta::Method::Accessor::_inline_pre_body
# spent 4µs making 1 call to Moose::Meta::Method::Accessor::_inline_post_body | |||
| 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 | |||
| 96 | 15 | 139µs | 9µ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 | |||
| 111 | 8 | 41µs | 5µ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 | |||
| 116 | 32 | 155µs | 5µ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 | |||
| 121 | 20 | 193µs | 10µ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 | |||
| 126 | 4 | 25µs | 6µ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 | |||
| 132 | 2 | 19µs | 9µs | my $self = shift; |
| 133 | $self->_instance_is_inlinable ? $self->_generate_writer_method_inline(@_) # spent 724µs making 1 call to Moose::Meta::Method::Accessor::_generate_writer_method_inline
# spent 28µs making 1 call to Moose::Meta::Method::Accessor::_instance_is_inlinable | |||
| 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 | |||
| 138 | 14 | 85µs | 6µ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 | ||||
| 143 | sub _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 | ||||
| 149 | sub _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 | ||||
| 155 | 11 | 16µs | 1µ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 |
| 156 | 11 | 15µs | 1µ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 |
| 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 | |||
| 159 | 36 | 178µs | 5µ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 | |||
| 171 | 24 | 91µs | 4µ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 | |||
| 180 | 26 | 108µs | 4µ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 | |||
| 191 | 30 | 129µs | 4µ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 | ||||
| 239 | sub _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 | |||
| 250 | 16 | 94µs | 6µ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 | |||
| 256 | 24 | 99µs | 4µ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 | |||
| 268 | 24 | 93µs | 4µ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 | |||
| 275 | 22 | 121µs | 6µ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 | ||||
| 280 | sub _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 | |||
| 287 | 30 | 127µs | 4µ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 | ||||
| 310 | 1 | 4µs | 4µs | 1; |
| 311 | ||||
| 312 | __END__ | |||
| 313 | ||||
| 314 | =pod | |||
| 315 | ||||
| 316 | =head1 NAME | |||
| 317 | ||||
| 318 | Moose::Meta::Method::Accessor - A Moose Method metaclass for accessors | |||
| 319 | ||||
| 320 | =head1 DESCRIPTION | |||
| 321 | ||||
| 322 | This class is a subclass of L<Class::MOP::Method::Accessor> that | |||
| 323 | provides additional Moose-specific functionality, all of which is | |||
| 324 | private. | |||
| 325 | ||||
| 326 | To understand this class, you should read the the | |||
| 327 | L<Class::MOP::Method::Accessor> documentation. | |||
| 328 | ||||
| 329 | =head1 BUGS | |||
| 330 | ||||
| 331 | See L<Moose/BUGS> for details on reporting bugs. | |||
| 332 | ||||
| 333 | =head1 AUTHOR | |||
| 334 | ||||
| 335 | Stevan Little E<lt>stevan@iinteractive.comE<gt> | |||
| 336 | ||||
| 337 | Yuval Kogman E<lt>nothingmuch@woobling.comE<gt> | |||
| 338 | ||||
| 339 | =head1 COPYRIGHT AND LICENSE | |||
| 340 | ||||
| 341 | Copyright 2006-2010 by Infinity Interactive, Inc. | |||
| 342 | ||||
| 343 | L<http://www.iinteractive.com> | |||
| 344 | ||||
| 345 | This library is free software; you can redistribute it and/or modify | |||
| 346 | it under the same terms as Perl itself. | |||
| 347 | ||||
| 348 | =cut |