| Filename | /home/doy/coding/src/Moose/blib/lib//Moose/Meta/Attribute.pm |
| Statements | Executed 21607 statements in 314ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 124 | 3 | 2 | 79.0ms | 334ms | Moose::Meta::Attribute::new |
| 193 | 5 | 1 | 24.5ms | 848ms | Moose::Meta::Attribute::_process_accessors |
| 195 | 5 | 3 | 22.7ms | 134ms | Moose::Meta::Attribute::_inline_set_value |
| 1 | 1 | 1 | 20.6ms | 314ms | Moose::Meta::Attribute::BEGIN@20 |
| 122 | 2 | 2 | 18.7ms | 146ms | Moose::Meta::Attribute::_process_options |
| 210 | 2 | 1 | 13.3ms | 20.9ms | Moose::Meta::Attribute::_inline_check_constraint |
| 121 | 2 | 2 | 7.72ms | 551ms | Moose::Meta::Attribute::interpolate_class_and_new (recurses: max depth 1, inclusive time 7.74ms) |
| 123 | 2 | 1 | 7.72ms | 131ms | Moose::Meta::Attribute::_inline_get_value |
| 125 | 3 | 2 | 7.58ms | 1.04s | Moose::Meta::Attribute::install_accessors |
| 195 | 1 | 1 | 6.73ms | 33.8ms | Moose::Meta::Attribute::_inline_tc_code |
| 195 | 1 | 1 | 6.07ms | 9.70ms | Moose::Meta::Attribute::_inline_weaken_value |
| 210 | 2 | 1 | 5.91ms | 8.50ms | Moose::Meta::Attribute::_inline_check_coercion |
| 122 | 1 | 1 | 5.33ms | 102ms | Moose::Meta::Attribute::_process_isa_option |
| 128 | 2 | 2 | 4.93ms | 20.9ms | Moose::Meta::Attribute::_inline_check_lazy |
| 199 | 2 | 2 | 4.80ms | 7.62ms | Moose::Meta::Attribute::_writer_value_needs_copy |
| 9 | 1 | 1 | 4.77ms | 65.1ms | Moose::Meta::Attribute::install_delegation |
| 211 | 3 | 1 | 4.26ms | 4.26ms | Moose::Meta::Attribute::_inline_throw_error |
| 123 | 2 | 1 | 4.17ms | 225ms | Moose::Meta::Attribute::interpolate_class (recurses: max depth 1, inclusive time 120µs) |
| 123 | 1 | 1 | 3.62ms | 5.54ms | Moose::Meta::Attribute::_auto_deref |
| 123 | 1 | 1 | 3.51ms | 9.06ms | Moose::Meta::Attribute::_inline_return_auto_deref |
| 122 | 1 | 1 | 3.08ms | 3.08ms | Moose::Meta::Attribute::_process_is_option |
| 1 | 1 | 1 | 3.05ms | 3.97ms | Moose::Meta::Attribute::BEGIN@17 |
| 123 | 1 | 1 | 2.86ms | 3.66ms | Moose::Meta::Attribute::_check_associated_methods |
| 1 | 1 | 1 | 2.71ms | 3.80ms | Moose::Meta::Attribute::BEGIN@18 |
| 124 | 2 | 1 | 2.67ms | 2.75ms | Moose::Meta::Attribute::_process_lazy_build_option |
| 19 | 1 | 1 | 2.19ms | 11.0ms | Moose::Meta::Attribute::_inline_init_from_default |
| 122 | 1 | 1 | 2.15ms | 10.3ms | Moose::Meta::Attribute::_process_does_option |
| 2 | 1 | 1 | 2.14ms | 17.5ms | Moose::Meta::Attribute::clone |
| 203 | 2 | 2 | 1.87ms | 1.87ms | Moose::Meta::Attribute::accessor_metaclass |
| 122 | 1 | 1 | 1.79ms | 1.79ms | Moose::Meta::Attribute::_process_required_option |
| 122 | 1 | 1 | 1.78ms | 1.80ms | Moose::Meta::Attribute::_process_coerce_option |
| 122 | 1 | 1 | 1.72ms | 1.72ms | Moose::Meta::Attribute::_process_trigger_option |
| 122 | 1 | 1 | 1.71ms | 1.71ms | Moose::Meta::Attribute::_process_auto_deref_option |
| 122 | 1 | 1 | 1.70ms | 1.70ms | Moose::Meta::Attribute::_process_lazy_option |
| 14 | 1 | 1 | 1.63ms | 7.71ms | Moose::Meta::Attribute::initialize_instance_slot |
| 23 | 1 | 1 | 1.54ms | 12.5ms | Moose::Meta::Attribute::_make_delegation_method |
| 19 | 1 | 1 | 1.34ms | 2.07ms | Moose::Meta::Attribute::_inline_generate_default |
| 39 | 1 | 1 | 1.19ms | 2.08ms | Moose::Meta::Attribute::_inline_get_old_value_for_trigger |
| 41 | 2 | 2 | 1.19ms | 1.97ms | Moose::Meta::Attribute::_inline_trigger |
| 39 | 1 | 1 | 1.13ms | 2.06ms | Moose::Meta::Attribute::_inline_check_required |
| 19 | 1 | 1 | 937µs | 3.72ms | Moose::Meta::Attribute::_inline_init_slot |
| 11 | 1 | 1 | 641µs | 2.61ms | Moose::Meta::Attribute::_coerce_and_verify |
| 9 | 1 | 1 | 559µs | 1.75ms | Moose::Meta::Attribute::verify_against_type_constraint |
| 124 | 1 | 1 | 558µs | 558µs | Moose::Meta::Attribute::CORE:sort (opcode) |
| 2 | 1 | 1 | 446µs | 18.1ms | Moose::Meta::Attribute::clone_and_inherit_options |
| 7 | 1 | 1 | 390µs | 481µs | Moose::Meta::Attribute::_canonicalize_handles |
| 44 | 2 | 1 | 375µs | 375µs | Moose::Meta::Attribute::CORE:match (opcode) |
| 5 | 1 | 1 | 374µs | 4.97ms | Moose::Meta::Attribute::does |
| 33 | 2 | 2 | 279µs | 279µs | Moose::Meta::Attribute::delegation_metaclass |
| 2 | 1 | 1 | 150µs | 421µs | Moose::Meta::Attribute::_weaken_value |
| 5 | 1 | 1 | 101µs | 3.76ms | Moose::Meta::Attribute::__ANON__[:40] |
| 1 | 1 | 1 | 70µs | 89µs | Moose::Meta::Attribute::BEGIN@4 |
| 3 | 1 | 1 | 61µs | 61µs | Moose::Meta::Attribute::_inline_copy_value |
| 1 | 1 | 1 | 39µs | 228µs | Moose::Meta::Attribute::BEGIN@8 |
| 1 | 1 | 1 | 39µs | 108µs | Moose::Meta::Attribute::BEGIN@5 |
| 1 | 1 | 1 | 38µs | 70µs | Moose::Meta::Attribute::BEGIN@16 |
| 1 | 1 | 1 | 38µs | 213µs | Moose::Meta::Attribute::BEGIN@10 |
| 1 | 1 | 1 | 37µs | 164µs | Moose::Meta::Attribute::BEGIN@9 |
| 1 | 1 | 1 | 36µs | 37.9ms | Moose::Meta::Attribute::BEGIN@23 |
| 2 | 1 | 1 | 30µs | 30µs | Moose::Meta::Attribute::illegal_options_for_inheritance |
| 1 | 1 | 1 | 30µs | 30µs | Moose::Meta::Attribute::BEGIN@21 |
| 1 | 1 | 1 | 23µs | 23µs | Moose::Meta::Attribute::BEGIN@19 |
| 1 | 1 | 1 | 20µs | 20µs | Moose::Meta::Attribute::BEGIN@11 |
| 1 | 1 | 1 | 19µs | 19µs | Moose::Meta::Attribute::BEGIN@7 |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Attribute::Custom::Moose::register_implementation |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Attribute::__ANON__[:311] |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Attribute::__ANON__[:523] |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Attribute::__ANON__[:997] |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Attribute::_call_builder |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Attribute::_find_delegate_metaclass |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Attribute::_get_delegate_method_list |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Attribute::_make_initializer_writer_callback |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Attribute::get_value |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Attribute::remove_accessors |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Attribute::remove_delegation |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Attribute::set_value |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Attribute::throw_error |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | |||||
| 2 | package Moose::Meta::Attribute; | ||||
| 3 | |||||
| 4 | 3 | 98µs | 2 | 107µs | # spent 89µs (70+18) within Moose::Meta::Attribute::BEGIN@4 which was called:
# once (70µs+18µs) by Moose::Meta::TypeCoercion::BEGIN@8 at line 4 # spent 89µs making 1 call to Moose::Meta::Attribute::BEGIN@4
# spent 18µs making 1 call to strict::import |
| 5 | 3 | 95µs | 2 | 177µs | # spent 108µs (39+69) within Moose::Meta::Attribute::BEGIN@5 which was called:
# once (39µs+69µs) by Moose::Meta::TypeCoercion::BEGIN@8 at line 5 # spent 108µs making 1 call to Moose::Meta::Attribute::BEGIN@5
# spent 69µs making 1 call to warnings::import |
| 6 | |||||
| 7 | 3 | 145µs | 1 | 19µs | # spent 19µs within Moose::Meta::Attribute::BEGIN@7 which was called:
# once (19µs+0s) by Moose::Meta::TypeCoercion::BEGIN@8 at line 7 # spent 19µs making 1 call to Moose::Meta::Attribute::BEGIN@7 |
| 8 | 3 | 107µs | 2 | 416µs | # spent 228µs (39+189) within Moose::Meta::Attribute::BEGIN@8 which was called:
# once (39µs+189µs) by Moose::Meta::TypeCoercion::BEGIN@8 at line 8 # spent 228µs making 1 call to Moose::Meta::Attribute::BEGIN@8
# spent 189µs making 1 call to Exporter::import |
| 9 | 3 | 94µs | 2 | 292µs | # spent 164µs (37+128) within Moose::Meta::Attribute::BEGIN@9 which was called:
# once (37µs+128µs) by Moose::Meta::TypeCoercion::BEGIN@8 at line 9 # spent 164µs making 1 call to Moose::Meta::Attribute::BEGIN@9
# spent 128µs making 1 call to Exporter::import |
| 10 | 3 | 90µs | 2 | 387µs | # spent 213µs (38+175) within Moose::Meta::Attribute::BEGIN@10 which was called:
# once (38µs+175µs) by Moose::Meta::TypeCoercion::BEGIN@8 at line 10 # spent 213µs making 1 call to Moose::Meta::Attribute::BEGIN@10
# spent 175µs making 1 call to Exporter::import |
| 11 | 3 | 156µs | 1 | 20µs | # spent 20µs within Moose::Meta::Attribute::BEGIN@11 which was called:
# once (20µs+0s) by Moose::Meta::TypeCoercion::BEGIN@8 at line 11 # spent 20µs making 1 call to Moose::Meta::Attribute::BEGIN@11 |
| 12 | |||||
| 13 | 1 | 7µs | our $VERSION = '1.19'; | ||
| 14 | 1 | 5µs | our $AUTHORITY = 'cpan:STEVAN'; | ||
| 15 | |||||
| 16 | 3 | 94µs | 2 | 102µs | # spent 70µs (38+32) within Moose::Meta::Attribute::BEGIN@16 which was called:
# once (38µs+32µs) by Moose::Meta::TypeCoercion::BEGIN@8 at line 16 # spent 70µs making 1 call to Moose::Meta::Attribute::BEGIN@16
# spent 32µs making 1 call to Package::DeprecationManager::__ANON__[Package/DeprecationManager.pm:61] |
| 17 | 3 | 514µs | 1 | 3.97ms | # spent 3.97ms (3.05+917µs) within Moose::Meta::Attribute::BEGIN@17 which was called:
# once (3.05ms+917µs) by Moose::Meta::TypeCoercion::BEGIN@8 at line 17 # spent 3.97ms making 1 call to Moose::Meta::Attribute::BEGIN@17 |
| 18 | 3 | 514µs | 1 | 3.80ms | # spent 3.80ms (2.71+1.08) within Moose::Meta::Attribute::BEGIN@18 which was called:
# once (2.71ms+1.08ms) by Moose::Meta::TypeCoercion::BEGIN@8 at line 18 # spent 3.80ms making 1 call to Moose::Meta::Attribute::BEGIN@18 |
| 19 | 3 | 166µs | 1 | 23µs | # spent 23µs within Moose::Meta::Attribute::BEGIN@19 which was called:
# once (23µs+0s) by Moose::Meta::TypeCoercion::BEGIN@8 at line 19 # spent 23µs making 1 call to Moose::Meta::Attribute::BEGIN@19 |
| 20 | 3 | 749µs | 1 | 314ms | # spent 314ms (20.6+293) within Moose::Meta::Attribute::BEGIN@20 which was called:
# once (20.6ms+293ms) by Moose::Meta::TypeCoercion::BEGIN@8 at line 20 # spent 314ms making 1 call to Moose::Meta::Attribute::BEGIN@20 |
| 21 | 3 | 109µs | 1 | 30µs | # spent 30µs within Moose::Meta::Attribute::BEGIN@21 which was called:
# once (30µs+0s) by Moose::Meta::TypeCoercion::BEGIN@8 at line 21 # spent 30µs making 1 call to Moose::Meta::Attribute::BEGIN@21 |
| 22 | |||||
| 23 | 3 | 17.7ms | 2 | 75.7ms | # spent 37.9ms (36µs+37.8) within Moose::Meta::Attribute::BEGIN@23 which was called:
# once (36µs+37.8ms) by Moose::Meta::TypeCoercion::BEGIN@8 at line 23 # spent 37.9ms making 1 call to Moose::Meta::Attribute::BEGIN@23
# spent 37.8ms making 1 call to base::import |
| 24 | |||||
| 25 | 1 | 22µs | 1 | 9.11ms | Class::MOP::MiniTrait::apply(__PACKAGE__, 'Moose::Meta::Object::Trait'); # spent 9.11ms making 1 call to Class::MOP::MiniTrait::apply |
| 26 | |||||
| 27 | 1 | 67µs | 2 | 3.04ms | __PACKAGE__->meta->add_attribute('traits' => ( # spent 2.96ms making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 83µs making 1 call to Class::MOP::Object::meta |
| 28 | reader => 'applied_traits', | ||||
| 29 | predicate => 'has_applied_traits', | ||||
| 30 | )); | ||||
| 31 | |||||
| 32 | # we need to have a ->does method in here to | ||||
| 33 | # more easily support traits, and the introspection | ||||
| 34 | # of those traits. We extend the does check to look | ||||
| 35 | # for metatrait aliases. | ||||
| 36 | # spent 4.97ms (374µs+4.60) within Moose::Meta::Attribute::does which was called 5 times, avg 995µs/call:
# 5 times (374µs+4.60ms) by Moose::Meta::Attribute::interpolate_class at line 119, avg 995µs/call | ||||
| 37 | 5 | 30µs | my ($self, $role_name) = @_; | ||
| 38 | # spent 3.76ms (101µs+3.66) within Moose::Meta::Attribute::__ANON__[/home/doy/coding/src/Moose/blib/lib//Moose/Meta/Attribute.pm:40] which was called 5 times, avg 753µs/call:
# 5 times (101µs+3.66ms) by Try::Tiny::try at line 71 of Try/Tiny.pm, avg 753µs/call | ||||
| 39 | 5 | 99µs | 5 | 3.66ms | Moose::Util::resolve_metatrait_alias(Attribute => $role_name) # spent 3.66ms making 5 calls to Moose::Util::resolve_metatrait_alias, avg 732µs/call |
| 40 | 5 | 131µs | 5 | 4.14ms | }; # spent 4.14ms making 5 calls to Try::Tiny::try, avg 827µs/call |
| 41 | 5 | 18µs | return 0 if !defined($name); # failed to load class | ||
| 42 | 5 | 152µs | 5 | 462µs | return $self->Moose::Object::does($name); # spent 462µs making 5 calls to Moose::Object::does, avg 92µs/call |
| 43 | } | ||||
| 44 | |||||
| 45 | sub throw_error { | ||||
| 46 | my $self = shift; | ||||
| 47 | my $class = ( ref $self && $self->associated_class ) || "Moose::Meta::Class"; | ||||
| 48 | unshift @_, "message" if @_ % 2 == 1; | ||||
| 49 | unshift @_, attr => $self if ref $self; | ||||
| 50 | unshift @_, $class; | ||||
| 51 | my $handler = $class->can("throw_error"); # to avoid incrementing depth by 1 | ||||
| 52 | goto $handler; | ||||
| 53 | } | ||||
| 54 | |||||
| 55 | # spent 4.26ms within Moose::Meta::Attribute::_inline_throw_error which was called 211 times, avg 20µs/call:
# 190 times (3.83ms+0s) by Moose::Meta::Attribute::_inline_check_constraint at line 646, avg 20µs/call
# 19 times (389µs+0s) by Moose::Meta::Attribute::_inline_generate_default at line 803, avg 20µs/call
# 2 times (40µs+0s) by Moose::Meta::Attribute::_inline_check_required at line 611, avg 20µs/call | ||||
| 56 | 211 | 1.05ms | my ( $self, $msg, $args ) = @_; | ||
| 57 | 211 | 3.83ms | "\$meta->throw_error($msg" . ($args ? ", $args" : "") . ")"; # FIXME makes deparsing *REALLY* hard | ||
| 58 | } | ||||
| 59 | |||||
| 60 | # spent 334ms (79.0+255) within Moose::Meta::Attribute::new which was called 124 times, avg 2.70ms/call:
# 121 times (77.2ms+249ms) by Moose::Meta::Attribute::interpolate_class_and_new at line 88, avg 2.69ms/call
# 2 times (1.23ms+1.05ms) by Moose::Meta::Attribute::clone at line 244, avg 1.14ms/call
# once (664µs+5.47ms) by Moose::BEGIN@21 at line 20 of Moose/Meta/TypeCoercion.pm | ||||
| 61 | 124 | 1.48ms | my ($class, $name, %options) = @_; | ||
| 62 | 124 | 1.81ms | 122 | 148ms | $class->_process_options($name, \%options) unless $options{__hack_no_process_options}; # used from clone()... YECHKKK FIXME ICKY YUCK GROSS # spent 145ms making 120 calls to Moose::Meta::Attribute::_process_options, avg 1.20ms/call
# spent 1.70ms making 1 call to Class::MOP::Class::__ANON__::SERIAL::2::_process_options
# spent 1.62ms making 1 call to Class::MOP::Class::__ANON__::SERIAL::5::_process_options |
| 63 | |||||
| 64 | 124 | 446µs | delete $options{__hack_no_process_options}; | ||
| 65 | |||||
| 66 | my %attrs = | ||||
| 67 | ( map { $_ => 1 } | ||||
| 68 | 3476 | 58.4ms | 3476 | 18.0ms | grep { defined } # spent 18.0ms making 3476 calls to Class::MOP::Mixin::AttributeCore::init_arg, avg 5µs/call |
| 69 | 124 | 23.5ms | 248 | 25.3ms | map { $_->init_arg() } # spent 11.3ms making 119 calls to Class::MOP::Object::meta, avg 95µs/call
# spent 9.53ms making 118 calls to Class::MOP::Class::Immutable::Class::MOP::Class::get_all_attributes, avg 81µs/call
# spent 4.03ms making 6 calls to Class::MOP::Class::get_all_attributes, avg 672µs/call
# spent 282µs making 3 calls to Class::MOP::Class::__ANON__::SERIAL::1::meta, avg 94µs/call
# spent 101µs making 1 call to Class::MOP::Class::__ANON__::SERIAL::2::meta
# spent 98µs making 1 call to Class::MOP::Class::__ANON__::SERIAL::5::meta |
| 70 | $class->meta()->get_all_attributes() | ||||
| 71 | ); | ||||
| 72 | |||||
| 73 | 124 | 3.87ms | 124 | 558µs | my @bad = sort grep { ! $attrs{$_} } keys %options; # spent 558µs making 124 calls to Moose::Meta::Attribute::CORE:sort, avg 4µs/call |
| 74 | |||||
| 75 | 124 | 337µs | if (@bad) | ||
| 76 | { | ||||
| 77 | Carp::cluck "Found unknown argument(s) passed to '$name' attribute constructor in '$class': @bad"; | ||||
| 78 | } | ||||
| 79 | |||||
| 80 | 124 | 7.33ms | 124 | 63.6ms | return $class->SUPER::new($name, %options); # spent 63.6ms making 124 calls to Class::MOP::Attribute::new, avg 513µs/call |
| 81 | } | ||||
| 82 | |||||
| 83 | # spent 551ms (7.72+543) within Moose::Meta::Attribute::interpolate_class_and_new which was called 121 times, avg 4.55ms/call:
# 114 times (7.23ms+538ms) by Moose::Meta::Class::_process_new_attribute at line 622 of Moose/Meta/Class.pm, avg 4.78ms/call
# 7 times (490µs+4.59ms) by Moose::Meta::Role::Attribute::attribute_for_class at line 67 of Moose/Meta/Role/Attribute.pm, avg 725µs/call | ||||
| 84 | 121 | 1.39ms | my ($class, $name, %args) = @_; | ||
| 85 | |||||
| 86 | 121 | 1.94ms | 121 | 224ms | my ( $new_class, @traits ) = $class->interpolate_class(\%args); # spent 225ms making 121 calls to Moose::Meta::Attribute::interpolate_class, avg 1.86ms/call, recursion: max depth 1, sum of overlapping time 120µs |
| 87 | |||||
| 88 | 121 | 3.87ms | 121 | 326ms | $new_class->new($name, %args, ( scalar(@traits) ? ( traits => \@traits ) : () ) ); # spent 326ms making 121 calls to Moose::Meta::Attribute::new, avg 2.69ms/call |
| 89 | } | ||||
| 90 | |||||
| 91 | # spent 225ms (4.17+220) within Moose::Meta::Attribute::interpolate_class which was called 123 times, avg 1.83ms/call:
# 121 times (4.11ms+220ms) by Moose::Meta::Attribute::interpolate_class_and_new at line 86, avg 1.85ms/call
# 2 times (63µs+0s) by Moose::Meta::Attribute::clone_and_inherit_options at line 214, avg 31µs/call | ||||
| 92 | 123 | 482µs | my ($class, $options) = @_; | ||
| 93 | |||||
| 94 | 123 | 325µs | $class = ref($class) || $class; | ||
| 95 | |||||
| 96 | 123 | 600µs | if ( my $metaclass_name = delete $options->{metaclass} ) { | ||
| 97 | my $new_class = Moose::Util::resolve_metaclass_alias( Attribute => $metaclass_name ); | ||||
| 98 | |||||
| 99 | if ( $class ne $new_class ) { | ||||
| 100 | if ( $new_class->can("interpolate_class") ) { | ||||
| 101 | return $new_class->interpolate_class($options); | ||||
| 102 | } else { | ||||
| 103 | $class = $new_class; | ||||
| 104 | } | ||||
| 105 | } | ||||
| 106 | } | ||||
| 107 | |||||
| 108 | 123 | 258µs | my @traits; | ||
| 109 | |||||
| 110 | 123 | 407µs | if (my $traits = $options->{traits}) { | ||
| 111 | 5 | 13µs | my $i = 0; | ||
| 112 | 5 | 24µs | while ($i < @$traits) { | ||
| 113 | 5 | 18µs | my $trait = $traits->[$i++]; | ||
| 114 | 5 | 9µs | next if ref($trait); # options to a trait we discarded | ||
| 115 | |||||
| 116 | 5 | 66µs | 5 | 89.8ms | $trait = Moose::Util::resolve_metatrait_alias(Attribute => $trait) # spent 89.8ms making 5 calls to Moose::Util::resolve_metatrait_alias, avg 18.0ms/call |
| 117 | || $trait; | ||||
| 118 | |||||
| 119 | 5 | 72µs | 5 | 4.97ms | next if $class->does($trait); # spent 4.97ms making 5 calls to Moose::Meta::Attribute::does, avg 995µs/call |
| 120 | |||||
| 121 | 5 | 24µs | push @traits, $trait; | ||
| 122 | |||||
| 123 | # are there options? | ||||
| 124 | 5 | 38µs | push @traits, $traits->[$i++] | ||
| 125 | if $traits->[$i] && ref($traits->[$i]); | ||||
| 126 | } | ||||
| 127 | |||||
| 128 | 5 | 24µs | if (@traits) { | ||
| 129 | 5 | 115µs | 5 | 126ms | my $anon_class = Moose::Meta::Class->create_anon_class( # spent 126ms making 5 calls to Moose::Meta::Class::create_anon_class, avg 25.1ms/call |
| 130 | superclasses => [ $class ], | ||||
| 131 | roles => [ @traits ], | ||||
| 132 | cache => 1, | ||||
| 133 | ); | ||||
| 134 | |||||
| 135 | 5 | 113µs | 5 | 33µs | $class = $anon_class->name; # spent 33µs making 5 calls to Class::MOP::Package::name, avg 7µs/call |
| 136 | } | ||||
| 137 | } | ||||
| 138 | |||||
| 139 | 123 | 2.14ms | return ( wantarray ? ( $class, @traits ) : $class ); | ||
| 140 | } | ||||
| 141 | |||||
| 142 | # ... | ||||
| 143 | |||||
| 144 | # method-generating options shouldn't be overridden | ||||
| 145 | # spent 30µs within Moose::Meta::Attribute::illegal_options_for_inheritance which was called 2 times, avg 15µs/call:
# 2 times (30µs+0s) by Moose::Meta::Attribute::clone_and_inherit_options at line 173, avg 15µs/call | ||||
| 146 | 2 | 45µs | qw(reader writer accessor clearer predicate) | ||
| 147 | } | ||||
| 148 | |||||
| 149 | # NOTE/TODO | ||||
| 150 | # This method *must* be able to handle | ||||
| 151 | # Class::MOP::Attribute instances as | ||||
| 152 | # well. Yes, I know that is wrong, but | ||||
| 153 | # apparently we didn't realize it was | ||||
| 154 | # doing that and now we have some code | ||||
| 155 | # which is dependent on it. The real | ||||
| 156 | # solution of course is to push this | ||||
| 157 | # feature back up into Class::MOP::Attribute | ||||
| 158 | # but I not right now, I am too lazy. | ||||
| 159 | # However if you are reading this and | ||||
| 160 | # looking for something to do,.. please | ||||
| 161 | # be my guest. | ||||
| 162 | # - stevan | ||||
| 163 | # spent 18.1ms (446µs+17.7) within Moose::Meta::Attribute::clone_and_inherit_options which was called 2 times, avg 9.07ms/call:
# 2 times (446µs+17.7ms) by Moose::Meta::Class::_process_inherited_attribute at line 630 of Moose/Meta/Class.pm, avg 9.07ms/call | ||||
| 164 | 2 | 15µs | my ($self, %options) = @_; | ||
| 165 | |||||
| 166 | # NOTE: | ||||
| 167 | # we may want to extends a Class::MOP::Attribute | ||||
| 168 | # in which case we need to be able to use the | ||||
| 169 | # core set of legal options that have always | ||||
| 170 | # been here. But we allows Moose::Meta::Attribute | ||||
| 171 | # instances to changes them. | ||||
| 172 | # - SL | ||||
| 173 | 2 | 90µs | 4 | 47µs | my @illegal_options = $self->can('illegal_options_for_inheritance') # spent 30µs making 2 calls to Moose::Meta::Attribute::illegal_options_for_inheritance, avg 15µs/call
# spent 17µs making 2 calls to UNIVERSAL::can, avg 8µs/call |
| 174 | ? $self->illegal_options_for_inheritance | ||||
| 175 | : (); | ||||
| 176 | |||||
| 177 | 2 | 19µs | my @found_illegal_options = grep { exists $options{$_} && exists $self->{$_} ? $_ : undef } @illegal_options; | ||
| 178 | 2 | 7µs | (scalar @found_illegal_options == 0) | ||
| 179 | || $self->throw_error("Illegal inherited options => (" . (join ', ' => @found_illegal_options) . ")", data => \%options); | ||||
| 180 | |||||
| 181 | 2 | 6µs | if ($options{isa}) { | ||
| 182 | my $type_constraint; | ||||
| 183 | if (blessed($options{isa}) && $options{isa}->isa('Moose::Meta::TypeConstraint')) { | ||||
| 184 | $type_constraint = $options{isa}; | ||||
| 185 | } | ||||
| 186 | else { | ||||
| 187 | $type_constraint = Moose::Util::TypeConstraints::find_or_create_isa_type_constraint($options{isa}); | ||||
| 188 | (defined $type_constraint) | ||||
| 189 | || $self->throw_error("Could not find the type constraint '" . $options{isa} . "'", data => $options{isa}); | ||||
| 190 | } | ||||
| 191 | |||||
| 192 | $options{type_constraint} = $type_constraint; | ||||
| 193 | } | ||||
| 194 | |||||
| 195 | 2 | 6µs | if ($options{does}) { | ||
| 196 | my $type_constraint; | ||||
| 197 | if (blessed($options{does}) && $options{does}->isa('Moose::Meta::TypeConstraint')) { | ||||
| 198 | $type_constraint = $options{does}; | ||||
| 199 | } | ||||
| 200 | else { | ||||
| 201 | $type_constraint = Moose::Util::TypeConstraints::find_or_create_does_type_constraint($options{does}); | ||||
| 202 | (defined $type_constraint) | ||||
| 203 | || $self->throw_error("Could not find the type constraint '" . $options{does} . "'", data => $options{does}); | ||||
| 204 | } | ||||
| 205 | |||||
| 206 | $options{type_constraint} = $type_constraint; | ||||
| 207 | } | ||||
| 208 | |||||
| 209 | # NOTE: | ||||
| 210 | # this doesn't apply to Class::MOP::Attributes, | ||||
| 211 | # so we can ignore it for them. | ||||
| 212 | # - SL | ||||
| 213 | 2 | 63µs | 2 | 14µs | if ($self->can('interpolate_class')) { # spent 14µs making 2 calls to UNIVERSAL::can, avg 7µs/call |
| 214 | 2 | 36µs | 2 | 63µs | ( $options{metaclass}, my @traits ) = $self->interpolate_class(\%options); # spent 63µs making 2 calls to Moose::Meta::Attribute::interpolate_class, avg 31µs/call |
| 215 | |||||
| 216 | 2 | 4µs | my %seen; | ||
| 217 | 2 | 32µs | 2 | 29µs | my @all_traits = grep { $seen{$_}++ } @{ $self->applied_traits || [] }, @traits; # spent 29µs making 2 calls to Moose::Meta::Attribute::applied_traits, avg 14µs/call |
| 218 | 2 | 8µs | $options{traits} = \@all_traits if @all_traits; | ||
| 219 | } | ||||
| 220 | |||||
| 221 | # This method can be called on a CMOP::Attribute object, so we need to | ||||
| 222 | # make sure we can call this method. | ||||
| 223 | 2 | 98µs | 6 | 59µs | $self->_process_lazy_build_option( $self->name, \%options ) # spent 32µs making 2 calls to Moose::Meta::Attribute::_process_lazy_build_option, avg 16µs/call
# spent 14µs making 2 calls to UNIVERSAL::can, avg 7µs/call
# spent 13µs making 2 calls to Class::MOP::Mixin::AttributeCore::name, avg 7µs/call |
| 224 | if $self->can('_process_lazy_build_option'); | ||||
| 225 | |||||
| 226 | 2 | 71µs | 2 | 17.5ms | $self->clone(%options); # spent 17.5ms making 2 calls to Moose::Meta::Attribute::clone, avg 8.75ms/call |
| 227 | } | ||||
| 228 | |||||
| 229 | # spent 17.5ms (2.14+15.3) within Moose::Meta::Attribute::clone which was called 2 times, avg 8.75ms/call:
# 2 times (2.14ms+15.3ms) by Moose::Meta::Attribute::clone_and_inherit_options at line 226, avg 8.75ms/call | ||||
| 230 | 2 | 16µs | my ( $self, %params ) = @_; | ||
| 231 | |||||
| 232 | 2 | 11µs | my $class = delete $params{metaclass} || ref $self; | ||
| 233 | |||||
| 234 | 2 | 5µs | my ( @init, @non_init ); | ||
| 235 | |||||
| 236 | 58 | 751µs | 60 | 9.11ms | foreach my $attr ( grep { $_->has_value($self) } Class::MOP::class_of($self)->get_all_attributes ) { # spent 8.89ms making 56 calls to Class::MOP::Attribute::has_value, avg 159µs/call
# spent 146µs making 2 calls to Class::MOP::Class::Immutable::Class::MOP::Class::get_all_attributes, avg 73µs/call
# spent 71µs making 2 calls to Class::MOP::class_of, avg 36µs/call |
| 237 | 21 | 348µs | 21 | 202µs | push @{ $attr->has_init_arg ? \@init : \@non_init }, $attr; # spent 202µs making 21 calls to Class::MOP::Mixin::AttributeCore::has_init_arg, avg 10µs/call |
| 238 | } | ||||
| 239 | |||||
| 240 | 23 | 666µs | 42 | 3.77ms | my %new_params = ( ( map { $_->init_arg => $_->get_value($self) } @init ), %params ); # spent 3.66ms making 21 calls to Class::MOP::Attribute::get_value, avg 174µs/call
# spent 107µs making 21 calls to Class::MOP::Mixin::AttributeCore::init_arg, avg 5µs/call |
| 241 | |||||
| 242 | 2 | 11µs | my $name = delete $new_params{name}; | ||
| 243 | |||||
| 244 | 2 | 109µs | 2 | 2.27ms | my $clone = $class->new($name, %new_params, __hack_no_process_options => 1 ); # spent 2.27ms making 2 calls to Moose::Meta::Attribute::new, avg 1.14ms/call |
| 245 | |||||
| 246 | 2 | 14µs | foreach my $attr ( @non_init ) { | ||
| 247 | $attr->set_value($clone, $attr->get_value($self)); | ||||
| 248 | } | ||||
| 249 | |||||
| 250 | 2 | 46µs | return $clone; | ||
| 251 | } | ||||
| 252 | |||||
| 253 | # spent 146ms (18.7+127) within Moose::Meta::Attribute::_process_options which was called 122 times, avg 1.20ms/call:
# 120 times (18.2ms+126ms) by Moose::Meta::Attribute::new at line 62, avg 1.20ms/call
# 2 times (498µs+856µs) by Class::MOP::Method::Wrapped::__ANON__[/home/doy/coding/src/Class-MOP/blib/lib//Class/MOP/Method/Wrapped.pm:49] at line 48 of Class/MOP/Method/Wrapped.pm, avg 677µs/call | ||||
| 254 | 122 | 561µs | my ( $class, $name, $options ) = @_; | ||
| 255 | |||||
| 256 | 122 | 1.43ms | 122 | 3.08ms | $class->_process_is_option( $name, $options ); # spent 3.08ms making 122 calls to Moose::Meta::Attribute::_process_is_option, avg 25µs/call |
| 257 | 122 | 1.58ms | 122 | 102ms | $class->_process_isa_option( $name, $options ); # spent 102ms making 122 calls to Moose::Meta::Attribute::_process_isa_option, avg 839µs/call |
| 258 | 122 | 1.57ms | 122 | 10.3ms | $class->_process_does_option( $name, $options ); # spent 10.3ms making 122 calls to Moose::Meta::Attribute::_process_does_option, avg 85µs/call |
| 259 | 122 | 1.49ms | 122 | 1.80ms | $class->_process_coerce_option( $name, $options ); # spent 1.80ms making 122 calls to Moose::Meta::Attribute::_process_coerce_option, avg 15µs/call |
| 260 | 122 | 1.42ms | 122 | 1.72ms | $class->_process_trigger_option( $name, $options ); # spent 1.72ms making 122 calls to Moose::Meta::Attribute::_process_trigger_option, avg 14µs/call |
| 261 | 122 | 1.42ms | 122 | 1.71ms | $class->_process_auto_deref_option( $name, $options ); # spent 1.71ms making 122 calls to Moose::Meta::Attribute::_process_auto_deref_option, avg 14µs/call |
| 262 | 122 | 1.44ms | 122 | 2.72ms | $class->_process_lazy_build_option( $name, $options ); # spent 2.72ms making 122 calls to Moose::Meta::Attribute::_process_lazy_build_option, avg 22µs/call |
| 263 | 122 | 1.51ms | 122 | 1.70ms | $class->_process_lazy_option( $name, $options ); # spent 1.70ms making 122 calls to Moose::Meta::Attribute::_process_lazy_option, avg 14µs/call |
| 264 | 122 | 2.68ms | 122 | 1.79ms | $class->_process_required_option( $name, $options ); # spent 1.79ms making 122 calls to Moose::Meta::Attribute::_process_required_option, avg 15µs/call |
| 265 | } | ||||
| 266 | |||||
| 267 | # spent 3.08ms within Moose::Meta::Attribute::_process_is_option which was called 122 times, avg 25µs/call:
# 122 times (3.08ms+0s) by Moose::Meta::Attribute::_process_options at line 256, avg 25µs/call | ||||
| 268 | 122 | 444µs | my ( $class, $name, $options ) = @_; | ||
| 269 | |||||
| 270 | 122 | 422µs | return unless $options->{is}; | ||
| 271 | |||||
| 272 | ### ------------------------- | ||||
| 273 | ## is => ro, writer => _foo # turns into (reader => foo, writer => _foo) as before | ||||
| 274 | ## is => rw, writer => _foo # turns into (reader => foo, writer => _foo) | ||||
| 275 | ## is => rw, accessor => _foo # turns into (accessor => _foo) | ||||
| 276 | ## is => ro, accessor => _foo # error, accesor is rw | ||||
| 277 | ### ------------------------- | ||||
| 278 | |||||
| 279 | 115 | 1.99ms | if ( $options->{is} eq 'ro' ) { | ||
| 280 | 91 | 218µs | $class->throw_error( | ||
| 281 | "Cannot define an accessor name on a read-only attribute, accessors are read/write", | ||||
| 282 | data => $options ) | ||||
| 283 | if exists $options->{accessor}; | ||||
| 284 | 91 | 494µs | $options->{reader} ||= $name; | ||
| 285 | } | ||||
| 286 | elsif ( $options->{is} eq 'rw' ) { | ||||
| 287 | if ( $options->{writer} ) { | ||||
| 288 | $options->{reader} ||= $name; | ||||
| 289 | } | ||||
| 290 | else { | ||||
| 291 | 24 | 141µs | $options->{accessor} ||= $name; | ||
| 292 | } | ||||
| 293 | } | ||||
| 294 | elsif ( $options->{is} eq 'bare' ) { | ||||
| 295 | return; | ||||
| 296 | # do nothing, but don't complain (later) about missing methods | ||||
| 297 | } | ||||
| 298 | else { | ||||
| 299 | $class->throw_error( "I do not understand this option (is => " | ||||
| 300 | . $options->{is} | ||||
| 301 | . ") on attribute ($name)", data => $options->{is} ); | ||||
| 302 | } | ||||
| 303 | } | ||||
| 304 | |||||
| 305 | # spent 102ms (5.33+97.0) within Moose::Meta::Attribute::_process_isa_option which was called 122 times, avg 839µs/call:
# 122 times (5.33ms+97.0ms) by Moose::Meta::Attribute::_process_options at line 257, avg 839µs/call | ||||
| 306 | 122 | 581µs | my ( $class, $name, $options ) = @_; | ||
| 307 | |||||
| 308 | 122 | 627µs | return unless exists $options->{isa}; | ||
| 309 | |||||
| 310 | 100 | 255µs | if ( exists $options->{does} ) { | ||
| 311 | if ( try { $options->{isa}->can('does') } ) { | ||||
| 312 | ( $options->{isa}->does( $options->{does} ) ) | ||||
| 313 | || $class->throw_error( | ||||
| 314 | "Cannot have an isa option and a does option if the isa does not do the does on attribute ($name)", | ||||
| 315 | data => $options ); | ||||
| 316 | } | ||||
| 317 | else { | ||||
| 318 | $class->throw_error( | ||||
| 319 | "Cannot have an isa option which cannot ->does() on attribute ($name)", | ||||
| 320 | data => $options ); | ||||
| 321 | } | ||||
| 322 | } | ||||
| 323 | |||||
| 324 | # allow for anon-subtypes here ... | ||||
| 325 | 100 | 2.95ms | 100 | 552µs | if ( blessed( $options->{isa} ) # spent 552µs making 100 calls to Scalar::Util::blessed, avg 6µs/call |
| 326 | && $options->{isa}->isa('Moose::Meta::TypeConstraint') ) { | ||||
| 327 | $options->{type_constraint} = $options->{isa}; | ||||
| 328 | } | ||||
| 329 | else { | ||||
| 330 | 100 | 1.64ms | 100 | 96.5ms | $options->{type_constraint} # spent 96.5ms making 100 calls to Moose::Util::TypeConstraints::find_or_create_isa_type_constraint, avg 965µs/call |
| 331 | = Moose::Util::TypeConstraints::find_or_create_isa_type_constraint( | ||||
| 332 | $options->{isa} ); | ||||
| 333 | } | ||||
| 334 | } | ||||
| 335 | |||||
| 336 | # spent 10.3ms (2.15+8.18) within Moose::Meta::Attribute::_process_does_option which was called 122 times, avg 85µs/call:
# 122 times (2.15ms+8.18ms) by Moose::Meta::Attribute::_process_options at line 258, avg 85µs/call | ||||
| 337 | 122 | 569µs | my ( $class, $name, $options ) = @_; | ||
| 338 | |||||
| 339 | 122 | 1.46ms | return unless exists $options->{does} && ! exists $options->{isa}; | ||
| 340 | |||||
| 341 | # allow for anon-subtypes here ... | ||||
| 342 | 11 | 323µs | 11 | 57µs | if ( blessed( $options->{does} ) # spent 57µs making 11 calls to Scalar::Util::blessed, avg 5µs/call |
| 343 | && $options->{does}->isa('Moose::Meta::TypeConstraint') ) { | ||||
| 344 | $options->{type_constraint} = $options->{does}; | ||||
| 345 | } | ||||
| 346 | else { | ||||
| 347 | 11 | 174µs | 11 | 8.13ms | $options->{type_constraint} # spent 8.13ms making 11 calls to Moose::Util::TypeConstraints::find_or_create_does_type_constraint, avg 739µs/call |
| 348 | = Moose::Util::TypeConstraints::find_or_create_does_type_constraint( | ||||
| 349 | $options->{does} ); | ||||
| 350 | } | ||||
| 351 | } | ||||
| 352 | |||||
| 353 | # spent 1.80ms (1.78+24µs) within Moose::Meta::Attribute::_process_coerce_option which was called 122 times, avg 15µs/call:
# 122 times (1.78ms+24µs) by Moose::Meta::Attribute::_process_options at line 259, avg 15µs/call | ||||
| 354 | 122 | 541µs | my ( $class, $name, $options ) = @_; | ||
| 355 | |||||
| 356 | 122 | 2.03ms | return unless $options->{coerce}; | ||
| 357 | |||||
| 358 | 2 | 6µs | ( exists $options->{type_constraint} ) | ||
| 359 | || $class->throw_error( | ||||
| 360 | "You cannot have coercion without specifying a type constraint on attribute ($name)", | ||||
| 361 | data => $options ); | ||||
| 362 | |||||
| 363 | 2 | 6µs | $class->throw_error( | ||
| 364 | "You cannot have a weak reference to a coerced value on attribute ($name)", | ||||
| 365 | data => $options ) | ||||
| 366 | if $options->{weak_ref}; | ||||
| 367 | |||||
| 368 | 2 | 43µs | 2 | 24µs | unless ( $options->{type_constraint}->has_coercion ) { # spent 24µs making 2 calls to Moose::Meta::TypeConstraint::has_coercion, avg 12µs/call |
| 369 | my $type = $options->{type_constraint}->name; | ||||
| 370 | |||||
| 371 | Moose::Deprecated::deprecated( | ||||
| 372 | feature => 'coerce without coercion', | ||||
| 373 | message => | ||||
| 374 | "You cannot coerce an attribute ($name) unless its type ($type) has a coercion" | ||||
| 375 | ); | ||||
| 376 | } | ||||
| 377 | } | ||||
| 378 | |||||
| 379 | # spent 1.72ms within Moose::Meta::Attribute::_process_trigger_option which was called 122 times, avg 14µs/call:
# 122 times (1.72ms+0s) by Moose::Meta::Attribute::_process_options at line 260, avg 14µs/call | ||||
| 380 | 122 | 550µs | my ( $class, $name, $options ) = @_; | ||
| 381 | |||||
| 382 | 122 | 1.48ms | return unless exists $options->{trigger}; | ||
| 383 | |||||
| 384 | ( 'CODE' eq ref $options->{trigger} ) | ||||
| 385 | || $class->throw_error("Trigger must be a CODE ref on attribute ($name)", data => $options->{trigger}); | ||||
| 386 | } | ||||
| 387 | |||||
| 388 | # spent 1.71ms within Moose::Meta::Attribute::_process_auto_deref_option which was called 122 times, avg 14µs/call:
# 122 times (1.71ms+0s) by Moose::Meta::Attribute::_process_options at line 261, avg 14µs/call | ||||
| 389 | 122 | 583µs | my ( $class, $name, $options ) = @_; | ||
| 390 | |||||
| 391 | 122 | 1.52ms | return unless $options->{auto_deref}; | ||
| 392 | |||||
| 393 | ( exists $options->{type_constraint} ) | ||||
| 394 | || $class->throw_error( | ||||
| 395 | "You cannot auto-dereference without specifying a type constraint on attribute ($name)", | ||||
| 396 | data => $options ); | ||||
| 397 | |||||
| 398 | ( $options->{type_constraint}->is_a_type_of('ArrayRef') | ||||
| 399 | || $options->{type_constraint}->is_a_type_of('HashRef') ) | ||||
| 400 | || $class->throw_error( | ||||
| 401 | "You cannot auto-dereference anything other than a ArrayRef or HashRef on attribute ($name)", | ||||
| 402 | data => $options ); | ||||
| 403 | } | ||||
| 404 | |||||
| 405 | # spent 2.75ms (2.67+85µs) within Moose::Meta::Attribute::_process_lazy_build_option which was called 124 times, avg 22µs/call:
# 122 times (2.63ms+85µs) by Moose::Meta::Attribute::_process_options at line 262, avg 22µs/call
# 2 times (32µs+0s) by Moose::Meta::Attribute::clone_and_inherit_options at line 223, avg 16µs/call | ||||
| 406 | 124 | 573µs | my ( $class, $name, $options ) = @_; | ||
| 407 | |||||
| 408 | 124 | 1.49ms | return unless $options->{lazy_build}; | ||
| 409 | |||||
| 410 | 16 | 48µs | $class->throw_error( | ||
| 411 | "You can not use lazy_build and default for the same attribute ($name)", | ||||
| 412 | data => $options ) | ||||
| 413 | if exists $options->{default}; | ||||
| 414 | |||||
| 415 | 16 | 65µs | $options->{lazy} = 1; | ||
| 416 | 16 | 227µs | $options->{builder} ||= "_build_${name}"; | ||
| 417 | |||||
| 418 | 16 | 498µs | 16 | 85µs | if ( $name =~ /^_/ ) { # spent 85µs making 16 calls to Moose::Meta::Attribute::CORE:match, avg 5µs/call |
| 419 | 2 | 15µs | $options->{clearer} ||= "_clear${name}"; | ||
| 420 | 2 | 13µs | $options->{predicate} ||= "_has${name}"; | ||
| 421 | } | ||||
| 422 | else { | ||||
| 423 | 14 | 104µs | $options->{clearer} ||= "clear_${name}"; | ||
| 424 | 14 | 125µs | $options->{predicate} ||= "has_${name}"; | ||
| 425 | } | ||||
| 426 | } | ||||
| 427 | |||||
| 428 | # spent 1.70ms within Moose::Meta::Attribute::_process_lazy_option which was called 122 times, avg 14µs/call:
# 122 times (1.70ms+0s) by Moose::Meta::Attribute::_process_options at line 263, avg 14µs/call | ||||
| 429 | 122 | 471µs | my ( $class, $name, $options ) = @_; | ||
| 430 | |||||
| 431 | 122 | 1.29ms | return unless $options->{lazy}; | ||
| 432 | |||||
| 433 | 19 | 258µs | ( exists $options->{default} || defined $options->{builder} ) | ||
| 434 | || $class->throw_error( | ||||
| 435 | "You cannot have a lazy attribute ($name) without specifying a default value for it", | ||||
| 436 | data => $options ); | ||||
| 437 | } | ||||
| 438 | |||||
| 439 | # spent 1.79ms within Moose::Meta::Attribute::_process_required_option which was called 122 times, avg 15µs/call:
# 122 times (1.79ms+0s) by Moose::Meta::Attribute::_process_options at line 264, avg 15µs/call | ||||
| 440 | 122 | 497µs | my ( $class, $name, $options ) = @_; | ||
| 441 | |||||
| 442 | 122 | 1.63ms | if ( | ||
| 443 | $options->{required} | ||||
| 444 | && !( | ||||
| 445 | ( !exists $options->{init_arg} || defined $options->{init_arg} ) | ||||
| 446 | || exists $options->{default} | ||||
| 447 | || defined $options->{builder} | ||||
| 448 | ) | ||||
| 449 | ) { | ||||
| 450 | $class->throw_error( | ||||
| 451 | "You cannot have a required attribute ($name) without a default, builder, or an init_arg", | ||||
| 452 | data => $options ); | ||||
| 453 | } | ||||
| 454 | } | ||||
| 455 | |||||
| 456 | # spent 7.71ms (1.63+6.08) within Moose::Meta::Attribute::initialize_instance_slot which was called 14 times, avg 551µs/call:
# 14 times (1.63ms+6.08ms) by Class::MOP::Class::_construct_instance at line 579 of Class/MOP/Class.pm, avg 551µs/call | ||||
| 457 | 14 | 53µs | my ($self, $meta_instance, $instance, $params) = @_; | ||
| 458 | 14 | 294µs | 14 | 84µs | my $init_arg = $self->init_arg(); # spent 84µs making 14 calls to Class::MOP::Mixin::AttributeCore::init_arg, avg 6µs/call |
| 459 | # try to fetch the init arg from the %params ... | ||||
| 460 | |||||
| 461 | 14 | 26µs | my $val; | ||
| 462 | 14 | 24µs | my $value_is_set; | ||
| 463 | 14 | 80µs | if ( defined($init_arg) and exists $params->{$init_arg}) { | ||
| 464 | 2 | 7µs | $val = $params->{$init_arg}; | ||
| 465 | 2 | 5µs | $value_is_set = 1; | ||
| 466 | } | ||||
| 467 | else { | ||||
| 468 | # skip it if it's lazy | ||||
| 469 | 12 | 150µs | 12 | 156µs | return if $self->is_lazy; # spent 156µs making 12 calls to Moose::Meta::Mixin::AttributeCore::is_lazy, avg 13µs/call |
| 470 | # and die if it's required and doesn't have a default value | ||||
| 471 | 10 | 126µs | 11 | 131µs | $self->throw_error("Attribute (" . $self->name . ") is required", object => $instance, data => $params) # spent 119µs making 10 calls to Moose::Meta::Mixin::AttributeCore::is_required, avg 12µs/call
# spent 11µs making 1 call to Class::MOP::Mixin::AttributeCore::has_default |
| 472 | if $self->is_required && !$self->has_default && !$self->has_builder; | ||||
| 473 | |||||
| 474 | # if nothing was in the %params, we can use the | ||||
| 475 | # attribute's default value (if it has one) | ||||
| 476 | 10 | 138µs | 11 | 110µs | if ($self->has_default) { # spent 99µs making 10 calls to Class::MOP::Mixin::AttributeCore::has_default, avg 10µs/call
# spent 11µs making 1 call to Class::MOP::Mixin::AttributeCore::has_builder |
| 477 | 9 | 100µs | 9 | 374µs | $val = $self->default($instance); # spent 374µs making 9 calls to Class::MOP::Mixin::AttributeCore::default, avg 42µs/call |
| 478 | 9 | 22µs | $value_is_set = 1; | ||
| 479 | } | ||||
| 480 | elsif ($self->has_builder) { | ||||
| 481 | $val = $self->_call_builder($instance); | ||||
| 482 | $value_is_set = 1; | ||||
| 483 | } | ||||
| 484 | } | ||||
| 485 | |||||
| 486 | 12 | 31µs | return unless $value_is_set; | ||
| 487 | |||||
| 488 | 11 | 132µs | 11 | 2.61ms | $val = $self->_coerce_and_verify( $val, $instance ); # spent 2.61ms making 11 calls to Moose::Meta::Attribute::_coerce_and_verify, avg 237µs/call |
| 489 | |||||
| 490 | 11 | 147µs | 11 | 2.16ms | $self->set_initial_value($instance, $val); # spent 2.16ms making 11 calls to Class::MOP::Attribute::set_initial_value, avg 197µs/call |
| 491 | |||||
| 492 | 11 | 190µs | 4 | 451µs | if ( ref $val && $self->is_weak_ref ) { # spent 421µs making 2 calls to Moose::Meta::Attribute::_weaken_value, avg 211µs/call
# spent 30µs making 2 calls to Moose::Meta::Mixin::AttributeCore::is_weak_ref, avg 15µs/call |
| 493 | $self->_weaken_value($instance); | ||||
| 494 | } | ||||
| 495 | } | ||||
| 496 | |||||
| 497 | sub _call_builder { | ||||
| 498 | my ( $self, $instance ) = @_; | ||||
| 499 | |||||
| 500 | my $builder = $self->builder(); | ||||
| 501 | |||||
| 502 | return $instance->$builder() | ||||
| 503 | if $instance->can( $self->builder ); | ||||
| 504 | |||||
| 505 | $self->throw_error( blessed($instance) | ||||
| 506 | . " does not support builder method '" | ||||
| 507 | . $self->builder | ||||
| 508 | . "' for attribute '" | ||||
| 509 | . $self->name | ||||
| 510 | . "'", | ||||
| 511 | object => $instance, | ||||
| 512 | ); | ||||
| 513 | } | ||||
| 514 | |||||
| 515 | ## Slot management | ||||
| 516 | |||||
| 517 | sub _make_initializer_writer_callback { | ||||
| 518 | my $self = shift; | ||||
| 519 | my ($meta_instance, $instance, $slot_name) = @_; | ||||
| 520 | my $old_callback = $self->SUPER::_make_initializer_writer_callback(@_); | ||||
| 521 | return sub { | ||||
| 522 | $old_callback->($self->_coerce_and_verify($_[0], $instance)); | ||||
| 523 | }; | ||||
| 524 | } | ||||
| 525 | |||||
| 526 | sub set_value { | ||||
| 527 | my ($self, $instance, @args) = @_; | ||||
| 528 | my $value = $args[0]; | ||||
| 529 | |||||
| 530 | my $attr_name = $self->name; | ||||
| 531 | |||||
| 532 | if ($self->is_required and not @args) { | ||||
| 533 | $self->throw_error("Attribute ($attr_name) is required", object => $instance); | ||||
| 534 | } | ||||
| 535 | |||||
| 536 | $value = $self->_coerce_and_verify( $value, $instance ); | ||||
| 537 | |||||
| 538 | my @old; | ||||
| 539 | if ( $self->has_trigger && $self->has_value($instance) ) { | ||||
| 540 | @old = $self->get_value($instance, 'for trigger'); | ||||
| 541 | } | ||||
| 542 | |||||
| 543 | $self->SUPER::set_value($instance, $value); | ||||
| 544 | |||||
| 545 | if ( ref $value && $self->is_weak_ref ) { | ||||
| 546 | $self->_weaken_value($instance); | ||||
| 547 | } | ||||
| 548 | |||||
| 549 | if ($self->has_trigger) { | ||||
| 550 | $self->trigger->($instance, $value, @old); | ||||
| 551 | } | ||||
| 552 | } | ||||
| 553 | |||||
| 554 | # spent 134ms (22.7+111) within Moose::Meta::Attribute::_inline_set_value which was called 195 times, avg 685µs/call:
# 105 times (11.1ms+42.9ms) by Moose::Meta::Class::_inline_init_attr_from_constructor at line 374 of Moose/Meta/Class.pm, avg 514µs/call
# 51 times (5.28ms+19.6ms) by Moose::Meta::Class::_inline_init_attr_from_default at line 399 of Moose/Meta/Class.pm, avg 488µs/call
# 26 times (4.24ms+37.3ms) by Class::MOP::Method::Accessor::__ANON__[/home/doy/coding/src/Class-MOP/blib/lib//Class/MOP/Method/Accessor.pm:118] at line 110 of Class/MOP/Method/Accessor.pm, avg 1.60ms/call
# 11 times (1.70ms+7.22ms) by Class::MOP::Method::Accessor::__ANON__[/home/doy/coding/src/Class-MOP/blib/lib//Class/MOP/Method/Accessor.pm:182] at line 177 of Class/MOP/Method/Accessor.pm, avg 811µs/call
# 2 times (337µs+3.96ms) by Class::MOP::Class::_inline_init_attr_from_constructor at line 684 of Class/MOP/Class.pm, avg 2.15ms/call | ||||
| 555 | 195 | 560µs | my $self = shift; | ||
| 556 | 195 | 926µs | my ($instance, $value, $tc, $tc_obj, $for_constructor) = @_; | ||
| 557 | |||||
| 558 | 195 | 448µs | my $old = '@old'; | ||
| 559 | 195 | 414µs | my $copy = '$val'; | ||
| 560 | 195 | 406µs | $tc ||= '$type_constraint'; | ||
| 561 | 195 | 370µs | $tc_obj ||= '$type_constraint_obj'; | ||
| 562 | |||||
| 563 | 195 | 373µs | my @code; | ||
| 564 | 195 | 1.98ms | 195 | 7.49ms | if ($self->_writer_value_needs_copy) { # spent 7.49ms making 195 calls to Moose::Meta::Attribute::_writer_value_needs_copy, avg 38µs/call |
| 565 | 3 | 37µs | 3 | 61µs | push @code, $self->_inline_copy_value($value, $copy); # spent 61µs making 3 calls to Moose::Meta::Attribute::_inline_copy_value, avg 20µs/call |
| 566 | 3 | 9µs | $value = $copy; | ||
| 567 | } | ||||
| 568 | |||||
| 569 | # constructors already handle required checks | ||||
| 570 | 195 | 804µs | 39 | 2.06ms | push @code, $self->_inline_check_required # spent 2.06ms making 39 calls to Moose::Meta::Attribute::_inline_check_required, avg 53µs/call |
| 571 | unless $for_constructor; | ||||
| 572 | |||||
| 573 | 195 | 2.93ms | 195 | 33.8ms | push @code, $self->_inline_tc_code($value, $tc, $tc_obj); # spent 33.8ms making 195 calls to Moose::Meta::Attribute::_inline_tc_code, avg 173µs/call |
| 574 | |||||
| 575 | # constructors do triggers all at once at the end | ||||
| 576 | 195 | 796µs | 39 | 2.08ms | push @code, $self->_inline_get_old_value_for_trigger($instance, $old) # spent 2.08ms making 39 calls to Moose::Meta::Attribute::_inline_get_old_value_for_trigger, avg 53µs/call |
| 577 | unless $for_constructor; | ||||
| 578 | |||||
| 579 | 195 | 7.17ms | 390 | 63.6ms | push @code, ( # spent 53.9ms making 195 calls to Class::MOP::Attribute::_inline_set_value, avg 276µs/call
# spent 9.70ms making 195 calls to Moose::Meta::Attribute::_inline_weaken_value, avg 50µs/call |
| 580 | $self->SUPER::_inline_set_value($instance, $value), | ||||
| 581 | $self->_inline_weaken_value($instance, $value), | ||||
| 582 | ); | ||||
| 583 | |||||
| 584 | # constructors do triggers all at once at the end | ||||
| 585 | 195 | 793µs | 39 | 1.89ms | push @code, $self->_inline_trigger($instance, $value, $old) # spent 1.89ms making 39 calls to Moose::Meta::Attribute::_inline_trigger, avg 49µs/call |
| 586 | unless $for_constructor; | ||||
| 587 | |||||
| 588 | 195 | 3.56ms | return @code; | ||
| 589 | } | ||||
| 590 | |||||
| 591 | # spent 7.62ms (4.80+2.82) within Moose::Meta::Attribute::_writer_value_needs_copy which was called 199 times, avg 38µs/call:
# 195 times (4.71ms+2.78ms) by Moose::Meta::Attribute::_inline_set_value at line 564, avg 38µs/call
# 4 times (94µs+42µs) by Moose::Meta::Method::Accessor::_writer_value_needs_copy at line 93 of Moose/Meta/Method/Accessor.pm, avg 34µs/call | ||||
| 592 | 199 | 526µs | my $self = shift; | ||
| 593 | 199 | 3.95ms | 199 | 2.82ms | return $self->should_coerce; # spent 2.82ms making 199 calls to Moose::Meta::Mixin::AttributeCore::should_coerce, avg 14µs/call |
| 594 | } | ||||
| 595 | |||||
| 596 | # spent 61µs within Moose::Meta::Attribute::_inline_copy_value which was called 3 times, avg 20µs/call:
# 3 times (61µs+0s) by Moose::Meta::Attribute::_inline_set_value at line 565, avg 20µs/call | ||||
| 597 | 3 | 8µs | my $self = shift; | ||
| 598 | 3 | 14µs | my ($value, $copy) = @_; | ||
| 599 | |||||
| 600 | 3 | 83µs | return 'my ' . $copy . ' = ' . $value . ';' | ||
| 601 | } | ||||
| 602 | |||||
| 603 | # spent 2.06ms (1.13+922µs) within Moose::Meta::Attribute::_inline_check_required which was called 39 times, avg 53µs/call:
# 39 times (1.13ms+922µs) by Moose::Meta::Attribute::_inline_set_value at line 570, avg 53µs/call | ||||
| 604 | 39 | 122µs | my $self = shift; | ||
| 605 | |||||
| 606 | 39 | 809µs | 39 | 870µs | return unless $self->is_required; # spent 870µs making 39 calls to Moose::Meta::Mixin::AttributeCore::is_required, avg 22µs/call |
| 607 | |||||
| 608 | 2 | 47µs | 2 | 12µs | my $attr_name = quotemeta($self->name); # spent 12µs making 2 calls to Class::MOP::Mixin::AttributeCore::name, avg 6µs/call |
| 609 | |||||
| 610 | return ( | ||||
| 611 | 2 | 62µs | 2 | 40µs | 'if (@_ < 2) {', # spent 40µs making 2 calls to Moose::Meta::Attribute::_inline_throw_error, avg 20µs/call |
| 612 | $self->_inline_throw_error( | ||||
| 613 | '"Attribute (' . $attr_name . ') is required, so cannot ' | ||||
| 614 | . 'be set to undef"' # defined $_[1] is not good enough | ||||
| 615 | ) . ';', | ||||
| 616 | '}', | ||||
| 617 | ); | ||||
| 618 | } | ||||
| 619 | |||||
| 620 | # spent 33.8ms (6.73+27.1) within Moose::Meta::Attribute::_inline_tc_code which was called 195 times, avg 173µs/call:
# 195 times (6.73ms+27.1ms) by Moose::Meta::Attribute::_inline_set_value at line 573, avg 173µs/call | ||||
| 621 | 195 | 669µs | my $self = shift; | ||
| 622 | return ( | ||||
| 623 | 195 | 5.33ms | 390 | 27.1ms | $self->_inline_check_coercion(@_), # spent 19.3ms making 195 calls to Moose::Meta::Attribute::_inline_check_constraint, avg 99µs/call
# spent 7.72ms making 195 calls to Moose::Meta::Attribute::_inline_check_coercion, avg 40µs/call |
| 624 | $self->_inline_check_constraint(@_), | ||||
| 625 | ); | ||||
| 626 | } | ||||
| 627 | |||||
| 628 | # spent 8.50ms (5.91+2.59) within Moose::Meta::Attribute::_inline_check_coercion which was called 210 times, avg 40µs/call:
# 195 times (5.35ms+2.37ms) by Moose::Meta::Attribute::_inline_tc_code at line 623, avg 40µs/call
# 15 times (560µs+223µs) by Moose::Meta::Attribute::_inline_init_from_default at line 787, avg 52µs/call | ||||
| 629 | 210 | 572µs | my $self = shift; | ||
| 630 | 210 | 839µs | my ($value, $tc, $tc_obj) = @_; | ||
| 631 | |||||
| 632 | 210 | 3.95ms | 218 | 2.59ms | return unless $self->should_coerce && $self->type_constraint->has_coercion; # spent 2.49ms making 210 calls to Moose::Meta::Mixin::AttributeCore::should_coerce, avg 12µs/call
# spent 53µs making 4 calls to Moose::Meta::TypeConstraint::has_coercion, avg 13µs/call
# spent 50µs making 4 calls to Moose::Meta::Mixin::AttributeCore::type_constraint, avg 13µs/call |
| 633 | |||||
| 634 | 4 | 94µs | return $value . ' = ' . $tc_obj . '->coerce(' . $value . ');'; | ||
| 635 | } | ||||
| 636 | |||||
| 637 | # spent 20.9ms (13.3+7.57) within Moose::Meta::Attribute::_inline_check_constraint which was called 210 times, avg 100µs/call:
# 195 times (12.3ms+7.06ms) by Moose::Meta::Attribute::_inline_tc_code at line 623, avg 99µs/call
# 15 times (1.05ms+513µs) by Moose::Meta::Attribute::_inline_init_from_default at line 787, avg 104µs/call | ||||
| 638 | 210 | 592µs | my $self = shift; | ||
| 639 | 210 | 781µs | my ($value, $tc, $tc_obj) = @_; | ||
| 640 | |||||
| 641 | 210 | 2.43ms | 210 | 2.64ms | return unless $self->has_type_constraint; # spent 2.64ms making 210 calls to Moose::Meta::Mixin::AttributeCore::has_type_constraint, avg 13µs/call |
| 642 | |||||
| 643 | 190 | 3.74ms | 190 | 1.11ms | my $attr_name = quotemeta($self->name); # spent 1.11ms making 190 calls to Class::MOP::Mixin::AttributeCore::name, avg 6µs/call |
| 644 | |||||
| 645 | return ( | ||||
| 646 | 190 | 6.07ms | 190 | 3.83ms | 'if (!' . $tc . '->(' . $value . ')) {', # spent 3.83ms making 190 calls to Moose::Meta::Attribute::_inline_throw_error, avg 20µs/call |
| 647 | $self->_inline_throw_error( | ||||
| 648 | '"Attribute (' . $attr_name . ') does not pass the type ' | ||||
| 649 | . 'constraint because: " . ' | ||||
| 650 | . $tc_obj . '->get_message(' . $value . ')', | ||||
| 651 | 'data => ' . $value | ||||
| 652 | ) . ';', | ||||
| 653 | '}', | ||||
| 654 | ); | ||||
| 655 | } | ||||
| 656 | |||||
| 657 | # spent 2.08ms (1.19+890µs) within Moose::Meta::Attribute::_inline_get_old_value_for_trigger which was called 39 times, avg 53µs/call:
# 39 times (1.19ms+890µs) by Moose::Meta::Attribute::_inline_set_value at line 576, avg 53µs/call | ||||
| 658 | 39 | 121µs | my $self = shift; | ||
| 659 | 39 | 152µs | my ($instance, $old) = @_; | ||
| 660 | |||||
| 661 | 39 | 904µs | 39 | 890µs | return unless $self->has_trigger; # spent 890µs making 39 calls to Moose::Meta::Mixin::AttributeCore::has_trigger, avg 23µs/call |
| 662 | |||||
| 663 | return ( | ||||
| 664 | 'my ' . $old . ' = ' . $self->_inline_instance_has($instance), | ||||
| 665 | '? ' . $self->_inline_instance_get($instance), | ||||
| 666 | ': ();', | ||||
| 667 | ); | ||||
| 668 | } | ||||
| 669 | |||||
| 670 | # spent 9.70ms (6.07+3.63) within Moose::Meta::Attribute::_inline_weaken_value which was called 195 times, avg 50µs/call:
# 195 times (6.07ms+3.63ms) by Moose::Meta::Attribute::_inline_set_value at line 579, avg 50µs/call | ||||
| 671 | 195 | 575µs | my $self = shift; | ||
| 672 | 195 | 715µs | my ($instance, $value) = @_; | ||
| 673 | |||||
| 674 | 195 | 3.71ms | 195 | 2.87ms | return unless $self->is_weak_ref; # spent 2.87ms making 195 calls to Moose::Meta::Mixin::AttributeCore::is_weak_ref, avg 15µs/call |
| 675 | |||||
| 676 | 10 | 261µs | 20 | 213µs | my $mi = $self->associated_class->get_meta_instance; # spent 107µs making 9 calls to Class::MOP::Class::get_meta_instance, avg 12µs/call
# spent 60µs making 10 calls to Class::MOP::Attribute::associated_class, avg 6µs/call
# spent 46µs making 1 call to Class::MOP::Class::Immutable::Class::MOP::Class::get_meta_instance |
| 677 | return ( | ||||
| 678 | 10 | 431µs | 20 | 546µs | $mi->inline_weaken_slot_value($instance, $self->name, $value), # spent 495µs making 10 calls to Class::MOP::Instance::inline_weaken_slot_value, avg 49µs/call
# spent 52µs making 10 calls to Class::MOP::Mixin::AttributeCore::name, avg 5µs/call |
| 679 | 'if ref ' . $value . ';', | ||||
| 680 | ); | ||||
| 681 | } | ||||
| 682 | |||||
| 683 | # spent 1.97ms (1.19+783µs) within Moose::Meta::Attribute::_inline_trigger which was called 41 times, avg 48µs/call:
# 39 times (1.13ms+762µs) by Moose::Meta::Attribute::_inline_set_value at line 585, avg 49µs/call
# 2 times (59µs+22µs) by Moose::Meta::Method::Accessor::_inline_trigger at line 117 of Moose/Meta/Method/Accessor.pm, avg 40µs/call | ||||
| 684 | 41 | 127µs | my $self = shift; | ||
| 685 | 41 | 170µs | my ($instance, $value, $old) = @_; | ||
| 686 | |||||
| 687 | 41 | 915µs | 41 | 783µs | return unless $self->has_trigger; # spent 783µs making 41 calls to Moose::Meta::Mixin::AttributeCore::has_trigger, avg 19µs/call |
| 688 | |||||
| 689 | return '$attr->trigger->(' . $instance . ', ' . $value . ', ' . $old . ');'; | ||||
| 690 | } | ||||
| 691 | |||||
| 692 | # spent 421µs (150+271) within Moose::Meta::Attribute::_weaken_value which was called 2 times, avg 211µs/call:
# 2 times (150µs+271µs) by Moose::Meta::Attribute::initialize_instance_slot at line 492, avg 211µs/call | ||||
| 693 | 2 | 7µs | my ( $self, $instance ) = @_; | ||
| 694 | |||||
| 695 | 2 | 76µs | 6 | 187µs | my $meta_instance = Class::MOP::Class->initialize( blessed($instance) ) # spent 96µs making 2 calls to Class::MOP::Class::Immutable::Class::MOP::Class::get_meta_instance, avg 48µs/call
# spent 76µs making 2 calls to Class::MOP::Class::initialize, avg 38µs/call
# spent 15µs making 2 calls to Scalar::Util::blessed, avg 8µs/call |
| 696 | ->get_meta_instance; | ||||
| 697 | |||||
| 698 | 2 | 78µs | 4 | 85µs | $meta_instance->weaken_slot_value( $instance, $self->name ); # spent 74µs making 2 calls to Class::MOP::Instance::weaken_slot_value, avg 37µs/call
# spent 11µs making 2 calls to Class::MOP::Mixin::AttributeCore::name, avg 5µs/call |
| 699 | } | ||||
| 700 | |||||
| 701 | sub get_value { | ||||
| 702 | my ($self, $instance, $for_trigger) = @_; | ||||
| 703 | |||||
| 704 | if ($self->is_lazy) { | ||||
| 705 | unless ($self->has_value($instance)) { | ||||
| 706 | my $value; | ||||
| 707 | if ($self->has_default) { | ||||
| 708 | $value = $self->default($instance); | ||||
| 709 | } elsif ( $self->has_builder ) { | ||||
| 710 | $value = $self->_call_builder($instance); | ||||
| 711 | } | ||||
| 712 | |||||
| 713 | $value = $self->_coerce_and_verify( $value, $instance ); | ||||
| 714 | |||||
| 715 | $self->set_initial_value($instance, $value); | ||||
| 716 | } | ||||
| 717 | } | ||||
| 718 | |||||
| 719 | if ( $self->should_auto_deref && ! $for_trigger ) { | ||||
| 720 | |||||
| 721 | my $type_constraint = $self->type_constraint; | ||||
| 722 | |||||
| 723 | if ($type_constraint->is_a_type_of('ArrayRef')) { | ||||
| 724 | my $rv = $self->SUPER::get_value($instance); | ||||
| 725 | return unless defined $rv; | ||||
| 726 | return wantarray ? @{ $rv } : $rv; | ||||
| 727 | } | ||||
| 728 | elsif ($type_constraint->is_a_type_of('HashRef')) { | ||||
| 729 | my $rv = $self->SUPER::get_value($instance); | ||||
| 730 | return unless defined $rv; | ||||
| 731 | return wantarray ? %{ $rv } : $rv; | ||||
| 732 | } | ||||
| 733 | else { | ||||
| 734 | $self->throw_error("Can not auto de-reference the type constraint '" . $type_constraint->name . "'", object => $instance, type_constraint => $type_constraint); | ||||
| 735 | } | ||||
| 736 | |||||
| 737 | } | ||||
| 738 | else { | ||||
| 739 | |||||
| 740 | return $self->SUPER::get_value($instance); | ||||
| 741 | } | ||||
| 742 | } | ||||
| 743 | |||||
| 744 | # spent 131ms (7.72+123) within Moose::Meta::Attribute::_inline_get_value which was called 123 times, avg 1.06ms/call:
# 97 times (6.08ms+116ms) by Class::MOP::Method::Accessor::__ANON__[/home/doy/coding/src/Class-MOP/blib/lib//Class/MOP/Method/Accessor.pm:152] at line 140 of Class/MOP/Method/Accessor.pm, avg 1.26ms/call
# 26 times (1.64ms+7.06ms) by Class::MOP::Method::Accessor::__ANON__[/home/doy/coding/src/Class-MOP/blib/lib//Class/MOP/Method/Accessor.pm:118] at line 110 of Class/MOP/Method/Accessor.pm, avg 335µs/call | ||||
| 745 | 123 | 399µs | my $self = shift; | ||
| 746 | 123 | 472µs | my ($instance, $tc, $tc_obj) = @_; | ||
| 747 | |||||
| 748 | 123 | 1.66ms | 123 | 93.2ms | my $slot_access = $self->_inline_instance_get($instance); # spent 93.2ms making 123 calls to Class::MOP::Attribute::_inline_instance_get, avg 758µs/call |
| 749 | 123 | 366µs | $tc ||= '$type_constraint'; | ||
| 750 | 123 | 278µs | $tc_obj ||= '$type_constraint_obj'; | ||
| 751 | |||||
| 752 | return ( | ||||
| 753 | 123 | 4.29ms | 246 | 29.7ms | $self->_inline_check_lazy($instance, $tc, $tc_obj), # spent 20.6ms making 123 calls to Moose::Meta::Attribute::_inline_check_lazy, avg 168µs/call
# spent 9.06ms making 123 calls to Moose::Meta::Attribute::_inline_return_auto_deref, avg 74µs/call |
| 754 | $self->_inline_return_auto_deref($slot_access), | ||||
| 755 | ); | ||||
| 756 | } | ||||
| 757 | |||||
| 758 | # spent 20.9ms (4.93+15.9) within Moose::Meta::Attribute::_inline_check_lazy which was called 128 times, avg 163µs/call:
# 123 times (4.75ms+15.9ms) by Moose::Meta::Attribute::_inline_get_value at line 753, avg 168µs/call
# 5 times (175µs+74µs) by Moose::Meta::Method::Accessor::_inline_check_lazy at line 105 of Moose/Meta/Method/Accessor.pm, avg 50µs/call | ||||
| 759 | 128 | 396µs | my $self = shift; | ||
| 760 | 128 | 632µs | my ($instance, $tc, $tc_obj) = @_; | ||
| 761 | |||||
| 762 | 128 | 2.61ms | 128 | 2.37ms | return unless $self->is_lazy; # spent 2.37ms making 128 calls to Moose::Meta::Mixin::AttributeCore::is_lazy, avg 18µs/call |
| 763 | |||||
| 764 | 19 | 266µs | 19 | 2.54ms | my $slot_exists = $self->_inline_instance_has($instance); # spent 2.54ms making 19 calls to Class::MOP::Attribute::_inline_instance_has, avg 134µs/call |
| 765 | |||||
| 766 | return ( | ||||
| 767 | 19 | 535µs | 19 | 11.0ms | 'if (!' . $slot_exists . ') {', # spent 11.0ms making 19 calls to Moose::Meta::Attribute::_inline_init_from_default, avg 580µs/call |
| 768 | $self->_inline_init_from_default($instance, '$default', $tc, $tc_obj, 'lazy'), | ||||
| 769 | '}', | ||||
| 770 | ); | ||||
| 771 | } | ||||
| 772 | |||||
| 773 | # spent 11.0ms (2.19+8.83) within Moose::Meta::Attribute::_inline_init_from_default which was called 19 times, avg 580µs/call:
# 19 times (2.19ms+8.83ms) by Moose::Meta::Attribute::_inline_check_lazy at line 767, avg 580µs/call | ||||
| 774 | 19 | 57µs | my $self = shift; | ||
| 775 | 19 | 110µs | my ($instance, $default, $tc, $tc_obj, $for_lazy) = @_; | ||
| 776 | |||||
| 777 | 19 | 503µs | 38 | 452µs | if (!($self->has_default || $self->has_builder)) { # spent 238µs making 19 calls to Class::MOP::Mixin::AttributeCore::has_builder, avg 13µs/call
# spent 214µs making 19 calls to Class::MOP::Mixin::AttributeCore::has_default, avg 11µs/call |
| 778 | $self->throw_error( | ||||
| 779 | 'You cannot have a lazy attribute ' | ||||
| 780 | . '(' . $self->name . ') ' | ||||
| 781 | . 'without specifying a default value for it', | ||||
| 782 | attr => $self, | ||||
| 783 | ); | ||||
| 784 | } | ||||
| 785 | |||||
| 786 | return ( | ||||
| 787 | 19 | 1.16ms | 87 | 8.38ms | $self->_inline_generate_default($instance, $default), # spent 3.72ms making 19 calls to Moose::Meta::Attribute::_inline_init_slot, avg 196µs/call
# spent 2.07ms making 19 calls to Moose::Meta::Attribute::_inline_generate_default, avg 109µs/call
# spent 1.56ms making 15 calls to Moose::Meta::Attribute::_inline_check_constraint, avg 104µs/call
# spent 783µs making 15 calls to Moose::Meta::Attribute::_inline_check_coercion, avg 52µs/call
# spent 241µs making 19 calls to Moose::Meta::Mixin::AttributeCore::has_type_constraint, avg 13µs/call |
| 788 | # intentionally not using _inline_tc_code, since that can be overridden | ||||
| 789 | # to do things like possibly only do member tc checks, which isn't | ||||
| 790 | # appropriate for checking the result of a default | ||||
| 791 | $self->has_type_constraint | ||||
| 792 | ? ($self->_inline_check_coercion($default, $tc, $tc_obj, $for_lazy), | ||||
| 793 | $self->_inline_check_constraint($default, $tc, $tc_obj, $for_lazy)) | ||||
| 794 | : (), | ||||
| 795 | $self->_inline_init_slot($instance, $default), | ||||
| 796 | ); | ||||
| 797 | } | ||||
| 798 | |||||
| 799 | # spent 2.07ms (1.34+730µs) within Moose::Meta::Attribute::_inline_generate_default which was called 19 times, avg 109µs/call:
# 19 times (1.34ms+730µs) by Moose::Meta::Attribute::_inline_init_from_default at line 787, avg 109µs/call | ||||
| 800 | 19 | 58µs | my $self = shift; | ||
| 801 | 19 | 78µs | my ($instance, $default) = @_; | ||
| 802 | |||||
| 803 | 19 | 1.05ms | 57 | 730µs | if ($self->has_default) { # spent 389µs making 19 calls to Moose::Meta::Attribute::_inline_throw_error, avg 20µs/call
# spent 180µs making 19 calls to Class::MOP::Mixin::AttributeCore::has_builder, avg 9µs/call
# spent 162µs making 19 calls to Class::MOP::Mixin::AttributeCore::has_default, avg 9µs/call |
| 804 | return 'my ' . $default . ' = $attr->default(' . $instance . ');'; | ||||
| 805 | } | ||||
| 806 | elsif ($self->has_builder) { | ||||
| 807 | return ( | ||||
| 808 | 'my ' . $default . ';', | ||||
| 809 | 'if (my $builder = ' . $instance . '->can($attr->builder)) {', | ||||
| 810 | $default . ' = ' . $instance . '->$builder;', | ||||
| 811 | '}', | ||||
| 812 | 'else {', | ||||
| 813 | 'my $class = ref(' . $instance . ') || ' . $instance . ';', | ||||
| 814 | 'my $builder_name = $attr->builder;', | ||||
| 815 | 'my $attr_name = $attr->name;', | ||||
| 816 | $self->_inline_throw_error( | ||||
| 817 | '"$class does not support builder method ' | ||||
| 818 | . '\'$builder_name\' for attribute \'$attr_name\'"' | ||||
| 819 | ) . ';', | ||||
| 820 | '}', | ||||
| 821 | ); | ||||
| 822 | } | ||||
| 823 | else { | ||||
| 824 | $self->throw_error( | ||||
| 825 | "Can't generate a default for " . $self->name | ||||
| 826 | . " since no default or builder was specified" | ||||
| 827 | ); | ||||
| 828 | } | ||||
| 829 | } | ||||
| 830 | |||||
| 831 | # spent 3.72ms (937µs+2.78) within Moose::Meta::Attribute::_inline_init_slot which was called 19 times, avg 196µs/call:
# 19 times (937µs+2.78ms) by Moose::Meta::Attribute::_inline_init_from_default at line 787, avg 196µs/call | ||||
| 832 | 19 | 60µs | my $self = shift; | ||
| 833 | 19 | 74µs | my ($inv, $value) = @_; | ||
| 834 | |||||
| 835 | 19 | 232µs | 19 | 207µs | if ($self->has_initializer) { # spent 207µs making 19 calls to Class::MOP::Mixin::AttributeCore::has_initializer, avg 11µs/call |
| 836 | return '$attr->set_initial_value(' . $inv . ', ' . $value . ');'; | ||||
| 837 | } | ||||
| 838 | else { | ||||
| 839 | 19 | 486µs | 19 | 2.58ms | return $self->_inline_instance_set($inv, $value) . ';'; # spent 2.58ms making 19 calls to Class::MOP::Attribute::_inline_instance_set, avg 136µs/call |
| 840 | } | ||||
| 841 | } | ||||
| 842 | |||||
| 843 | # spent 9.06ms (3.51+5.54) within Moose::Meta::Attribute::_inline_return_auto_deref which was called 123 times, avg 74µs/call:
# 123 times (3.51ms+5.54ms) by Moose::Meta::Attribute::_inline_get_value at line 753, avg 74µs/call | ||||
| 844 | 123 | 414µs | my $self = shift; | ||
| 845 | |||||
| 846 | 123 | 2.76ms | 123 | 5.54ms | return 'return ' . $self->_auto_deref(@_) . ';'; # spent 5.54ms making 123 calls to Moose::Meta::Attribute::_auto_deref, avg 45µs/call |
| 847 | } | ||||
| 848 | |||||
| 849 | # spent 5.54ms (3.62+1.92) within Moose::Meta::Attribute::_auto_deref which was called 123 times, avg 45µs/call:
# 123 times (3.62ms+1.92ms) by Moose::Meta::Attribute::_inline_return_auto_deref at line 846, avg 45µs/call | ||||
| 850 | 123 | 348µs | my $self = shift; | ||
| 851 | 123 | 466µs | my ($ref_value) = @_; | ||
| 852 | |||||
| 853 | 123 | 2.85ms | 123 | 1.92ms | return $ref_value unless $self->should_auto_deref; # spent 1.92ms making 123 calls to Moose::Meta::Mixin::AttributeCore::should_auto_deref, avg 16µs/call |
| 854 | |||||
| 855 | my $type_constraint = $self->type_constraint; | ||||
| 856 | |||||
| 857 | my $sigil; | ||||
| 858 | if ($type_constraint->is_a_type_of('ArrayRef')) { | ||||
| 859 | $sigil = '@'; | ||||
| 860 | } | ||||
| 861 | elsif ($type_constraint->is_a_type_of('HashRef')) { | ||||
| 862 | $sigil = '%'; | ||||
| 863 | } | ||||
| 864 | else { | ||||
| 865 | $self->throw_error( | ||||
| 866 | 'Can not auto de-reference the type constraint \'' | ||||
| 867 | . $type_constraint->name | ||||
| 868 | . '\'', | ||||
| 869 | type_constraint => $type_constraint, | ||||
| 870 | ); | ||||
| 871 | } | ||||
| 872 | |||||
| 873 | return 'wantarray ' | ||||
| 874 | . '? ' . $sigil . '{ (' . $ref_value . ') || return } ' | ||||
| 875 | . ': (' . $ref_value . ')'; | ||||
| 876 | } | ||||
| 877 | |||||
| 878 | ## installing accessors | ||||
| 879 | |||||
| 880 | 203 | 2.89ms | # spent 1.87ms within Moose::Meta::Attribute::accessor_metaclass which was called 203 times, avg 9µs/call:
# 193 times (1.76ms+0s) by Class::MOP::Attribute::__ANON__[/home/doy/coding/src/Class-MOP/blib/lib//Class/MOP/Attribute.pm:401] at line 393 of Class/MOP/Attribute.pm, avg 9µs/call
# 10 times (111µs+0s) by Moose::Meta::Attribute::Native::Trait::_native_accessor_class_for at line 173 of Moose/Meta/Attribute/Native/Trait.pm, avg 11µs/call | ||
| 881 | |||||
| 882 | # spent 1.04s (7.58ms+1.04) within Moose::Meta::Attribute::install_accessors which was called 125 times, avg 8.35ms/call:
# 122 times (7.31ms+985ms) by Class::MOP::Class::__ANON__[/home/doy/coding/src/Class-MOP/blib/lib//Class/MOP/Class.pm:932] at line 931 of Class/MOP/Class.pm, avg 8.13ms/call
# 2 times (212µs+44.5ms) by Class::MOP::Method::Wrapped::__ANON__[/home/doy/coding/src/Class-MOP/blib/lib//Class/MOP/Method/Wrapped.pm:43] at line 33 of Class/MOP/Method/Wrapped.pm, avg 22.4ms/call
# once (60µs+6.30ms) by Class::MOP::Class::_inline_accessors at line 1446 of Class/MOP/Class.pm | ||||
| 883 | 125 | 372µs | my $self = shift; | ||
| 884 | 125 | 3.21ms | 125 | 968ms | $self->SUPER::install_accessors(@_); # spent 968ms making 125 calls to Class::MOP::Attribute::install_accessors, avg 7.75ms/call |
| 885 | 125 | 2.00ms | 134 | 67.2ms | $self->install_delegation if $self->has_handles; # spent 65.1ms making 9 calls to Moose::Meta::Attribute::install_delegation, avg 7.23ms/call
# spent 2.09ms making 125 calls to Moose::Meta::Mixin::AttributeCore::has_handles, avg 17µs/call |
| 886 | 125 | 1.52ms | return; | ||
| 887 | } | ||||
| 888 | |||||
| 889 | # spent 3.66ms (2.86+799µs) within Moose::Meta::Attribute::_check_associated_methods which was called 123 times, avg 30µs/call:
# 123 times (2.86ms+799µs) by Moose::Meta::Class::add_attribute at line 491 of Moose/Meta/Class.pm, avg 30µs/call | ||||
| 890 | 123 | 403µs | my $self = shift; | ||
| 891 | 123 | 3.54ms | 123 | 799µs | unless ( # spent 799µs making 123 calls to Class::MOP::Attribute::associated_methods, avg 6µs/call |
| 892 | @{ $self->associated_methods } | ||||
| 893 | || ($self->_is_metadata || '') eq 'bare' | ||||
| 894 | ) { | ||||
| 895 | Carp::cluck( | ||||
| 896 | 'Attribute (' . $self->name . ') of class ' | ||||
| 897 | . $self->associated_class->name | ||||
| 898 | . ' has no associated methods' | ||||
| 899 | . ' (did you mean to provide an "is" argument?)' | ||||
| 900 | . "\n" | ||||
| 901 | ) | ||||
| 902 | } | ||||
| 903 | } | ||||
| 904 | |||||
| 905 | # spent 848ms (24.5+824) within Moose::Meta::Attribute::_process_accessors which was called 193 times, avg 4.39ms/call:
# 97 times (12.2ms+448ms) by Class::MOP::Attribute::install_accessors at line 419 of Class/MOP/Attribute.pm, avg 4.75ms/call
# 30 times (3.94ms+99.6ms) by Class::MOP::Attribute::install_accessors at line 427 of Class/MOP/Attribute.pm, avg 3.45ms/call
# 29 times (3.87ms+95.5ms) by Class::MOP::Attribute::install_accessors at line 431 of Class/MOP/Attribute.pm, avg 3.43ms/call
# 26 times (3.20ms+137ms) by Class::MOP::Attribute::install_accessors at line 415 of Class/MOP/Attribute.pm, avg 5.41ms/call
# 11 times (1.36ms+43.0ms) by Class::MOP::Attribute::install_accessors at line 423 of Class/MOP/Attribute.pm, avg 4.03ms/call | ||||
| 906 | 193 | 587µs | my $self = shift; | ||
| 907 | 193 | 931µs | my ($type, $accessor, $generate_as_inline_methods) = @_; | ||
| 908 | |||||
| 909 | 193 | 638µs | $accessor = ( keys %$accessor )[0] if ( ref($accessor) || '' ) eq 'HASH'; | ||
| 910 | 193 | 5.48ms | 386 | 34.3ms | my $method = $self->associated_class->get_method($accessor); # spent 33.2ms making 193 calls to Class::MOP::Mixin::HasMethods::get_method, avg 172µs/call
# spent 1.06ms making 193 calls to Class::MOP::Attribute::associated_class, avg 5µs/call |
| 911 | |||||
| 912 | 193 | 489µs | 4 | 29µs | if ( $method # spent 11µs making 1 call to Class::MOP::Method::Accessor::associated_attribute
# spent 10µs making 2 calls to Class::MOP::Mixin::AttributeCore::name, avg 5µs/call
# spent 8µs making 1 call to UNIVERSAL::isa |
| 913 | && $method->isa('Class::MOP::Method::Accessor') | ||||
| 914 | && $method->associated_attribute->name ne $self->name ) { | ||||
| 915 | |||||
| 916 | my $other_attr_name = $method->associated_attribute->name; | ||||
| 917 | my $name = $self->name; | ||||
| 918 | |||||
| 919 | Carp::cluck( | ||||
| 920 | "You are overwriting an accessor ($accessor) for the $other_attr_name attribute" | ||||
| 921 | . " with a new accessor method for the $name attribute" ); | ||||
| 922 | } | ||||
| 923 | |||||
| 924 | 193 | 460µs | 1 | 6µs | if ( # spent 6µs making 1 call to UNIVERSAL::isa |
| 925 | $method | ||||
| 926 | && !$method->isa('Class::MOP::Method::Accessor') | ||||
| 927 | && ( !$self->definition_context | ||||
| 928 | || $method->package_name eq $self->definition_context->{package} ) | ||||
| 929 | ) { | ||||
| 930 | |||||
| 931 | Carp::cluck( | ||||
| 932 | "You are overwriting a locally defined method ($accessor) with " | ||||
| 933 | . "an accessor" ); | ||||
| 934 | } | ||||
| 935 | |||||
| 936 | 193 | 10.7ms | 770 | 41.2ms | if ( !$self->associated_class->has_method($accessor) # spent 26.2ms making 193 calls to Class::MOP::Mixin::HasMethods::has_method, avg 136µs/call
# spent 12.6ms making 192 calls to Class::MOP::Package::has_package_symbol, avg 65µs/call
# spent 2.40ms making 385 calls to Class::MOP::Attribute::associated_class, avg 6µs/call |
| 937 | && $self->associated_class->has_package_symbol( '&' . $accessor ) ) { | ||||
| 938 | |||||
| 939 | Carp::cluck( | ||||
| 940 | "You are overwriting a locally defined function ($accessor) with " | ||||
| 941 | . "an accessor" ); | ||||
| 942 | } | ||||
| 943 | |||||
| 944 | 193 | 7.27ms | 193 | 748ms | $self->SUPER::_process_accessors(@_); # spent 748ms making 193 calls to Class::MOP::Attribute::_process_accessors, avg 3.88ms/call |
| 945 | } | ||||
| 946 | |||||
| 947 | sub remove_accessors { | ||||
| 948 | my $self = shift; | ||||
| 949 | $self->SUPER::remove_accessors(@_); | ||||
| 950 | $self->remove_delegation if $self->has_handles; | ||||
| 951 | return; | ||||
| 952 | } | ||||
| 953 | |||||
| 954 | # spent 65.1ms (4.77+60.3) within Moose::Meta::Attribute::install_delegation which was called 9 times, avg 7.23ms/call:
# 9 times (4.77ms+60.3ms) by Moose::Meta::Attribute::install_accessors at line 885, avg 7.23ms/call | ||||
| 955 | 9 | 29µs | my $self = shift; | ||
| 956 | |||||
| 957 | # NOTE: | ||||
| 958 | # Here we canonicalize the 'handles' option | ||||
| 959 | # this will sort out any details and always | ||||
| 960 | # return an hash of methods which we want | ||||
| 961 | # to delagate to, see that method for details | ||||
| 962 | 9 | 181µs | 9 | 752µs | my %handles = $self->_canonicalize_handles; # spent 481µs making 7 calls to Moose::Meta::Attribute::_canonicalize_handles, avg 69µs/call
# spent 143µs making 1 call to Class::MOP::Class::__ANON__::SERIAL::5::_canonicalize_handles
# spent 128µs making 1 call to Class::MOP::Class::__ANON__::SERIAL::2::_canonicalize_handles |
| 963 | |||||
| 964 | |||||
| 965 | # install the delegation ... | ||||
| 966 | 9 | 195µs | 9 | 65µs | my $associated_class = $self->associated_class; # spent 65µs making 9 calls to Class::MOP::Attribute::associated_class, avg 7µs/call |
| 967 | 9 | 221µs | foreach my $handle (keys %handles) { | ||
| 968 | 28 | 119µs | my $method_to_call = $handles{$handle}; | ||
| 969 | 28 | 530µs | 28 | 146µs | my $class_name = $associated_class->name; # spent 146µs making 28 calls to Class::MOP::Package::name, avg 5µs/call |
| 970 | 28 | 123µs | my $name = "${class_name}::${handle}"; | ||
| 971 | |||||
| 972 | 28 | 325µs | 28 | 4.05ms | (!$associated_class->has_method($handle)) # spent 4.05ms making 28 calls to Class::MOP::Mixin::HasMethods::has_method, avg 145µs/call |
| 973 | || $self->throw_error("You cannot overwrite a locally defined method ($handle) with a delegation", method_name => $handle); | ||||
| 974 | |||||
| 975 | # NOTE: | ||||
| 976 | # handles is not allowed to delegate | ||||
| 977 | # any of these methods, as they will | ||||
| 978 | # override the ones in your class, which | ||||
| 979 | # is almost certainly not what you want. | ||||
| 980 | |||||
| 981 | # FIXME warn when $handle was explicitly specified, but not if the source is a regex or something | ||||
| 982 | #cluck("Not delegating method '$handle' because it is a core method") and | ||||
| 983 | 28 | 2.06ms | 84 | 1.02ms | next if $class_name->isa("Moose::Object") and $handle =~ /^BUILD|DEMOLISH$/ || Moose::Object->can($handle); # spent 475µs making 28 calls to UNIVERSAL::can, avg 17µs/call
# spent 290µs making 28 calls to Moose::Meta::Attribute::CORE:match, avg 10µs/call
# spent 253µs making 28 calls to UNIVERSAL::isa, avg 9µs/call |
| 984 | |||||
| 985 | 28 | 386µs | 28 | 42.1ms | my $method = $self->_make_delegation_method($handle, $method_to_call); # spent 19.2ms making 3 calls to Class::MOP::Class::__ANON__::SERIAL::5::_make_delegation_method, avg 6.39ms/call
# spent 12.5ms making 23 calls to Moose::Meta::Attribute::_make_delegation_method, avg 543µs/call
# spent 10.4ms making 2 calls to Class::MOP::Class::__ANON__::SERIAL::2::_make_delegation_method, avg 5.20ms/call |
| 986 | |||||
| 987 | 28 | 1.28ms | 84 | 11.8ms | $self->associated_class->add_method($method->name, $method); # spent 11.4ms making 28 calls to Class::MOP::Mixin::HasMethods::add_method, avg 409µs/call
# spent 189µs making 28 calls to Class::MOP::Attribute::associated_class, avg 7µs/call
# spent 126µs making 28 calls to Class::MOP::Method::name, avg 5µs/call |
| 988 | 28 | 528µs | 28 | 459µs | $self->associate_method($method); # spent 459µs making 28 calls to Class::MOP::Attribute::associate_method, avg 16µs/call |
| 989 | } | ||||
| 990 | } | ||||
| 991 | |||||
| 992 | sub remove_delegation { | ||||
| 993 | my $self = shift; | ||||
| 994 | my %handles = $self->_canonicalize_handles; | ||||
| 995 | my $associated_class = $self->associated_class; | ||||
| 996 | foreach my $handle (keys %handles) { | ||||
| 997 | next unless any { $handle eq $_ } | ||||
| 998 | map { $_->name } | ||||
| 999 | @{ $self->associated_methods }; | ||||
| 1000 | $self->associated_class->remove_method($handle); | ||||
| 1001 | } | ||||
| 1002 | } | ||||
| 1003 | |||||
| 1004 | # private methods to help delegation ... | ||||
| 1005 | |||||
| 1006 | # spent 481µs (390+91) within Moose::Meta::Attribute::_canonicalize_handles which was called 7 times, avg 69µs/call:
# 7 times (390µs+91µs) by Moose::Meta::Attribute::install_delegation at line 962, avg 69µs/call | ||||
| 1007 | 7 | 18µs | my $self = shift; | ||
| 1008 | 7 | 152µs | 7 | 91µs | my $handles = $self->handles; # spent 91µs making 7 calls to Moose::Meta::Mixin::AttributeCore::handles, avg 13µs/call |
| 1009 | 7 | 35µs | if (my $handle_type = ref($handles)) { | ||
| 1010 | 7 | 221µs | if ($handle_type eq 'HASH') { | ||
| 1011 | return %{$handles}; | ||||
| 1012 | } | ||||
| 1013 | elsif ($handle_type eq 'ARRAY') { | ||||
| 1014 | return map { $_ => $_ } @{$handles}; | ||||
| 1015 | } | ||||
| 1016 | elsif ($handle_type eq 'Regexp') { | ||||
| 1017 | ($self->has_type_constraint) | ||||
| 1018 | || $self->throw_error("Cannot delegate methods based on a Regexp without a type constraint (isa)", data => $handles); | ||||
| 1019 | return map { ($_ => $_) } | ||||
| 1020 | grep { /$handles/ } $self->_get_delegate_method_list; | ||||
| 1021 | } | ||||
| 1022 | elsif ($handle_type eq 'CODE') { | ||||
| 1023 | return $handles->($self, $self->_find_delegate_metaclass); | ||||
| 1024 | } | ||||
| 1025 | elsif (blessed($handles) && $handles->isa('Moose::Meta::TypeConstraint::DuckType')) { | ||||
| 1026 | return map { $_ => $_ } @{ $handles->methods }; | ||||
| 1027 | } | ||||
| 1028 | elsif (blessed($handles) && $handles->isa('Moose::Meta::TypeConstraint::Role')) { | ||||
| 1029 | $handles = $handles->role; | ||||
| 1030 | } | ||||
| 1031 | else { | ||||
| 1032 | $self->throw_error("Unable to canonicalize the 'handles' option with $handles", data => $handles); | ||||
| 1033 | } | ||||
| 1034 | } | ||||
| 1035 | |||||
| 1036 | Class::MOP::load_class($handles); | ||||
| 1037 | my $role_meta = Class::MOP::class_of($handles); | ||||
| 1038 | |||||
| 1039 | (blessed $role_meta && $role_meta->isa('Moose::Meta::Role')) | ||||
| 1040 | || $self->throw_error("Unable to canonicalize the 'handles' option with $handles because its metaclass is not a Moose::Meta::Role", data => $handles); | ||||
| 1041 | |||||
| 1042 | return map { $_ => $_ } | ||||
| 1043 | map { $_->name } | ||||
| 1044 | grep { !$_->isa('Class::MOP::Method::Meta') } ( | ||||
| 1045 | $role_meta->_get_local_methods, | ||||
| 1046 | $role_meta->get_required_method_list, | ||||
| 1047 | ); | ||||
| 1048 | } | ||||
| 1049 | |||||
| 1050 | sub _get_delegate_method_list { | ||||
| 1051 | my $self = shift; | ||||
| 1052 | my $meta = $self->_find_delegate_metaclass; | ||||
| 1053 | if ($meta->isa('Class::MOP::Class')) { | ||||
| 1054 | return map { $_->name } # NOTE: !never! delegate &meta | ||||
| 1055 | grep { $_->package_name ne 'Moose::Object' && !$_->isa('Class::MOP::Method::Meta') } | ||||
| 1056 | $meta->get_all_methods; | ||||
| 1057 | } | ||||
| 1058 | elsif ($meta->isa('Moose::Meta::Role')) { | ||||
| 1059 | return $meta->get_method_list; | ||||
| 1060 | } | ||||
| 1061 | else { | ||||
| 1062 | $self->throw_error("Unable to recognize the delegate metaclass '$meta'", data => $meta); | ||||
| 1063 | } | ||||
| 1064 | } | ||||
| 1065 | |||||
| 1066 | sub _find_delegate_metaclass { | ||||
| 1067 | my $self = shift; | ||||
| 1068 | if (my $class = $self->_isa_metadata) { | ||||
| 1069 | unless ( Class::MOP::is_class_loaded($class) ) { | ||||
| 1070 | $self->throw_error( | ||||
| 1071 | sprintf( | ||||
| 1072 | 'The %s attribute is trying to delegate to a class which has not been loaded - %s', | ||||
| 1073 | $self->name, $class | ||||
| 1074 | ) | ||||
| 1075 | ); | ||||
| 1076 | } | ||||
| 1077 | # we might be dealing with a non-Moose class, | ||||
| 1078 | # and need to make our own metaclass. if there's | ||||
| 1079 | # already a metaclass, it will be returned | ||||
| 1080 | return Class::MOP::Class->initialize($class); | ||||
| 1081 | } | ||||
| 1082 | elsif (my $role = $self->_does_metadata) { | ||||
| 1083 | unless ( Class::MOP::is_class_loaded($class) ) { | ||||
| 1084 | $self->throw_error( | ||||
| 1085 | sprintf( | ||||
| 1086 | 'The %s attribute is trying to delegate to a role which has not been loaded - %s', | ||||
| 1087 | $self->name, $role | ||||
| 1088 | ) | ||||
| 1089 | ); | ||||
| 1090 | } | ||||
| 1091 | |||||
| 1092 | return Class::MOP::class_of($role); | ||||
| 1093 | } | ||||
| 1094 | else { | ||||
| 1095 | $self->throw_error("Cannot find delegate metaclass for attribute " . $self->name); | ||||
| 1096 | } | ||||
| 1097 | } | ||||
| 1098 | |||||
| 1099 | 33 | 415µs | # spent 279µs within Moose::Meta::Attribute::delegation_metaclass which was called 33 times, avg 8µs/call:
# 23 times (190µs+0s) by Moose::Meta::Attribute::_make_delegation_method at line 1109, avg 8µs/call
# 10 times (89µs+0s) by Moose::Meta::Attribute::Native::Trait::_native_accessor_class_for at line 173 of Moose/Meta/Attribute/Native/Trait.pm, avg 9µs/call | ||
| 1100 | |||||
| 1101 | # spent 12.5ms (1.54+11.0) within Moose::Meta::Attribute::_make_delegation_method which was called 23 times, avg 543µs/call:
# 23 times (1.54ms+11.0ms) by Moose::Meta::Attribute::install_delegation at line 985, avg 543µs/call | ||||
| 1102 | 23 | 120µs | my ( $self, $handle_name, $method_to_call ) = @_; | ||
| 1103 | |||||
| 1104 | 23 | 52µs | my @curried_arguments; | ||
| 1105 | |||||
| 1106 | 23 | 63µs | ($method_to_call, @curried_arguments) = @$method_to_call | ||
| 1107 | if 'ARRAY' eq ref($method_to_call); | ||||
| 1108 | |||||
| 1109 | 23 | 1.44ms | 92 | 11.0ms | return $self->delegation_metaclass->new( # spent 10.5ms making 23 calls to Moose::Meta::Method::Delegation::new, avg 457µs/call
# spent 190µs making 23 calls to Moose::Meta::Attribute::delegation_metaclass, avg 8µs/call
# spent 143µs making 23 calls to Class::MOP::Attribute::associated_class, avg 6µs/call
# spent 106µs making 23 calls to Class::MOP::Package::name, avg 5µs/call |
| 1110 | name => $handle_name, | ||||
| 1111 | package_name => $self->associated_class->name, | ||||
| 1112 | attribute => $self, | ||||
| 1113 | delegate_to_method => $method_to_call, | ||||
| 1114 | curried_arguments => \@curried_arguments, | ||||
| 1115 | ); | ||||
| 1116 | } | ||||
| 1117 | |||||
| 1118 | # spent 2.61ms (641µs+1.97) within Moose::Meta::Attribute::_coerce_and_verify which was called 11 times, avg 237µs/call:
# 11 times (641µs+1.97ms) by Moose::Meta::Attribute::initialize_instance_slot at line 488, avg 237µs/call | ||||
| 1119 | 11 | 31µs | my $self = shift; | ||
| 1120 | 11 | 25µs | my $val = shift; | ||
| 1121 | 11 | 22µs | my $instance = shift; | ||
| 1122 | |||||
| 1123 | 11 | 164µs | 11 | 115µs | return $val unless $self->has_type_constraint; # spent 115µs making 11 calls to Moose::Meta::Mixin::AttributeCore::has_type_constraint, avg 10µs/call |
| 1124 | |||||
| 1125 | 9 | 98µs | 9 | 103µs | $val = $self->type_constraint->coerce($val) # spent 103µs making 9 calls to Moose::Meta::Mixin::AttributeCore::should_coerce, avg 11µs/call |
| 1126 | if $self->should_coerce && $self->type_constraint->has_coercion; | ||||
| 1127 | |||||
| 1128 | 9 | 108µs | 9 | 1.75ms | $self->verify_against_type_constraint($val, instance => $instance); # spent 1.75ms making 9 calls to Moose::Meta::Attribute::verify_against_type_constraint, avg 195µs/call |
| 1129 | |||||
| 1130 | 9 | 105µs | return $val; | ||
| 1131 | } | ||||
| 1132 | |||||
| 1133 | # spent 1.75ms (559µs+1.19) within Moose::Meta::Attribute::verify_against_type_constraint which was called 9 times, avg 195µs/call:
# 9 times (559µs+1.19ms) by Moose::Meta::Attribute::_coerce_and_verify at line 1128, avg 195µs/call | ||||
| 1134 | 9 | 26µs | my $self = shift; | ||
| 1135 | 9 | 20µs | my $val = shift; | ||
| 1136 | |||||
| 1137 | 9 | 88µs | 9 | 80µs | return 1 if !$self->has_type_constraint; # spent 80µs making 9 calls to Moose::Meta::Mixin::AttributeCore::has_type_constraint, avg 9µs/call |
| 1138 | |||||
| 1139 | 9 | 103µs | 9 | 110µs | my $type_constraint = $self->type_constraint; # spent 110µs making 9 calls to Moose::Meta::Mixin::AttributeCore::type_constraint, avg 12µs/call |
| 1140 | |||||
| 1141 | 9 | 197µs | 9 | 1.00ms | $type_constraint->check($val) # spent 1.00ms making 9 calls to Moose::Meta::TypeConstraint::check, avg 111µs/call |
| 1142 | || $self->throw_error("Attribute (" | ||||
| 1143 | . $self->name | ||||
| 1144 | . ") does not pass the type constraint because: " | ||||
| 1145 | . $type_constraint->get_message($val), data => $val, @_); | ||||
| 1146 | } | ||||
| 1147 | |||||
| 1148 | package Moose::Meta::Attribute::Custom::Moose; | ||||
| 1149 | sub register_implementation { 'Moose::Meta::Attribute' } | ||||
| 1150 | |||||
| 1151 | 1 | 30µs | 1; | ||
| 1152 | |||||
| 1153 | __END__ | ||||
sub Moose::Meta::Attribute::CORE:match; # opcode | |||||
# spent 558µs within Moose::Meta::Attribute::CORE:sort which was called 124 times, avg 4µs/call:
# 124 times (558µs+0s) by Moose::Meta::Attribute::new at line 73, avg 4µs/call |