| Filename | /home/hinrik/perl5/perlbrew/perls/perl-5.13.5/lib/site_perl/5.13.5/x86_64-linux/Mouse/Util/TypeConstraints.pm |
| Statements | Executed 1370 statements in 7.88ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 92 | 3 | 2 | 1.44ms | 2.80ms | Mouse::Util::TypeConstraints::find_or_parse_type_constraint |
| 24 | 1 | 1 | 1.11ms | 2.90ms | Mouse::Util::TypeConstraints::_define_type |
| 87 | 2 | 2 | 792µs | 3.58ms | Mouse::Util::TypeConstraints::find_or_create_isa_type_constraint (recurses: max depth 1, inclusive time 59µs) |
| 26 | 3 | 3 | 345µs | 436µs | Mouse::Util::TypeConstraints::find_type_constraint |
| 142 | 6 | 1 | 247µs | 247µs | Mouse::Util::TypeConstraints::CORE:subst (opcode) |
| 12 | 2 | 2 | 175µs | 1.82ms | Mouse::Util::TypeConstraints::class_type |
| 10 | 1 | 1 | 163µs | 866µs | Mouse::Util::TypeConstraints::_parse_single_type (recurses: max depth 1, inclusive time 91µs) |
| 24 | 3 | 2 | 154µs | 3.06ms | Mouse::Util::TypeConstraints::subtype |
| 11 | 2 | 2 | 136µs | 1.48ms | Mouse::Util::TypeConstraints::role_type |
| 10 | 2 | 1 | 123µs | 949µs | Mouse::Util::TypeConstraints::_parse_type (recurses: max depth 1, inclusive time 134µs) |
| 10 | 1 | 1 | 121µs | 277µs | Mouse::Util::TypeConstraints::_parse_name |
| 10 | 1 | 1 | 103µs | 123µs | Mouse::Util::TypeConstraints::_find_or_create_regular_type |
| 10 | 1 | 1 | 101µs | 235µs | Mouse::Util::TypeConstraints::_parse_param (recurses: max depth 1, inclusive time 19µs) |
| 24 | 1 | 1 | 86µs | 86µs | Mouse::Util::TypeConstraints::CORE:match (opcode) |
| 2 | 1 | 1 | 48µs | 263µs | Mouse::Util::TypeConstraints::_find_or_create_parameterized_type |
| 3 | 3 | 2 | 41µs | 356µs | Mouse::Util::TypeConstraints::__ANON__[:217] |
| 4 | 1 | 1 | 41µs | 921µs | Mouse::Util::TypeConstraints::find_or_create_does_type_constraint |
| 1 | 1 | 1 | 24µs | 62µs | Mouse::Util::TypeConstraints::BEGIN@2 |
| 2 | 1 | 1 | 23µs | 29µs | Mouse::Util::TypeConstraints::_parameterize_HashRef_for (xsub) |
| 1 | 1 | 1 | 18µs | 107µs | Mouse::Util::TypeConstraints::coerce |
| 1 | 1 | 1 | 11µs | 20µs | Mouse::Util::TypeConstraints::BEGIN@5 |
| 1 | 1 | 1 | 7µs | 7µs | Mouse::Util::TypeConstraints::BEGIN@4 |
| 1 | 1 | 1 | 6µs | 6µs | Mouse::Util::TypeConstraints::BEGIN@7 |
| 1 | 1 | 1 | 5µs | 5µs | Mouse::Util::TypeConstraints::BEGIN@8 |
| 1 | 1 | 1 | 4µs | 4µs | Mouse::Util::TypeConstraints::as |
| 1 | 1 | 1 | 3µs | 3µs | Mouse::Util::TypeConstraints::from |
| 1 | 1 | 1 | 3µs | 3µs | Mouse::Util::TypeConstraints::via |
| 0 | 0 | 0 | 0s | 0s | Mouse::Util::TypeConstraints::__ANON__[:241] |
| 0 | 0 | 0 | 0s | 0s | Mouse::Util::TypeConstraints::__ANON__[:261] |
| 0 | 0 | 0 | 0s | 0s | Mouse::Util::TypeConstraints::_find_or_create_union_type |
| 0 | 0 | 0 | 0s | 0s | Mouse::Util::TypeConstraints::duck_type |
| 0 | 0 | 0 | 0s | 0s | Mouse::Util::TypeConstraints::enum |
| 0 | 0 | 0 | 0s | 0s | Mouse::Util::TypeConstraints::list_all_builtin_type_constraints |
| 0 | 0 | 0 | 0s | 0s | Mouse::Util::TypeConstraints::list_all_type_constraints |
| 0 | 0 | 0 | 0s | 0s | Mouse::Util::TypeConstraints::message |
| 0 | 0 | 0 | 0s | 0s | Mouse::Util::TypeConstraints::optimize_as |
| 0 | 0 | 0 | 0s | 0s | Mouse::Util::TypeConstraints::optimized_constraints |
| 0 | 0 | 0 | 0s | 0s | Mouse::Util::TypeConstraints::register_type_constraint |
| 0 | 0 | 0 | 0s | 0s | Mouse::Util::TypeConstraints::type |
| 0 | 0 | 0 | 0s | 0s | Mouse::Util::TypeConstraints::where |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package Mouse::Util::TypeConstraints; | ||||
| 2 | 2 | 28µs | 2 | 100µ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 # spent 62µs making 1 call to Mouse::Util::TypeConstraints::BEGIN@2
# spent 38µs making 1 call to Mouse::Exporter::do_import |
| 3 | |||||
| 4 | 2 | 24µs | 1 | 7µs | # spent 7µs within Mouse::Util::TypeConstraints::BEGIN@4 which was called:
# once (7µs+0s) by Mouse::BEGIN@18 at line 4 # spent 7µs making 1 call to Mouse::Util::TypeConstraints::BEGIN@4 |
| 5 | 2 | 25µs | 2 | 28µ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 # spent 20µs making 1 call to Mouse::Util::TypeConstraints::BEGIN@5
# spent 9µs making 1 call to Mouse::Exporter::import |
| 6 | |||||
| 7 | 2 | 21µs | 1 | 6µs | # spent 6µs within Mouse::Util::TypeConstraints::BEGIN@7 which was called:
# once (6µs+0s) by Mouse::BEGIN@18 at line 7 # spent 6µs making 1 call to Mouse::Util::TypeConstraints::BEGIN@7 |
| 8 | 2 | 1.82ms | 1 | 5µs | # spent 5µs within Mouse::Util::TypeConstraints::BEGIN@8 which was called:
# once (5µs+0s) by Mouse::BEGIN@18 at line 8 # spent 5µs making 1 call to Mouse::Util::TypeConstraints::BEGIN@8 |
| 9 | |||||
| 10 | 1 | 9µs | 1 | 281µs | Mouse::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 | |||||
| 24 | 1 | 2µs | our @CARP_NOT = qw(Mouse::Meta::Attribute); | ||
| 25 | |||||
| 26 | 1 | 1µs | my %TYPE; | ||
| 27 | |||||
| 28 | # The root type | ||||
| 29 | 1 | 5µs | 1 | 63µs | $TYPE{Any} = Mouse::Meta::TypeConstraint->new( # spent 63µs making 1 call to Mouse::Meta::TypeConstraint::new |
| 30 | name => 'Any', | ||||
| 31 | ); | ||||
| 32 | |||||
| 33 | 1 | 17µ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 | 112µs | 20 | 598µs | while (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 | ||||
| 78 | 1 | 2µs | $TYPE{Maybe} {constraint_generator} = \&_parameterize_Maybe_for; | ||
| 79 | 1 | 1µs | $TYPE{ArrayRef}{constraint_generator} = \&_parameterize_ArrayRef_for; | ||
| 80 | 1 | 2µs | $TYPE{HashRef} {constraint_generator} = \&_parameterize_HashRef_for; | ||
| 81 | |||||
| 82 | # sugars | ||||
| 83 | 1 | 5µ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 | ||
| 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 | 1 | 5µ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 | ||
| 89 | 1 | 5µ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 | ||
| 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 | 1µs | 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 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 | ||||
| 104 | 24 | 28µs | my $is_subtype = shift; | ||
| 105 | 24 | 22µs | my $name; | ||
| 106 | 24 | 25µs | my %args; | ||
| 107 | |||||
| 108 | 24 | 127µ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 | 24 | 29µs | if(!defined $name){ | ||
| 123 | $name = $args{name}; | ||||
| 124 | } | ||||
| 125 | |||||
| 126 | 24 | 38µs | $args{name} = $name; | ||
| 127 | |||||
| 128 | 24 | 40µs | my $parent = delete $args{as}; | ||
| 129 | 24 | 28µs | if($is_subtype && !$parent){ | ||
| 130 | $parent = delete $args{name}; | ||||
| 131 | $name = undef; | ||||
| 132 | } | ||||
| 133 | |||||
| 134 | 24 | 110µs | 24 | 685µ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 | |||||
| 138 | 24 | 49µs | if(defined $name){ | ||
| 139 | # set 'package_defined_in' only if it is not a core package | ||||
| 140 | 24 | 31µs | my $this = $args{package_defined_in}; | ||
| 141 | 24 | 50µs | if(!$this){ | ||
| 142 | 24 | 37µs | $this = caller(1); | ||
| 143 | 24 | 181µs | 24 | 86µ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 | 24 | 35µs | 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 | 24 | 29µs | $args{constraint} = delete $args{where} if exists $args{where}; | ||
| 166 | 24 | 51µs | $args{optimized} = delete $args{optimized_as} if exists $args{optimized_as}; | ||
| 167 | |||||
| 168 | 24 | 142µs | 24 | 959µ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 | 24 | 114µ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 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 | ||||
| 183 | 24 | 153µs | 24 | 2.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 | ||||
| 187 | 1 | 1µs | my $type_name = shift; | ||
| 188 | 1 | 9µs | 2 | 16µ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 | |||||
| 191 | 1 | 5µs | 1 | 73µs | $type->_add_type_coercions(@_); # spent 73µs making 1 call to Mouse::Meta::TypeConstraint::_add_type_coercions |
| 192 | 1 | 4µs | 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 | ||||
| 196 | 12 | 24µs | my($name, $options) = @_; | ||
| 197 | 12 | 21µs | my $class = $options->{class} || $name; | ||
| 198 | |||||
| 199 | # ClassType | ||||
| 200 | 12 | 181µs | 24 | 1.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 | ||||
| 208 | 11 | 18µs | my($name, $options) = @_; | ||
| 209 | 11 | 18µs | 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 | ||||
| 215 | 3 | 47µs | 6 | 315µ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 | }, | ||||
| 218 | 11 | 99µs | 11 | 1.34ms | role => $role, # spent 1.34ms making 11 calls to Mouse::Util::TypeConstraints::subtype, avg 122µs/call |
| 219 | ); | ||||
| 220 | } | ||||
| 221 | |||||
| 222 | sub 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 | |||||
| 246 | sub 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 | ||||
| 266 | 10 | 27µs | my($spec, $create) = @_; | ||
| 267 | |||||
| 268 | 10 | 27µs | return $TYPE{$spec} if exists $TYPE{$spec}; | ||
| 269 | |||||
| 270 | 6 | 23µs | 6 | 20µ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 | 6 | 25µs | 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 | ||||
| 285 | 2 | 3µs | my($base, $param) = @_; | ||
| 286 | |||||
| 287 | 2 | 29µs | 4 | 10µ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 | |||||
| 289 | 2 | 25µs | 2 | 206µs | $TYPE{$name} ||= $base->parameterize($param, $name); # spent 206µs making 2 calls to Mouse::Meta::TypeConstraint::parameterize, avg 103µs/call |
| 290 | } | ||||
| 291 | |||||
| 292 | sub _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 | ||||
| 309 | 10 | 13µs | my($c) = @_; | ||
| 310 | |||||
| 311 | 10 | 53µs | 10 | 15µs | if($c->{spec} =~ s/^\[//){ # spent 15µs making 10 calls to Mouse::Util::TypeConstraints::CORE:subst, avg 2µs/call |
| 312 | 2 | 9µs | 2 | 0s | 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 | |||||
| 314 | 2 | 18µs | 2 | 4µ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 | 8 | 33µs | 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 | ||||
| 325 | 10 | 13µs | my($c, $create) = @_; | ||
| 326 | |||||
| 327 | 10 | 74µs | 10 | 33µs | if($c->{spec} =~ s/\A ([\w.:]+) //xms){ # spent 33µs making 10 calls to Mouse::Util::TypeConstraints::CORE:subst, avg 3µs/call |
| 328 | 10 | 66µs | 10 | 123µ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 | ||||
| 335 | 10 | 13µs | my($c, $create) = @_; | ||
| 336 | |||||
| 337 | 10 | 38µs | 10 | 277µs | my $type = _parse_name($c, $create); # spent 277µs making 10 calls to Mouse::Util::TypeConstraints::_parse_name, avg 28µs/call |
| 338 | 10 | 41µs | 10 | 235µ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 | |||||
| 340 | 10 | 26µs | 2 | 263µ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 | 2 | 8µs | return $type; | ||
| 346 | } | ||||
| 347 | } | ||||
| 348 | elsif(defined $param){ | ||||
| 349 | Carp::croak("Undefined type with parameter [$param] in '$c->{orig}'"); | ||||
| 350 | } | ||||
| 351 | else{ | ||||
| 352 | 6 | 21µs | 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 | ||||
| 358 | 10 | 15µs | my($c, $create) = @_; | ||
| 359 | |||||
| 360 | 10 | 46µs | 10 | 866µ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 |
| 361 | 10 | 15µs | if($c->{spec}){ # can be an union type | ||
| 362 | 2 | 2µs | my @types; | ||
| 363 | 2 | 14µs | 2 | 3µ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 | 2 | 3µs | if(@types){ | ||
| 367 | return _find_or_create_union_type($type, @types); | ||||
| 368 | } | ||||
| 369 | } | ||||
| 370 | 10 | 34µs | 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 | ||||
| 375 | 26 | 42µs | my($spec) = @_; | ||
| 376 | 26 | 153µs | 26 | 42µ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 | |||||
| 378 | 26 | 141µs | 26 | 50µs | $spec =~ s/\s+//g; # spent 50µs making 26 calls to Mouse::Util::TypeConstraints::CORE:subst, avg 2µs/call |
| 379 | 26 | 105µs | return $TYPE{$spec}; | ||
| 380 | } | ||||
| 381 | |||||
| 382 | sub 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 | ||||
| 393 | 92 | 117µs | my($spec) = @_; | ||
| 394 | 92 | 511µs | 92 | 131µ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 | |||||
| 396 | 92 | 445µs | 92 | 143µs | $spec =~ s/\s+//g; # spent 143µs making 92 calls to Mouse::Util::TypeConstraints::CORE:subst, avg 2µs/call |
| 397 | 92 | 795µs | 84 | 140µs | return $TYPE{$spec} || do{ # spent 140µs making 84 calls to Mouse::Meta::TypeConstraint::_identity, avg 2µs/call |
| 398 | 8 | 21µs | my $context = { | ||
| 399 | spec => $spec, | ||||
| 400 | orig => $spec, | ||||
| 401 | }; | ||||
| 402 | 8 | 31µs | 8 | 949µs | my $type = _parse_type($context); # spent 949µs making 8 calls to Mouse::Util::TypeConstraints::_parse_type, avg 119µs/call |
| 403 | |||||
| 404 | 8 | 10µs | if($context->{spec}){ | ||
| 405 | Carp::croak("Syntax error: extra elements '$context->{spec}' in '$context->{orig}'"); | ||||
| 406 | } | ||||
| 407 | 8 | 14µs | $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 | ||||
| 412 | # XXX: Moose does not register a new role_type, but Mouse does. | ||||
| 413 | 4 | 37µs | 8 | 880µ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 | ||||
| 417 | # XXX: Moose does not register a new class_type, but Mouse does. | ||||
| 418 | 87 | 882µs | 174 | 2.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 | |||||
| 421 | 1 | 22µs | 1; | ||
| 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 | |||||
# 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 | |||||
# 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 |