Filename | /usr/local/lib/perl/5.18.2/Moose/Meta/Attribute.pm |
Statements | Executed 26679 statements in 73.2ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
196 | 1 | 1 | 22.2ms | 30.8ms | _eval_environment | Moose::Meta::Attribute::
110 | 3 | 2 | 14.1ms | 92.8ms | new | Moose::Meta::Attribute::
246 | 4 | 3 | 7.81ms | 41.4ms | _inline_set_value | Moose::Meta::Attribute::
146 | 3 | 1 | 7.66ms | 193ms | _process_accessors | Moose::Meta::Attribute::
35 | 1 | 1 | 6.90ms | 83.8ms | install_delegation | Moose::Meta::Attribute::
1 | 1 | 1 | 5.77ms | 77.6ms | BEGIN@16 | Moose::Meta::Attribute::
246 | 1 | 1 | 5.68ms | 22.8ms | _inline_tc_code | Moose::Meta::Attribute::
108 | 2 | 2 | 5.11ms | 143ms | interpolate_class_and_new (recurses: max depth 1, inclusive time 687µs) | Moose::Meta::Attribute::
288 | 2 | 1 | 4.32ms | 21.7ms | _inline_check_constraint | Moose::Meta::Attribute::
109 | 2 | 2 | 2.60ms | 13.2ms | _process_options | Moose::Meta::Attribute::
1 | 1 | 1 | 1.73ms | 2.28ms | BEGIN@6 | Moose::Meta::Attribute::
109 | 2 | 1 | 1.16ms | 46.6ms | interpolate_class (recurses: max depth 1, inclusive time 15µs) | Moose::Meta::Attribute::
111 | 1 | 1 | 1.09ms | 33.9ms | _inline_get_value | Moose::Meta::Attribute::
110 | 2 | 1 | 1.01ms | 7.98ms | _process_isa_option | Moose::Meta::Attribute::
161 | 2 | 2 | 974µs | 15.1ms | _inline_check_lazy | Moose::Meta::Attribute::
288 | 2 | 1 | 936µs | 1.41ms | _inline_weaken_value | Moose::Meta::Attribute::
42 | 1 | 1 | 878µs | 8.97ms | _inline_init_from_default | Moose::Meta::Attribute::
111 | 3 | 2 | 837µs | 291ms | install_accessors | Moose::Meta::Attribute::
288 | 2 | 1 | 804µs | 1.12ms | _inline_check_coercion | Moose::Meta::Attribute::
1 | 1 | 1 | 690µs | 975µs | BEGIN@13 | Moose::Meta::Attribute::
260 | 2 | 2 | 634µs | 951µs | _writer_value_needs_copy | Moose::Meta::Attribute::
294 | 2 | 1 | 594µs | 594µs | _inline_throw_exception | Moose::Meta::Attribute::
1 | 1 | 1 | 535µs | 752µs | BEGIN@14 | Moose::Meta::Attribute::
42 | 1 | 1 | 467µs | 673µs | _inline_generate_default | Moose::Meta::Attribute::
111 | 1 | 1 | 446µs | 1.10ms | _inline_return_auto_deref | Moose::Meta::Attribute::
111 | 1 | 1 | 425µs | 653µs | _auto_deref | Moose::Meta::Attribute::
109 | 1 | 1 | 404µs | 489µs | _check_associated_methods | Moose::Meta::Attribute::
109 | 1 | 1 | 398µs | 398µs | _process_is_option | Moose::Meta::Attribute::
32 | 1 | 1 | 373µs | 2.05ms | does | Moose::Meta::Attribute::
42 | 1 | 1 | 320µs | 1.26ms | _inline_init_slot | Moose::Meta::Attribute::
246 | 2 | 2 | 290µs | 290µs | accessor_metaclass | Moose::Meta::Attribute::
33 | 1 | 1 | 269µs | 439µs | initialize_instance_slot | Moose::Meta::Attribute::
110 | 2 | 1 | 264µs | 1.15ms | _process_does_option | Moose::Meta::Attribute::
109 | 1 | 1 | 211µs | 211µs | _process_required_option | Moose::Meta::Attribute::
109 | 1 | 1 | 191µs | 192µs | _process_coerce_option | Moose::Meta::Attribute::
109 | 1 | 1 | 188µs | 188µs | _process_trigger_option | Moose::Meta::Attribute::
109 | 1 | 1 | 187µs | 187µs | _process_lazy_option | Moose::Meta::Attribute::
56 | 1 | 1 | 165µs | 165µs | CORE:match (opcode) | Moose::Meta::Attribute::
110 | 2 | 1 | 157µs | 157µs | _process_lazy_build_option | Moose::Meta::Attribute::
109 | 1 | 1 | 155µs | 155µs | _process_auto_deref_option | Moose::Meta::Attribute::
1 | 1 | 1 | 137µs | 1.08ms | clone | Moose::Meta::Attribute::
106 | 2 | 2 | 123µs | 123µs | delegation_metaclass | Moose::Meta::Attribute::
145 | 2 | 1 | 69µs | 69µs | CORE:sort (opcode) | Moose::Meta::Attribute::
6 | 1 | 1 | 59µs | 507µs | _make_delegation_method | Moose::Meta::Attribute::
14 | 2 | 2 | 54µs | 109µs | _inline_trigger | Moose::Meta::Attribute::
1 | 1 | 1 | 52µs | 1.15ms | clone_and_inherit_options | Moose::Meta::Attribute::
7 | 1 | 1 | 43µs | 101µs | _inline_check_required | Moose::Meta::Attribute::
3 | 1 | 1 | 33µs | 40µs | _canonicalize_handles | Moose::Meta::Attribute::
7 | 1 | 1 | 28µs | 74µs | _inline_get_old_value_for_trigger | Moose::Meta::Attribute::
1 | 1 | 1 | 25µs | 69µs | BEGIN@8 | Moose::Meta::Attribute::
1 | 1 | 1 | 16µs | 37µs | _weaken_value | Moose::Meta::Attribute::
1 | 1 | 1 | 14µs | 212µs | remove_accessors | Moose::Meta::Attribute::
1 | 1 | 1 | 10µs | 46µs | BEGIN@21 | Moose::Meta::Attribute::
1 | 1 | 1 | 10µs | 44µs | BEGIN@7 | Moose::Meta::Attribute::
1 | 1 | 1 | 8µs | 17µs | BEGIN@1 | Moose::Meta::TypeCoercion::
1 | 1 | 1 | 8µs | 37µs | BEGIN@9 | Moose::Meta::Attribute::
1 | 1 | 1 | 7µs | 8.21ms | BEGIN@19 | Moose::Meta::Attribute::
1 | 1 | 1 | 7µs | 12µs | BEGIN@12 | Moose::Meta::Attribute::
1 | 1 | 1 | 6µs | 108µs | BEGIN@15 | Moose::Meta::Attribute::
1 | 1 | 1 | 6µs | 6µs | BEGIN@17 | Moose::Meta::Attribute::
1 | 1 | 1 | 5µs | 8µs | _coerce_and_verify | Moose::Meta::Attribute::
1 | 1 | 1 | 5µs | 8µs | BEGIN@2 | Moose::Meta::TypeCoercion::
1 | 1 | 1 | 4µs | 4µs | BEGIN@10 | Moose::Meta::Attribute::
1 | 1 | 1 | 3µs | 3µs | _inline_copy_value | Moose::Meta::Attribute::
1 | 1 | 1 | 3µs | 3µs | illegal_options_for_inheritance | Moose::Meta::Attribute::
0 | 0 | 0 | 0s | 0s | register_implementation | Moose::Meta::Attribute::Custom::Moose::
0 | 0 | 0 | 0s | 0s | __ANON__[:1115] | Moose::Meta::Attribute::
0 | 0 | 0 | 0s | 0s | __ANON__[:139] | Moose::Meta::Attribute::
0 | 0 | 0 | 0s | 0s | __ANON__[:312] | Moose::Meta::Attribute::
0 | 0 | 0 | 0s | 0s | __ANON__[:39] | Moose::Meta::Attribute::
0 | 0 | 0 | 0s | 0s | __ANON__[:542] | Moose::Meta::Attribute::
0 | 0 | 0 | 0s | 0s | _call_builder | Moose::Meta::Attribute::
0 | 0 | 0 | 0s | 0s | _find_delegate_metaclass | Moose::Meta::Attribute::
0 | 0 | 0 | 0s | 0s | _get_delegate_method_list | Moose::Meta::Attribute::
0 | 0 | 0 | 0s | 0s | _make_initializer_writer_callback | Moose::Meta::Attribute::
0 | 0 | 0 | 0s | 0s | get_value | Moose::Meta::Attribute::
0 | 0 | 0 | 0s | 0s | remove_delegation | Moose::Meta::Attribute::
0 | 0 | 0 | 0s | 0s | set_value | Moose::Meta::Attribute::
0 | 0 | 0 | 0s | 0s | verify_against_type_constraint | Moose::Meta::Attribute::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | 2 | 18µs | 2 | 26µs | # spent 17µs (8+9) within Moose::Meta::TypeCoercion::BEGIN@1 which was called:
# once (8µs+9µs) by Moose::Meta::TypeCoercion::BEGIN@8 at line 1 # spent 17µs making 1 call to Moose::Meta::TypeCoercion::BEGIN@1
# spent 9µs making 1 call to strict::import |
2 | 2 | 38µs | 2 | 11µs | # spent 8µs (5+3) within Moose::Meta::TypeCoercion::BEGIN@2 which was called:
# once (5µs+3µs) by Moose::Meta::TypeCoercion::BEGIN@8 at line 2 # spent 8µs making 1 call to Moose::Meta::TypeCoercion::BEGIN@2
# spent 3µs making 1 call to warnings::import |
3 | package Moose::Meta::Attribute; | ||||
4 | 1 | 800ns | our $VERSION = '2.1604'; | ||
5 | |||||
6 | 2 | 94µs | 1 | 2.28ms | # spent 2.28ms (1.73+553µs) within Moose::Meta::Attribute::BEGIN@6 which was called:
# once (1.73ms+553µs) by Moose::Meta::TypeCoercion::BEGIN@8 at line 6 # spent 2.28ms making 1 call to Moose::Meta::Attribute::BEGIN@6 |
7 | 2 | 42µs | 2 | 78µs | # spent 44µs (10+34) within Moose::Meta::Attribute::BEGIN@7 which was called:
# once (10µs+34µs) by Moose::Meta::TypeCoercion::BEGIN@8 at line 7 # spent 44µs making 1 call to Moose::Meta::Attribute::BEGIN@7
# spent 34µs making 1 call to Exporter::import |
8 | 3 | 44µs | 3 | 93µs | # spent 69µs (25+43) within Moose::Meta::Attribute::BEGIN@8 which was called:
# once (25µs+43µs) by Moose::Meta::TypeCoercion::BEGIN@8 at line 8 # spent 69µs making 1 call to Moose::Meta::Attribute::BEGIN@8
# spent 14µs making 1 call to UNIVERSAL::VERSION
# spent 11µs making 1 call to List::Util::import |
9 | 2 | 21µs | 2 | 67µs | # spent 37µs (8+30) within Moose::Meta::Attribute::BEGIN@9 which was called:
# once (8µs+30µs) by Moose::Meta::TypeCoercion::BEGIN@8 at line 9 # spent 37µs making 1 call to Moose::Meta::Attribute::BEGIN@9
# spent 30µs making 1 call to Exporter::import |
10 | 2 | 18µs | 1 | 4µs | # spent 4µs within Moose::Meta::Attribute::BEGIN@10 which was called:
# once (4µs+0s) by Moose::Meta::TypeCoercion::BEGIN@8 at line 10 # spent 4µs making 1 call to Moose::Meta::Attribute::BEGIN@10 |
11 | |||||
12 | 2 | 19µs | 2 | 18µs | # spent 12µs (7+6) within Moose::Meta::Attribute::BEGIN@12 which was called:
# once (7µs+6µs) by Moose::Meta::TypeCoercion::BEGIN@8 at line 12 # spent 12µs making 1 call to Moose::Meta::Attribute::BEGIN@12
# spent 6µs making 1 call to Package::DeprecationManager::__ANON__[Package/DeprecationManager.pm:61] |
13 | 2 | 95µs | 1 | 975µs | # spent 975µs (690+285) within Moose::Meta::Attribute::BEGIN@13 which was called:
# once (690µs+285µs) by Moose::Meta::TypeCoercion::BEGIN@8 at line 13 # spent 975µs making 1 call to Moose::Meta::Attribute::BEGIN@13 |
14 | 2 | 90µs | 1 | 752µs | # spent 752µs (535+216) within Moose::Meta::Attribute::BEGIN@14 which was called:
# once (535µs+216µs) by Moose::Meta::TypeCoercion::BEGIN@8 at line 14 # spent 752µs making 1 call to Moose::Meta::Attribute::BEGIN@14 |
15 | 2 | 23µs | 2 | 209µs | # spent 108µs (6+101) within Moose::Meta::Attribute::BEGIN@15 which was called:
# once (6µs+101µs) by Moose::Meta::TypeCoercion::BEGIN@8 at line 15 # spent 108µs making 1 call to Moose::Meta::Attribute::BEGIN@15
# spent 101µs making 1 call to Sub::Exporter::__ANON__[Sub/Exporter.pm:337] |
16 | 2 | 95µs | 1 | 77.6ms | # spent 77.6ms (5.77+71.9) within Moose::Meta::Attribute::BEGIN@16 which was called:
# once (5.77ms+71.9ms) by Moose::Meta::TypeCoercion::BEGIN@8 at line 16 # spent 77.6ms making 1 call to Moose::Meta::Attribute::BEGIN@16 |
17 | 2 | 26µs | 1 | 6µs | # spent 6µs within Moose::Meta::Attribute::BEGIN@17 which was called:
# once (6µs+0s) by Moose::Meta::TypeCoercion::BEGIN@8 at line 17 # spent 6µs making 1 call to Moose::Meta::Attribute::BEGIN@17 |
18 | |||||
19 | 2 | 54µs | 2 | 16.4ms | # spent 8.21ms (7µs+8.20) within Moose::Meta::Attribute::BEGIN@19 which was called:
# once (7µs+8.20ms) by Moose::Meta::TypeCoercion::BEGIN@8 at line 19 # spent 8.21ms making 1 call to Moose::Meta::Attribute::BEGIN@19
# spent 8.20ms making 1 call to parent::import |
20 | |||||
21 | 2 | 4.11ms | 2 | 82µs | # spent 46µs (10+36) within Moose::Meta::Attribute::BEGIN@21 which was called:
# once (10µs+36µs) by Moose::Meta::TypeCoercion::BEGIN@8 at line 21 # spent 46µs making 1 call to Moose::Meta::Attribute::BEGIN@21
# spent 36µs making 1 call to Exporter::import |
22 | |||||
23 | 1 | 3µs | 1 | 1.37ms | Class::MOP::MiniTrait::apply(__PACKAGE__, 'Moose::Meta::Object::Trait'); # spent 1.37ms making 1 call to Class::MOP::MiniTrait::apply |
24 | |||||
25 | 1 | 8µs | 3 | 475µs | __PACKAGE__->meta->add_attribute('traits' => ( # spent 457µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 10µs making 1 call to Class::MOP::Object::meta
# spent 8µs making 1 call to Class::MOP::_definition_context |
26 | reader => 'applied_traits', | ||||
27 | predicate => 'has_applied_traits', | ||||
28 | Class::MOP::_definition_context(), | ||||
29 | )); | ||||
30 | |||||
31 | # we need to have a ->does method in here to | ||||
32 | # more easily support traits, and the introspection | ||||
33 | # of those traits. We extend the does check to look | ||||
34 | # for metatrait aliases. | ||||
35 | # spent 2.05ms (373µs+1.68) within Moose::Meta::Attribute::does which was called 32 times, avg 64µs/call:
# 32 times (373µs+1.68ms) by Moose::Meta::Attribute::interpolate_class at line 132, avg 64µs/call | ||||
36 | 32 | 18µs | my ($self, $role_name) = @_; | ||
37 | my $name = try { | ||||
38 | 32 | 74µs | 32 | 569µs | Moose::Util::resolve_metatrait_alias(Attribute => $role_name) # spent 569µs making 32 calls to Moose::Util::resolve_metatrait_alias, avg 18µs/call |
39 | 32 | 179µs | 32 | 1.12ms | }; # spent 1.12ms making 32 calls to Try::Tiny::try, avg 35µs/call |
40 | 32 | 10µs | return 0 if !defined($name); # failed to load class | ||
41 | 32 | 152µs | 32 | 558µs | return $self->Moose::Object::does($name); # spent 558µs making 32 calls to Moose::Object::does, avg 17µs/call |
42 | } | ||||
43 | |||||
44 | # spent 594µs within Moose::Meta::Attribute::_inline_throw_exception which was called 294 times, avg 2µs/call:
# 286 times (570µs+0s) by Moose::Meta::Attribute::_inline_check_constraint at line 686, avg 2µs/call
# 8 times (25µs+0s) by Moose::Meta::Attribute::_inline_generate_default at line 919, avg 3µs/call | ||||
45 | 294 | 123µs | my ( $self, $exception_type, $throw_args ) = @_; | ||
46 | 294 | 729µs | return 'die Module::Runtime::use_module("Moose::Exception::' . $exception_type . '")->new(' . ($throw_args || '') . ')'; | ||
47 | } | ||||
48 | |||||
49 | # spent 92.8ms (14.1+78.7) within Moose::Meta::Attribute::new which was called 110 times, avg 844µs/call:
# 108 times (14.0ms+78.0ms) by Moose::Meta::Attribute::interpolate_class_and_new at line 99, avg 851µs/call
# once (89µs+626µs) by Moose::BEGIN@26 at line 19 of Moose/Meta/TypeCoercion.pm
# once (85µs+79µs) by Moose::Meta::Attribute::clone at line 245 | ||||
50 | 110 | 170µs | my ($class, $name, %options) = @_; | ||
51 | 110 | 227µs | 109 | 35.0ms | $class->_process_options($name, \%options) unless $options{__hack_no_process_options}; # used from clone()... YECHKKK FIXME ICKY YUCK GROSS # spent 15.0ms making 11 calls to Moose::Meta::Class::__ANON__::SERIAL::7::_process_options, avg 1.36ms/call
# spent 10.7ms making 77 calls to Moose::Meta::Attribute::_process_options, avg 138µs/call
# spent 9.38ms making 21 calls to Moose::Meta::Class::__ANON__::SERIAL::1::_process_options, avg 447µs/call |
52 | |||||
53 | 110 | 63µs | delete $options{__hack_no_process_options}; | ||
54 | |||||
55 | my %attrs = | ||||
56 | ( map { $_ => 1 } | ||||
57 | 3112 | 10.9ms | 3112 | 1.21ms | grep { defined } # spent 1.21ms making 3112 calls to Class::MOP::Mixin::AttributeCore::init_arg, avg 389ns/call |
58 | 110 | 2.60ms | 220 | 5.25ms | map { $_->init_arg() } # spent 2.64ms making 33 calls to Class::MOP::Class::get_all_attributes, avg 80µs/call
# spent 1.38ms making 77 calls to Class::MOP::Class::Immutable::Class::MOP::Class::get_all_attributes, avg 18µs/call
# spent 869µs making 78 calls to Class::MOP::Object::meta, avg 11µs/call
# spent 216µs making 21 calls to Moose::Meta::Class::__ANON__::SERIAL::1::meta, avg 10µs/call
# spent 136µs making 11 calls to Moose::Meta::Class::__ANON__::SERIAL::7::meta, avg 12µs/call |
59 | $class->meta()->get_all_attributes() | ||||
60 | ); | ||||
61 | |||||
62 | 110 | 527µs | 110 | 47µs | my @bad = sort grep { ! $attrs{$_} } keys %options; # spent 47µs making 110 calls to Moose::Meta::Attribute::CORE:sort, avg 427ns/call |
63 | |||||
64 | 110 | 48µs | if (@bad) | ||
65 | { | ||||
66 | my $s = @bad > 1 ? 's' : ''; | ||||
67 | my $list = join "', '", @bad; | ||||
68 | |||||
69 | my $package = $options{definition_context}{package}; | ||||
70 | my $context = $options{definition_context}{context} | ||||
71 | || 'attribute constructor'; | ||||
72 | my $type = $options{definition_context}{type} || 'class'; | ||||
73 | |||||
74 | my $location = ''; | ||||
75 | if (defined($package)) { | ||||
76 | $location = " in "; | ||||
77 | $location .= "$type " if $type; | ||||
78 | $location .= $package; | ||||
79 | } | ||||
80 | |||||
81 | Carp::cluck "Found unknown argument$s '$list' in the $context for '$name'$location"; | ||||
82 | } | ||||
83 | |||||
84 | 110 | 4.47ms | 110 | 37.2ms | return $class->SUPER::new($name, %options); # spent 37.2ms making 110 calls to Class::MOP::Attribute::new, avg 338µs/call |
85 | } | ||||
86 | |||||
87 | # spent 143ms (5.11+138) within Moose::Meta::Attribute::interpolate_class_and_new which was called 108 times, avg 1.32ms/call:
# 60 times (4.52ms+72.2ms) by Moose::Meta::Role::Attribute::attribute_for_class at line 90 of Moose/Meta/Role/Attribute.pm, avg 1.28ms/call
# 48 times (590µs+65.6ms) by Moose::Meta::Class::_process_new_attribute at line 712 of Moose/Meta/Class.pm, avg 1.38ms/call | ||||
88 | 108 | 41µs | my $class = shift; | ||
89 | 108 | 31µs | my $name = shift; | ||
90 | |||||
91 | 108 | 96µs | throw_exception( MustPassEvenNumberOfAttributeOptions => attribute_name => $name, | ||
92 | options => \@_ | ||||
93 | ) | ||||
94 | if @_ % 2 == 1; | ||||
95 | |||||
96 | 108 | 216µs | my %args = @_; | ||
97 | |||||
98 | 108 | 275µs | 108 | 46.6ms | my ( $new_class, @traits ) = $class->interpolate_class(\%args); # spent 46.6ms making 108 calls to Moose::Meta::Attribute::interpolate_class, avg 431µs/call, recursion: max depth 1, sum of overlapping time 15µs |
99 | 108 | 603µs | 108 | 92.0ms | $new_class->new($name, %args, ( scalar(@traits) ? ( traits => \@traits ) : () ) ); # spent 92.0ms making 108 calls to Moose::Meta::Attribute::new, avg 851µs/call |
100 | } | ||||
101 | |||||
102 | # spent 46.6ms (1.16+45.4) within Moose::Meta::Attribute::interpolate_class which was called 109 times, avg 427µs/call:
# 108 times (1.16ms+45.4ms) by Moose::Meta::Attribute::interpolate_class_and_new at line 98, avg 431µs/call
# once (4µs+0s) by Moose::Meta::Attribute::clone_and_inherit_options at line 215 | ||||
103 | 109 | 61µs | my ($class, $options) = @_; | ||
104 | |||||
105 | 109 | 54µs | $class = ref($class) || $class; | ||
106 | |||||
107 | 109 | 95µs | if ( my $metaclass_name = delete $options->{metaclass} ) { | ||
108 | my $new_class = Moose::Util::resolve_metaclass_alias( Attribute => $metaclass_name ); | ||||
109 | |||||
110 | if ( $class ne $new_class ) { | ||||
111 | if ( $new_class->can("interpolate_class") ) { | ||||
112 | return $new_class->interpolate_class($options); | ||||
113 | } else { | ||||
114 | $class = $new_class; | ||||
115 | } | ||||
116 | } | ||||
117 | } | ||||
118 | |||||
119 | 109 | 31µs | my @traits; | ||
120 | |||||
121 | 109 | 58µs | if (my $traits = $options->{traits}) { | ||
122 | 32 | 9µs | my $i = 0; | ||
123 | 32 | 6µs | my $has_foreign_options = 0; | ||
124 | |||||
125 | 32 | 29µs | while ($i < @$traits) { | ||
126 | 32 | 22µs | my $trait = $traits->[$i++]; | ||
127 | 32 | 10µs | next if ref($trait); # options to a trait we discarded | ||
128 | |||||
129 | 32 | 72µs | 32 | 23.6ms | $trait = Moose::Util::resolve_metatrait_alias(Attribute => $trait) # spent 23.6ms making 32 calls to Moose::Util::resolve_metatrait_alias, avg 737µs/call |
130 | || $trait; | ||||
131 | |||||
132 | 32 | 69µs | 32 | 2.05ms | next if $class->does($trait); # spent 2.05ms making 32 calls to Moose::Meta::Attribute::does, avg 64µs/call |
133 | |||||
134 | 32 | 18µs | push @traits, $trait; | ||
135 | |||||
136 | # are there options? | ||||
137 | 32 | 31µs | if ($traits->[$i] && ref($traits->[$i])) { | ||
138 | $has_foreign_options = 1 | ||||
139 | if any { $_ ne '-alias' && $_ ne '-excludes' } keys %{ $traits->[$i] }; | ||||
140 | |||||
141 | push @traits, $traits->[$i++]; | ||||
142 | } | ||||
143 | } | ||||
144 | |||||
145 | 32 | 21µs | if (@traits) { | ||
146 | 32 | 69µs | my %options = ( | ||
147 | superclasses => [ $class ], | ||||
148 | roles => [ @traits ], | ||||
149 | ); | ||||
150 | |||||
151 | 32 | 18µs | if ($has_foreign_options) { | ||
152 | $options{weaken} = 0; | ||||
153 | } | ||||
154 | else { | ||||
155 | 32 | 23µs | $options{cache} = 1; | ||
156 | } | ||||
157 | |||||
158 | 32 | 97µs | 32 | 19.7ms | my $anon_class = Moose::Meta::Class->create_anon_class(%options); # spent 19.7ms making 32 calls to Class::MOP::Class::create_anon_class, avg 617µs/call |
159 | 32 | 122µs | 32 | 28µs | $class = $anon_class->name; # spent 28µs making 32 calls to Class::MOP::Package::name, avg 872ns/call |
160 | } | ||||
161 | } | ||||
162 | |||||
163 | 109 | 333µs | return ( wantarray ? ( $class, @traits ) : $class ); | ||
164 | } | ||||
165 | |||||
166 | # ... | ||||
167 | |||||
168 | # method-generating options shouldn't be overridden | ||||
169 | # spent 3µs within Moose::Meta::Attribute::illegal_options_for_inheritance which was called:
# once (3µs+0s) by Moose::Meta::Attribute::clone_and_inherit_options at line 197 | ||||
170 | 1 | 4µs | qw(reader writer accessor clearer predicate) | ||
171 | } | ||||
172 | |||||
173 | # NOTE/TODO | ||||
174 | # This method *must* be able to handle | ||||
175 | # Class::MOP::Attribute instances as | ||||
176 | # well. Yes, I know that is wrong, but | ||||
177 | # apparently we didn't realize it was | ||||
178 | # doing that and now we have some code | ||||
179 | # which is dependent on it. The real | ||||
180 | # solution of course is to push this | ||||
181 | # feature back up into Class::MOP::Attribute | ||||
182 | # but I not right now, I am too lazy. | ||||
183 | # However if you are reading this and | ||||
184 | # looking for something to do,.. please | ||||
185 | # be my guest. | ||||
186 | # - stevan | ||||
187 | # spent 1.15ms (52µs+1.10) within Moose::Meta::Attribute::clone_and_inherit_options which was called:
# once (52µs+1.10ms) by Moose::Meta::Class::_process_inherited_attribute at line 724 of Moose/Meta/Class.pm | ||||
188 | 1 | 1µs | my ($self, %options) = @_; | ||
189 | |||||
190 | # NOTE: | ||||
191 | # we may want to extends a Class::MOP::Attribute | ||||
192 | # in which case we need to be able to use the | ||||
193 | # core set of legal options that have always | ||||
194 | # been here. But we allows Moose::Meta::Attribute | ||||
195 | # instances to changes them. | ||||
196 | # - SL | ||||
197 | 1 | 6µs | 2 | 4µs | my @illegal_options = $self->can('illegal_options_for_inheritance') # spent 3µs making 1 call to Moose::Meta::Attribute::illegal_options_for_inheritance
# spent 900ns making 1 call to UNIVERSAL::can |
198 | ? $self->illegal_options_for_inheritance | ||||
199 | : (); | ||||
200 | |||||
201 | 1 | 3µs | my @found_illegal_options = grep { exists $options{$_} && exists $self->{$_} ? $_ : undef } @illegal_options; | ||
202 | 1 | 400ns | (scalar @found_illegal_options == 0) | ||
203 | || throw_exception( IllegalInheritedOptions => illegal_options => \@found_illegal_options, | ||||
204 | params => \%options | ||||
205 | ); | ||||
206 | |||||
207 | 1 | 6µs | 2 | 3µs | $self->_process_isa_option( $self->name, \%options ); # spent 2µs making 1 call to Moose::Meta::Attribute::_process_isa_option
# spent 800ns making 1 call to Class::MOP::Mixin::AttributeCore::name |
208 | 1 | 4µs | 2 | 2µs | $self->_process_does_option( $self->name, \%options ); # spent 2µs making 1 call to Moose::Meta::Attribute::_process_does_option
# spent 300ns making 1 call to Class::MOP::Mixin::AttributeCore::name |
209 | |||||
210 | # NOTE: | ||||
211 | # this doesn't apply to Class::MOP::Attributes, | ||||
212 | # so we can ignore it for them. | ||||
213 | # - SL | ||||
214 | 1 | 4µs | 1 | 700ns | if ($self->can('interpolate_class')) { # spent 700ns making 1 call to UNIVERSAL::can |
215 | 1 | 3µs | 1 | 4µs | ( $options{metaclass}, my @traits ) = $self->interpolate_class(\%options); # spent 4µs making 1 call to Moose::Meta::Attribute::interpolate_class |
216 | |||||
217 | 1 | 300ns | my %seen; | ||
218 | 1 | 3µs | 1 | 3µs | my @all_traits = grep { $seen{$_}++ } @{ $self->applied_traits || [] }, @traits; # spent 3µs making 1 call to Moose::Meta::Attribute::applied_traits |
219 | 1 | 800ns | $options{traits} = \@all_traits if @all_traits; | ||
220 | } | ||||
221 | |||||
222 | # This method can be called on a CMOP::Attribute object, so we need to | ||||
223 | # make sure we can call this method. | ||||
224 | 1 | 8µs | 3 | 3µs | $self->_process_lazy_build_option( $self->name, \%options ) # spent 2µs making 1 call to Moose::Meta::Attribute::_process_lazy_build_option
# spent 1µs making 1 call to UNIVERSAL::can
# spent 400ns making 1 call to Class::MOP::Mixin::AttributeCore::name |
225 | if $self->can('_process_lazy_build_option'); | ||||
226 | |||||
227 | 1 | 6µs | 1 | 1.08ms | $self->clone(%options); # spent 1.08ms making 1 call to Moose::Meta::Attribute::clone |
228 | } | ||||
229 | |||||
230 | # spent 1.08ms (137µs+940µs) within Moose::Meta::Attribute::clone which was called:
# once (137µs+940µs) by Moose::Meta::Attribute::clone_and_inherit_options at line 227 | ||||
231 | 1 | 900ns | my ( $self, %params ) = @_; | ||
232 | |||||
233 | 1 | 900ns | my $class = delete $params{metaclass} || ref $self; | ||
234 | |||||
235 | 1 | 200ns | my ( @init, @non_init ); | ||
236 | |||||
237 | 29 | 33µs | 30 | 543µs | foreach my $attr ( grep { $_->has_value($self) } Class::MOP::class_of($self)->get_all_attributes ) { # spent 521µs making 28 calls to Class::MOP::Attribute::has_value, avg 19µs/call
# spent 18µs making 1 call to Class::MOP::Class::Immutable::Class::MOP::Class::get_all_attributes
# spent 4µs making 1 call to Class::MOP::class_of |
238 | 11 | 17µs | 11 | 9µs | push @{ $attr->has_init_arg ? \@init : \@non_init }, $attr; # spent 9µs making 11 calls to Class::MOP::Mixin::AttributeCore::has_init_arg, avg 809ns/call |
239 | } | ||||
240 | |||||
241 | 12 | 39µs | 22 | 224µs | my %new_params = ( ( map { $_->init_arg => $_->get_value($self) } @init ), %params ); # spent 220µs making 11 calls to Class::MOP::Attribute::get_value, avg 20µs/call
# spent 4µs making 11 calls to Class::MOP::Mixin::AttributeCore::init_arg, avg 373ns/call |
242 | |||||
243 | 1 | 900ns | my $name = delete $new_params{name}; | ||
244 | |||||
245 | 1 | 5µs | 1 | 165µs | my $clone = $class->new($name, %new_params, __hack_no_process_options => 1 ); # spent 165µs making 1 call to Moose::Meta::Attribute::new |
246 | |||||
247 | 1 | 900ns | foreach my $attr ( @non_init ) { | ||
248 | $attr->set_value($clone, $attr->get_value($self)); | ||||
249 | } | ||||
250 | |||||
251 | 1 | 5µs | return $clone; | ||
252 | } | ||||
253 | |||||
254 | # spent 13.2ms (2.60+10.6) within Moose::Meta::Attribute::_process_options which was called 109 times, avg 121µs/call:
# 77 times (1.77ms+8.89ms) by Moose::Meta::Attribute::new at line 51, avg 138µs/call
# 32 times (835µs+1.72ms) by Moose::Meta::Class::__ANON__::SERIAL::1::_wrapped__process_options or Moose::Meta::Class::__ANON__::SERIAL::7::_wrapped__process_options at line 44 of Class/MOP/Method/Wrapped.pm, avg 80µs/call | ||||
255 | 109 | 46µs | my ( $class, $name, $options ) = @_; | ||
256 | |||||
257 | 109 | 172µs | 109 | 398µs | $class->_process_is_option( $name, $options ); # spent 398µs making 109 calls to Moose::Meta::Attribute::_process_is_option, avg 4µs/call |
258 | 109 | 224µs | 109 | 7.98ms | $class->_process_isa_option( $name, $options ); # spent 7.98ms making 109 calls to Moose::Meta::Attribute::_process_isa_option, avg 73µs/call |
259 | 109 | 187µs | 109 | 1.15ms | $class->_process_does_option( $name, $options ); # spent 1.15ms making 109 calls to Moose::Meta::Attribute::_process_does_option, avg 11µs/call |
260 | 109 | 179µs | 109 | 192µs | $class->_process_coerce_option( $name, $options ); # spent 192µs making 109 calls to Moose::Meta::Attribute::_process_coerce_option, avg 2µs/call |
261 | 109 | 179µs | 109 | 188µs | $class->_process_trigger_option( $name, $options ); # spent 188µs making 109 calls to Moose::Meta::Attribute::_process_trigger_option, avg 2µs/call |
262 | 109 | 158µs | 109 | 155µs | $class->_process_auto_deref_option( $name, $options ); # spent 155µs making 109 calls to Moose::Meta::Attribute::_process_auto_deref_option, avg 1µs/call |
263 | 109 | 156µs | 109 | 156µs | $class->_process_lazy_build_option( $name, $options ); # spent 156µs making 109 calls to Moose::Meta::Attribute::_process_lazy_build_option, avg 1µs/call |
264 | 109 | 155µs | 109 | 187µs | $class->_process_lazy_option( $name, $options ); # spent 187µs making 109 calls to Moose::Meta::Attribute::_process_lazy_option, avg 2µs/call |
265 | 109 | 345µs | 109 | 211µs | $class->_process_required_option( $name, $options ); # spent 211µs making 109 calls to Moose::Meta::Attribute::_process_required_option, avg 2µs/call |
266 | } | ||||
267 | |||||
268 | # spent 398µs within Moose::Meta::Attribute::_process_is_option which was called 109 times, avg 4µs/call:
# 109 times (398µs+0s) by Moose::Meta::Attribute::_process_options at line 257, avg 4µs/call | ||||
269 | 109 | 40µs | my ( $class, $name, $options ) = @_; | ||
270 | |||||
271 | 109 | 49µs | return unless $options->{is}; | ||
272 | |||||
273 | ### ------------------------- | ||||
274 | ## is => ro, writer => _foo # turns into (reader => foo, writer => _foo) as before | ||||
275 | ## is => rw, writer => _foo # turns into (reader => foo, writer => _foo) | ||||
276 | ## is => rw, accessor => _foo # turns into (accessor => _foo) | ||||
277 | ## is => ro, accessor => _foo # error, accesor is rw | ||||
278 | ### ------------------------- | ||||
279 | |||||
280 | 108 | 301µs | if ( $options->{is} eq 'ro' ) { | ||
281 | 108 | 54µs | throw_exception("AccessorMustReadWrite" => attribute_name => $name, | ||
282 | params => $options, | ||||
283 | ) | ||||
284 | if exists $options->{accessor}; | ||||
285 | 108 | 85µs | $options->{reader} ||= $name; | ||
286 | } | ||||
287 | elsif ( $options->{is} eq 'rw' ) { | ||||
288 | if ( $options->{writer} ) { | ||||
289 | $options->{reader} ||= $name; | ||||
290 | } | ||||
291 | else { | ||||
292 | $options->{accessor} ||= $name; | ||||
293 | } | ||||
294 | } | ||||
295 | elsif ( $options->{is} eq 'bare' ) { | ||||
296 | return; | ||||
297 | # do nothing, but don't complain (later) about missing methods | ||||
298 | } | ||||
299 | else { | ||||
300 | throw_exception( InvalidValueForIs => attribute_name => $name, | ||||
301 | params => $options, | ||||
302 | ); | ||||
303 | } | ||||
304 | } | ||||
305 | |||||
306 | # spent 7.98ms (1.01+6.97) within Moose::Meta::Attribute::_process_isa_option which was called 110 times, avg 73µs/call:
# 109 times (1.01ms+6.97ms) by Moose::Meta::Attribute::_process_options at line 258, avg 73µs/call
# once (2µs+0s) by Moose::Meta::Attribute::clone_and_inherit_options at line 207 | ||||
307 | 110 | 44µs | my ( $class, $name, $options ) = @_; | ||
308 | |||||
309 | 110 | 75µs | return unless exists $options->{isa}; | ||
310 | |||||
311 | 99 | 32µs | if ( exists $options->{does} ) { | ||
312 | if ( try { $options->{isa}->can('does') } ) { | ||||
313 | ( $options->{isa}->does( $options->{does} ) ) | ||||
314 | || throw_exception( IsaDoesNotDoTheRole => attribute_name => $name, | ||||
315 | params => $options, | ||||
316 | ); | ||||
317 | } | ||||
318 | else { | ||||
319 | throw_exception( IsaLacksDoesMethod => attribute_name => $name, | ||||
320 | params => $options, | ||||
321 | ); | ||||
322 | } | ||||
323 | } | ||||
324 | |||||
325 | # allow for anon-subtypes here ... | ||||
326 | # | ||||
327 | # Checking for Specio explicitly is completely revolting. At some point | ||||
328 | # this needs to be refactored so that Moose core defines a standard type | ||||
329 | # API that all types must implement. Unfortunately, the current core API | ||||
330 | # is _not_ the right API, so we probably need to A) come up with the new | ||||
331 | # API (Specio is a good start); B) refactor the core types to implement | ||||
332 | # that API; C) do duck type checking on type objects. | ||||
333 | 99 | 620µs | 198 | 71µs | if ( blessed( $options->{isa} ) # spent 71µs making 198 calls to Scalar::Util::blessed, avg 360ns/call |
334 | && $options->{isa}->isa('Moose::Meta::TypeConstraint') ) { | ||||
335 | $options->{type_constraint} = $options->{isa}; | ||||
336 | } | ||||
337 | elsif ( | ||||
338 | blessed( $options->{isa} ) | ||||
339 | && $options->{isa}->can('does') | ||||
340 | && $options->{isa}->does('Specio::Constraint::Role::Interface') | ||||
341 | ) { | ||||
342 | $options->{type_constraint} = $options->{isa}; | ||||
343 | } | ||||
344 | else { | ||||
345 | 99 | 362µs | 99 | 6.90ms | $options->{type_constraint} # spent 6.90ms making 99 calls to Moose::Util::TypeConstraints::find_or_create_isa_type_constraint, avg 70µs/call |
346 | = Moose::Util::TypeConstraints::find_or_create_isa_type_constraint( | ||||
347 | $options->{isa}, | ||||
348 | { package_defined_in => $options->{definition_context}->{package} } | ||||
349 | ); | ||||
350 | } | ||||
351 | } | ||||
352 | |||||
353 | # spent 1.15ms (264µs+889µs) within Moose::Meta::Attribute::_process_does_option which was called 110 times, avg 10µs/call:
# 109 times (263µs+889µs) by Moose::Meta::Attribute::_process_options at line 259, avg 11µs/call
# once (2µs+0s) by Moose::Meta::Attribute::clone_and_inherit_options at line 208 | ||||
354 | 110 | 49µs | my ( $class, $name, $options ) = @_; | ||
355 | |||||
356 | 110 | 248µs | return unless exists $options->{does} && ! exists $options->{isa}; | ||
357 | |||||
358 | # allow for anon-subtypes here ... | ||||
359 | 9 | 46µs | 9 | 5µs | if ( blessed( $options->{does} ) # spent 5µs making 9 calls to Scalar::Util::blessed, avg 544ns/call |
360 | && $options->{does}->isa('Moose::Meta::TypeConstraint') ) { | ||||
361 | $options->{type_constraint} = $options->{does}; | ||||
362 | } | ||||
363 | else { | ||||
364 | 9 | 38µs | 9 | 884µs | $options->{type_constraint} # spent 884µs making 9 calls to Moose::Util::TypeConstraints::find_or_create_does_type_constraint, avg 98µs/call |
365 | = Moose::Util::TypeConstraints::find_or_create_does_type_constraint( | ||||
366 | $options->{does}, | ||||
367 | { package_defined_in => $options->{definition_context}->{package} } | ||||
368 | ); | ||||
369 | } | ||||
370 | } | ||||
371 | |||||
372 | # spent 192µs (191+1) within Moose::Meta::Attribute::_process_coerce_option which was called 109 times, avg 2µs/call:
# 109 times (191µs+1µs) by Moose::Meta::Attribute::_process_options at line 260, avg 2µs/call | ||||
373 | 109 | 37µs | my ( $class, $name, $options ) = @_; | ||
374 | |||||
375 | 109 | 218µs | return unless $options->{coerce}; | ||
376 | |||||
377 | 1 | 500ns | ( exists $options->{type_constraint} ) | ||
378 | || throw_exception( CoercionNeedsTypeConstraint => attribute_name => $name, | ||||
379 | params => $options, | ||||
380 | ); | ||||
381 | |||||
382 | 1 | 900ns | throw_exception( CannotCoerceAWeakRef => attribute_name => $name, | ||
383 | params => $options, | ||||
384 | ) | ||||
385 | if $options->{weak_ref}; | ||||
386 | |||||
387 | 1 | 3µs | 1 | 1µs | unless ( $options->{type_constraint}->has_coercion ) { # spent 1µs making 1 call to Moose::Meta::TypeConstraint::has_coercion |
388 | my $type = $options->{type_constraint}->name; | ||||
389 | |||||
390 | throw_exception( CannotCoerceAttributeWhichHasNoCoercion => attribute_name => $name, | ||||
391 | type_name => $type, | ||||
392 | params => $options | ||||
393 | ); | ||||
394 | } | ||||
395 | } | ||||
396 | |||||
397 | # spent 188µs within Moose::Meta::Attribute::_process_trigger_option which was called 109 times, avg 2µs/call:
# 109 times (188µs+0s) by Moose::Meta::Attribute::_process_options at line 261, avg 2µs/call | ||||
398 | 109 | 44µs | my ( $class, $name, $options ) = @_; | ||
399 | |||||
400 | 109 | 234µs | return unless exists $options->{trigger}; | ||
401 | |||||
402 | ( 'CODE' eq ref $options->{trigger} ) | ||||
403 | || throw_exception( TriggerMustBeACodeRef => attribute_name => $name, | ||||
404 | params => $options, | ||||
405 | ); | ||||
406 | } | ||||
407 | |||||
408 | # spent 155µs within Moose::Meta::Attribute::_process_auto_deref_option which was called 109 times, avg 1µs/call:
# 109 times (155µs+0s) by Moose::Meta::Attribute::_process_options at line 262, avg 1µs/call | ||||
409 | 109 | 38µs | my ( $class, $name, $options ) = @_; | ||
410 | |||||
411 | 109 | 212µs | return unless $options->{auto_deref}; | ||
412 | |||||
413 | ( exists $options->{type_constraint} ) | ||||
414 | || throw_exception( CannotAutoDerefWithoutIsa => attribute_name => $name, | ||||
415 | params => $options, | ||||
416 | ); | ||||
417 | |||||
418 | ( $options->{type_constraint}->is_a_type_of('ArrayRef') | ||||
419 | || $options->{type_constraint}->is_a_type_of('HashRef') ) | ||||
420 | || throw_exception( AutoDeRefNeedsArrayRefOrHashRef => attribute_name => $name, | ||||
421 | params => $options, | ||||
422 | ); | ||||
423 | } | ||||
424 | |||||
425 | sub _process_lazy_build_option { | ||||
426 | 110 | 37µs | my ( $class, $name, $options ) = @_; | ||
427 | |||||
428 | 110 | 232µs | return unless $options->{lazy_build}; | ||
429 | |||||
430 | throw_exception( CannotUseLazyBuildAndDefaultSimultaneously => attribute_name => $name, | ||||
431 | params => $options, | ||||
432 | ) | ||||
433 | if exists $options->{default}; | ||||
434 | |||||
435 | $options->{lazy} = 1; | ||||
436 | $options->{builder} ||= "_build_${name}"; | ||||
437 | |||||
438 | if ( $name =~ /^_/ ) { | ||||
439 | $options->{clearer} ||= "_clear${name}"; | ||||
440 | $options->{predicate} ||= "_has${name}"; | ||||
441 | } | ||||
442 | else { | ||||
443 | $options->{clearer} ||= "clear_${name}"; | ||||
444 | $options->{predicate} ||= "has_${name}"; | ||||
445 | } | ||||
446 | } | ||||
447 | |||||
448 | # spent 187µs within Moose::Meta::Attribute::_process_lazy_option which was called 109 times, avg 2µs/call:
# 109 times (187µs+0s) by Moose::Meta::Attribute::_process_options at line 264, avg 2µs/call | ||||
449 | 109 | 37µs | my ( $class, $name, $options ) = @_; | ||
450 | |||||
451 | 109 | 200µs | return unless $options->{lazy}; | ||
452 | |||||
453 | 17 | 37µs | ( exists $options->{default} || defined $options->{builder} ) | ||
454 | || throw_exception( LazyAttributeNeedsADefault => params => $options, | ||||
455 | attribute_name => $name, | ||||
456 | ); | ||||
457 | } | ||||
458 | |||||
459 | # spent 211µs within Moose::Meta::Attribute::_process_required_option which was called 109 times, avg 2µs/call:
# 109 times (211µs+0s) by Moose::Meta::Attribute::_process_options at line 265, avg 2µs/call | ||||
460 | 109 | 43µs | my ( $class, $name, $options ) = @_; | ||
461 | |||||
462 | 109 | 253µs | if ( | ||
463 | $options->{required} | ||||
464 | && !( | ||||
465 | ( !exists $options->{init_arg} || defined $options->{init_arg} ) | ||||
466 | || exists $options->{default} | ||||
467 | || defined $options->{builder} | ||||
468 | ) | ||||
469 | ) { | ||||
470 | throw_exception( RequiredAttributeNeedsADefault => params => $options, | ||||
471 | attribute_name => $name, | ||||
472 | ); | ||||
473 | } | ||||
474 | } | ||||
475 | |||||
476 | # spent 439µs (269+170) within Moose::Meta::Attribute::initialize_instance_slot which was called 33 times, avg 13µs/call:
# 33 times (269µs+170µs) by Class::MOP::Class::_construct_instance at line 526 of Class/MOP/Class.pm, avg 13µs/call | ||||
477 | 33 | 13µs | my ($self, $meta_instance, $instance, $params) = @_; | ||
478 | 33 | 86µs | 33 | 13µs | my $init_arg = $self->init_arg(); # spent 13µs making 33 calls to Class::MOP::Mixin::AttributeCore::init_arg, avg 394ns/call |
479 | # try to fetch the init arg from the %params ... | ||||
480 | |||||
481 | 33 | 6µs | my $val; | ||
482 | 33 | 5µs | my $value_is_set; | ||
483 | 33 | 28µs | if ( defined($init_arg) and exists $params->{$init_arg}) { | ||
484 | 1 | 900ns | $val = $params->{$init_arg}; | ||
485 | 1 | 200ns | $value_is_set = 1; | ||
486 | } | ||||
487 | else { | ||||
488 | # skip it if it's lazy | ||||
489 | 32 | 125µs | 32 | 67µs | return if $self->is_lazy; # spent 67µs making 32 calls to Moose::Meta::Mixin::AttributeCore::is_lazy, avg 2µs/call |
490 | # and die if it's required and doesn't have a default value | ||||
491 | my $class_name = blessed( $instance ); | ||||
492 | throw_exception(AttributeIsRequired => attribute_name => $self->name, | ||||
493 | class_name => $class_name, | ||||
494 | params => $params, | ||||
495 | ) | ||||
496 | if $self->is_required && !$self->has_default && !$self->has_builder; | ||||
497 | |||||
498 | # if nothing was in the %params, we can use the | ||||
499 | # attribute's default value (if it has one) | ||||
500 | if ($self->has_default) { | ||||
501 | $val = $self->default($instance); | ||||
502 | $value_is_set = 1; | ||||
503 | } | ||||
504 | elsif ($self->has_builder) { | ||||
505 | $val = $self->_call_builder($instance); | ||||
506 | $value_is_set = 1; | ||||
507 | } | ||||
508 | } | ||||
509 | |||||
510 | 1 | 200ns | return unless $value_is_set; | ||
511 | |||||
512 | 1 | 2µs | 1 | 8µs | $val = $self->_coerce_and_verify( $val, $instance ); # spent 8µs making 1 call to Moose::Meta::Attribute::_coerce_and_verify |
513 | |||||
514 | 1 | 6µs | 1 | 43µs | $self->set_initial_value($instance, $val); # spent 43µs making 1 call to Class::MOP::Attribute::set_initial_value |
515 | |||||
516 | 1 | 6µs | 2 | 39µs | if ( ref $val && $self->is_weak_ref ) { # spent 37µs making 1 call to Moose::Meta::Attribute::_weaken_value
# spent 2µs making 1 call to Moose::Meta::Mixin::AttributeCore::is_weak_ref |
517 | $self->_weaken_value($instance); | ||||
518 | } | ||||
519 | } | ||||
520 | |||||
521 | sub _call_builder { | ||||
522 | my ( $self, $instance ) = @_; | ||||
523 | |||||
524 | my $builder = $self->builder(); | ||||
525 | |||||
526 | return $instance->$builder() | ||||
527 | if $instance->can( $self->builder ); | ||||
528 | |||||
529 | throw_exception( BuilderDoesNotExist => instance => $instance, | ||||
530 | attribute => $self, | ||||
531 | ); | ||||
532 | } | ||||
533 | |||||
534 | ## Slot management | ||||
535 | |||||
536 | sub _make_initializer_writer_callback { | ||||
537 | my $self = shift; | ||||
538 | my ($meta_instance, $instance, $slot_name) = @_; | ||||
539 | my $old_callback = $self->SUPER::_make_initializer_writer_callback(@_); | ||||
540 | return sub { | ||||
541 | $old_callback->($self->_coerce_and_verify($_[0], $instance)); | ||||
542 | }; | ||||
543 | } | ||||
544 | |||||
545 | sub set_value { | ||||
546 | my ($self, $instance, @args) = @_; | ||||
547 | my $value = $args[0]; | ||||
548 | |||||
549 | my $attr_name = quotemeta($self->name); | ||||
550 | |||||
551 | my $class_name = blessed( $instance ); | ||||
552 | if ($self->is_required and not @args) { | ||||
553 | throw_exception( AttributeIsRequired => attribute_name => $self->name, | ||||
554 | class_name => $class_name, | ||||
555 | ); | ||||
556 | } | ||||
557 | |||||
558 | $value = $self->_coerce_and_verify( $value, $instance ); | ||||
559 | |||||
560 | my @old; | ||||
561 | if ( $self->has_trigger && $self->has_value($instance) ) { | ||||
562 | @old = $self->get_value($instance, 'for trigger'); | ||||
563 | } | ||||
564 | |||||
565 | $self->SUPER::set_value($instance, $value); | ||||
566 | |||||
567 | if ( ref $value && $self->is_weak_ref ) { | ||||
568 | $self->_weaken_value($instance); | ||||
569 | } | ||||
570 | |||||
571 | if ($self->has_trigger) { | ||||
572 | $self->trigger->($instance, $value, @old); | ||||
573 | } | ||||
574 | } | ||||
575 | |||||
576 | # spent 41.4ms (7.81+33.5) within Moose::Meta::Attribute::_inline_set_value which was called 246 times, avg 168µs/call:
# 169 times (6.90ms+26.2ms) by Moose::Meta::Class::_inline_init_attr_from_constructor at line 398 of Moose/Meta/Class.pm, avg 196µs/call
# 70 times (734µs+6.15ms) by Moose::Meta::Class::_inline_init_attr_from_default at line 425 of Moose/Meta/Class.pm, avg 98µs/call
# 5 times (122µs+726µs) by Class::MOP::Method::Accessor::try {...} at line 191 of Class/MOP/Method/Accessor.pm, avg 169µs/call
# 2 times (51µs+501µs) by Class::MOP::Class::_inline_init_attr_from_constructor at line 631 of Class/MOP/Class.pm, avg 276µs/call | ||||
577 | 246 | 43µs | my $self = shift; | ||
578 | 246 | 119µs | my ($instance, $value, $tc, $coercion, $message, $for_constructor) = @_; | ||
579 | |||||
580 | 246 | 37µs | my $old = '@old'; | ||
581 | 246 | 29µs | my $copy = '$val'; | ||
582 | 246 | 29µs | $tc ||= '$type_constraint'; | ||
583 | 246 | 10µs | $coercion ||= '$type_coercion'; | ||
584 | 246 | 19µs | $message ||= '$type_message'; | ||
585 | |||||
586 | 246 | 25µs | my @code; | ||
587 | 246 | 199µs | 246 | 895µs | if ($self->_writer_value_needs_copy) { # spent 895µs making 246 calls to Moose::Meta::Attribute::_writer_value_needs_copy, avg 4µs/call |
588 | 1 | 2µs | 1 | 3µs | push @code, $self->_inline_copy_value($value, $copy); # spent 3µs making 1 call to Moose::Meta::Attribute::_inline_copy_value |
589 | 1 | 500ns | $value = $copy; | ||
590 | } | ||||
591 | |||||
592 | # constructors already handle required checks | ||||
593 | 246 | 49µs | 7 | 101µs | push @code, $self->_inline_check_required # spent 101µs making 7 calls to Moose::Meta::Attribute::_inline_check_required, avg 14µs/call |
594 | unless $for_constructor; | ||||
595 | |||||
596 | 246 | 410µs | 246 | 22.8ms | push @code, $self->_inline_tc_code($value, $tc, $coercion, $message); # spent 22.8ms making 246 calls to Moose::Meta::Attribute::_inline_tc_code, avg 93µs/call |
597 | |||||
598 | # constructors do triggers all at once at the end | ||||
599 | 246 | 40µs | 7 | 74µs | push @code, $self->_inline_get_old_value_for_trigger($instance, $old) # spent 74µs making 7 calls to Moose::Meta::Attribute::_inline_get_old_value_for_trigger, avg 11µs/call |
600 | unless $for_constructor; | ||||
601 | |||||
602 | 246 | 598µs | 492 | 9.64ms | push @code, ( # spent 8.51ms making 246 calls to Class::MOP::Attribute::_inline_set_value, avg 35µs/call
# spent 1.13ms making 246 calls to Moose::Meta::Attribute::_inline_weaken_value, avg 5µs/call |
603 | $self->SUPER::_inline_set_value($instance, $value), | ||||
604 | $self->_inline_weaken_value($instance, $value), | ||||
605 | ); | ||||
606 | |||||
607 | # constructors do triggers all at once at the end | ||||
608 | 246 | 38µs | 7 | 73µs | push @code, $self->_inline_trigger($instance, $value, $old) # spent 73µs making 7 calls to Moose::Meta::Attribute::_inline_trigger, avg 10µs/call |
609 | unless $for_constructor; | ||||
610 | |||||
611 | 246 | 725µs | return @code; | ||
612 | } | ||||
613 | |||||
614 | # spent 951µs (634+316) within Moose::Meta::Attribute::_writer_value_needs_copy which was called 260 times, avg 4µs/call:
# 246 times (591µs+303µs) by Moose::Meta::Attribute::_inline_set_value at line 587, avg 4µs/call
# 14 times (43µs+13µs) by Moose::Meta::Method::Accessor::_writer_value_needs_copy at line 85 of Moose/Meta/Method/Accessor.pm, avg 4µs/call | ||||
615 | 260 | 37µs | my $self = shift; | ||
616 | 260 | 544µs | 260 | 316µs | return $self->should_coerce; # spent 316µs making 260 calls to Moose::Meta::Mixin::AttributeCore::should_coerce, avg 1µs/call |
617 | } | ||||
618 | |||||
619 | # spent 3µs within Moose::Meta::Attribute::_inline_copy_value which was called:
# once (3µs+0s) by Moose::Meta::Attribute::_inline_set_value at line 588 | ||||
620 | 1 | 900ns | my $self = shift; | ||
621 | 1 | 500ns | my ($value, $copy) = @_; | ||
622 | |||||
623 | 1 | 4µs | return 'my ' . $copy . ' = ' . $value . ';' | ||
624 | } | ||||
625 | |||||
626 | # spent 101µs (43+58) within Moose::Meta::Attribute::_inline_check_required which was called 7 times, avg 14µs/call:
# 7 times (43µs+58µs) by Moose::Meta::Attribute::_inline_set_value at line 593, avg 14µs/call | ||||
627 | 7 | 2µs | my $self = shift; | ||
628 | |||||
629 | 7 | 30µs | 7 | 58µs | return unless $self->is_required; # spent 58µs making 7 calls to Moose::Meta::Mixin::AttributeCore::is_required, avg 8µs/call |
630 | |||||
631 | my $attr_name = quotemeta($self->name); | ||||
632 | |||||
633 | return ( | ||||
634 | 'if (@_ < 2) {', | ||||
635 | $self->_inline_throw_exception( AttributeIsRequired => | ||||
636 | 'attribute_name => "'.$attr_name.'",'. | ||||
637 | 'class_name => $class_name' | ||||
638 | ) . ';', | ||||
639 | '}', | ||||
640 | ); | ||||
641 | } | ||||
642 | |||||
643 | # spent 22.8ms (5.68+17.1) within Moose::Meta::Attribute::_inline_tc_code which was called 246 times, avg 93µs/call:
# 246 times (5.68ms+17.1ms) by Moose::Meta::Attribute::_inline_set_value at line 596, avg 93µs/call | ||||
644 | 246 | 37µs | my $self = shift; | ||
645 | 246 | 98µs | my ($value, $tc, $coercion, $message, $is_lazy) = @_; | ||
646 | return ( | ||||
647 | 246 | 722µs | 492 | 17.1ms | $self->_inline_check_coercion( # spent 16.3ms making 246 calls to Moose::Meta::Attribute::_inline_check_constraint, avg 66µs/call
# spent 823µs making 246 calls to Moose::Meta::Attribute::_inline_check_coercion, avg 3µs/call |
648 | $value, $tc, $coercion, $is_lazy, | ||||
649 | ), | ||||
650 | $self->_inline_check_constraint( | ||||
651 | $value, $tc, $message, $is_lazy, | ||||
652 | ), | ||||
653 | ); | ||||
654 | } | ||||
655 | |||||
656 | # spent 1.12ms (804µs+315µs) within Moose::Meta::Attribute::_inline_check_coercion which was called 288 times, avg 4µs/call:
# 246 times (601µs+222µs) by Moose::Meta::Attribute::_inline_tc_code at line 647, avg 3µs/call
# 42 times (203µs+93µs) by Moose::Meta::Attribute::_inline_init_from_default at line 891, avg 7µs/call | ||||
657 | 288 | 44µs | my $self = shift; | ||
658 | 288 | 91µs | my ($value, $tc, $coercion) = @_; | ||
659 | |||||
660 | 288 | 604µs | 290 | 277µs | return unless $self->should_coerce && $self->type_constraint->has_coercion; # spent 275µs making 288 calls to Moose::Meta::Mixin::AttributeCore::should_coerce, avg 955ns/call
# spent 1µs making 1 call to Moose::Meta::TypeConstraint::has_coercion
# spent 700ns making 1 call to Moose::Meta::Mixin::AttributeCore::type_constraint |
661 | |||||
662 | 1 | 7µs | 4 | 38µs | if ( $self->type_constraint->can_be_inlined ) { # spent 29µs making 1 call to Moose::Meta::TypeConstraint::_inline_check
# spent 8µs making 1 call to Moose::Meta::TypeConstraint::can_be_inlined
# spent 1µs making 2 calls to Moose::Meta::Mixin::AttributeCore::type_constraint, avg 700ns/call |
663 | return ( | ||||
664 | 'if (! (' . $self->type_constraint->_inline_check($value) . ')) {', | ||||
665 | $value . ' = ' . $coercion . '->(' . $value . ');', | ||||
666 | '}', | ||||
667 | ); | ||||
668 | } | ||||
669 | else { | ||||
670 | return ( | ||||
671 | 'if (!' . $tc . '->(' . $value . ')) {', | ||||
672 | $value . ' = ' . $coercion . '->(' . $value . ');', | ||||
673 | '}', | ||||
674 | ); | ||||
675 | } | ||||
676 | } | ||||
677 | |||||
678 | # spent 21.7ms (4.32+17.4) within Moose::Meta::Attribute::_inline_check_constraint which was called 288 times, avg 75µs/call:
# 246 times (3.42ms+12.8ms) by Moose::Meta::Attribute::_inline_tc_code at line 647, avg 66µs/call
# 42 times (904µs+4.52ms) by Moose::Meta::Attribute::_inline_init_from_default at line 891, avg 129µs/call | ||||
679 | 288 | 54µs | my $self = shift; | ||
680 | 288 | 93µs | my ($value, $tc, $message) = @_; | ||
681 | |||||
682 | 288 | 243µs | 288 | 289µs | return unless $self->has_type_constraint; # spent 289µs making 288 calls to Moose::Meta::Mixin::AttributeCore::has_type_constraint, avg 1µs/call |
683 | |||||
684 | 286 | 624µs | 286 | 120µs | my $attr_name = quotemeta($self->name); # spent 120µs making 286 calls to Class::MOP::Mixin::AttributeCore::name, avg 421ns/call |
685 | |||||
686 | 286 | 6.81ms | 1430 | 17.0ms | if ( $self->type_constraint->can_be_inlined ) { # spent 9.10ms making 253 calls to Moose::Meta::TypeConstraint::_inline_check, avg 36µs/call
# spent 3.26ms making 33 calls to Moose::Meta::TypeConstraint::Parameterized::_inline_check, avg 99µs/call
# spent 2.27ms making 253 calls to Moose::Meta::TypeConstraint::can_be_inlined, avg 9µs/call
# spent 1.23ms making 33 calls to Moose::Meta::TypeConstraint::Parameterized::can_be_inlined, avg 37µs/call
# spent 570µs making 286 calls to Moose::Meta::Attribute::_inline_throw_exception, avg 2µs/call
# spent 532µs making 572 calls to Moose::Meta::Mixin::AttributeCore::type_constraint, avg 929ns/call |
687 | return ( | ||||
688 | 'if (! (' . $self->type_constraint->_inline_check($value) . ')) {', | ||||
689 | 'my $msg = do { local $_ = ' . $value . '; ' | ||||
690 | . $message . '->(' . $value . ');' | ||||
691 | . '};'. | ||||
692 | $self->_inline_throw_exception( ValidationFailedForInlineTypeConstraint => | ||||
693 | 'type_constraint_message => $msg , '. | ||||
694 | 'class_name => $class_name, '. | ||||
695 | 'attribute_name => "'.$attr_name.'",'. | ||||
696 | 'value => '.$value | ||||
697 | ).';', | ||||
698 | '}', | ||||
699 | ); | ||||
700 | } | ||||
701 | else { | ||||
702 | return ( | ||||
703 | 'if (!' . $tc . '->(' . $value . ')) {', | ||||
704 | 'my $msg = do { local $_ = ' . $value . '; ' | ||||
705 | . $message . '->(' . $value . ');' | ||||
706 | . '};'. | ||||
707 | $self->_inline_throw_exception( ValidationFailedForInlineTypeConstraint => | ||||
708 | 'type_constraint_message => $msg , '. | ||||
709 | 'class_name => $class_name, '. | ||||
710 | 'attribute_name => "'.$attr_name.'",'. | ||||
711 | 'value => '.$value | ||||
712 | ).';', | ||||
713 | '}', | ||||
714 | ); | ||||
715 | } | ||||
716 | } | ||||
717 | |||||
718 | # spent 74µs (28+47) within Moose::Meta::Attribute::_inline_get_old_value_for_trigger which was called 7 times, avg 11µs/call:
# 7 times (28µs+47µs) by Moose::Meta::Attribute::_inline_set_value at line 599, avg 11µs/call | ||||
719 | 7 | 2µs | my $self = shift; | ||
720 | 7 | 3µs | my ($instance, $old) = @_; | ||
721 | |||||
722 | 7 | 22µs | 7 | 47µs | return unless $self->has_trigger; # spent 47µs making 7 calls to Moose::Meta::Mixin::AttributeCore::has_trigger, avg 7µs/call |
723 | |||||
724 | return ( | ||||
725 | 'my ' . $old . ' = ' . $self->_inline_instance_has($instance), | ||||
726 | '? ' . $self->_inline_instance_get($instance), | ||||
727 | ': ();', | ||||
728 | ); | ||||
729 | } | ||||
730 | |||||
731 | # spent 1.41ms (936µs+477µs) within Moose::Meta::Attribute::_inline_weaken_value which was called 288 times, avg 5µs/call:
# 246 times (745µs+389µs) by Moose::Meta::Attribute::_inline_set_value at line 602, avg 5µs/call
# 42 times (191µs+88µs) by Moose::Meta::Attribute::_inline_init_from_default at line 891, avg 7µs/call | ||||
732 | 288 | 57µs | my $self = shift; | ||
733 | 288 | 81µs | my ($instance, $value) = @_; | ||
734 | |||||
735 | 288 | 666µs | 288 | 400µs | return unless $self->is_weak_ref; # spent 400µs making 288 calls to Moose::Meta::Mixin::AttributeCore::is_weak_ref, avg 1µs/call |
736 | |||||
737 | 9 | 29µs | 18 | 17µs | my $mi = $self->associated_class->get_meta_instance; # spent 7µs making 1 call to Class::MOP::Class::Immutable::Class::MOP::Class::get_meta_instance
# spent 6µs making 8 calls to Class::MOP::Class::get_meta_instance, avg 762ns/call
# spent 4µs making 9 calls to Class::MOP::Attribute::associated_class, avg 400ns/call |
738 | return ( | ||||
739 | 9 | 57µs | 18 | 60µs | $mi->inline_weaken_slot_value($instance, $self->name), # spent 57µs making 9 calls to Class::MOP::Instance::inline_weaken_slot_value, avg 6µs/call
# spent 3µs making 9 calls to Class::MOP::Mixin::AttributeCore::name, avg 367ns/call |
740 | 'if ref ' . $value . ';', | ||||
741 | ); | ||||
742 | } | ||||
743 | |||||
744 | # spent 109µs (54+55) within Moose::Meta::Attribute::_inline_trigger which was called 14 times, avg 8µs/call:
# 7 times (24µs+49µs) by Moose::Meta::Attribute::_inline_set_value at line 608, avg 10µs/call
# 7 times (30µs+6µs) by Moose::Meta::Method::Accessor::_inline_trigger at line 113 of Moose/Meta/Method/Accessor.pm, avg 5µs/call | ||||
745 | 14 | 4µs | my $self = shift; | ||
746 | 14 | 7µs | my ($instance, $value, $old) = @_; | ||
747 | |||||
748 | 14 | 40µs | 14 | 55µs | return unless $self->has_trigger; # spent 55µs making 14 calls to Moose::Meta::Mixin::AttributeCore::has_trigger, avg 4µs/call |
749 | |||||
750 | return '$trigger->(' . $instance . ', ' . $value . ', ' . $old . ');'; | ||||
751 | } | ||||
752 | |||||
753 | # spent 30.8ms (22.2+8.60) within Moose::Meta::Attribute::_eval_environment which was called 196 times, avg 157µs/call:
# 196 times (22.2ms+8.60ms) by Moose::Meta::Method::Accessor::_eval_environment at line 46 of Moose/Meta/Method/Accessor.pm, avg 157µs/call | ||||
754 | 196 | 52µs | my $self = shift; | ||
755 | |||||
756 | 196 | 116µs | my $env = { }; | ||
757 | |||||
758 | 196 | 314µs | 196 | 362µs | $env->{'$trigger'} = \($self->trigger) # spent 362µs making 196 calls to Moose::Meta::Mixin::AttributeCore::has_trigger, avg 2µs/call |
759 | if $self->has_trigger; | ||||
760 | 196 | 418µs | 294 | 421µs | $env->{'$attr_default'} = \($self->default) # spent 226µs making 196 calls to Class::MOP::Mixin::AttributeCore::has_default, avg 1µs/call
# spent 195µs making 98 calls to Class::MOP::Mixin::AttributeCore::default, avg 2µs/call |
761 | if $self->has_default; | ||||
762 | |||||
763 | 196 | 449µs | 196 | 329µs | if ($self->has_type_constraint) { # spent 329µs making 196 calls to Moose::Meta::Mixin::AttributeCore::has_type_constraint, avg 2µs/call |
764 | 194 | 234µs | 194 | 282µs | my $tc_obj = $self->type_constraint; # spent 282µs making 194 calls to Moose::Meta::Mixin::AttributeCore::type_constraint, avg 1µs/call |
765 | |||||
766 | 194 | 304µs | 194 | 2.89ms | $env->{'$type_constraint'} = \( # spent 1.89ms making 165 calls to Moose::Meta::TypeConstraint::can_be_inlined, avg 11µs/call
# spent 1.00ms making 29 calls to Moose::Meta::TypeConstraint::Parameterized::can_be_inlined, avg 35µs/call |
767 | $tc_obj->_compiled_type_constraint | ||||
768 | ) unless $tc_obj->can_be_inlined; | ||||
769 | # these two could probably get inlined versions too | ||||
770 | 194 | 306µs | 196 | 286µs | $env->{'$type_coercion'} = \( # spent 284µs making 194 calls to Moose::Meta::TypeConstraint::has_coercion, avg 1µs/call
# spent 1µs making 1 call to Moose::Meta::TypeCoercion::_compiled_type_coercion
# spent 1µs making 1 call to Moose::Meta::TypeConstraint::coercion |
771 | $tc_obj->coercion->_compiled_type_coercion | ||||
772 | ) if $tc_obj->has_coercion; | ||||
773 | 194 | 635µs | 388 | 584µs | $env->{'$type_message'} = \( # spent 315µs making 194 calls to Moose::Meta::TypeConstraint::_default_message, avg 2µs/call
# spent 270µs making 194 calls to Moose::Meta::TypeConstraint::has_message, avg 1µs/call |
774 | $tc_obj->has_message ? $tc_obj->message : $tc_obj->_default_message | ||||
775 | ); | ||||
776 | |||||
777 | 194 | 620µs | 194 | 2.92ms | $env = { %$env, %{ $tc_obj->inline_environment } }; # spent 1.60ms making 165 calls to Moose::Meta::TypeConstraint::inline_environment, avg 10µs/call
# spent 1.32ms making 29 calls to Moose::Meta::TypeConstraint::Parameterized::inline_environment, avg 46µs/call |
778 | } | ||||
779 | |||||
780 | 196 | 5.81ms | 392 | 259µs | $env->{'$class_name'} = \($self->associated_class->name); # spent 153µs making 196 calls to Class::MOP::Attribute::associated_class, avg 783ns/call
# spent 106µs making 196 calls to Class::MOP::Package::name, avg 541ns/call |
781 | |||||
782 | # XXX ugh, fix these | ||||
783 | 196 | 205µs | 196 | 195µs | $env->{'$attr'} = \$self # spent 195µs making 196 calls to Class::MOP::Mixin::AttributeCore::has_initializer, avg 995ns/call |
784 | if $self->has_initializer && $self->is_lazy; | ||||
785 | # pretty sure this is only going to be closed over if you use a custom | ||||
786 | # error class at this point, but we should still get rid of this | ||||
787 | # at some point | ||||
788 | 196 | 5.68ms | 196 | 76µs | $env->{'$meta'} = \($self->associated_class); # spent 76µs making 196 calls to Class::MOP::Attribute::associated_class, avg 386ns/call |
789 | |||||
790 | 196 | 365µs | return $env; | ||
791 | } | ||||
792 | |||||
793 | # spent 37µs (16+21) within Moose::Meta::Attribute::_weaken_value which was called:
# once (16µs+21µs) by Moose::Meta::Attribute::initialize_instance_slot at line 516 | ||||
794 | 1 | 400ns | my ( $self, $instance ) = @_; | ||
795 | |||||
796 | 1 | 6µs | 3 | 14µs | my $meta_instance = Class::MOP::Class->initialize( blessed($instance) ) # spent 9µs making 1 call to Class::MOP::Class::Immutable::Class::MOP::Class::get_meta_instance
# spent 4µs making 1 call to Class::MOP::Class::initialize
# spent 1µs making 1 call to Scalar::Util::blessed |
797 | ->get_meta_instance; | ||||
798 | |||||
799 | 1 | 8µs | 2 | 7µs | $meta_instance->weaken_slot_value( $instance, $self->name ); # spent 6µs making 1 call to Class::MOP::Instance::weaken_slot_value
# spent 600ns making 1 call to Class::MOP::Mixin::AttributeCore::name |
800 | } | ||||
801 | |||||
802 | sub get_value { | ||||
803 | my ($self, $instance, $for_trigger) = @_; | ||||
804 | |||||
805 | if ($self->is_lazy) { | ||||
806 | unless ($self->has_value($instance)) { | ||||
807 | my $value; | ||||
808 | if ($self->has_default) { | ||||
809 | $value = $self->default($instance); | ||||
810 | } elsif ( $self->has_builder ) { | ||||
811 | $value = $self->_call_builder($instance); | ||||
812 | } | ||||
813 | |||||
814 | $value = $self->_coerce_and_verify( $value, $instance ); | ||||
815 | |||||
816 | $self->set_initial_value($instance, $value); | ||||
817 | |||||
818 | if ( ref $value && $self->is_weak_ref ) { | ||||
819 | $self->_weaken_value($instance); | ||||
820 | } | ||||
821 | } | ||||
822 | } | ||||
823 | |||||
824 | if ( $self->should_auto_deref && ! $for_trigger ) { | ||||
825 | |||||
826 | my $type_constraint = $self->type_constraint; | ||||
827 | |||||
828 | if ($type_constraint->is_a_type_of('ArrayRef')) { | ||||
829 | my $rv = $self->SUPER::get_value($instance); | ||||
830 | return unless defined $rv; | ||||
831 | return wantarray ? @{ $rv } : $rv; | ||||
832 | } | ||||
833 | elsif ($type_constraint->is_a_type_of('HashRef')) { | ||||
834 | my $rv = $self->SUPER::get_value($instance); | ||||
835 | return unless defined $rv; | ||||
836 | return wantarray ? %{ $rv } : $rv; | ||||
837 | } | ||||
838 | else { | ||||
839 | throw_exception( CannotAutoDereferenceTypeConstraint => type_name => $type_constraint->name, | ||||
840 | instance => $instance, | ||||
841 | attribute => $self | ||||
842 | ); | ||||
843 | } | ||||
844 | |||||
845 | } | ||||
846 | else { | ||||
847 | |||||
848 | return $self->SUPER::get_value($instance); | ||||
849 | } | ||||
850 | } | ||||
851 | |||||
852 | # spent 33.9ms (1.09+32.8) within Moose::Meta::Attribute::_inline_get_value which was called 111 times, avg 305µs/call:
# 111 times (1.09ms+32.8ms) by Class::MOP::Method::Accessor::try {...} at line 151 of Class/MOP/Method/Accessor.pm, avg 305µs/call | ||||
853 | 111 | 37µs | my $self = shift; | ||
854 | 111 | 54µs | my ($instance, $tc, $coercion, $message) = @_; | ||
855 | |||||
856 | 111 | 213µs | 111 | 23.1ms | my $slot_access = $self->_inline_instance_get($instance); # spent 23.1ms making 111 calls to Class::MOP::Attribute::_inline_instance_get, avg 208µs/call |
857 | 111 | 49µs | $tc ||= '$type_constraint'; | ||
858 | 111 | 32µs | $coercion ||= '$type_coercion'; | ||
859 | 111 | 19µs | $message ||= '$type_message'; | ||
860 | |||||
861 | return ( | ||||
862 | 111 | 506µs | 222 | 9.66ms | $self->_inline_check_lazy($instance, $tc, $coercion, $message), # spent 8.56ms making 111 calls to Moose::Meta::Attribute::_inline_check_lazy, avg 77µs/call
# spent 1.10ms making 111 calls to Moose::Meta::Attribute::_inline_return_auto_deref, avg 10µs/call |
863 | $self->_inline_return_auto_deref($slot_access), | ||||
864 | ); | ||||
865 | } | ||||
866 | |||||
867 | # spent 15.1ms (974µs+14.1) within Moose::Meta::Attribute::_inline_check_lazy which was called 161 times, avg 94µs/call:
# 111 times (593µs+7.97ms) by Moose::Meta::Attribute::_inline_get_value at line 862, avg 77µs/call
# 50 times (381µs+6.13ms) by Moose::Meta::Method::Accessor::_inline_check_lazy at line 101 of Moose/Meta/Method/Accessor.pm, avg 130µs/call | ||||
868 | 161 | 42µs | my $self = shift; | ||
869 | 161 | 90µs | my ($instance, $tc, $coercion, $message) = @_; | ||
870 | |||||
871 | 161 | 465µs | 161 | 377µs | return unless $self->is_lazy; # spent 377µs making 161 calls to Moose::Meta::Mixin::AttributeCore::is_lazy, avg 2µs/call |
872 | |||||
873 | 42 | 98µs | 42 | 4.76ms | my $slot_exists = $self->_inline_instance_has($instance); # spent 4.76ms making 42 calls to Class::MOP::Attribute::_inline_instance_has, avg 113µs/call |
874 | |||||
875 | return ( | ||||
876 | 42 | 229µs | 42 | 8.97ms | 'if (!' . $slot_exists . ') {', # spent 8.97ms making 42 calls to Moose::Meta::Attribute::_inline_init_from_default, avg 213µs/call |
877 | $self->_inline_init_from_default($instance, '$default', $tc, $coercion, $message, 'lazy'), | ||||
878 | '}', | ||||
879 | ); | ||||
880 | } | ||||
881 | |||||
882 | # spent 8.97ms (878µs+8.09) within Moose::Meta::Attribute::_inline_init_from_default which was called 42 times, avg 213µs/call:
# 42 times (878µs+8.09ms) by Moose::Meta::Attribute::_inline_check_lazy at line 876, avg 213µs/call | ||||
883 | 42 | 13µs | my $self = shift; | ||
884 | 42 | 30µs | my ($instance, $default, $tc, $coercion, $message, $for_lazy) = @_; | ||
885 | |||||
886 | 42 | 80µs | 50 | 75µs | if (!($self->has_default || $self->has_builder)) { # spent 64µs making 42 calls to Class::MOP::Mixin::AttributeCore::has_default, avg 2µs/call
# spent 12µs making 8 calls to Class::MOP::Mixin::AttributeCore::has_builder, avg 2µs/call |
887 | throw_exception( LazyAttributeNeedsADefault => attribute => $self ); | ||||
888 | } | ||||
889 | |||||
890 | return ( | ||||
891 | 42 | 508µs | 252 | 8.01ms | $self->_inline_generate_default($instance, $default), # spent 5.43ms making 42 calls to Moose::Meta::Attribute::_inline_check_constraint, avg 129µs/call
# spent 1.26ms making 42 calls to Moose::Meta::Attribute::_inline_init_slot, avg 30µs/call
# spent 673µs making 42 calls to Moose::Meta::Attribute::_inline_generate_default, avg 16µs/call
# spent 296µs making 42 calls to Moose::Meta::Attribute::_inline_check_coercion, avg 7µs/call
# spent 279µs making 42 calls to Moose::Meta::Attribute::_inline_weaken_value, avg 7µs/call
# spent 79µs making 42 calls to Moose::Meta::Mixin::AttributeCore::has_type_constraint, avg 2µs/call |
892 | # intentionally not using _inline_tc_code, since that can be overridden | ||||
893 | # to do things like possibly only do member tc checks, which isn't | ||||
894 | # appropriate for checking the result of a default | ||||
895 | $self->has_type_constraint | ||||
896 | ? ($self->_inline_check_coercion($default, $tc, $coercion, $for_lazy), | ||||
897 | $self->_inline_check_constraint($default, $tc, $message, $for_lazy)) | ||||
898 | : (), | ||||
899 | $self->_inline_init_slot($instance, $default), | ||||
900 | $self->_inline_weaken_value($instance, $default), | ||||
901 | ); | ||||
902 | } | ||||
903 | |||||
904 | # spent 673µs (467+206) within Moose::Meta::Attribute::_inline_generate_default which was called 42 times, avg 16µs/call:
# 42 times (467µs+206µs) by Moose::Meta::Attribute::_inline_init_from_default at line 891, avg 16µs/call | ||||
905 | 42 | 13µs | my $self = shift; | ||
906 | 42 | 21µs | my ($instance, $default) = @_; | ||
907 | |||||
908 | 42 | 46µs | 50 | 29µs | if ($self->has_default) { # spent 24µs making 42 calls to Class::MOP::Mixin::AttributeCore::has_default, avg 576ns/call
# spent 4µs making 8 calls to Class::MOP::Mixin::AttributeCore::has_builder, avg 562ns/call |
909 | 34 | 22µs | my $source = 'my ' . $default . ' = $attr_default'; | ||
910 | 34 | 69µs | 34 | 124µs | $source .= '->(' . $instance . ')' # spent 124µs making 34 calls to Class::MOP::Mixin::AttributeCore::is_default_a_coderef, avg 4µs/call |
911 | if $self->is_default_a_coderef; | ||||
912 | 34 | 79µs | return $source . ';'; | ||
913 | } | ||||
914 | elsif ($self->has_builder) { | ||||
915 | 8 | 63µs | 16 | 23µs | my $builder = B::perlstring($self->builder); # spent 17µs making 8 calls to B::perlstring, avg 2µs/call
# spent 6µs making 8 calls to Class::MOP::Mixin::AttributeCore::builder, avg 738ns/call |
916 | 8 | 19µs | 8 | 2µs | my $builder_str = quotemeta($self->builder); # spent 2µs making 8 calls to Class::MOP::Mixin::AttributeCore::builder, avg 312ns/call |
917 | 8 | 18µs | 8 | 2µs | my $attr_name_str = quotemeta($self->name); # spent 2µs making 8 calls to Class::MOP::Mixin::AttributeCore::name, avg 300ns/call |
918 | return ( | ||||
919 | 8 | 65µs | 8 | 25µs | 'my ' . $default . ';', # spent 25µs making 8 calls to Moose::Meta::Attribute::_inline_throw_exception, avg 3µs/call |
920 | 'if (my $builder = ' . $instance . '->can(' . $builder . ')) {', | ||||
921 | $default . ' = ' . $instance . '->$builder;', | ||||
922 | '}', | ||||
923 | 'else {', | ||||
924 | 'my $class = ref(' . $instance . ') || ' . $instance . ';', | ||||
925 | $self->_inline_throw_exception( | ||||
926 | BuilderMethodNotSupportedForInlineAttribute => | ||||
927 | 'class_name => $class,'. | ||||
928 | 'attribute_name => "'.$attr_name_str.'",'. | ||||
929 | 'instance => '.$instance.','. | ||||
930 | 'builder => "'.$builder_str.'"' | ||||
931 | ) . ';', | ||||
932 | '}', | ||||
933 | ); | ||||
934 | } | ||||
935 | else { | ||||
936 | confess( | ||||
937 | "Can't generate a default for " . $self->name | ||||
938 | . " since no default or builder was specified" | ||||
939 | ); | ||||
940 | } | ||||
941 | } | ||||
942 | |||||
943 | # spent 1.26ms (320µs+938µs) within Moose::Meta::Attribute::_inline_init_slot which was called 42 times, avg 30µs/call:
# 42 times (320µs+938µs) by Moose::Meta::Attribute::_inline_init_from_default at line 891, avg 30µs/call | ||||
944 | 42 | 16µs | my $self = shift; | ||
945 | 42 | 24µs | my ($inv, $value) = @_; | ||
946 | |||||
947 | 42 | 76µs | 42 | 68µs | if ($self->has_initializer) { # spent 68µs making 42 calls to Class::MOP::Mixin::AttributeCore::has_initializer, avg 2µs/call |
948 | return '$attr->set_initial_value(' . $inv . ', ' . $value . ');'; | ||||
949 | } | ||||
950 | else { | ||||
951 | 42 | 191µs | 42 | 869µs | return $self->_inline_instance_set($inv, $value) . ';'; # spent 869µs making 42 calls to Class::MOP::Attribute::_inline_instance_set, avg 21µs/call |
952 | } | ||||
953 | } | ||||
954 | |||||
955 | # spent 1.10ms (446µs+653µs) within Moose::Meta::Attribute::_inline_return_auto_deref which was called 111 times, avg 10µs/call:
# 111 times (446µs+653µs) by Moose::Meta::Attribute::_inline_get_value at line 862, avg 10µs/call | ||||
956 | 111 | 28µs | my $self = shift; | ||
957 | |||||
958 | 111 | 375µs | 111 | 653µs | return 'return ' . $self->_auto_deref(@_) . ';'; # spent 653µs making 111 calls to Moose::Meta::Attribute::_auto_deref, avg 6µs/call |
959 | } | ||||
960 | |||||
961 | # spent 653µs (425+228) within Moose::Meta::Attribute::_auto_deref which was called 111 times, avg 6µs/call:
# 111 times (425µs+228µs) by Moose::Meta::Attribute::_inline_return_auto_deref at line 958, avg 6µs/call | ||||
962 | 111 | 28µs | my $self = shift; | ||
963 | 111 | 38µs | my ($ref_value) = @_; | ||
964 | |||||
965 | 111 | 385µs | 111 | 228µs | return $ref_value unless $self->should_auto_deref; # spent 228µs making 111 calls to Moose::Meta::Mixin::AttributeCore::should_auto_deref, avg 2µs/call |
966 | |||||
967 | my $type_constraint = $self->type_constraint; | ||||
968 | |||||
969 | my $sigil; | ||||
970 | if ($type_constraint->is_a_type_of('ArrayRef')) { | ||||
971 | $sigil = '@'; | ||||
972 | } | ||||
973 | elsif ($type_constraint->is_a_type_of('HashRef')) { | ||||
974 | $sigil = '%'; | ||||
975 | } | ||||
976 | else { | ||||
977 | confess( | ||||
978 | 'Can not auto de-reference the type constraint \'' | ||||
979 | . $type_constraint->name | ||||
980 | . '\'' | ||||
981 | ); | ||||
982 | } | ||||
983 | |||||
984 | return 'wantarray ' | ||||
985 | . '? ' . $sigil . '{ (' . $ref_value . ') || return } ' | ||||
986 | . ': (' . $ref_value . ')'; | ||||
987 | } | ||||
988 | |||||
989 | ## installing accessors | ||||
990 | |||||
991 | 246 | 460µs | # spent 290µs within Moose::Meta::Attribute::accessor_metaclass which was called 246 times, avg 1µs/call:
# 146 times (153µs+0s) by Class::MOP::Attribute::try {...} at line 407 of Class/MOP/Attribute.pm, avg 1µs/call
# 100 times (137µs+0s) by Moose::Meta::Attribute::Native::Trait::_native_accessor_class_for at line 136 of Moose/Meta/Attribute/Native/Trait.pm, avg 1µs/call | ||
992 | |||||
993 | # spent 291ms (837µs+291) within Moose::Meta::Attribute::install_accessors which was called 111 times, avg 2.63ms/call:
# 78 times (497µs+153ms) by Class::MOP::Class::try {...} at line 899 of Class/MOP/Class.pm, avg 1.97ms/call
# 32 times (334µs+136ms) by Moose::Meta::Class::__ANON__::SERIAL::1::_wrapped_install_accessors or Moose::Meta::Class::__ANON__::SERIAL::7::_wrapped_install_accessors at line 44 of Class/MOP/Method/Wrapped.pm, avg 4.28ms/call
# once (6µs+976µs) by Class::MOP::Class::_inline_accessors at line 1425 of Class/MOP/Class.pm | ||||
994 | 111 | 33µs | my $self = shift; | ||
995 | 111 | 209µs | 111 | 207ms | $self->SUPER::install_accessors(@_); # spent 207ms making 111 calls to Class::MOP::Attribute::install_accessors, avg 1.86ms/call |
996 | 111 | 269µs | 146 | 84.0ms | $self->install_delegation if $self->has_handles; # spent 83.8ms making 35 calls to Moose::Meta::Attribute::install_delegation, avg 2.39ms/call
# spent 238µs making 111 calls to Moose::Meta::Mixin::AttributeCore::has_handles, avg 2µs/call |
997 | 111 | 228µs | return; | ||
998 | } | ||||
999 | |||||
1000 | # spent 489µs (404+85) within Moose::Meta::Attribute::_check_associated_methods which was called 109 times, avg 4µs/call:
# 109 times (404µs+85µs) by Moose::Meta::Class::add_attribute at line 576 of Moose/Meta/Class.pm, avg 4µs/call | ||||
1001 | 109 | 32µs | my $self = shift; | ||
1002 | 109 | 533µs | 109 | 85µs | unless ( # spent 85µs making 109 calls to Class::MOP::Attribute::associated_methods, avg 783ns/call |
1003 | @{ $self->associated_methods } | ||||
1004 | || ($self->_is_metadata || '') eq 'bare' | ||||
1005 | ) { | ||||
1006 | Carp::cluck( | ||||
1007 | 'Attribute (' . $self->name . ') of class ' | ||||
1008 | . $self->associated_class->name | ||||
1009 | . ' has no associated methods' | ||||
1010 | . ' (did you mean to provide an "is" argument?)' | ||||
1011 | . "\n" | ||||
1012 | ) | ||||
1013 | } | ||||
1014 | } | ||||
1015 | |||||
1016 | # spent 193ms (7.66+185) within Moose::Meta::Attribute::_process_accessors which was called 146 times, avg 1.32ms/call:
# 111 times (1.88ms+149ms) by Class::MOP::Attribute::install_accessors at line 450 of Class/MOP/Attribute.pm, avg 1.36ms/call
# 30 times (5.72ms+27.4ms) by Class::MOP::Attribute::install_accessors at line 458 of Class/MOP/Attribute.pm, avg 1.11ms/call
# 5 times (64µs+9.16ms) by Class::MOP::Attribute::install_accessors at line 454 of Class/MOP/Attribute.pm, avg 1.85ms/call | ||||
1017 | 146 | 36µs | my $self = shift; | ||
1018 | 146 | 85µs | my ($type, $accessor, $generate_as_inline_methods) = @_; | ||
1019 | |||||
1020 | 146 | 60µs | $accessor = ( keys %$accessor )[0] if ( ref($accessor) || '' ) eq 'HASH'; | ||
1021 | 146 | 444µs | 292 | 3.68ms | my $method = $self->associated_class->get_method($accessor); # spent 3.62ms making 146 calls to Class::MOP::Mixin::HasMethods::get_method, avg 25µs/call
# spent 51µs making 146 calls to Class::MOP::Attribute::associated_class, avg 349ns/call |
1022 | |||||
1023 | 146 | 42µs | 5 | 3µs | if ( $method # spent 1µs making 1 call to Class::MOP::Method::Accessor::associated_attribute
# spent 800ns making 2 calls to Class::MOP::Mixin::AttributeCore::name, avg 400ns/call
# spent 700ns making 1 call to UNIVERSAL::isa
# spent 500ns making 1 call to Class::MOP::Method::__ANON__[Class/MOP/Method.pm:16] |
1024 | && $method->isa('Class::MOP::Method::Accessor') | ||||
1025 | && $method->associated_attribute->name ne $self->name ) { | ||||
1026 | |||||
1027 | my $other_attr_name = $method->associated_attribute->name; | ||||
1028 | my $name = $self->name; | ||||
1029 | |||||
1030 | Carp::cluck( | ||||
1031 | "You are overwriting an accessor ($accessor) for the $other_attr_name attribute" | ||||
1032 | . " with a new accessor method for the $name attribute" ); | ||||
1033 | } | ||||
1034 | |||||
1035 | 146 | 43µs | 3 | 4µs | if ( # spent 3µs making 1 call to Class::MOP::Method::is_stub
# spent 500ns making 1 call to Class::MOP::Method::__ANON__[Class/MOP/Method.pm:16]
# spent 500ns making 1 call to UNIVERSAL::isa |
1036 | $method | ||||
1037 | && !$method->is_stub | ||||
1038 | && !$method->isa('Class::MOP::Method::Accessor') | ||||
1039 | && ( !$self->definition_context | ||||
1040 | || $method->package_name eq $self->definition_context->{package} ) | ||||
1041 | ) { | ||||
1042 | |||||
1043 | Carp::cluck( | ||||
1044 | "You are overwriting a locally defined method ($accessor) with " | ||||
1045 | . "an accessor" ); | ||||
1046 | } | ||||
1047 | |||||
1048 | 146 | 956µs | 582 | 3.45ms | if ( !$self->associated_class->has_method($accessor) # spent 2.21ms making 146 calls to Class::MOP::Mixin::HasMethods::has_method, avg 15µs/call
# spent 1.11ms making 145 calls to Class::MOP::Package::has_package_symbol, avg 8µs/call
# spent 132µs making 291 calls to Class::MOP::Attribute::associated_class, avg 453ns/call |
1049 | && $self->associated_class->has_package_symbol( '&' . $accessor ) ) { | ||||
1050 | |||||
1051 | Carp::cluck( | ||||
1052 | "You are overwriting a locally defined function ($accessor) with " | ||||
1053 | . "an accessor" ); | ||||
1054 | } | ||||
1055 | |||||
1056 | 146 | 619µs | 146 | 178ms | $self->SUPER::_process_accessors(@_); # spent 178ms making 146 calls to Class::MOP::Attribute::_process_accessors, avg 1.22ms/call |
1057 | } | ||||
1058 | |||||
1059 | # spent 212µs (14+198) within Moose::Meta::Attribute::remove_accessors which was called:
# once (14µs+198µs) by Class::MOP::Class::remove_attribute at line 915 of Class/MOP/Class.pm | ||||
1060 | 1 | 300ns | my $self = shift; | ||
1061 | 1 | 4µs | 1 | 196µs | $self->SUPER::remove_accessors(@_); # spent 196µs making 1 call to Class::MOP::Attribute::remove_accessors |
1062 | 1 | 2µs | 1 | 2µs | $self->remove_delegation if $self->has_handles; # spent 2µs making 1 call to Moose::Meta::Mixin::AttributeCore::has_handles |
1063 | 1 | 3µs | return; | ||
1064 | } | ||||
1065 | |||||
1066 | # spent 83.8ms (6.90+76.9) within Moose::Meta::Attribute::install_delegation which was called 35 times, avg 2.39ms/call:
# 35 times (6.90ms+76.9ms) by Moose::Meta::Attribute::install_accessors at line 996, avg 2.39ms/call | ||||
1067 | 35 | 13µs | my $self = shift; | ||
1068 | |||||
1069 | # NOTE: | ||||
1070 | # Here we canonicalize the 'handles' option | ||||
1071 | # this will sort out any details and always | ||||
1072 | # return an hash of methods which we want | ||||
1073 | # to delagate to, see that method for details | ||||
1074 | 35 | 94µs | 35 | 850µs | my %handles = $self->_canonicalize_handles; # spent 520µs making 21 calls to Moose::Meta::Class::__ANON__::SERIAL::1::_canonicalize_handles, avg 25µs/call
# spent 291µs making 11 calls to Moose::Meta::Class::__ANON__::SERIAL::7::_canonicalize_handles, avg 26µs/call
# spent 40µs making 3 calls to Moose::Meta::Attribute::_canonicalize_handles, avg 13µs/call |
1075 | |||||
1076 | # install the delegation ... | ||||
1077 | 35 | 97µs | 35 | 22µs | my $associated_class = $self->associated_class; # spent 22µs making 35 calls to Class::MOP::Attribute::associated_class, avg 626ns/call |
1078 | 35 | 81µs | 35 | 13µs | my $class_name = $associated_class->name; # spent 13µs making 35 calls to Class::MOP::Package::name, avg 371ns/call |
1079 | |||||
1080 | 35 | 227µs | 35 | 22µs | foreach my $handle ( sort keys %handles ) { # spent 22µs making 35 calls to Moose::Meta::Attribute::CORE:sort, avg 620ns/call |
1081 | 56 | 32µs | my $method_to_call = $handles{$handle}; | ||
1082 | 56 | 45µs | my $name = "${class_name}::${handle}"; | ||
1083 | |||||
1084 | 56 | 82µs | 56 | 1.18ms | if ( my $method = $associated_class->get_method($handle) ) { # spent 1.18ms making 56 calls to Class::MOP::Mixin::HasMethods::get_method, avg 21µs/call |
1085 | throw_exception( | ||||
1086 | CannotDelegateLocalMethodIsPresent => attribute => $self, | ||||
1087 | method => $method, | ||||
1088 | ) unless $method->is_stub; | ||||
1089 | } | ||||
1090 | |||||
1091 | # NOTE: | ||||
1092 | # handles is not allowed to delegate | ||||
1093 | # any of these methods, as they will | ||||
1094 | # override the ones in your class, which | ||||
1095 | # is almost certainly not what you want. | ||||
1096 | |||||
1097 | # FIXME warn when $handle was explicitly specified, but not if the source is a regex or something | ||||
1098 | #cluck("Not delegating method '$handle' because it is a core method") and | ||||
1099 | next | ||||
1100 | 56 | 842µs | 168 | 416µs | if $class_name->isa("Moose::Object") # spent 181µs making 56 calls to UNIVERSAL::can, avg 3µs/call
# spent 165µs making 56 calls to Moose::Meta::Attribute::CORE:match, avg 3µs/call
# spent 70µs making 56 calls to UNIVERSAL::isa, avg 1µs/call |
1101 | and $handle =~ /^BUILD|DEMOLISH$/ || Moose::Object->can($handle); | ||||
1102 | |||||
1103 | 56 | 147µs | 56 | 69.8ms | my $method = $self->_make_delegation_method($handle, $method_to_call); # spent 45.7ms making 33 calls to Moose::Meta::Class::__ANON__::SERIAL::1::_make_delegation_method, avg 1.38ms/call
# spent 23.7ms making 17 calls to Moose::Meta::Class::__ANON__::SERIAL::7::_make_delegation_method, avg 1.39ms/call
# spent 507µs making 6 calls to Moose::Meta::Attribute::_make_delegation_method, avg 84µs/call |
1104 | |||||
1105 | 56 | 568µs | 168 | 4.44ms | $self->associated_class->add_method($method->name, $method); # spent 4.31ms making 56 calls to Class::MOP::Mixin::HasMethods::add_method, avg 77µs/call
# spent 87µs making 56 calls to Class::MOP::Attribute::associated_class, avg 2µs/call
# spent 40µs making 56 calls to Class::MOP::Method::name, avg 707ns/call |
1106 | 56 | 180µs | 56 | 132µs | $self->associate_method($method); # spent 132µs making 56 calls to Class::MOP::Attribute::associate_method, avg 2µs/call |
1107 | } | ||||
1108 | } | ||||
1109 | |||||
1110 | sub remove_delegation { | ||||
1111 | my $self = shift; | ||||
1112 | my %handles = $self->_canonicalize_handles; | ||||
1113 | my $associated_class = $self->associated_class; | ||||
1114 | foreach my $handle (keys %handles) { | ||||
1115 | next unless any { $handle eq $_ } | ||||
1116 | map { $_->name } | ||||
1117 | @{ $self->associated_methods }; | ||||
1118 | $self->associated_class->remove_method($handle); | ||||
1119 | } | ||||
1120 | } | ||||
1121 | |||||
1122 | # private methods to help delegation ... | ||||
1123 | |||||
1124 | # spent 40µs (33+7) within Moose::Meta::Attribute::_canonicalize_handles which was called 3 times, avg 13µs/call:
# 3 times (33µs+7µs) by Moose::Meta::Attribute::install_delegation at line 1074, avg 13µs/call | ||||
1125 | 3 | 700ns | my $self = shift; | ||
1126 | 3 | 13µs | 3 | 7µs | my $handles = $self->handles; # spent 7µs making 3 calls to Moose::Meta::Mixin::AttributeCore::handles, avg 2µs/call |
1127 | 3 | 2µs | if (my $handle_type = ref($handles)) { | ||
1128 | 3 | 18µs | if ($handle_type eq 'HASH') { | ||
1129 | return %{$handles}; | ||||
1130 | } | ||||
1131 | elsif ($handle_type eq 'ARRAY') { | ||||
1132 | return map { $_ => $_ } @{$handles}; | ||||
1133 | } | ||||
1134 | elsif ($handle_type eq 'Regexp') { | ||||
1135 | ($self->has_type_constraint) | ||||
1136 | || throw_exception( CannotDelegateWithoutIsa => attribute => $self ); | ||||
1137 | return map { ($_ => $_) } | ||||
1138 | grep { /$handles/ } $self->_get_delegate_method_list; | ||||
1139 | } | ||||
1140 | elsif ($handle_type eq 'CODE') { | ||||
1141 | return $handles->($self, $self->_find_delegate_metaclass); | ||||
1142 | } | ||||
1143 | elsif (blessed($handles) && $handles->isa('Moose::Meta::TypeConstraint::DuckType')) { | ||||
1144 | return map { $_ => $_ } @{ $handles->methods }; | ||||
1145 | } | ||||
1146 | elsif (blessed($handles) && $handles->isa('Moose::Meta::TypeConstraint::Role')) { | ||||
1147 | $handles = $handles->role; | ||||
1148 | } | ||||
1149 | else { | ||||
1150 | throw_exception( UnableToCanonicalizeHandles => attribute => $self, | ||||
1151 | handles => $handles | ||||
1152 | ); | ||||
1153 | } | ||||
1154 | } | ||||
1155 | |||||
1156 | Moose::Util::_load_user_class($handles); | ||||
1157 | my $role_meta = Class::MOP::class_of($handles); | ||||
1158 | |||||
1159 | (blessed $role_meta && $role_meta->isa('Moose::Meta::Role')) | ||||
1160 | || throw_exception( UnableToCanonicalizeNonRolePackage => attribute => $self, | ||||
1161 | handles => $handles | ||||
1162 | ); | ||||
1163 | |||||
1164 | return map { $_ => $_ } | ||||
1165 | map { $_->name } | ||||
1166 | grep { !$_->isa('Class::MOP::Method::Meta') } ( | ||||
1167 | $role_meta->_get_local_methods, | ||||
1168 | $role_meta->get_required_method_list, | ||||
1169 | ); | ||||
1170 | } | ||||
1171 | |||||
1172 | sub _get_delegate_method_list { | ||||
1173 | my $self = shift; | ||||
1174 | my $meta = $self->_find_delegate_metaclass; | ||||
1175 | if ($meta->isa('Class::MOP::Class')) { | ||||
1176 | return map { $_->name } # NOTE: !never! delegate &meta | ||||
1177 | grep { $_->package_name ne 'Moose::Object' && !$_->isa('Class::MOP::Method::Meta') } | ||||
1178 | $meta->get_all_methods; | ||||
1179 | } | ||||
1180 | elsif ($meta->isa('Moose::Meta::Role')) { | ||||
1181 | return $meta->get_method_list; | ||||
1182 | } | ||||
1183 | else { | ||||
1184 | throw_exception( UnableToRecognizeDelegateMetaclass => attribute => $self, | ||||
1185 | delegate_metaclass => $meta | ||||
1186 | ); | ||||
1187 | } | ||||
1188 | } | ||||
1189 | |||||
1190 | sub _find_delegate_metaclass { | ||||
1191 | my $self = shift; | ||||
1192 | my $class = $self->_isa_metadata; | ||||
1193 | my $role = $self->_does_metadata; | ||||
1194 | |||||
1195 | if ( $class ) { | ||||
1196 | # make sure isa is actually a class | ||||
1197 | unless ( $self->type_constraint->isa("Moose::Meta::TypeConstraint::Class") ) { | ||||
1198 | throw_exception( DelegationToATypeWhichIsNotAClass => attribute => $self ); | ||||
1199 | } | ||||
1200 | |||||
1201 | # make sure the class is loaded | ||||
1202 | unless ( Moose::Util::_is_package_loaded($class) ) { | ||||
1203 | throw_exception( DelegationToAClassWhichIsNotLoaded => attribute => $self, | ||||
1204 | class_name => $class | ||||
1205 | ); | ||||
1206 | } | ||||
1207 | # we might be dealing with a non-Moose class, | ||||
1208 | # and need to make our own metaclass. if there's | ||||
1209 | # already a metaclass, it will be returned | ||||
1210 | return Class::MOP::Class->initialize($class); | ||||
1211 | } | ||||
1212 | elsif ( $role ) { | ||||
1213 | unless ( Moose::Util::_is_package_loaded($role) ) { | ||||
1214 | throw_exception( DelegationToARoleWhichIsNotLoaded => attribute => $self, | ||||
1215 | role_name => $role | ||||
1216 | ); | ||||
1217 | } | ||||
1218 | |||||
1219 | return Class::MOP::class_of($role); | ||||
1220 | } | ||||
1221 | else { | ||||
1222 | throw_exception( CannotFindDelegateMetaclass => attribute => $self ); | ||||
1223 | } | ||||
1224 | } | ||||
1225 | |||||
1226 | 106 | 208µs | # spent 123µs within Moose::Meta::Attribute::delegation_metaclass which was called 106 times, avg 1µs/call:
# 100 times (117µs+0s) by Moose::Meta::Attribute::Native::Trait::_native_accessor_class_for at line 136 of Moose/Meta/Attribute/Native/Trait.pm, avg 1µs/call
# 6 times (6µs+0s) by Moose::Meta::Attribute::_make_delegation_method at line 1236, avg 983ns/call | ||
1227 | |||||
1228 | # spent 507µs (59+448) within Moose::Meta::Attribute::_make_delegation_method which was called 6 times, avg 84µs/call:
# 6 times (59µs+448µs) by Moose::Meta::Attribute::install_delegation at line 1103, avg 84µs/call | ||||
1229 | 6 | 3µs | my ( $self, $handle_name, $method_to_call ) = @_; | ||
1230 | |||||
1231 | 6 | 800ns | my @curried_arguments; | ||
1232 | |||||
1233 | 6 | 2µs | ($method_to_call, @curried_arguments) = @$method_to_call | ||
1234 | if 'ARRAY' eq ref($method_to_call); | ||||
1235 | |||||
1236 | 6 | 53µs | 24 | 448µs | return $self->delegation_metaclass->new( # spent 437µs making 6 calls to Moose::Meta::Method::Delegation::new, avg 73µs/call
# spent 6µs making 6 calls to Moose::Meta::Attribute::delegation_metaclass, avg 983ns/call
# spent 3µs making 6 calls to Class::MOP::Attribute::associated_class, avg 517ns/call
# spent 2µs making 6 calls to Class::MOP::Package::name, avg 317ns/call |
1237 | name => $handle_name, | ||||
1238 | package_name => $self->associated_class->name, | ||||
1239 | attribute => $self, | ||||
1240 | delegate_to_method => $method_to_call, | ||||
1241 | curried_arguments => \@curried_arguments, | ||||
1242 | ); | ||||
1243 | } | ||||
1244 | |||||
1245 | # spent 8µs (5+3) within Moose::Meta::Attribute::_coerce_and_verify which was called:
# once (5µs+3µs) by Moose::Meta::Attribute::initialize_instance_slot at line 512 | ||||
1246 | 1 | 200ns | my $self = shift; | ||
1247 | 1 | 200ns | my $val = shift; | ||
1248 | 1 | 200ns | my $instance = shift; | ||
1249 | |||||
1250 | 1 | 6µs | 1 | 2µs | return $val unless $self->has_type_constraint; # spent 2µs making 1 call to Moose::Meta::Mixin::AttributeCore::has_type_constraint |
1251 | |||||
1252 | $val = $self->type_constraint->coerce($val) | ||||
1253 | if $self->should_coerce && $self->type_constraint->has_coercion; | ||||
1254 | |||||
1255 | $self->verify_against_type_constraint($val, instance => $instance); | ||||
1256 | |||||
1257 | return $val; | ||||
1258 | } | ||||
1259 | |||||
1260 | sub verify_against_type_constraint { | ||||
1261 | my $self = shift; | ||||
1262 | my $val = shift; | ||||
1263 | |||||
1264 | return 1 if !$self->has_type_constraint; | ||||
1265 | |||||
1266 | my $type_constraint = $self->type_constraint; | ||||
1267 | |||||
1268 | $type_constraint->check($val) | ||||
1269 | || throw_exception( ValidationFailedForTypeConstraint => type => $type_constraint, | ||||
1270 | value => $val, | ||||
1271 | attribute => $self, | ||||
1272 | ); | ||||
1273 | } | ||||
1274 | |||||
1275 | package Moose::Meta::Attribute::Custom::Moose; | ||||
1276 | 1 | 400ns | our $VERSION = '2.1403'; | ||
1277 | |||||
1278 | sub register_implementation { 'Moose::Meta::Attribute' } | ||||
1279 | 1 | 6µs | 1; | ||
1280 | |||||
1281 | # ABSTRACT: The Moose attribute metaclass | ||||
1282 | |||||
1283 | __END__ | ||||
# spent 165µs within Moose::Meta::Attribute::CORE:match which was called 56 times, avg 3µs/call:
# 56 times (165µs+0s) by Moose::Meta::Attribute::install_delegation at line 1100, avg 3µs/call | |||||
sub Moose::Meta::Attribute::CORE:sort; # opcode |