| Filename | /usr/local/lib/perl/5.10.1/Mouse/Util/TypeConstraints.pm |
| Statements | Executed 646 statements in 4.50ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 51 | 1 | 1 | 356µs | 515µs | Mouse::Util::TypeConstraints::find_or_parse_type_constraint |
| 8 | 1 | 1 | 249µs | 670µs | Mouse::Util::TypeConstraints::_define_type |
| 51 | 2 | 2 | 243µs | 1.01ms | Mouse::Util::TypeConstraints::find_or_create_isa_type_constraint (recurses: max depth 1, inclusive time 31µs) |
| 8 | 1 | 1 | 76µs | 96µs | Mouse::Util::TypeConstraints::find_type_constraint |
| 8 | 2 | 2 | 75µs | 832µs | Mouse::Util::TypeConstraints::class_type |
| 8 | 1 | 1 | 43µs | 713µs | Mouse::Util::TypeConstraints::subtype |
| 2 | 1 | 1 | 22µs | 27µs | Mouse::Util::TypeConstraints::_find_or_create_regular_type |
| 12 | 3 | 1 | 21µs | 21µs | Mouse::Util::TypeConstraints::CORE:subst (opcode) |
| 2 | 1 | 1 | 21µs | 57µs | Mouse::Util::TypeConstraints::_parse_name |
| 2 | 1 | 1 | 20µs | 92µs | Mouse::Util::TypeConstraints::_parse_single_type |
| 8 | 1 | 1 | 19µs | 19µs | Mouse::Util::TypeConstraints::CORE:match (opcode) |
| 1 | 1 | 1 | 15µs | 42µs | Mouse::Util::TypeConstraints::BEGIN@2 |
| 2 | 1 | 1 | 15µs | 106µs | Mouse::Util::TypeConstraints::_parse_type |
| 2 | 1 | 1 | 13µs | 14µs | Mouse::Util::TypeConstraints::_parse_param |
| 1 | 1 | 1 | 10µs | 14µs | Mouse::Util::TypeConstraints::BEGIN@5 |
| 1 | 1 | 1 | 6µs | 6µs | Mouse::Util::TypeConstraints::BEGIN@4 |
| 1 | 1 | 1 | 5µs | 5µs | Mouse::Util::TypeConstraints::BEGIN@7 |
| 1 | 1 | 1 | 5µs | 5µs | Mouse::Util::TypeConstraints::BEGIN@8 |
| 0 | 0 | 0 | 0s | 0s | Mouse::Util::TypeConstraints::__ANON__[:217] |
| 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_parameterized_type |
| 0 | 0 | 0 | 0s | 0s | Mouse::Util::TypeConstraints::_find_or_create_union_type |
| 0 | 0 | 0 | 0s | 0s | Mouse::Util::TypeConstraints::as |
| 0 | 0 | 0 | 0s | 0s | Mouse::Util::TypeConstraints::coerce |
| 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::find_or_create_does_type_constraint |
| 0 | 0 | 0 | 0s | 0s | Mouse::Util::TypeConstraints::from |
| 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::role_type |
| 0 | 0 | 0 | 0s | 0s | Mouse::Util::TypeConstraints::type |
| 0 | 0 | 0 | 0s | 0s | Mouse::Util::TypeConstraints::via |
| 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 | 3 | 35µs | 2 | 70µs | # spent 42µs (15+27) within Mouse::Util::TypeConstraints::BEGIN@2 which was called:
# once (15µs+27µs) by Mouse::BEGIN@18 at line 2 # spent 42µs making 1 call to Mouse::Util::TypeConstraints::BEGIN@2
# spent 27µs making 1 call to Mouse::Exporter::do_import |
| 3 | |||||
| 4 | 3 | 32µs | 1 | 6µs | # spent 6µs within Mouse::Util::TypeConstraints::BEGIN@4 which was called:
# once (6µs+0s) by Mouse::BEGIN@18 at line 4 # spent 6µs making 1 call to Mouse::Util::TypeConstraints::BEGIN@4 |
| 5 | 3 | 31µs | 2 | 19µs | # spent 14µs (10+5) within Mouse::Util::TypeConstraints::BEGIN@5 which was called:
# once (10µs+5µs) by Mouse::BEGIN@18 at line 5 # spent 14µs making 1 call to Mouse::Util::TypeConstraints::BEGIN@5
# spent 5µs making 1 call to Mouse::Exporter::import |
| 6 | |||||
| 7 | 3 | 28µs | 1 | 5µs | # spent 5µs within Mouse::Util::TypeConstraints::BEGIN@7 which was called:
# once (5µs+0s) by Mouse::BEGIN@18 at line 7 # spent 5µs making 1 call to Mouse::Util::TypeConstraints::BEGIN@7 |
| 8 | 3 | 2.90ms | 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 | 7µs | 1 | 161µs | Mouse::Exporter->setup_import_methods( # spent 161µ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 | 1µs | our @CARP_NOT = qw(Mouse::Meta::Attribute); | ||
| 25 | |||||
| 26 | 1 | 300ns | my %TYPE; | ||
| 27 | |||||
| 28 | # The root type | ||||
| 29 | 1 | 3µs | 1 | 64µs | $TYPE{Any} = Mouse::Meta::TypeConstraint->new( # spent 64µs making 1 call to Mouse::Meta::TypeConstraint::new |
| 30 | name => 'Any', | ||||
| 31 | ); | ||||
| 32 | |||||
| 33 | 1 | 13µ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 | 88µs | 20 | 394µs | while (my ($name, $parent, $code) = splice @builtins, 0, 3) { # spent 394µs making 20 calls to Mouse::Meta::TypeConstraint::new, avg 20µ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 | 900ns | $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 | 800ns | undef @builtins; # free the allocated memory | ||
| 99 | 1 | 8µ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 670µs (249+421) within Mouse::Util::TypeConstraints::_define_type which was called 8 times, avg 84µs/call:
# 8 times (249µs+421µs) by Mouse::Util::TypeConstraints::subtype at line 183, avg 84µs/call | ||||
| 104 | 152 | 267µ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 | |||||
| 134 | 8 | 78µs | if(defined $parent) { # spent 109µs making 8 calls to Mouse::Util::TypeConstraints::find_or_create_isa_type_constraint, avg 14µs/call, recursion: max depth 1, sum of overlapping time 31µs | ||
| 135 | $args{parent} = find_or_create_isa_type_constraint($parent); | ||||
| 136 | } | ||||
| 137 | |||||
| 138 | if(defined $name){ | ||||
| 139 | # set 'package_defined_in' only if it is not a core package | ||||
| 140 | my $this = $args{package_defined_in}; | ||||
| 141 | if(!$this){ | ||||
| 142 | $this = caller(1); | ||||
| 143 | 8 | 19µs | if($this !~ /\A Mouse \b/xms){ # spent 19µs making 8 calls to Mouse::Util::TypeConstraints::CORE:match, avg 2µ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 | |||||
| 168 | 8 | 293µs | my $constraint = Mouse::Meta::TypeConstraint->new(%args); # spent 293µs making 8 calls to Mouse::Meta::TypeConstraint::new, avg 37µs/call | ||
| 169 | |||||
| 170 | 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 713µs (43+670) within Mouse::Util::TypeConstraints::subtype which was called 8 times, avg 89µs/call:
# 8 times (43µs+670µs) by Mouse::Util::TypeConstraints::class_type at line 200, avg 89µs/call | ||||
| 183 | 8 | 29µs | 8 | 670µs | return _define_type 1, @_; # spent 670µs making 8 calls to Mouse::Util::TypeConstraints::_define_type, avg 84µs/call |
| 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 832µs (75+757) within Mouse::Util::TypeConstraints::class_type which was called 8 times, avg 104µs/call:
# 6 times (53µs+497µs) by Mouse::init_meta at line 143 of Mouse.pm, avg 92µs/call
# 2 times (21µs+260µs) by Mouse::Util::TypeConstraints::find_or_create_isa_type_constraint at line 423, avg 141µs/call | ||||
| 196 | 24 | 121µs | my($name, $options) = @_; | ||
| 197 | my $class = $options->{class} || $name; | ||||
| 198 | |||||
| 199 | # ClassType | ||||
| 200 | 16 | 757µs | return subtype $name => ( # spent 713µs making 8 calls to Mouse::Util::TypeConstraints::subtype, avg 89µs/call
# spent 44µs making 8 calls to Mouse::Util::generate_isa_predicate_for, avg 6µs/call | ||
| 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 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 27µs (22+5) within Mouse::Util::TypeConstraints::_find_or_create_regular_type which was called 2 times, avg 14µs/call:
# 2 times (22µs+5µs) by Mouse::Util::TypeConstraints::_parse_name at line 329, avg 14µs/call | ||||
| 266 | 8 | 20µs | my($spec, $create) = @_; | ||
| 267 | |||||
| 268 | return $TYPE{$spec} if exists $TYPE{$spec}; | ||||
| 269 | |||||
| 270 | 2 | 5µs | my $meta = Mouse::Util::get_metaclass_by_name($spec); # spent 5µs making 2 calls to Mouse::Meta::Module::_get_metaclass_by_name, avg 2µ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 | sub _find_or_create_parameterized_type{ | ||||
| 285 | my($base, $param) = @_; | ||||
| 286 | |||||
| 287 | my $name = sprintf '%s[%s]', $base->name, $param->name; | ||||
| 288 | |||||
| 289 | $TYPE{$name} ||= $base->parameterize($param, $name); | ||||
| 290 | } | ||||
| 291 | |||||
| 292 | sub _find_or_create_union_type{ | ||||
| 293 | return if grep{ not defined } @_; # all things must be defined | ||||
| 294 | my @types = sort | ||||
| 295 | map{ $_->{type_constraints} ? @{$_->{type_constraints}} : $_ } @_; | ||||
| 296 | |||||
| 297 | my $name = join '|', @types; | ||||
| 298 | |||||
| 299 | # UnionType | ||||
| 300 | $TYPE{$name} ||= Mouse::Meta::TypeConstraint->new( | ||||
| 301 | name => $name, | ||||
| 302 | type_constraints => \@types, | ||||
| 303 | ); | ||||
| 304 | } | ||||
| 305 | |||||
| 306 | # The type parser | ||||
| 307 | |||||
| 308 | # param : '[' type ']' | NOTHING | ||||
| 309 | # spent 14µs (13+800ns) within Mouse::Util::TypeConstraints::_parse_param which was called 2 times, avg 7µs/call:
# 2 times (13µs+800ns) by Mouse::Util::TypeConstraints::_parse_single_type at line 339, avg 7µs/call | ||||
| 310 | 6 | 16µs | my($c) = @_; | ||
| 311 | |||||
| 312 | 2 | 800ns | if($c->{spec} =~ s/^\[//){ # spent 800ns making 2 calls to Mouse::Util::TypeConstraints::CORE:subst, avg 400ns/call | ||
| 313 | my $type = _parse_type($c, 1); | ||||
| 314 | |||||
| 315 | if($c->{spec} =~ s/^\]//){ | ||||
| 316 | return $type; | ||||
| 317 | } | ||||
| 318 | Carp::croak("Syntax error in type: missing right square bracket in '$c->{orig}'"); | ||||
| 319 | } | ||||
| 320 | |||||
| 321 | return undef; | ||||
| 322 | } | ||||
| 323 | |||||
| 324 | # name : [\w.:]+ | ||||
| 325 | # spent 57µs (21+37) within Mouse::Util::TypeConstraints::_parse_name which was called 2 times, avg 29µs/call:
# 2 times (21µs+37µs) by Mouse::Util::TypeConstraints::_parse_single_type at line 338, avg 29µs/call | ||||
| 326 | 6 | 31µs | my($c, $create) = @_; | ||
| 327 | |||||
| 328 | 2 | 10µs | if($c->{spec} =~ s/\A ([\w.:]+) //xms){ # spent 10µs making 2 calls to Mouse::Util::TypeConstraints::CORE:subst, avg 5µs/call | ||
| 329 | 2 | 27µs | return _find_or_create_regular_type($1, $create); # spent 27µs making 2 calls to Mouse::Util::TypeConstraints::_find_or_create_regular_type, avg 14µs/call | ||
| 330 | } | ||||
| 331 | Carp::croak("Syntax error in type: expect type name near '$c->{spec}' in '$c->{orig}'"); | ||||
| 332 | } | ||||
| 333 | |||||
| 334 | # single_type : name param | ||||
| 335 | # spent 92µs (20+71) within Mouse::Util::TypeConstraints::_parse_single_type which was called 2 times, avg 46µs/call:
# 2 times (20µs+71µs) by Mouse::Util::TypeConstraints::_parse_type at line 361, avg 46µs/call | ||||
| 336 | 10 | 18µs | my($c, $create) = @_; | ||
| 337 | |||||
| 338 | 2 | 57µs | my $type = _parse_name($c, $create); # spent 57µs making 2 calls to Mouse::Util::TypeConstraints::_parse_name, avg 29µs/call | ||
| 339 | 2 | 14µs | my $param = _parse_param($c); # spent 14µs making 2 calls to Mouse::Util::TypeConstraints::_parse_param, avg 7µs/call | ||
| 340 | |||||
| 341 | if(defined $type){ | ||||
| 342 | if(defined $param){ | ||||
| 343 | return _find_or_create_parameterized_type($type, $param); | ||||
| 344 | } | ||||
| 345 | else { | ||||
| 346 | return $type; | ||||
| 347 | } | ||||
| 348 | } | ||||
| 349 | elsif(defined $param){ | ||||
| 350 | Carp::croak("Undefined type with parameter [$param] in '$c->{orig}'"); | ||||
| 351 | } | ||||
| 352 | else{ | ||||
| 353 | return undef; | ||||
| 354 | } | ||||
| 355 | } | ||||
| 356 | |||||
| 357 | # type : single_type ('|' single_type)* | ||||
| 358 | # spent 106µs (15+92) within Mouse::Util::TypeConstraints::_parse_type which was called 2 times, avg 53µs/call:
# 2 times (15µs+92µs) by Mouse::Util::TypeConstraints::find_or_parse_type_constraint at line 405, avg 53µs/call | ||||
| 359 | 8 | 14µs | my($c, $create) = @_; | ||
| 360 | |||||
| 361 | 2 | 92µs | my $type = _parse_single_type($c, $create); # spent 92µs making 2 calls to Mouse::Util::TypeConstraints::_parse_single_type, avg 46µs/call | ||
| 362 | if($c->{spec}){ # can be an union type | ||||
| 363 | my @types; | ||||
| 364 | while($c->{spec} =~ s/^\|//){ | ||||
| 365 | push @types, _parse_single_type($c, $create); | ||||
| 366 | } | ||||
| 367 | if(@types){ | ||||
| 368 | return _find_or_create_union_type($type, @types); | ||||
| 369 | } | ||||
| 370 | } | ||||
| 371 | return $type; | ||||
| 372 | } | ||||
| 373 | |||||
| 374 | |||||
| 375 | # spent 96µs (76+20) within Mouse::Util::TypeConstraints::find_type_constraint which was called 8 times, avg 12µs/call:
# 8 times (76µs+20µs) by Mouse::init_meta at line 143 of Mouse.pm, avg 12µs/call | ||||
| 376 | 32 | 98µs | my($spec) = @_; | ||
| 377 | 8 | 9µs | return $spec if Mouse::Util::is_a_type_constraint($spec) or not defined $spec; # spent 9µs making 8 calls to Mouse::Util::is_a_type_constraint, avg 1µs/call | ||
| 378 | |||||
| 379 | 8 | 10µs | $spec =~ s/\s+//g; # spent 10µs making 8 calls to Mouse::Util::TypeConstraints::CORE:subst, avg 1µs/call | ||
| 380 | return $TYPE{$spec}; | ||||
| 381 | } | ||||
| 382 | |||||
| 383 | sub register_type_constraint { | ||||
| 384 | my($constraint) = @_; | ||||
| 385 | Carp::croak("No type supplied / type is not a valid type constraint") | ||||
| 386 | unless Mouse::Util::is_a_type_constraint($constraint); | ||||
| 387 | return $TYPE{$constraint->name} = $constraint; | ||||
| 388 | } | ||||
| 389 | |||||
| 390 | # spent 515µs (356+159) within Mouse::Util::TypeConstraints::find_or_parse_type_constraint which was called 51 times, avg 10µs/call:
# 51 times (356µs+159µs) by Mouse::Util::TypeConstraints::find_or_create_isa_type_constraint at line 422, avg 10µs/call | ||||
| 391 | 263 | 486µs | my($spec) = @_; | ||
| 392 | 51 | 53µs | return $spec if Mouse::Util::is_a_type_constraint($spec) or not defined $spec; # spent 53µs making 51 calls to Mouse::Util::is_a_type_constraint, avg 1µs/call | ||
| 393 | |||||
| 394 | $spec =~ tr/ \t\r\n//d; | ||||
| 395 | |||||
| 396 | my $tc = $TYPE{$spec}; | ||||
| 397 | if(defined $tc) { | ||||
| 398 | return $tc; | ||||
| 399 | } | ||||
| 400 | |||||
| 401 | my %context = ( | ||||
| 402 | spec => $spec, | ||||
| 403 | orig => $spec, | ||||
| 404 | ); | ||||
| 405 | 2 | 106µs | $tc = _parse_type(\%context); # spent 106µs making 2 calls to Mouse::Util::TypeConstraints::_parse_type, avg 53µs/call | ||
| 406 | |||||
| 407 | if($context{spec}){ | ||||
| 408 | Carp::croak("Syntax error: extra elements '$context{spec}' in '$context{orig}'"); | ||||
| 409 | } | ||||
| 410 | |||||
| 411 | return $TYPE{$spec} = $tc; | ||||
| 412 | } | ||||
| 413 | |||||
| 414 | sub find_or_create_does_type_constraint{ | ||||
| 415 | # XXX: Moose does not register a new role_type, but Mouse does. | ||||
| 416 | my $tc = find_or_parse_type_constraint(@_); | ||||
| 417 | return defined($tc) ? $tc : role_type(@_); | ||||
| 418 | } | ||||
| 419 | |||||
| 420 | # spent 1.01ms (243µs+765µs) within Mouse::Util::TypeConstraints::find_or_create_isa_type_constraint which was called 51 times, avg 20µs/call:
# 43 times (201µs+730µs) by Mouse::Meta::Attribute::_process_options at line 56 of Mouse/Meta/Attribute.pm, avg 22µs/call
# 8 times (42µs+36µs) by Mouse::Util::TypeConstraints::_define_type at line 134, avg 10µs/call | ||||
| 421 | # XXX: Moose does not register a new class_type, but Mouse does. | ||||
| 422 | 102 | 216µs | 51 | 515µs | my $tc = find_or_parse_type_constraint(@_); # spent 515µs making 51 calls to Mouse::Util::TypeConstraints::find_or_parse_type_constraint, avg 10µs/call |
| 423 | 2 | 281µs | return defined($tc) ? $tc : class_type(@_); # spent 281µs making 2 calls to Mouse::Util::TypeConstraints::class_type, avg 141µs/call | ||
| 424 | } | ||||
| 425 | |||||
| 426 | 1 | 32µs | 1; | ||
| 427 | __END__ | ||||
# spent 19µs within Mouse::Util::TypeConstraints::CORE:match which was called 8 times, avg 2µs/call:
# 8 times (19µs+0s) by Mouse::Util::TypeConstraints::_define_type at line 143, avg 2µs/call | |||||
# spent 21µs within Mouse::Util::TypeConstraints::CORE:subst which was called 12 times, avg 2µs/call:
# 8 times (10µs+0s) by Mouse::Util::TypeConstraints::find_type_constraint at line 379, avg 1µs/call
# 2 times (10µs+0s) by Mouse::Util::TypeConstraints::_parse_name at line 328, avg 5µs/call
# 2 times (800ns+0s) by Mouse::Util::TypeConstraints::_parse_param at line 312, avg 400ns/call |