← Index
NYTProf Performance Profile   « block view • line view • sub view »
For bin/hailo
  Run on Thu Oct 21 22:50:37 2010
Reported on Thu Oct 21 22:52:07 2010

Filename/home/hinrik/perl5/perlbrew/perls/perl-5.13.5/lib/site_perl/5.13.5/x86_64-linux/Mouse/Util/TypeConstraints.pm
StatementsExecuted 1370 statements in 7.88ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
92321.44ms2.80msMouse::Util::TypeConstraints::::find_or_parse_type_constraintMouse::Util::TypeConstraints::find_or_parse_type_constraint
24111.11ms2.90msMouse::Util::TypeConstraints::::_define_typeMouse::Util::TypeConstraints::_define_type
8722792µs3.58msMouse::Util::TypeConstraints::::find_or_create_isa_type_constraintMouse::Util::TypeConstraints::find_or_create_isa_type_constraint (recurses: max depth 1, inclusive time 59µs)
2633345µs436µsMouse::Util::TypeConstraints::::find_type_constraintMouse::Util::TypeConstraints::find_type_constraint
14261247µs247µsMouse::Util::TypeConstraints::::CORE:substMouse::Util::TypeConstraints::CORE:subst (opcode)
1222175µs1.82msMouse::Util::TypeConstraints::::class_typeMouse::Util::TypeConstraints::class_type
1011163µs866µsMouse::Util::TypeConstraints::::_parse_single_typeMouse::Util::TypeConstraints::_parse_single_type (recurses: max depth 1, inclusive time 91µs)
2432154µs3.06msMouse::Util::TypeConstraints::::subtypeMouse::Util::TypeConstraints::subtype
1122136µs1.48msMouse::Util::TypeConstraints::::role_typeMouse::Util::TypeConstraints::role_type
1021123µs949µsMouse::Util::TypeConstraints::::_parse_typeMouse::Util::TypeConstraints::_parse_type (recurses: max depth 1, inclusive time 134µs)
1011121µs277µsMouse::Util::TypeConstraints::::_parse_nameMouse::Util::TypeConstraints::_parse_name
1011103µs123µsMouse::Util::TypeConstraints::::_find_or_create_regular_typeMouse::Util::TypeConstraints::_find_or_create_regular_type
1011101µs235µsMouse::Util::TypeConstraints::::_parse_paramMouse::Util::TypeConstraints::_parse_param (recurses: max depth 1, inclusive time 19µs)
241186µs86µsMouse::Util::TypeConstraints::::CORE:matchMouse::Util::TypeConstraints::CORE:match (opcode)
21148µs263µsMouse::Util::TypeConstraints::::_find_or_create_parameterized_typeMouse::Util::TypeConstraints::_find_or_create_parameterized_type
33241µs356µsMouse::Util::TypeConstraints::::__ANON__[:217]Mouse::Util::TypeConstraints::__ANON__[:217]
41141µs921µsMouse::Util::TypeConstraints::::find_or_create_does_type_constraintMouse::Util::TypeConstraints::find_or_create_does_type_constraint
11124µs62µsMouse::Util::TypeConstraints::::BEGIN@2Mouse::Util::TypeConstraints::BEGIN@2
21123µs29µsMouse::Util::TypeConstraints::::_parameterize_HashRef_forMouse::Util::TypeConstraints::_parameterize_HashRef_for (xsub)
11118µs107µsMouse::Util::TypeConstraints::::coerceMouse::Util::TypeConstraints::coerce
11111µs20µsMouse::Util::TypeConstraints::::BEGIN@5Mouse::Util::TypeConstraints::BEGIN@5
1117µs7µsMouse::Util::TypeConstraints::::BEGIN@4Mouse::Util::TypeConstraints::BEGIN@4
1116µs6µsMouse::Util::TypeConstraints::::BEGIN@7Mouse::Util::TypeConstraints::BEGIN@7
1115µs5µsMouse::Util::TypeConstraints::::BEGIN@8Mouse::Util::TypeConstraints::BEGIN@8
1114µs4µsMouse::Util::TypeConstraints::::asMouse::Util::TypeConstraints::as
1113µs3µsMouse::Util::TypeConstraints::::fromMouse::Util::TypeConstraints::from
1113µs3µsMouse::Util::TypeConstraints::::viaMouse::Util::TypeConstraints::via
0000s0sMouse::Util::TypeConstraints::::__ANON__[:241]Mouse::Util::TypeConstraints::__ANON__[:241]
0000s0sMouse::Util::TypeConstraints::::__ANON__[:261]Mouse::Util::TypeConstraints::__ANON__[:261]
0000s0sMouse::Util::TypeConstraints::::_find_or_create_union_typeMouse::Util::TypeConstraints::_find_or_create_union_type
0000s0sMouse::Util::TypeConstraints::::duck_typeMouse::Util::TypeConstraints::duck_type
0000s0sMouse::Util::TypeConstraints::::enumMouse::Util::TypeConstraints::enum
0000s0sMouse::Util::TypeConstraints::::list_all_builtin_type_constraintsMouse::Util::TypeConstraints::list_all_builtin_type_constraints
0000s0sMouse::Util::TypeConstraints::::list_all_type_constraintsMouse::Util::TypeConstraints::list_all_type_constraints
0000s0sMouse::Util::TypeConstraints::::messageMouse::Util::TypeConstraints::message
0000s0sMouse::Util::TypeConstraints::::optimize_asMouse::Util::TypeConstraints::optimize_as
0000s0sMouse::Util::TypeConstraints::::optimized_constraintsMouse::Util::TypeConstraints::optimized_constraints
0000s0sMouse::Util::TypeConstraints::::register_type_constraintMouse::Util::TypeConstraints::register_type_constraint
0000s0sMouse::Util::TypeConstraints::::typeMouse::Util::TypeConstraints::type
0000s0sMouse::Util::TypeConstraints::::whereMouse::Util::TypeConstraints::where
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package Mouse::Util::TypeConstraints;
2228µs2100µs
# spent 62µs (24+38) within Mouse::Util::TypeConstraints::BEGIN@2 which was called: # once (24µs+38µs) by Mouse::BEGIN@18 at line 2
use Mouse::Util; # enables strict and warnings
# spent 62µs making 1 call to Mouse::Util::TypeConstraints::BEGIN@2 # spent 38µs making 1 call to Mouse::Exporter::do_import
3
4224µs17µs
# spent 7µs within Mouse::Util::TypeConstraints::BEGIN@4 which was called: # once (7µs+0s) by Mouse::BEGIN@18 at line 4
use Mouse::Meta::TypeConstraint;
# spent 7µs making 1 call to Mouse::Util::TypeConstraints::BEGIN@4
5225µs228µs
# spent 20µs (11+9) within Mouse::Util::TypeConstraints::BEGIN@5 which was called: # once (11µs+9µs) by Mouse::BEGIN@18 at line 5
use Mouse::Exporter;
# spent 20µs making 1 call to Mouse::Util::TypeConstraints::BEGIN@5 # spent 9µs making 1 call to Mouse::Exporter::import
6
7221µs16µs
# spent 6µs within Mouse::Util::TypeConstraints::BEGIN@7 which was called: # once (6µs+0s) by Mouse::BEGIN@18 at line 7
use Carp ();
# spent 6µs making 1 call to Mouse::Util::TypeConstraints::BEGIN@7
821.82ms15µs
# spent 5µs within Mouse::Util::TypeConstraints::BEGIN@8 which was called: # once (5µs+0s) by Mouse::BEGIN@18 at line 8
use Scalar::Util ();
# spent 5µs making 1 call to Mouse::Util::TypeConstraints::BEGIN@8
9
1019µs1281µsMouse::Exporter->setup_import_methods(
# spent 281µ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 duck_type
16 enum
17 coerce
18
19 find_type_constraint
20 register_type_constraint
21 )],
22);
23
2412µsour @CARP_NOT = qw(Mouse::Meta::Attribute);
25
2611µsmy %TYPE;
27
28# The root type
2915µs163µs$TYPE{Any} = Mouse::Meta::TypeConstraint->new(
# spent 63µs making 1 call to Mouse::Meta::TypeConstraint::new
30 name => 'Any',
31);
32
33117µsmy @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
691112µs20598µswhile (my ($name, $parent, $code) = splice @builtins, 0, 3) {
# spent 598µs making 20 calls to Mouse::Meta::TypeConstraint::new, avg 30µ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
7812µs$TYPE{Maybe} {constraint_generator} = \&_parameterize_Maybe_for;
7911µs$TYPE{ArrayRef}{constraint_generator} = \&_parameterize_ArrayRef_for;
8012µs$TYPE{HashRef} {constraint_generator} = \&_parameterize_HashRef_for;
81
82# sugars
8315µs
# spent 4µs within Mouse::Util::TypeConstraints::as which was called: # once (4µs+0s) by Mouse::Util::_try_load_one_class at line 21 of MouseX/Getopt/Meta/Attribute/Trait.pm
sub as ($) { (as => $_[0]) } ## no critic
84sub where (&) { (where => $_[0]) } ## no critic
85sub message (&) { (message => $_[0]) } ## no critic
86sub optimize_as (&) { (optimize_as => $_[0]) } ## no critic
87
8815µs
# spent 3µs within Mouse::Util::TypeConstraints::from which was called: # once (3µs+0s) by Mouse::Util::_try_load_one_class at line 25 of MouseX/Getopt/Meta/Attribute/Trait.pm
sub from { @_ }
8915µs
# spent 3µs within Mouse::Util::TypeConstraints::via which was called: # once (3µs+0s) by Mouse::Util::_try_load_one_class at line 25 of MouseX/Getopt/Meta/Attribute/Trait.pm
sub via (&) { $_[0] } ## no critic
90
91# type utilities
92
93sub optimized_constraints { # DEPRECATED
94 Carp::cluck('optimized_constraints() has been deprecated');
95 return \%TYPE;
96}
97
9811µsundef @builtins; # free the allocated memory
9915µs@builtins = keys %TYPE; # reuse it
100sub list_all_builtin_type_constraints { @builtins }
101sub list_all_type_constraints { keys %TYPE }
102
103
# spent 2.90ms (1.11+1.79) within Mouse::Util::TypeConstraints::_define_type which was called 24 times, avg 121µs/call: # 24 times (1.11ms+1.79ms) by Mouse::Util::TypeConstraints::subtype at line 183, avg 121µs/call
sub _define_type {
104336834µs my $is_subtype = shift;
105 my $name;
106 my %args;
107
108 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 if(!defined $name){
123 $name = $args{name};
124 }
125
126 $args{name} = $name;
127
128 my $parent = delete $args{as};
129 if($is_subtype && !$parent){
130 $parent = delete $args{name};
131 $name = undef;
132 }
133
13424685µs if(defined $parent) {
# spent 744µs making 24 calls to Mouse::Util::TypeConstraints::find_or_create_isa_type_constraint, avg 31µs/call, recursion: max depth 1, sum of overlapping time 59µs
135 $args{parent} = find_or_create_isa_type_constraint($parent);
136 }
137
13872115µs if(defined $name){
139 # set 'package_defined_in' only if it is not a core package
140 my $this = $args{package_defined_in};
14148218µs if(!$this){
142 $this = caller(1);
1432486µs if($this !~ /\A Mouse \b/xms){
# spent 86µs making 24 calls to Mouse::Util::TypeConstraints::CORE:match, avg 4µs/call
144 $args{package_defined_in} = $this;
145 }
146 }
147
148 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 $args{constraint} = delete $args{where} if exists $args{where};
166 $args{optimized} = delete $args{optimized_as} if exists $args{optimized_as};
167
16824959µs my $constraint = Mouse::Meta::TypeConstraint->new(%args);
# spent 959µs making 24 calls to Mouse::Meta::TypeConstraint::new, avg 40µs/call
169
170 if(defined $name){
171 return $TYPE{$name} = $constraint;
172 }
173 else{
174 return $constraint;
175 }
176}
177
178sub type {
179 return _define_type 0, @_;
180}
181
182
# spent 3.06ms (154µs+2.90) within Mouse::Util::TypeConstraints::subtype which was called 24 times, avg 127µs/call: # 12 times (79µs+1.51ms) by Mouse::Util::TypeConstraints::class_type at line 200, avg 133µs/call # 11 times (69µs+1.27ms) by Mouse::Util::TypeConstraints::role_type at line 218, avg 122µs/call # once (6µs+122µs) by Mouse::Util::_try_load_one_class at line 21 of MouseX/Getopt/Meta/Attribute/Trait.pm
sub subtype {
18324153µs242.90ms return _define_type 1, @_;
# spent 2.90ms making 24 calls to Mouse::Util::TypeConstraints::_define_type, avg 121µs/call
184}
185
186
# spent 107µs (18+89) within Mouse::Util::TypeConstraints::coerce which was called: # once (18µs+89µs) by Mouse::Util::_try_load_one_class at line 25 of MouseX/Getopt/Meta/Attribute/Trait.pm
sub coerce { # coerce $type, from $from, via { ... }, ...
187419µs my $type_name = shift;
188216µs my $type = find_type_constraint($type_name)
# spent 14µs making 1 call to Mouse::Util::TypeConstraints::find_type_constraint # spent 2µs making 1 call to Mouse::Meta::TypeConstraint::_identity
189 or Carp::croak("Cannot find type '$type_name', perhaps you forgot to load it.");
190
191173µs $type->_add_type_coercions(@_);
# spent 73µs making 1 call to Mouse::Meta::TypeConstraint::_add_type_coercions
192 return;
193}
194
195
# spent 1.82ms (175µs+1.65) within Mouse::Util::TypeConstraints::class_type which was called 12 times, avg 152µs/call: # 10 times (146µs+1.38ms) by Mouse::init_meta at line 143 of Mouse.pm, avg 152µs/call # 2 times (30µs+267µs) by Mouse::Util::TypeConstraints::find_or_create_isa_type_constraint at line 418, avg 149µs/call
sub class_type {
19636225µs my($name, $options) = @_;
197 my $class = $options->{class} || $name;
198
199 # ClassType
200241.65ms return subtype $name => (
# spent 1.59ms making 12 calls to Mouse::Util::TypeConstraints::subtype, avg 133µs/call # spent 55µs making 12 calls to Mouse::Util::generate_isa_predicate_for, avg 5µs/call
201 as => 'Object',
202 optimized_as => Mouse::Util::generate_isa_predicate_for($class),
203 class => $class,
204 );
205}
206
207
# spent 1.48ms (136µs+1.34) within Mouse::Util::TypeConstraints::role_type which was called 11 times, avg 134µs/call: # 7 times (90µs+864µs) by Mouse::Role::init_meta at line 124 of Mouse/Role.pm, avg 136µs/call # 4 times (46µs+476µs) by Mouse::Util::TypeConstraints::find_or_create_does_type_constraint at line 413, avg 130µs/call
sub role_type {
20833135µs my($name, $options) = @_;
209 my $role = $options->{role} || $name;
210
211 # RoleType
212 return subtype $name => (
213 as => 'Object',
214
# spent 356µs (41+315) within Mouse::Util::TypeConstraints::__ANON__[/home/hinrik/perl5/perlbrew/perls/perl-5.13.5/lib/site_perl/5.13.5/x86_64-linux/Mouse/Util/TypeConstraints.pm:217] which was called 3 times, avg 119µs/call: # once (13µs+106µs) by Hailo::_tokenizer at line 288 of lib/Hailo.pm # once (13µs+105µs) by Hailo::_engine at line 286 of lib/Hailo.pm # once (15µs+104µs) by Hailo::_storage at line 221 of lib/Hailo/Command.pm
optimized_as => sub {
215347µs6315µs return Scalar::Util::blessed($_[0])
# spent 310µs making 3 calls to Mouse::Util::does_role, avg 103µs/call # spent 6µs making 3 calls to Scalar::Util::blessed, avg 2µs/call
216 && Mouse::Util::does_role($_[0], $role);
217 },
218111.34ms role => $role,
# spent 1.34ms making 11 calls to Mouse::Util::TypeConstraints::subtype, avg 122µs/call
219 );
220}
221
222sub duck_type {
223 my($name, @methods);
224
225 if(ref($_[0]) ne 'ARRAY'){
226 $name = shift;
227 }
228
229 @methods = (@_ == 1 && ref($_[0]) eq 'ARRAY') ? @{$_[0]} : @_;
230
231 # DuckType
232 return _define_type 1, $name => (
233 as => 'Object',
234 optimized_as => Mouse::Util::generate_can_predicate_for(\@methods),
235 message => sub {
236 my($object) = @_;
237 my @missing = grep { !$object->can($_) } @methods;
238 return ref($object)
239 . ' is missing methods '
240 . Mouse::Util::quoted_english_list(@missing);
241 },
242 methods => \@methods,
243 );
244}
245
246sub enum {
247 my($name, %valid);
248
249 if(!(@_ == 1 && ref($_[0]) eq 'ARRAY')){
250 $name = shift;
251 }
252
253 %valid = map{ $_ => undef }
254 (@_ == 1 && ref($_[0]) eq 'ARRAY' ? @{$_[0]} : @_);
255
256 # EnumType
257 return _define_type 1, $name => (
258 as => 'Str',
259 optimized_as => sub{
260 return defined($_[0]) && !ref($_[0]) && exists $valid{$_[0]};
261 },
262 );
263}
264
265
# spent 123µs (103+20) within Mouse::Util::TypeConstraints::_find_or_create_regular_type which was called 10 times, avg 12µs/call: # 10 times (103µs+20µs) by Mouse::Util::TypeConstraints::_parse_name at line 328, avg 12µs/call
sub _find_or_create_regular_type{
26632102µs my($spec, $create) = @_;
267
268 return $TYPE{$spec} if exists $TYPE{$spec};
269
270620µs my $meta = Mouse::Util::get_metaclass_by_name($spec);
# spent 20µs making 6 calls to Mouse::Meta::Module::_get_metaclass_by_name, avg 3µs/call
271
272 if(!defined $meta){
273 return $create ? class_type($spec) : undef;
274 }
275
276 if(Mouse::Util::is_a_metarole($meta)){
277 return role_type($spec);
278 }
279 else{
280 return class_type($spec);
281 }
282}
283
284
# spent 263µs (48+216) within Mouse::Util::TypeConstraints::_find_or_create_parameterized_type which was called 2 times, avg 132µs/call: # 2 times (48µs+216µs) by Mouse::Util::TypeConstraints::_parse_single_type at line 340, avg 132µs/call
sub _find_or_create_parameterized_type{
285658µs my($base, $param) = @_;
286
287410µs my $name = sprintf '%s[%s]', $base->name, $param->name;
# spent 10µs making 4 calls to Mouse::Meta::TypeConstraint::name, avg 2µs/call
288
2892206µs $TYPE{$name} ||= $base->parameterize($param, $name);
# spent 206µs making 2 calls to Mouse::Meta::TypeConstraint::parameterize, avg 103µs/call
290}
291
292sub _find_or_create_union_type{
293 return if grep{ not defined } @_;
294 my @types = sort map{ $_->{type_constraints} ? @{$_->{type_constraints}} : $_ } @_;
295
296 my $name = join '|', @types;
297
298 # UnionType
299 $TYPE{$name} ||= Mouse::Meta::TypeConstraint->new(
300 name => $name,
301 type_constraints => \@types,
302 );
303}
304
305# The type parser
306
307# param : '[' type ']' | NOTHING
308
# spent 235µs (101+134) within Mouse::Util::TypeConstraints::_parse_param which was called 10 times, avg 24µs/call: # 10 times (101µs+134µs) by Mouse::Util::TypeConstraints::_parse_single_type at line 338, avg 24µs/call
sub _parse_param {
30928100µs my($c) = @_;
310
311427µs1015µs if($c->{spec} =~ s/^\[//){
# spent 15µs making 10 calls to Mouse::Util::TypeConstraints::CORE:subst, avg 2µs/call
31220s my $type = _parse_type($c, 1);
# spent 134µs making 2 calls to Mouse::Util::TypeConstraints::_parse_type, avg 67µs/call, recursion: max depth 1, sum of overlapping time 134µs
313
31424µs if($c->{spec} =~ s/^\]//){
# spent 4µs making 2 calls to Mouse::Util::TypeConstraints::CORE:subst, avg 2µs/call
315 return $type;
316 }
317 Carp::croak("Syntax error in type: missing right square bracket in '$c->{orig}'");
318 }
319
320 return undef;
321}
322
323# name : [\w.:]+
324
# spent 277µs (121+156) within Mouse::Util::TypeConstraints::_parse_name which was called 10 times, avg 28µs/call: # 10 times (121µs+156µs) by Mouse::Util::TypeConstraints::_parse_single_type at line 337, avg 28µs/call
sub _parse_name {
3252087µs my($c, $create) = @_;
326
3271066µs1033µs if($c->{spec} =~ s/\A ([\w.:]+) //xms){
# spent 33µs making 10 calls to Mouse::Util::TypeConstraints::CORE:subst, avg 3µs/call
32810123µs return _find_or_create_regular_type($1, $create);
# spent 123µs making 10 calls to Mouse::Util::TypeConstraints::_find_or_create_regular_type, avg 12µs/call
329 }
330 Carp::croak("Syntax error in type: expect type name near '$c->{spec}' in '$c->{orig}'");
331}
332
333# single_type : name param
334
# spent 866µs (163+703) within Mouse::Util::TypeConstraints::_parse_single_type which was called 10 times, avg 87µs/call: # 10 times (163µs+703µs) by Mouse::Util::TypeConstraints::_parse_type at line 360, avg 87µs/call
sub _parse_single_type {
33540118µs my($c, $create) = @_;
336
33710277µs my $type = _parse_name($c, $create);
# spent 277µs making 10 calls to Mouse::Util::TypeConstraints::_parse_name, avg 28µs/call
33810235µs my $param = _parse_param($c);
# spent 254µs making 10 calls to Mouse::Util::TypeConstraints::_parse_param, avg 25µs/call, recursion: max depth 1, sum of overlapping time 19µs
339
340829µs2263µs if(defined $type){
# spent 263µs making 2 calls to Mouse::Util::TypeConstraints::_find_or_create_parameterized_type, avg 132µs/call
341 if(defined $param){
342 return _find_or_create_parameterized_type($type, $param);
343 }
344 else {
345 return $type;
346 }
347 }
348 elsif(defined $param){
349 Carp::croak("Undefined type with parameter [$param] in '$c->{orig}'");
350 }
351 else{
352 return undef;
353 }
354}
355
356# type : single_type ('|' single_type)*
357
# spent 949µs (123+826) within Mouse::Util::TypeConstraints::_parse_type which was called 10 times, avg 95µs/call: # 8 times (83µs+866µs) by Mouse::Util::TypeConstraints::find_or_parse_type_constraint at line 402, avg 119µs/call # 2 times (40µs+-40µs) by Mouse::Util::TypeConstraints::_parse_param at line 312, avg 0s/call
sub _parse_type {
35840111µs my($c, $create) = @_;
359
36010866µs my $type = _parse_single_type($c, $create);
# spent 957µs making 10 calls to Mouse::Util::TypeConstraints::_parse_single_type, avg 96µs/call, recursion: max depth 1, sum of overlapping time 91µs
361619µs if($c->{spec}){ # can be an union type
362 my @types;
36323µs while($c->{spec} =~ s/^\|//){
# spent 3µs making 2 calls to Mouse::Util::TypeConstraints::CORE:subst, avg 1µs/call
364 push @types, _parse_single_type($c, $create);
365 }
366 if(@types){
367 return _find_or_create_union_type($type, @types);
368 }
369 }
370 return $type;
371}
372
373
374
# spent 436µs (345+91) within Mouse::Util::TypeConstraints::find_type_constraint which was called 26 times, avg 17µs/call: # 15 times (198µs+54µs) by Mouse::init_meta at line 143 of Mouse.pm, avg 17µs/call # 10 times (135µs+34µs) by Mouse::Role::init_meta at line 124 of Mouse/Role.pm, avg 17µs/call # once (11µs+3µs) by Mouse::Util::TypeConstraints::coerce at line 188
sub find_type_constraint {
375104440µs my($spec) = @_;
3762642µs return $spec if Mouse::Util::is_a_type_constraint($spec) or not defined $spec;
# spent 42µs making 26 calls to Mouse::Util::is_a_type_constraint, avg 2µs/call
377
3782650µs $spec =~ s/\s+//g;
# spent 50µs making 26 calls to Mouse::Util::TypeConstraints::CORE:subst, avg 2µs/call
379 return $TYPE{$spec};
380}
381
382sub register_type_constraint {
383 my($constraint) = @_;
384 Carp::croak("No type supplied / type is not a valid type constraint")
385 unless Mouse::Util::is_a_type_constraint($constraint);
386 my $name = $constraint->name;
387 Carp::croak("Can't register an unnamed type constraint")
388 unless defined $name;
389 return $TYPE{$name} = $constraint;
390}
391
392
# spent 2.80ms (1.44+1.36) within Mouse::Util::TypeConstraints::find_or_parse_type_constraint which was called 92 times, avg 30µs/call: # 87 times (1.34ms+1.09ms) by Mouse::Util::TypeConstraints::find_or_create_isa_type_constraint at line 418, avg 28µs/call # 4 times (87µs+272µs) by Mouse::Util::TypeConstraints::find_or_create_does_type_constraint at line 413, avg 90µs/call # once (14µs+4µs) by Mouse::Meta::TypeConstraint::_add_type_coercions at line 93 of Mouse/Meta/TypeConstraint.pm
sub find_or_parse_type_constraint {
3933681.87ms my($spec) = @_;
39492131µs return $spec if Mouse::Util::is_a_type_constraint($spec) or not defined $spec;
# spent 131µs making 92 calls to Mouse::Util::is_a_type_constraint, avg 1µs/call
395
39692143µs $spec =~ s/\s+//g;
# spent 143µs making 92 calls to Mouse::Util::TypeConstraints::CORE:subst, avg 2µs/call
3973276µs84140µs return $TYPE{$spec} || do{
# spent 140µs making 84 calls to Mouse::Meta::TypeConstraint::_identity, avg 2µs/call
398 my $context = {
399 spec => $spec,
400 orig => $spec,
401 };
4028949µs my $type = _parse_type($context);
# spent 949µs making 8 calls to Mouse::Util::TypeConstraints::_parse_type, avg 119µs/call
403
404 if($context->{spec}){
405 Carp::croak("Syntax error: extra elements '$context->{spec}' in '$context->{orig}'");
406 }
407 $type;
408 };
409}
410
411
# spent 921µs (41+880) within Mouse::Util::TypeConstraints::find_or_create_does_type_constraint which was called 4 times, avg 230µs/call: # 4 times (41µs+880µs) by Mouse::Meta::Attribute::_process_options at line 56 of Mouse/Meta/Attribute.pm, avg 230µs/call
sub find_or_create_does_type_constraint{
412 # XXX: Moose does not register a new role_type, but Mouse does.
413437µs8880µs return find_or_parse_type_constraint(@_) || role_type(@_);
# spent 522µs making 4 calls to Mouse::Util::TypeConstraints::role_type, avg 130µs/call # spent 359µs making 4 calls to Mouse::Util::TypeConstraints::find_or_parse_type_constraint, avg 90µs/call
414}
415
416
# spent 3.58ms (792µs+2.79) within Mouse::Util::TypeConstraints::find_or_create_isa_type_constraint which was called 87 times, avg 41µs/call: # 63 times (572µs+2.32ms) by Mouse::Meta::Attribute::_process_options at line 56 of Mouse/Meta/Attribute.pm, avg 46µs/call # 24 times (220µs+465µs) by Mouse::Util::TypeConstraints::_define_type at line 134, avg 29µs/call
sub find_or_create_isa_type_constraint {
417 # XXX: Moose does not register a new class_type, but Mouse does.
41887882µs1742.84ms return find_or_parse_type_constraint(@_) || class_type(@_);
# spent 2.42ms making 87 calls to Mouse::Util::TypeConstraints::find_or_parse_type_constraint, avg 28µs/call # spent 297µs making 2 calls to Mouse::Util::TypeConstraints::class_type, avg 149µs/call # spent 124µs making 85 calls to Mouse::Meta::TypeConstraint::_identity, avg 1µs/call
419}
420
421122µs1;
422__END__
 
# spent 86µs within Mouse::Util::TypeConstraints::CORE:match which was called 24 times, avg 4µs/call: # 24 times (86µs+0s) by Mouse::Util::TypeConstraints::_define_type at line 143, avg 4µs/call
sub Mouse::Util::TypeConstraints::CORE:match; # opcode
# spent 247µs within Mouse::Util::TypeConstraints::CORE:subst which was called 142 times, avg 2µs/call: # 92 times (143µs+0s) by Mouse::Util::TypeConstraints::find_or_parse_type_constraint at line 396, avg 2µs/call # 26 times (50µs+0s) by Mouse::Util::TypeConstraints::find_type_constraint at line 378, avg 2µs/call # 10 times (33µs+0s) by Mouse::Util::TypeConstraints::_parse_name at line 327, avg 3µs/call # 10 times (15µs+0s) by Mouse::Util::TypeConstraints::_parse_param at line 311, avg 2µs/call # 2 times (4µs+0s) by Mouse::Util::TypeConstraints::_parse_param at line 314, avg 2µs/call # 2 times (3µs+0s) by Mouse::Util::TypeConstraints::_parse_type at line 363, avg 1µs/call
sub Mouse::Util::TypeConstraints::CORE:subst; # opcode
# spent 29µs (23+6) within Mouse::Util::TypeConstraints::_parameterize_HashRef_for which was called 2 times, avg 15µs/call: # 2 times (23µs+6µs) by Mouse::Meta::TypeConstraint::new at line 32 of Mouse/Meta/TypeConstraint.pm, avg 15µs/call
sub Mouse::Util::TypeConstraints::_parameterize_HashRef_for; # xsub