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