Filename | /home/hinrik/perl5/perlbrew/perls/perl-5.13.5/lib/site_perl/5.13.5/x86_64-linux/Mouse/Meta/Attribute.pm |
Statements | Executed 2983 statements in 16.3ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
68 | 1 | 1 | 3.19ms | 9.20ms | install_accessors | Mouse::Meta::Attribute::
68 | 2 | 2 | 2.39ms | 9.06ms | new | Mouse::Meta::Attribute::
68 | 2 | 2 | 1.37ms | 5.26ms | interpolate_class (recurses: max depth 1, inclusive time 28µs) | Mouse::Meta::Attribute::
1 | 1 | 1 | 1.10ms | 1.20ms | BEGIN@6 | Mouse::Meta::Attribute::
7 | 1 | 1 | 806µs | 2.29ms | clone_and_inherit_options | Mouse::Meta::Attribute::
543 | 7 | 3 | 748µs | 748µs | name (xsub) | Mouse::Meta::Attribute::
68 | 1 | 1 | 636µs | 4.77ms | _process_options (xsub) | Mouse::Meta::Attribute::
90 | 1 | 1 | 481µs | 481µs | associate_method | Mouse::Meta::Attribute::
126 | 3 | 2 | 178µs | 178µs | init_arg (xsub) | Mouse::Meta::Attribute::
130 | 1 | 1 | 166µs | 166µs | insertion_order (xsub) | Mouse::Meta::Attribute::
90 | 2 | 2 | 136µs | 136µs | has_type_constraint (xsub) | Mouse::Meta::Attribute::
89 | 2 | 2 | 126µs | 126µs | type_constraint (xsub) | Mouse::Meta::Attribute::
90 | 2 | 2 | 122µs | 122µs | is_required (xsub) | Mouse::Meta::Attribute::
68 | 1 | 1 | 99µs | 99µs | associated_class (xsub) | Mouse::Meta::Attribute::
68 | 1 | 1 | 97µs | 97µs | is_lazy (xsub) | Mouse::Meta::Attribute::
67 | 1 | 1 | 95µs | 95µs | should_coerce (xsub) | Mouse::Meta::Attribute::
67 | 1 | 1 | 95µs | 95µs | should_auto_deref (xsub) | Mouse::Meta::Attribute::
68 | 1 | 1 | 94µs | 94µs | has_trigger (xsub) | Mouse::Meta::Attribute::
68 | 1 | 1 | 93µs | 93µs | accessor_metaclass (xsub) | Mouse::Meta::Attribute::
68 | 1 | 1 | 93µs | 93µs | has_builder (xsub) | Mouse::Meta::Attribute::
68 | 1 | 1 | 91µs | 91µs | is_weak_ref (xsub) | Mouse::Meta::Attribute::
59 | 1 | 1 | 84µs | 84µs | has_default (xsub) | Mouse::Meta::Attribute::
78 | 1 | 1 | 71µs | 71µs | CORE:match (opcode) | Mouse::Meta::Attribute::
22 | 1 | 1 | 30µs | 30µs | has_documentation (xsub) | Mouse::Meta::Attribute::
22 | 1 | 1 | 27µs | 27µs | documentation (xsub) | Mouse::Meta::Attribute::
16 | 2 | 2 | 25µs | 25µs | default (xsub) | Mouse::Meta::Attribute::
1 | 1 | 1 | 24µs | 96µs | BEGIN@2 | Mouse::Meta::Attribute::
7 | 1 | 1 | 23µs | 23µs | illegal_options_for_inheritance | Mouse::Meta::Attribute::
8 | 8 | 4 | 14µs | 14µs | builder (xsub) | Mouse::Meta::Attribute::
1 | 1 | 1 | 6µs | 6µs | BEGIN@4 | Mouse::Meta::Attribute::
1 | 1 | 1 | 2µs | 2µs | trigger (xsub) | Mouse::Meta::Attribute::
0 | 0 | 0 | 0s | 0s | _canonicalize_handles | Mouse::Meta::Attribute::
0 | 0 | 0 | 0s | 0s | _find_delegate_metaclass | Mouse::Meta::Attribute::
0 | 0 | 0 | 0s | 0s | _get_accessor_method_ref | Mouse::Meta::Attribute::
0 | 0 | 0 | 0s | 0s | _make_delegation_method | Mouse::Meta::Attribute::
0 | 0 | 0 | 0s | 0s | _throw_type_constraint_error | Mouse::Meta::Attribute::
0 | 0 | 0 | 0s | 0s | clear_value | Mouse::Meta::Attribute::
0 | 0 | 0 | 0s | 0s | get_read_method | Mouse::Meta::Attribute::
0 | 0 | 0 | 0s | 0s | get_read_method_ref | Mouse::Meta::Attribute::
0 | 0 | 0 | 0s | 0s | get_value | Mouse::Meta::Attribute::
0 | 0 | 0 | 0s | 0s | get_write_method | Mouse::Meta::Attribute::
0 | 0 | 0 | 0s | 0s | get_write_method_ref | Mouse::Meta::Attribute::
0 | 0 | 0 | 0s | 0s | has_read_method | Mouse::Meta::Attribute::
0 | 0 | 0 | 0s | 0s | has_value | Mouse::Meta::Attribute::
0 | 0 | 0 | 0s | 0s | has_write_method | Mouse::Meta::Attribute::
0 | 0 | 0 | 0s | 0s | set_value | Mouse::Meta::Attribute::
0 | 0 | 0 | 0s | 0s | verify_against_type_constraint | Mouse::Meta::Attribute::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package Mouse::Meta::Attribute; | ||||
2 | 2 | 28µs | 2 | 169µs | # spent 96µs (24+73) within Mouse::Meta::Attribute::BEGIN@2 which was called:
# once (24µs+73µs) by Mouse::BEGIN@16 at line 2 # spent 96µs making 1 call to Mouse::Meta::Attribute::BEGIN@2
# spent 72µs making 1 call to Mouse::Exporter::do_import |
3 | |||||
4 | 2 | 23µs | 1 | 6µs | # spent 6µs within Mouse::Meta::Attribute::BEGIN@4 which was called:
# once (6µs+0s) by Mouse::BEGIN@16 at line 4 # spent 6µs making 1 call to Mouse::Meta::Attribute::BEGIN@4 |
5 | |||||
6 | 2 | 1.44ms | 1 | 1.20ms | # spent 1.20ms (1.10+102µs) within Mouse::Meta::Attribute::BEGIN@6 which was called:
# once (1.10ms+102µs) by Mouse::BEGIN@16 at line 6 # spent 1.20ms making 1 call to Mouse::Meta::Attribute::BEGIN@6 |
7 | |||||
8 | 1 | 21µs | my %valid_options = map { $_ => undef } ( | ||
9 | 'accessor', | ||||
10 | 'auto_deref', | ||||
11 | 'builder', | ||||
12 | 'clearer', | ||||
13 | 'coerce', | ||||
14 | 'default', | ||||
15 | 'documentation', | ||||
16 | 'does', | ||||
17 | 'handles', | ||||
18 | 'init_arg', | ||||
19 | 'insertion_order', | ||||
20 | 'is', | ||||
21 | 'isa', | ||||
22 | 'lazy', | ||||
23 | 'lazy_build', | ||||
24 | 'name', | ||||
25 | 'predicate', | ||||
26 | 'reader', | ||||
27 | 'required', | ||||
28 | 'traits', | ||||
29 | 'trigger', | ||||
30 | 'type_constraint', | ||||
31 | 'weak_ref', | ||||
32 | 'writer', | ||||
33 | |||||
34 | # internally used | ||||
35 | 'associated_class', | ||||
36 | 'associated_methods', | ||||
37 | '__METACLASS__', | ||||
38 | |||||
39 | # Moose defines, but Mouse doesn't | ||||
40 | #'definition_context', | ||||
41 | #'initializer', | ||||
42 | |||||
43 | # special case for AttributeHelpers | ||||
44 | 'provides', | ||||
45 | 'curries', | ||||
46 | ); | ||||
47 | |||||
48 | 1 | 2µs | our @CARP_NOT = qw(Mouse::Meta::Class); | ||
49 | |||||
50 | # spent 9.06ms (2.39+6.67) within Mouse::Meta::Attribute::new which was called 68 times, avg 133µs/call:
# 61 times (2.18ms+6.29ms) by Mouse::Meta::Class::add_attribute at line 232 of Mouse/Meta/Class.pm, avg 139µs/call
# 7 times (216µs+385µs) by Mouse::Meta::Attribute::clone_and_inherit_options at line 196, avg 86µs/call | ||||
51 | 820 | 3.01ms | my $class = shift; | ||
52 | my $name = shift; | ||||
53 | |||||
54 | 68 | 215µs | my $args = $class->Mouse::Object::BUILDARGS(@_); # spent 215µs making 68 calls to Mouse::Object::BUILDARGS, avg 3µs/call | ||
55 | |||||
56 | 1 | 368µs | 142 | 8.91ms | $class->_process_options($name, $args); # spent 4.77ms making 68 calls to Mouse::Meta::Attribute::_process_options, avg 70µs/call
# spent 2.89ms making 63 calls to Mouse::Util::TypeConstraints::find_or_create_isa_type_constraint, avg 46µs/call
# spent 921µs making 4 calls to Mouse::Util::TypeConstraints::find_or_create_does_type_constraint, avg 230µs/call
# spent 323µs making 7 calls to Mouse::Meta::TypeConstraint::is_a_type_of, avg 46µs/call |
57 | |||||
58 | $args->{name} = $name; | ||||
59 | |||||
60 | # check options | ||||
61 | # (1) known by core | ||||
62 | my @bad = grep{ !exists $valid_options{$_} } keys %{$args}; | ||||
63 | |||||
64 | # (2) known by subclasses | ||||
65 | if(@bad && $class ne __PACKAGE__){ | ||||
66 | my %valid_attrs = ( | ||||
67 | map { $_ => undef } | ||||
68 | 36 | 50µs | grep { defined } # spent 50µs making 36 calls to Mouse::Meta::Attribute::init_arg, avg 1µs/call | ||
69 | 1 | 30µs | 40 | 408µs | map { $_->init_arg() } # spent 223µs making 18 calls to Mouse::Meta::Class::__ANON__::2::meta, avg 12µs/call
# spent 120µs making 18 calls to Mouse::Meta::Class::get_all_attributes, avg 7µs/call
# spent 58µs making 1 call to Mouse::Meta::Class::_calculate_all_attributes
# spent 3µs making 1 call to Mouse::Meta::Class::strict_constructor
# spent 2µs making 1 call to Mouse::Meta::Class::is_anon_class
# spent 2µs making 1 call to Mouse::Meta::Class::is_immutable |
70 | $class->meta->get_all_attributes() | ||||
71 | ); | ||||
72 | @bad = grep{ !exists $valid_attrs{$_} } @bad; | ||||
73 | } | ||||
74 | |||||
75 | # (3) bad options found | ||||
76 | if(@bad){ | ||||
77 | Carp::carp( | ||||
78 | "Found unknown argument(s) passed to '$name' attribute constructor in '$class': " | ||||
79 | . Mouse::Util::english_list(@bad)); | ||||
80 | } | ||||
81 | |||||
82 | my $self = bless $args, $class; | ||||
83 | 1 | 179µs | 83 | 2.00ms | if($class ne __PACKAGE__){ # spent 945µs making 28 calls to Mouse::Meta::Class::_initialize_object, avg 34µs/call
# spent 604µs making 17 calls to Mouse::Meta::TypeConstraint::coerce, avg 36µs/call
# spent 215µs making 18 calls to Mouse::Meta::Class::__ANON__::2::meta, avg 12µs/call
# spent 101µs making 8 calls to Mouse::Meta::Class::__ANON__::1::meta, avg 13µs/call
# spent 87µs making 2 calls to Mouse::Meta::Class::_calculate_all_attributes, avg 43µs/call
# spent 27µs making 2 calls to MouseX::Getopt::Meta::Attribute::NoGetopt::meta, avg 14µs/call
# spent 10µs making 2 calls to Mouse::Meta::Class::strict_constructor, avg 5µs/call
# spent 4µs making 2 calls to Mouse::Meta::TypeConstraint::_compiled_type_constraint, avg 2µs/call
# spent 3µs making 2 calls to Mouse::Meta::Class::is_immutable, avg 2µs/call
# spent 3µs making 2 calls to Mouse::Meta::Class::is_anon_class, avg 1µs/call |
84 | $class->meta->_initialize_object($self, $args); | ||||
85 | } | ||||
86 | return $self; | ||||
87 | } | ||||
88 | |||||
89 | sub has_read_method { $_[0]->has_reader || $_[0]->has_accessor } | ||||
90 | sub has_write_method { $_[0]->has_writer || $_[0]->has_accessor } | ||||
91 | |||||
92 | sub get_read_method { $_[0]->reader || $_[0]->accessor } | ||||
93 | sub get_write_method { $_[0]->writer || $_[0]->accessor } | ||||
94 | |||||
95 | sub get_read_method_ref{ | ||||
96 | my($self) = @_; | ||||
97 | return $self->{_mouse_cache_read_method_ref} | ||||
98 | ||= $self->_get_accessor_method_ref('get_read_method', '_generate_reader'); | ||||
99 | } | ||||
100 | |||||
101 | sub get_write_method_ref{ | ||||
102 | my($self) = @_; | ||||
103 | return $self->{_mouse_cache_write_method_ref} | ||||
104 | ||= $self->_get_accessor_method_ref('get_write_method', '_generate_writer'); | ||||
105 | } | ||||
106 | |||||
107 | # spent 5.26ms (1.37+3.89) within Mouse::Meta::Attribute::interpolate_class which was called 68 times, avg 77µs/call:
# 61 times (1.10ms+3.39ms) by Mouse::Meta::Class::add_attribute at line 229 of Mouse/Meta/Class.pm, avg 74µs/call
# 7 times (273µs+496µs) by Mouse::Meta::Attribute::clone_and_inherit_options at line 181, avg 110µs/call | ||||
108 | 522 | 1.36ms | my($class, $args) = @_; | ||
109 | |||||
110 | 2 | 70µs | if(my $metaclass = delete $args->{metaclass}){ # spent 70µs making 2 calls to Mouse::Util::resolve_metaclass_alias, avg 35µs/call | ||
111 | $class = Mouse::Util::resolve_metaclass_alias( Attribute => $metaclass ); | ||||
112 | } | ||||
113 | |||||
114 | my @traits; | ||||
115 | if(my $traits_ref = delete $args->{traits}){ | ||||
116 | |||||
117 | for (my $i = 0; $i < @{$traits_ref}; $i++) { | ||||
118 | 26 | 317µs | my $trait = Mouse::Util::resolve_metaclass_alias(Attribute => $traits_ref->[$i], trait => 1); # spent 317µs making 26 calls to Mouse::Util::resolve_metaclass_alias, avg 12µs/call | ||
119 | |||||
120 | 26 | 80µs | next if $class->does($trait); # spent 80µs making 26 calls to Mouse::Util::does, avg 3µs/call | ||
121 | |||||
122 | push @traits, $trait; | ||||
123 | |||||
124 | # are there options? | ||||
125 | push @traits, $traits_ref->[++$i] | ||||
126 | if ref($traits_ref->[$i+1]); | ||||
127 | } | ||||
128 | |||||
129 | 52 | 3.06ms | if (@traits) { # spent 3.01ms making 26 calls to Mouse::Meta::Class::create_anon_class, avg 116µs/call
# spent 43µs making 26 calls to Mouse::Meta::Module::name, avg 2µs/call | ||
130 | $class = Mouse::Meta::Class->create_anon_class( | ||||
131 | superclasses => [ $class ], | ||||
132 | roles => \@traits, | ||||
133 | cache => 1, | ||||
134 | )->name; | ||||
135 | } | ||||
136 | } | ||||
137 | |||||
138 | return( $class, @traits ); | ||||
139 | } | ||||
140 | |||||
141 | sub verify_against_type_constraint { | ||||
142 | my ($self, $value) = @_; | ||||
143 | |||||
144 | my $type_constraint = $self->{type_constraint}; | ||||
145 | return 1 if !$type_constraint; | ||||
146 | return 1 if $type_constraint->check($value); | ||||
147 | |||||
148 | $self->_throw_type_constraint_error($value, $type_constraint); | ||||
149 | } | ||||
150 | |||||
151 | sub _throw_type_constraint_error { | ||||
152 | my($self, $value, $type) = @_; | ||||
153 | |||||
154 | $self->throw_error( | ||||
155 | sprintf q{Attribute (%s) does not pass the type constraint because: %s}, | ||||
156 | $self->name, | ||||
157 | $type->get_message($value), | ||||
158 | ); | ||||
159 | } | ||||
160 | |||||
161 | # spent 23µs within Mouse::Meta::Attribute::illegal_options_for_inheritance which was called 7 times, avg 3µs/call:
# 7 times (23µs+0s) by Mouse::Meta::Attribute::clone_and_inherit_options at line 169, avg 3µs/call | ||||
162 | 7 | 30µs | return qw(reader writer accessor clearer predicate); | ||
163 | } | ||||
164 | |||||
165 | # spent 2.29ms (806µs+1.49) within Mouse::Meta::Attribute::clone_and_inherit_options which was called 7 times, avg 328µs/call:
# 7 times (806µs+1.49ms) by Mouse::Meta::Class::add_attribute at line 226 of Mouse/Meta/Class.pm, avg 328µs/call | ||||
166 | 247 | 888µs | my $self = shift; | ||
167 | 7 | 14µs | my $args = $self->Mouse::Object::BUILDARGS(@_); # spent 14µs making 7 calls to Mouse::Object::BUILDARGS, avg 2µs/call | ||
168 | |||||
169 | 7 | 23µs | foreach my $illegal($self->illegal_options_for_inheritance) { # spent 23µs making 7 calls to Mouse::Meta::Attribute::illegal_options_for_inheritance, avg 3µs/call | ||
170 | if(exists $args->{$illegal} and exists $self->{$illegal}) { | ||||
171 | $self->throw_error("Illegal inherited option: $illegal"); | ||||
172 | } | ||||
173 | } | ||||
174 | |||||
175 | foreach my $name(keys %{$self}){ | ||||
176 | if(!exists $args->{$name}){ | ||||
177 | $args->{$name} = $self->{$name}; # inherit from self | ||||
178 | } | ||||
179 | } | ||||
180 | |||||
181 | 7 | 769µs | my($attribute_class, @traits) = ref($self)->interpolate_class($args); # spent 769µs making 7 calls to Mouse::Meta::Attribute::interpolate_class, avg 110µs/call | ||
182 | $args->{traits} = \@traits if @traits; | ||||
183 | |||||
184 | # remove temporary caches | ||||
185 | foreach my $attr(keys %{$args}){ | ||||
186 | 78 | 71µs | if($attr =~ /\A _mouse_cache_/xms){ # spent 71µs making 78 calls to Mouse::Meta::Attribute::CORE:match, avg 914ns/call | ||
187 | delete $args->{$attr}; | ||||
188 | } | ||||
189 | } | ||||
190 | |||||
191 | # remove default if lazy_build => 1 | ||||
192 | if($args->{lazy_build}) { | ||||
193 | delete $args->{default}; | ||||
194 | } | ||||
195 | |||||
196 | 14 | 612µs | return $attribute_class->new($self->name, $args); # spent 601µs making 7 calls to Mouse::Meta::Attribute::new, avg 86µs/call
# spent 11µs making 7 calls to Mouse::Meta::Attribute::name, avg 2µs/call | ||
197 | } | ||||
198 | |||||
199 | |||||
200 | sub _get_accessor_method_ref { | ||||
201 | my($self, $type, $generator) = @_; | ||||
202 | |||||
203 | my $metaclass = $self->associated_class | ||||
204 | || $self->throw_error('No asocciated class for ' . $self->name); | ||||
205 | |||||
206 | my $accessor = $self->$type(); | ||||
207 | if($accessor){ | ||||
208 | return $metaclass->get_method_body($accessor); | ||||
209 | } | ||||
210 | else{ | ||||
211 | return $self->accessor_metaclass->$generator($self, $metaclass); | ||||
212 | } | ||||
213 | } | ||||
214 | |||||
215 | sub set_value { | ||||
216 | my($self, $object, $value) = @_; | ||||
217 | return $self->get_write_method_ref()->($object, $value); | ||||
218 | } | ||||
219 | |||||
220 | sub get_value { | ||||
221 | my($self, $object) = @_; | ||||
222 | return $self->get_read_method_ref()->($object); | ||||
223 | } | ||||
224 | |||||
225 | sub has_value { | ||||
226 | my($self, $object) = @_; | ||||
227 | my $accessor_ref = $self->{_mouse_cache_predicate_ref} | ||||
228 | ||= $self->_get_accessor_method_ref('predicate', '_generate_predicate'); | ||||
229 | |||||
230 | return $accessor_ref->($object); | ||||
231 | } | ||||
232 | |||||
233 | sub clear_value { | ||||
234 | my($self, $object) = @_; | ||||
235 | my $accessor_ref = $self->{_mouse_cache_crealer_ref} | ||||
236 | ||= $self->_get_accessor_method_ref('clearer', '_generate_clearer'); | ||||
237 | |||||
238 | return $accessor_ref->($object); | ||||
239 | } | ||||
240 | |||||
241 | # spent 481µs within Mouse::Meta::Attribute::associate_method which was called 90 times, avg 5µs/call:
# 90 times (481µs+0s) by Mouse::Meta::Attribute::install_accessors at line 259, avg 5µs/call | ||||
242 | #my($attribute, $method_name) = @_; | ||||
243 | 270 | 566µs | my($attribute) = @_; | ||
244 | $attribute->{associated_methods}++; | ||||
245 | return; | ||||
246 | } | ||||
247 | |||||
248 | # spent 9.20ms (3.19+6.01) within Mouse::Meta::Attribute::install_accessors which was called 68 times, avg 135µs/call:
# 68 times (3.19ms+6.01ms) by Mouse::Meta::Class::add_attribute at line 239 of Mouse/Meta/Class.pm, avg 135µs/call | ||||
249 | 1108 | 8.20ms | my($attribute) = @_; | ||
250 | |||||
251 | 68 | 99µs | my $metaclass = $attribute->associated_class; # spent 99µs making 68 calls to Mouse::Meta::Attribute::associated_class, avg 1µs/call | ||
252 | 68 | 93µs | my $accessor_class = $attribute->accessor_metaclass; # spent 93µs making 68 calls to Mouse::Meta::Attribute::accessor_metaclass, avg 1µs/call | ||
253 | |||||
254 | foreach my $type(qw(accessor reader writer predicate clearer)){ | ||||
255 | if(exists $attribute->{$type}){ | ||||
256 | my $generator = '_generate_' . $type; | ||||
257 | 1 | 169µs | 925 | 6.21ms | my $code = $accessor_class->$generator($attribute, $metaclass); # spent 2.43ms making 38 calls to Mouse::Meta::Method::Accessor::XS::_generate_accessor, avg 64µs/call
# spent 2.15ms making 30 calls to Mouse::Meta::Method::Accessor::XS::_generate_reader, avg 72µs/call
# spent 300µs making 7 calls to Mouse::Meta::TypeConstraint::is_a_type_of, avg 43µs/call
# spent 133µs making 90 calls to Mouse::Meta::Attribute::name, avg 1µs/call
# spent 105µs making 68 calls to Mouse::Meta::Attribute::has_type_constraint, avg 2µs/call
# spent 98µs making 13 calls to Mouse::Meta::Method::Accessor::XS::_generate_predicate, avg 8µs/call
# spent 97µs making 68 calls to Mouse::Meta::Attribute::is_lazy, avg 1µs/call
# spent 95µs making 67 calls to Mouse::Meta::Attribute::should_coerce, avg 1µs/call
# spent 95µs making 68 calls to Mouse::Meta::Attribute::init_arg, avg 1µs/call
# spent 95µs making 67 calls to Mouse::Meta::Attribute::should_auto_deref, avg 1µs/call
# spent 94µs making 68 calls to Mouse::Meta::Attribute::has_trigger, avg 1µs/call
# spent 93µs making 67 calls to Mouse::Meta::Attribute::type_constraint, avg 1µs/call
# spent 93µs making 68 calls to Mouse::Meta::Attribute::has_builder, avg 1µs/call
# spent 92µs making 68 calls to Mouse::Meta::Attribute::is_required, avg 1µs/call
# spent 91µs making 68 calls to Mouse::Meta::Attribute::is_weak_ref, avg 1µs/call
# spent 84µs making 59 calls to Mouse::Meta::Attribute::has_default, avg 1µs/call
# spent 68µs making 9 calls to Mouse::Meta::Method::Accessor::XS::_generate_clearer, avg 8µs/call
# spent 3µs making 2 calls to Mouse::Meta::TypeConstraint::has_coercion, avg 2µs/call |
258 | 90 | 595µs | $metaclass->add_method($attribute->{$type} => $code); # spent 595µs making 90 calls to Mouse::Meta::Module::add_method, avg 7µs/call | ||
259 | 90 | 481µs | $attribute->associate_method($attribute->{$type}); # spent 481µs making 90 calls to Mouse::Meta::Attribute::associate_method, avg 5µs/call | ||
260 | } | ||||
261 | } | ||||
262 | |||||
263 | # install delegation | ||||
264 | if(exists $attribute->{handles}){ | ||||
265 | my %handles = $attribute->_canonicalize_handles(); | ||||
266 | while(my($handle, $method_to_call) = each %handles){ | ||||
267 | next if Mouse::Object->can($handle); | ||||
268 | |||||
269 | if($metaclass->has_method($handle)) { | ||||
270 | $attribute->throw_error("You cannot overwrite a locally defined method ($handle) with a delegation"); | ||||
271 | } | ||||
272 | |||||
273 | $metaclass->add_method($handle => | ||||
274 | $attribute->_make_delegation_method( | ||||
275 | $handle, $method_to_call)); | ||||
276 | |||||
277 | $attribute->associate_method($handle); | ||||
278 | } | ||||
279 | } | ||||
280 | |||||
281 | return; | ||||
282 | } | ||||
283 | |||||
284 | sub delegation_metaclass() { ## no critic | ||||
285 | 'Mouse::Meta::Method::Delegation' | ||||
286 | } | ||||
287 | |||||
288 | sub _canonicalize_handles { | ||||
289 | my($self) = @_; | ||||
290 | my $handles = $self->{handles}; | ||||
291 | |||||
292 | my $handle_type = ref $handles; | ||||
293 | if ($handle_type eq 'HASH') { | ||||
294 | return %$handles; | ||||
295 | } | ||||
296 | elsif ($handle_type eq 'ARRAY') { | ||||
297 | return map { $_ => $_ } @$handles; | ||||
298 | } | ||||
299 | elsif ($handle_type eq 'Regexp') { | ||||
300 | my $meta = $self->_find_delegate_metaclass(); | ||||
301 | return map { $_ => $_ } | ||||
302 | grep { /$handles/ } | ||||
303 | Mouse::Util::is_a_metarole($meta) | ||||
304 | ? $meta->get_method_list | ||||
305 | : $meta->get_all_method_names; | ||||
306 | } | ||||
307 | elsif ($handle_type eq 'CODE') { | ||||
308 | return $handles->( $self, $self->_find_delegate_metaclass() ); | ||||
309 | } | ||||
310 | else { | ||||
311 | $self->throw_error("Unable to canonicalize the 'handles' option with $handles"); | ||||
312 | } | ||||
313 | } | ||||
314 | |||||
315 | sub _find_delegate_metaclass { | ||||
316 | my($self) = @_; | ||||
317 | my $meta; | ||||
318 | if($self->{isa}) { | ||||
319 | $meta = Mouse::Meta::Class->initialize("$self->{isa}"); | ||||
320 | } | ||||
321 | elsif($self->{does}) { | ||||
322 | $meta = Mouse::Util::get_metaclass_by_name("$self->{does}"); | ||||
323 | } | ||||
324 | defined($meta) or $self->throw_error( | ||||
325 | "Cannot find delegate metaclass for attribute " . $self->name); | ||||
326 | return $meta; | ||||
327 | } | ||||
328 | |||||
329 | |||||
330 | sub _make_delegation_method { | ||||
331 | my($self, $handle, $method_to_call) = @_; | ||||
332 | return Mouse::Util::load_class($self->delegation_metaclass) | ||||
333 | ->_generate_delegation($self, $handle, $method_to_call); | ||||
334 | } | ||||
335 | |||||
336 | 1 | 7µs | 1; | ||
337 | __END__ | ||||
# spent 71µs within Mouse::Meta::Attribute::CORE:match which was called 78 times, avg 914ns/call:
# 78 times (71µs+0s) by Mouse::Meta::Attribute::clone_and_inherit_options at line 186, avg 914ns/call | |||||
# spent 4.77ms (636µs+4.14) within Mouse::Meta::Attribute::_process_options which was called 68 times, avg 70µs/call:
# 68 times (636µs+4.14ms) by Mouse::Meta::Attribute::new at line 56, avg 70µs/call | |||||
# spent 93µs within Mouse::Meta::Attribute::accessor_metaclass which was called 68 times, avg 1µs/call:
# 68 times (93µs+0s) by Mouse::Meta::Attribute::install_accessors at line 252, avg 1µs/call | |||||
# spent 99µs within Mouse::Meta::Attribute::associated_class which was called 68 times, avg 1µs/call:
# 68 times (99µs+0s) by Mouse::Meta::Attribute::install_accessors at line 251, avg 1µs/call | |||||
# spent 14µs within Mouse::Meta::Attribute::builder which was called 8 times, avg 2µs/call:
# once (2µs+0s) by Hailo::Storage::sth at line 116 of lib/Hailo/Storage.pm
# once (2µs+0s) by Hailo::_engine at line 286 of lib/Hailo.pm
# once (2µs+0s) by Hailo::_storage at line 221 of lib/Hailo/Command.pm
# once (2µs+0s) by Hailo::Storage::dbh at line 62 of lib/Hailo/Storage/SQLite.pm
# once (2µs+0s) by Hailo::Storage::dbd_options at line 55 of lib/Hailo/Storage.pm
# once (2µs+0s) by Hailo::_tokenizer at line 288 of lib/Hailo.pm
# once (1µs+0s) by Hailo::Storage::dbi_options at line 39 of lib/Hailo/Storage.pm
# once (1µs+0s) by Hailo::Storage::dbd at line 54 of lib/Hailo/Storage.pm | |||||
# spent 25µs within Mouse::Meta::Attribute::default which was called 16 times, avg 2µs/call:
# 14 times (22µs+0s) by Mouse::Object::new at line 78 of MouseX/Getopt/Basic.pm, avg 2µs/call
# 2 times (3µs+0s) by Mouse::Object::new at line 201 of lib/Hailo.pm, avg 2µs/call | |||||
# spent 27µs within Mouse::Meta::Attribute::documentation which was called 22 times, avg 1µs/call:
# 22 times (27µs+0s) by MouseX::Getopt::Basic::_attrs_to_options at line 214 of MouseX/Getopt/Basic.pm, avg 1µs/call | |||||
# spent 93µs within Mouse::Meta::Attribute::has_builder which was called 68 times, avg 1µs/call:
# 68 times (93µs+0s) by Mouse::Meta::Method::Accessor::XS::_generate_accessor or Mouse::Meta::Method::Accessor::XS::_generate_reader at line 257, avg 1µs/call | |||||
# spent 84µs within Mouse::Meta::Attribute::has_default which was called 59 times, avg 1µs/call:
# 59 times (84µs+0s) by Mouse::Meta::Method::Accessor::XS::_generate_accessor or Mouse::Meta::Method::Accessor::XS::_generate_reader at line 257, avg 1µs/call | |||||
# spent 30µs within Mouse::Meta::Attribute::has_documentation which was called 22 times, avg 1µs/call:
# 22 times (30µs+0s) by MouseX::Getopt::Basic::_attrs_to_options at line 214 of MouseX/Getopt/Basic.pm, avg 1µs/call | |||||
# spent 94µs within Mouse::Meta::Attribute::has_trigger which was called 68 times, avg 1µs/call:
# 68 times (94µs+0s) by Mouse::Meta::Method::Accessor::XS::_generate_accessor or Mouse::Meta::Method::Accessor::XS::_generate_reader at line 257, avg 1µs/call | |||||
# spent 136µs within Mouse::Meta::Attribute::has_type_constraint which was called 90 times, avg 2µs/call:
# 68 times (105µs+0s) by Mouse::Meta::Method::Accessor::XS::_generate_accessor or Mouse::Meta::Method::Accessor::XS::_generate_reader at line 257, avg 2µs/call
# 22 times (31µs+0s) by MouseX::Getopt::Basic::_attrs_to_options at line 204 of MouseX/Getopt/Basic.pm, avg 1µs/call | |||||
# spent 178µs within Mouse::Meta::Attribute::init_arg which was called 126 times, avg 1µs/call:
# 68 times (95µs+0s) by Mouse::Meta::Method::Accessor::XS::_generate_accessor or Mouse::Meta::Method::Accessor::XS::_generate_reader at line 257, avg 1µs/call
# 36 times (50µs+0s) by Mouse::Meta::Attribute::new at line 68, avg 1µs/call
# 22 times (34µs+0s) by MouseX::Getopt::Basic::_attrs_to_options at line 214 of MouseX/Getopt/Basic.pm, avg 2µs/call | |||||
# spent 166µs within Mouse::Meta::Attribute::insertion_order which was called 130 times, avg 1µs/call:
# 130 times (166µs+0s) by MouseX::Getopt::Basic::CORE:sort at line 168 of MouseX/Getopt/Basic.pm, avg 1µs/call | |||||
# spent 97µs within Mouse::Meta::Attribute::is_lazy which was called 68 times, avg 1µs/call:
# 68 times (97µs+0s) by Mouse::Meta::Method::Accessor::XS::_generate_accessor or Mouse::Meta::Method::Accessor::XS::_generate_reader at line 257, avg 1µs/call | |||||
# spent 122µs within Mouse::Meta::Attribute::is_required which was called 90 times, avg 1µs/call:
# 68 times (92µs+0s) by Mouse::Meta::Method::Accessor::XS::_generate_accessor or Mouse::Meta::Method::Accessor::XS::_generate_reader at line 257, avg 1µs/call
# 22 times (30µs+0s) by MouseX::Getopt::Basic::_attrs_to_options at line 214 of MouseX/Getopt/Basic.pm, avg 1µs/call | |||||
# spent 91µs within Mouse::Meta::Attribute::is_weak_ref which was called 68 times, avg 1µs/call:
# 68 times (91µs+0s) by Mouse::Meta::Method::Accessor::XS::_generate_accessor or Mouse::Meta::Method::Accessor::XS::_generate_reader at line 257, avg 1µs/call | |||||
# spent 748µs within Mouse::Meta::Attribute::name which was called 543 times, avg 1µs/call:
# 352 times (471µs+0s) by Mouse::Meta::Class::_calculate_all_attributes at line 259 of Mouse/Meta/Class.pm, avg 1µs/call
# 90 times (133µs+0s) by Mouse::Meta::Method::Accessor::XS::_generate_accessor or Mouse::Meta::Method::Accessor::XS::_generate_clearer or Mouse::Meta::Method::Accessor::XS::_generate_predicate or Mouse::Meta::Method::Accessor::XS::_generate_reader at line 257, avg 1µs/call
# 39 times (51µs+0s) by Mouse::Meta::Class::find_attribute_by_name at line 195 of Mouse/Meta/Class.pm, avg 1µs/call
# 22 times (33µs+0s) by MouseX::Getopt::Basic::_attrs_to_options at line 204 of MouseX/Getopt/Basic.pm, avg 1µs/call
# 22 times (32µs+0s) by MouseX::Getopt::Basic::_get_cmd_flags_for_attr at line 181 of MouseX/Getopt/Basic.pm, avg 1µs/call
# 11 times (17µs+0s) by MouseX::Getopt::Basic::_compute_getopt_attrs at line 168 of MouseX/Getopt/Basic.pm, avg 2µs/call
# 7 times (11µs+0s) by Mouse::Meta::Attribute::clone_and_inherit_options at line 196, avg 2µs/call | |||||
# spent 95µs within Mouse::Meta::Attribute::should_auto_deref which was called 67 times, avg 1µs/call:
# 67 times (95µs+0s) by Mouse::Meta::Method::Accessor::XS::_generate_accessor or Mouse::Meta::Method::Accessor::XS::_generate_reader at line 257, avg 1µs/call | |||||
# spent 95µs within Mouse::Meta::Attribute::should_coerce which was called 67 times, avg 1µs/call:
# 67 times (95µs+0s) by Mouse::Meta::Method::Accessor::XS::_generate_accessor or Mouse::Meta::Method::Accessor::XS::_generate_reader at line 257, avg 1µs/call | |||||
# spent 2µs within Mouse::Meta::Attribute::trigger which was called:
# once (2µs+0s) by Mouse::Object::new at line 78 of MouseX/Getopt/Basic.pm | |||||
# spent 126µs within Mouse::Meta::Attribute::type_constraint which was called 89 times, avg 1µs/call:
# 67 times (93µs+0s) by Mouse::Meta::Method::Accessor::XS::_generate_accessor or Mouse::Meta::Method::Accessor::XS::_generate_reader at line 257, avg 1µs/call
# 22 times (33µs+0s) by MouseX::Getopt::Basic::_attrs_to_options at line 208 of MouseX/Getopt/Basic.pm, avg 1µs/call |