Filename | /opt/perl-5.18.1/lib/site_perl/5.18.1/darwin-thread-multi-2level/Mouse/Util/TypeConstraints.pm |
Statements | Executed 63 statements in 3.16ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 31µs | 70µs | _define_type | Mouse::Util::TypeConstraints::
2 | 1 | 1 | 20µs | 22µs | find_or_parse_type_constraint | Mouse::Util::TypeConstraints::
1 | 1 | 1 | 15µs | 46µs | BEGIN@2 | Mouse::Util::TypeConstraints::
1 | 1 | 1 | 13µs | 15µs | find_type_constraint | Mouse::Util::TypeConstraints::
2 | 2 | 2 | 12µs | 34µs | find_or_create_isa_type_constraint | Mouse::Util::TypeConstraints::
1 | 1 | 1 | 11µs | 97µs | class_type | Mouse::Util::TypeConstraints::
1 | 1 | 1 | 9µs | 13µs | BEGIN@5 | Mouse::Util::TypeConstraints::
1 | 1 | 1 | 5µs | 5µs | BEGIN@4 | Mouse::Util::TypeConstraints::
1 | 1 | 1 | 5µs | 75µs | subtype | Mouse::Util::TypeConstraints::
1 | 1 | 1 | 4µs | 4µs | BEGIN@7 | Mouse::Util::TypeConstraints::
1 | 1 | 1 | 4µs | 4µs | BEGIN@8 | Mouse::Util::TypeConstraints::
1 | 1 | 1 | 4µs | 4µs | CORE:match (opcode) | Mouse::Util::TypeConstraints::
1 | 1 | 1 | 2µs | 2µs | CORE:subst (opcode) | Mouse::Util::TypeConstraints::
0 | 0 | 0 | 0s | 0s | __ANON__[:217] | Mouse::Util::TypeConstraints::
0 | 0 | 0 | 0s | 0s | __ANON__[:246] | Mouse::Util::TypeConstraints::
0 | 0 | 0 | 0s | 0s | __ANON__[:266] | Mouse::Util::TypeConstraints::
0 | 0 | 0 | 0s | 0s | _find_or_create_parameterized_type | Mouse::Util::TypeConstraints::
0 | 0 | 0 | 0s | 0s | _find_or_create_regular_type | Mouse::Util::TypeConstraints::
0 | 0 | 0 | 0s | 0s | _find_or_create_union_type | Mouse::Util::TypeConstraints::
0 | 0 | 0 | 0s | 0s | _parse_name | Mouse::Util::TypeConstraints::
0 | 0 | 0 | 0s | 0s | _parse_param | Mouse::Util::TypeConstraints::
0 | 0 | 0 | 0s | 0s | _parse_single_type | Mouse::Util::TypeConstraints::
0 | 0 | 0 | 0s | 0s | _parse_type | Mouse::Util::TypeConstraints::
0 | 0 | 0 | 0s | 0s | as | Mouse::Util::TypeConstraints::
0 | 0 | 0 | 0s | 0s | coerce | Mouse::Util::TypeConstraints::
0 | 0 | 0 | 0s | 0s | duck_type | Mouse::Util::TypeConstraints::
0 | 0 | 0 | 0s | 0s | enum | Mouse::Util::TypeConstraints::
0 | 0 | 0 | 0s | 0s | find_or_create_does_type_constraint | Mouse::Util::TypeConstraints::
0 | 0 | 0 | 0s | 0s | from | Mouse::Util::TypeConstraints::
0 | 0 | 0 | 0s | 0s | list_all_builtin_type_constraints | Mouse::Util::TypeConstraints::
0 | 0 | 0 | 0s | 0s | list_all_type_constraints | Mouse::Util::TypeConstraints::
0 | 0 | 0 | 0s | 0s | maybe_type | Mouse::Util::TypeConstraints::
0 | 0 | 0 | 0s | 0s | message | Mouse::Util::TypeConstraints::
0 | 0 | 0 | 0s | 0s | optimize_as | Mouse::Util::TypeConstraints::
0 | 0 | 0 | 0s | 0s | optimized_constraints | Mouse::Util::TypeConstraints::
0 | 0 | 0 | 0s | 0s | register_type_constraint | Mouse::Util::TypeConstraints::
0 | 0 | 0 | 0s | 0s | role_type | Mouse::Util::TypeConstraints::
0 | 0 | 0 | 0s | 0s | type | Mouse::Util::TypeConstraints::
0 | 0 | 0 | 0s | 0s | via | Mouse::Util::TypeConstraints::
0 | 0 | 0 | 0s | 0s | where | Mouse::Util::TypeConstraints::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package Mouse::Util::TypeConstraints; | ||||
2 | 2 | 45µs | 2 | 77µs | # spent 46µs (15+31) within Mouse::Util::TypeConstraints::BEGIN@2 which was called:
# once (15µs+31µs) by Mouse::BEGIN@18 at line 2 # spent 46µs making 1 call to Mouse::Util::TypeConstraints::BEGIN@2
# spent 31µs making 1 call to Mouse::Exporter::do_import |
3 | |||||
4 | 2 | 31µs | 1 | 5µs | # spent 5µs within Mouse::Util::TypeConstraints::BEGIN@4 which was called:
# once (5µs+0s) by Mouse::BEGIN@18 at line 4 # spent 5µs making 1 call to Mouse::Util::TypeConstraints::BEGIN@4 |
5 | 2 | 29µs | 2 | 18µs | # spent 13µs (9+5) within Mouse::Util::TypeConstraints::BEGIN@5 which was called:
# once (9µs+5µs) by Mouse::BEGIN@18 at line 5 # spent 13µs making 1 call to Mouse::Util::TypeConstraints::BEGIN@5
# spent 4µs making 1 call to Mouse::Exporter::import |
6 | |||||
7 | 2 | 26µs | 1 | 4µs | # spent 4µs within Mouse::Util::TypeConstraints::BEGIN@7 which was called:
# once (4µs+0s) by Mouse::BEGIN@18 at line 7 # spent 4µs making 1 call to Mouse::Util::TypeConstraints::BEGIN@7 |
8 | 2 | 2.80ms | 1 | 4µs | # spent 4µs within Mouse::Util::TypeConstraints::BEGIN@8 which was called:
# once (4µs+0s) by Mouse::BEGIN@18 at line 8 # spent 4µs making 1 call to Mouse::Util::TypeConstraints::BEGIN@8 |
9 | |||||
10 | 1 | 7µs | 1 | 142µs | Mouse::Exporter->setup_import_methods( # spent 142µs making 1 call to Mouse::Exporter::setup_import_methods |
11 | as_is => [qw( | ||||
12 | as where message optimize_as | ||||
13 | from via | ||||
14 | |||||
15 | type subtype class_type role_type maybe_type duck_type | ||||
16 | enum | ||||
17 | coerce | ||||
18 | |||||
19 | find_type_constraint | ||||
20 | register_type_constraint | ||||
21 | )], | ||||
22 | ); | ||||
23 | |||||
24 | 1 | 1µs | our @CARP_NOT = qw(Mouse::Meta::Attribute); | ||
25 | |||||
26 | 1 | 100ns | my %TYPE; | ||
27 | |||||
28 | # The root type | ||||
29 | 1 | 2µs | 1 | 19µs | $TYPE{Any} = Mouse::Meta::TypeConstraint->new( # spent 19µs making 1 call to Mouse::Meta::TypeConstraint::new |
30 | name => 'Any', | ||||
31 | ); | ||||
32 | |||||
33 | 1 | 11µs | my @builtins = ( | ||
34 | # $name => $parent, $code, | ||||
35 | |||||
36 | # the base type | ||||
37 | Item => 'Any', undef, | ||||
38 | |||||
39 | # the maybe[] type | ||||
40 | Maybe => 'Item', undef, | ||||
41 | |||||
42 | # value types | ||||
43 | Undef => 'Item', \&Undef, | ||||
44 | Defined => 'Item', \&Defined, | ||||
45 | Bool => 'Item', \&Bool, | ||||
46 | Value => 'Defined', \&Value, | ||||
47 | Str => 'Value', \&Str, | ||||
48 | Num => 'Str', \&Num, | ||||
49 | Int => 'Num', \&Int, | ||||
50 | |||||
51 | # ref types | ||||
52 | Ref => 'Defined', \&Ref, | ||||
53 | ScalarRef => 'Ref', \&ScalarRef, | ||||
54 | ArrayRef => 'Ref', \&ArrayRef, | ||||
55 | HashRef => 'Ref', \&HashRef, | ||||
56 | CodeRef => 'Ref', \&CodeRef, | ||||
57 | RegexpRef => 'Ref', \&RegexpRef, | ||||
58 | GlobRef => 'Ref', \&GlobRef, | ||||
59 | |||||
60 | # object types | ||||
61 | FileHandle => 'GlobRef', \&FileHandle, | ||||
62 | Object => 'Ref', \&Object, | ||||
63 | |||||
64 | # special string types | ||||
65 | ClassName => 'Str', \&ClassName, | ||||
66 | RoleName => 'ClassName', \&RoleName, | ||||
67 | ); | ||||
68 | |||||
69 | 1 | 63µs | 20 | 318µs | while (my ($name, $parent, $code) = splice @builtins, 0, 3) { # spent 318µs making 20 calls to Mouse::Meta::TypeConstraint::new, avg 16µs/call |
70 | $TYPE{$name} = Mouse::Meta::TypeConstraint->new( | ||||
71 | name => $name, | ||||
72 | parent => $TYPE{$parent}, | ||||
73 | optimized => $code, | ||||
74 | ); | ||||
75 | } | ||||
76 | |||||
77 | # parametarizable types | ||||
78 | 1 | 800ns | $TYPE{Maybe} {constraint_generator} = \&_parameterize_Maybe_for; | ||
79 | 1 | 500ns | $TYPE{ArrayRef}{constraint_generator} = \&_parameterize_ArrayRef_for; | ||
80 | 1 | 400ns | $TYPE{HashRef} {constraint_generator} = \&_parameterize_HashRef_for; | ||
81 | |||||
82 | # sugars | ||||
83 | sub as ($) { (as => $_[0]) } ## no critic | ||||
84 | sub where (&) { (where => $_[0]) } ## no critic | ||||
85 | sub message (&) { (message => $_[0]) } ## no critic | ||||
86 | sub optimize_as (&) { (optimize_as => $_[0]) } ## no critic | ||||
87 | |||||
88 | sub from { @_ } | ||||
89 | sub via (&) { $_[0] } ## no critic | ||||
90 | |||||
91 | # type utilities | ||||
92 | |||||
93 | sub optimized_constraints { # DEPRECATED | ||||
94 | Carp::cluck('optimized_constraints() has been deprecated'); | ||||
95 | return \%TYPE; | ||||
96 | } | ||||
97 | |||||
98 | 1 | 500ns | undef @builtins; # free the allocated memory | ||
99 | 1 | 5µs | @builtins = keys %TYPE; # reuse it | ||
100 | sub list_all_builtin_type_constraints { @builtins } | ||||
101 | sub list_all_type_constraints { keys %TYPE } | ||||
102 | |||||
103 | # spent 70µs (31+39) within Mouse::Util::TypeConstraints::_define_type which was called:
# once (31µs+39µs) by Mouse::Util::TypeConstraints::subtype at line 183 | ||||
104 | 1 | 300ns | my $is_subtype = shift; | ||
105 | 1 | 100ns | my $name; | ||
106 | 1 | 200ns | my %args; | ||
107 | |||||
108 | 1 | 5µs | if(@_ == 1 && ref $_[0] ){ # @_ : { name => $name, where => ... } | ||
109 | %args = %{$_[0]}; | ||||
110 | } | ||||
111 | elsif(@_ == 2 && ref $_[1]) { # @_ : $name => { where => ... } | ||||
112 | $name = $_[0]; | ||||
113 | %args = %{$_[1]}; | ||||
114 | } | ||||
115 | elsif(@_ % 2) { # @_ : $name => ( where => ... ) | ||||
116 | ($name, %args) = @_; | ||||
117 | } | ||||
118 | else{ # @_ : (name => $name, where => ...) | ||||
119 | %args = @_; | ||||
120 | } | ||||
121 | |||||
122 | 1 | 100ns | if(!defined $name){ | ||
123 | $name = $args{name}; | ||||
124 | } | ||||
125 | |||||
126 | 1 | 400ns | $args{name} = $name; | ||
127 | |||||
128 | 1 | 700ns | my $parent = delete $args{as}; | ||
129 | 1 | 200ns | if($is_subtype && !$parent){ | ||
130 | $parent = delete $args{name}; | ||||
131 | $name = undef; | ||||
132 | } | ||||
133 | |||||
134 | 1 | 2µs | 1 | 17µs | if(defined $parent) { # spent 17µs making 1 call to Mouse::Util::TypeConstraints::find_or_create_isa_type_constraint |
135 | $args{parent} = find_or_create_isa_type_constraint($parent); | ||||
136 | } | ||||
137 | |||||
138 | 1 | 300ns | if(defined $name){ | ||
139 | # set 'package_defined_in' only if it is not a core package | ||||
140 | 1 | 300ns | my $this = $args{package_defined_in}; | ||
141 | 1 | 200ns | if(!$this){ | ||
142 | 1 | 600ns | $this = caller(1); | ||
143 | 1 | 9µs | 1 | 4µs | if($this !~ /\A Mouse \b/xms){ # spent 4µs making 1 call to Mouse::Util::TypeConstraints::CORE:match |
144 | $args{package_defined_in} = $this; | ||||
145 | } | ||||
146 | } | ||||
147 | |||||
148 | 1 | 500ns | if(defined $TYPE{$name}){ | ||
149 | my $that = $TYPE{$name}->{package_defined_in} || __PACKAGE__; | ||||
150 | if($this ne $that) { | ||||
151 | my $note = ''; | ||||
152 | if($that eq __PACKAGE__) { | ||||
153 | $note = sprintf " ('%s' is %s type constraint)", | ||||
154 | $name, | ||||
155 | scalar(grep { $name eq $_ } list_all_builtin_type_constraints()) | ||||
156 | ? 'a builtin' | ||||
157 | : 'an implicitly created'; | ||||
158 | } | ||||
159 | Carp::croak("The type constraint '$name' has already been created in $that" | ||||
160 | . " and cannot be created again in $this" . $note); | ||||
161 | } | ||||
162 | } | ||||
163 | } | ||||
164 | |||||
165 | 1 | 300ns | $args{constraint} = delete $args{where} if exists $args{where}; | ||
166 | 1 | 1µs | $args{optimized} = delete $args{optimized_as} if exists $args{optimized_as}; | ||
167 | |||||
168 | 1 | 4µs | 1 | 18µs | my $constraint = Mouse::Meta::TypeConstraint->new(%args); # spent 18µs making 1 call to Mouse::Meta::TypeConstraint::new |
169 | |||||
170 | 1 | 5µs | if(defined $name){ | ||
171 | return $TYPE{$name} = $constraint; | ||||
172 | } | ||||
173 | else{ | ||||
174 | return $constraint; | ||||
175 | } | ||||
176 | } | ||||
177 | |||||
178 | sub type { | ||||
179 | return _define_type 0, @_; | ||||
180 | } | ||||
181 | |||||
182 | # spent 75µs (5+70) within Mouse::Util::TypeConstraints::subtype which was called:
# once (5µs+70µs) by Mouse::Util::TypeConstraints::class_type at line 200 | ||||
183 | 1 | 4µs | 1 | 70µs | return _define_type 1, @_; # spent 70µs making 1 call to Mouse::Util::TypeConstraints::_define_type |
184 | } | ||||
185 | |||||
186 | sub coerce { # coerce $type, from $from, via { ... }, ... | ||||
187 | my $type_name = shift; | ||||
188 | my $type = find_type_constraint($type_name) | ||||
189 | or Carp::croak("Cannot find type '$type_name', perhaps you forgot to load it"); | ||||
190 | |||||
191 | $type->_add_type_coercions(@_); | ||||
192 | return; | ||||
193 | } | ||||
194 | |||||
195 | # spent 97µs (11+86) within Mouse::Util::TypeConstraints::class_type which was called:
# once (11µs+86µs) by Mouse::init_meta at line 143 of Mouse.pm | ||||
196 | 1 | 300ns | my($name, $options) = @_; | ||
197 | 1 | 600ns | my $class = $options->{class} || $name; | ||
198 | |||||
199 | # ClassType | ||||
200 | 1 | 21µs | 2 | 86µs | return subtype $name => ( # spent 75µs making 1 call to Mouse::Util::TypeConstraints::subtype
# spent 11µs making 1 call to Mouse::Util::generate_isa_predicate_for |
201 | as => 'Object', | ||||
202 | optimized_as => Mouse::Util::generate_isa_predicate_for($class), | ||||
203 | class => $class, | ||||
204 | ); | ||||
205 | } | ||||
206 | |||||
207 | sub role_type { | ||||
208 | my($name, $options) = @_; | ||||
209 | my $role = $options->{role} || $name; | ||||
210 | |||||
211 | # RoleType | ||||
212 | return subtype $name => ( | ||||
213 | as => 'Object', | ||||
214 | optimized_as => sub { | ||||
215 | return Scalar::Util::blessed($_[0]) | ||||
216 | && Mouse::Util::does_role($_[0], $role); | ||||
217 | }, | ||||
218 | role => $role, | ||||
219 | ); | ||||
220 | } | ||||
221 | |||||
222 | sub maybe_type { | ||||
223 | my $param = shift; | ||||
224 | return _find_or_create_parameterized_type($TYPE{Maybe}, $param); | ||||
225 | } | ||||
226 | |||||
227 | sub duck_type { | ||||
228 | my($name, @methods); | ||||
229 | |||||
230 | if(ref($_[0]) ne 'ARRAY'){ | ||||
231 | $name = shift; | ||||
232 | } | ||||
233 | |||||
234 | @methods = (@_ == 1 && ref($_[0]) eq 'ARRAY') ? @{$_[0]} : @_; | ||||
235 | |||||
236 | # DuckType | ||||
237 | return _define_type 1, $name => ( | ||||
238 | as => 'Object', | ||||
239 | optimized_as => Mouse::Util::generate_can_predicate_for(\@methods), | ||||
240 | message => sub { | ||||
241 | my($object) = @_; | ||||
242 | my @missing = grep { !$object->can($_) } @methods; | ||||
243 | return ref($object) | ||||
244 | . ' is missing methods ' | ||||
245 | . Mouse::Util::quoted_english_list(@missing); | ||||
246 | }, | ||||
247 | methods => \@methods, | ||||
248 | ); | ||||
249 | } | ||||
250 | |||||
251 | sub enum { | ||||
252 | my($name, %valid); | ||||
253 | |||||
254 | if(!(@_ == 1 && ref($_[0]) eq 'ARRAY')){ | ||||
255 | $name = shift; | ||||
256 | } | ||||
257 | |||||
258 | %valid = map{ $_ => undef } | ||||
259 | (@_ == 1 && ref($_[0]) eq 'ARRAY' ? @{$_[0]} : @_); | ||||
260 | |||||
261 | # EnumType | ||||
262 | return _define_type 1, $name => ( | ||||
263 | as => 'Str', | ||||
264 | optimized_as => sub{ | ||||
265 | return defined($_[0]) && !ref($_[0]) && exists $valid{$_[0]}; | ||||
266 | }, | ||||
267 | ); | ||||
268 | } | ||||
269 | |||||
270 | sub _find_or_create_regular_type{ | ||||
271 | my($spec, $create) = @_; | ||||
272 | |||||
273 | return $TYPE{$spec} if exists $TYPE{$spec}; | ||||
274 | |||||
275 | my $meta = Mouse::Util::get_metaclass_by_name($spec); | ||||
276 | |||||
277 | if(!defined $meta){ | ||||
278 | return $create ? class_type($spec) : undef; | ||||
279 | } | ||||
280 | |||||
281 | if(Mouse::Util::is_a_metarole($meta)){ | ||||
282 | return role_type($spec); | ||||
283 | } | ||||
284 | else{ | ||||
285 | return class_type($spec); | ||||
286 | } | ||||
287 | } | ||||
288 | |||||
289 | sub _find_or_create_parameterized_type{ | ||||
290 | my($base, $param) = @_; | ||||
291 | |||||
292 | my $name = sprintf '%s[%s]', $base->name, $param->name; | ||||
293 | |||||
294 | $TYPE{$name} ||= $base->parameterize($param, $name); | ||||
295 | } | ||||
296 | |||||
297 | sub _find_or_create_union_type{ | ||||
298 | return if grep{ not defined } @_; # all things must be defined | ||||
299 | my @types = sort | ||||
300 | map{ $_->{type_constraints} ? @{$_->{type_constraints}} : $_ } @_; | ||||
301 | |||||
302 | my $name = join '|', @types; | ||||
303 | |||||
304 | # UnionType | ||||
305 | $TYPE{$name} ||= Mouse::Meta::TypeConstraint->new( | ||||
306 | name => $name, | ||||
307 | type_constraints => \@types, | ||||
308 | ); | ||||
309 | } | ||||
310 | |||||
311 | # The type parser | ||||
312 | |||||
313 | # param : '[' type ']' | NOTHING | ||||
314 | sub _parse_param { | ||||
315 | my($c) = @_; | ||||
316 | |||||
317 | if($c->{spec} =~ s/^\[//){ | ||||
318 | my $type = _parse_type($c, 1); | ||||
319 | |||||
320 | if($c->{spec} =~ s/^\]//){ | ||||
321 | return $type; | ||||
322 | } | ||||
323 | Carp::croak("Syntax error in type: missing right square bracket in '$c->{orig}'"); | ||||
324 | } | ||||
325 | |||||
326 | return undef; | ||||
327 | } | ||||
328 | |||||
329 | # name : [\w.:]+ | ||||
330 | sub _parse_name { | ||||
331 | my($c, $create) = @_; | ||||
332 | |||||
333 | if($c->{spec} =~ s/\A ([\w.:]+) //xms){ | ||||
334 | return _find_or_create_regular_type($1, $create); | ||||
335 | } | ||||
336 | Carp::croak("Syntax error in type: expect type name near '$c->{spec}' in '$c->{orig}'"); | ||||
337 | } | ||||
338 | |||||
339 | # single_type : name param | ||||
340 | sub _parse_single_type { | ||||
341 | my($c, $create) = @_; | ||||
342 | |||||
343 | my $type = _parse_name($c, $create); | ||||
344 | my $param = _parse_param($c); | ||||
345 | |||||
346 | if(defined $type){ | ||||
347 | if(defined $param){ | ||||
348 | return _find_or_create_parameterized_type($type, $param); | ||||
349 | } | ||||
350 | else { | ||||
351 | return $type; | ||||
352 | } | ||||
353 | } | ||||
354 | elsif(defined $param){ | ||||
355 | Carp::croak("Undefined type with parameter [$param] in '$c->{orig}'"); | ||||
356 | } | ||||
357 | else{ | ||||
358 | return undef; | ||||
359 | } | ||||
360 | } | ||||
361 | |||||
362 | # type : single_type ('|' single_type)* | ||||
363 | sub _parse_type { | ||||
364 | my($c, $create) = @_; | ||||
365 | |||||
366 | my $type = _parse_single_type($c, $create); | ||||
367 | if($c->{spec}){ # can be an union type | ||||
368 | my @types; | ||||
369 | while($c->{spec} =~ s/^\|//){ | ||||
370 | push @types, _parse_single_type($c, $create); | ||||
371 | } | ||||
372 | if(@types){ | ||||
373 | return _find_or_create_union_type($type, @types); | ||||
374 | } | ||||
375 | } | ||||
376 | return $type; | ||||
377 | } | ||||
378 | |||||
379 | |||||
380 | # spent 15µs (13+3) within Mouse::Util::TypeConstraints::find_type_constraint which was called:
# once (13µs+3µs) by Mouse::init_meta at line 143 of Mouse.pm | ||||
381 | 1 | 400ns | my($spec) = @_; | ||
382 | 1 | 6µs | 1 | 800ns | return $spec if Mouse::Util::is_a_type_constraint($spec) or not defined $spec; # spent 800ns making 1 call to Mouse::Util::is_a_type_constraint |
383 | |||||
384 | 1 | 6µs | 1 | 2µs | $spec =~ s/\s+//g; # spent 2µs making 1 call to Mouse::Util::TypeConstraints::CORE:subst |
385 | 1 | 4µs | return $TYPE{$spec}; | ||
386 | } | ||||
387 | |||||
388 | sub register_type_constraint { | ||||
389 | my($constraint) = @_; | ||||
390 | Carp::croak("No type supplied / type is not a valid type constraint") | ||||
391 | unless Mouse::Util::is_a_type_constraint($constraint); | ||||
392 | return $TYPE{$constraint->name} = $constraint; | ||||
393 | } | ||||
394 | |||||
395 | # spent 22µs (20+2) within Mouse::Util::TypeConstraints::find_or_parse_type_constraint which was called 2 times, avg 11µs/call:
# 2 times (20µs+2µs) by Mouse::Util::TypeConstraints::find_or_create_isa_type_constraint at line 427, avg 11µs/call | ||||
396 | 2 | 900ns | my($spec) = @_; | ||
397 | 2 | 9µs | 2 | 2µs | return $spec if Mouse::Util::is_a_type_constraint($spec) or not defined $spec; # spent 2µs making 2 calls to Mouse::Util::is_a_type_constraint, avg 800ns/call |
398 | |||||
399 | 2 | 6µs | $spec =~ tr/ \t\r\n//d; | ||
400 | |||||
401 | 2 | 1µs | my $tc = $TYPE{$spec}; | ||
402 | 2 | 8µs | if(defined $tc) { | ||
403 | return $tc; | ||||
404 | } | ||||
405 | |||||
406 | my %context = ( | ||||
407 | spec => $spec, | ||||
408 | orig => $spec, | ||||
409 | ); | ||||
410 | $tc = _parse_type(\%context); | ||||
411 | |||||
412 | if($context{spec}){ | ||||
413 | Carp::croak("Syntax error: extra elements '$context{spec}' in '$context{orig}'"); | ||||
414 | } | ||||
415 | |||||
416 | return $TYPE{$spec} = $tc; | ||||
417 | } | ||||
418 | |||||
419 | sub find_or_create_does_type_constraint{ | ||||
420 | # XXX: Moose does not register a new role_type, but Mouse does. | ||||
421 | my $tc = find_or_parse_type_constraint(@_); | ||||
422 | return defined($tc) ? $tc : role_type(@_); | ||||
423 | } | ||||
424 | |||||
425 | # spent 34µs (12+22) within Mouse::Util::TypeConstraints::find_or_create_isa_type_constraint which was called 2 times, avg 17µs/call:
# once (6µs+11µs) by Mouse::Util::TypeConstraints::_define_type at line 134
# once (6µs+10µs) by Mouse::Meta::Attribute::_process_options at line 56 of Mouse/Meta/Attribute.pm | ||||
426 | # XXX: Moose does not register a new class_type, but Mouse does. | ||||
427 | 2 | 3µs | 2 | 22µs | my $tc = find_or_parse_type_constraint(@_); # spent 22µs making 2 calls to Mouse::Util::TypeConstraints::find_or_parse_type_constraint, avg 11µs/call |
428 | 2 | 8µs | return defined($tc) ? $tc : class_type(@_); | ||
429 | } | ||||
430 | |||||
431 | 1 | 28µs | 1; | ||
432 | __END__ | ||||
# spent 4µs within Mouse::Util::TypeConstraints::CORE:match which was called:
# once (4µs+0s) by Mouse::Util::TypeConstraints::_define_type at line 143 | |||||
# spent 2µs within Mouse::Util::TypeConstraints::CORE:subst which was called:
# once (2µs+0s) by Mouse::Util::TypeConstraints::find_type_constraint at line 384 |