| Filename | /home/doy/perl5/perlbrew/perls/perl-5.10.1/lib/site_perl/5.10.1/x86_64-linux/Moose/Util/TypeConstraints.pm |
| Statements | Executed 4858 statements in 92.9ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 475 | 13 | 6 | 20.6ms | 50.3ms | Moose::Util::TypeConstraints::find_type_constraint |
| 157 | 5 | 2 | 8.82ms | 96.8ms | Moose::Util::TypeConstraints::find_or_parse_type_constraint (recurses: max depth 3, inclusive time 26.1ms) |
| 127 | 3 | 3 | 4.76ms | 100ms | Moose::Util::TypeConstraints::find_or_create_isa_type_constraint (recurses: max depth 2, inclusive time 23.2ms) |
| 94 | 2 | 1 | 4.34ms | 17.4ms | Moose::Util::TypeConstraints::register_type_constraint |
| 157 | 1 | 1 | 3.68ms | 4.59ms | Moose::Util::TypeConstraints::normalize_type_constraint_name |
| 1 | 1 | 1 | 3.67ms | 15.1ms | Moose::Util::TypeConstraints::BEGIN@30 |
| 1 | 1 | 1 | 3.61ms | 3.92ms | Moose::Util::TypeConstraints::BEGIN@596 |
| 70 | 2 | 1 | 3.48ms | 66.6ms | Moose::Util::TypeConstraints::create_role_type_constraint |
| 91 | 13 | 1 | 3.10ms | 3.10ms | Moose::Util::TypeConstraints::CORE:regcomp (opcode) |
| 1 | 1 | 1 | 2.97ms | 10.1ms | Moose::Util::TypeConstraints::BEGIN@36 |
| 1 | 1 | 1 | 2.89ms | 8.91ms | Moose::Util::TypeConstraints::BEGIN@33 |
| 1 | 1 | 1 | 2.65ms | 8.57ms | Moose::Util::TypeConstraints::BEGIN@34 |
| 18 | 2 | 1 | 2.55ms | 17.8ms | Moose::Util::TypeConstraints::_create_type_constraint |
| 1 | 1 | 1 | 2.51ms | 3.05ms | Moose::Util::TypeConstraints::BEGIN@40 |
| 1 | 1 | 1 | 2.46ms | 8.30ms | Moose::Util::TypeConstraints::BEGIN@35 |
| 69 | 1 | 1 | 2.33ms | 81.2ms | Moose::Util::TypeConstraints::role_type |
| 1 | 1 | 1 | 2.09ms | 18.5ms | Moose::Util::TypeConstraints::BEGIN@31 |
| 1 | 1 | 1 | 2.01ms | 12.4ms | Moose::Util::TypeConstraints::BEGIN@39 |
| 34 | 2 | 1 | 1.91ms | 22.0ms | Moose::Util::TypeConstraints::create_class_type_constraint |
| 101 | 6 | 1 | 1.90ms | 1.90ms | Moose::Util::TypeConstraints::CORE:match (opcode) |
| 17 | 17 | 1 | 1.78ms | 19.3ms | Moose::Util::TypeConstraints::subtype |
| 32 | 2 | 1 | 1.12ms | 2.73ms | Moose::Util::TypeConstraints::_detect_type_constraint_union |
| 157 | 1 | 1 | 913µs | 913µs | Moose::Util::TypeConstraints::CORE:subst (opcode) |
| 6 | 1 | 1 | 908µs | 9.28ms | Moose::Util::TypeConstraints::create_type_constraint_union |
| 25 | 1 | 1 | 901µs | 21.2ms | Moose::Util::TypeConstraints::class_type |
| 10 | 1 | 1 | 852µs | 58.0ms | Moose::Util::TypeConstraints::create_parameterized_type_constraint (recurses: max depth 1, inclusive time 15.3ms) |
| 6 | 1 | 1 | 833µs | 1.42ms | Moose::Util::TypeConstraints::_parse_type_constraint_union |
| 20 | 1 | 1 | 688µs | 1.42ms | Moose::Util::TypeConstraints::_detect_parameterized_type_constraint |
| 11 | 1 | 1 | 486µs | 8.45ms | Moose::Util::TypeConstraints::find_or_create_does_type_constraint |
| 10 | 1 | 1 | 479µs | 1.10ms | Moose::Util::TypeConstraints::_parse_parameterized_type_constraint |
| 10 | 1 | 1 | 434µs | 55.8ms | Moose::Util::TypeConstraints::_create_parameterized_type_constraint (recurses: max depth 1, inclusive time 14.8ms) |
| 2 | 1 | 1 | 269µs | 4.48ms | Moose::Util::TypeConstraints::_install_type_coercions |
| 17 | 17 | 1 | 243µs | 243µs | Moose::Util::TypeConstraints::as |
| 5 | 1 | 1 | 240µs | 299µs | Moose::Util::TypeConstraints::__ANON__[:828] |
| 5 | 1 | 1 | 211µs | 274µs | Moose::Util::TypeConstraints::__ANON__[:807] |
| 17 | 17 | 1 | 190µs | 190µs | Moose::Util::TypeConstraints::where |
| 13 | 13 | 1 | 133µs | 133µs | Moose::Util::TypeConstraints::optimize_as |
| 10 | 1 | 1 | 109µs | 109µs | Moose::Util::TypeConstraints::get_all_parameterizable_types |
| 10 | 10 | 1 | 94µs | 94µs | Moose::Util::TypeConstraints::CORE:qr (opcode) |
| 2 | 1 | 1 | 89µs | 578µs | Moose::Util::TypeConstraints::find_or_create_type_constraint |
| 1 | 1 | 1 | 82µs | 1.18ms | Moose::Util::TypeConstraints::type |
| 5 | 1 | 1 | 79µs | 79µs | Moose::Util::TypeConstraints::__ANON__[:714] |
| 5 | 1 | 1 | 64µs | 64µs | Moose::Util::TypeConstraints::__ANON__[:707] |
| 2 | 2 | 2 | 60µs | 4.54ms | Moose::Util::TypeConstraints::coerce |
| 1 | 1 | 1 | 56µs | 157µs | Moose::Util::TypeConstraints::BEGIN@649 |
| 1 | 1 | 1 | 53µs | 64µs | Moose::Util::TypeConstraints::list_all_type_constraints |
| 1 | 1 | 1 | 46µs | 46µs | Moose::Util::TypeConstraints::BEGIN@4 |
| 1 | 1 | 1 | 44µs | 102µs | Moose::Util::TypeConstraints::BEGIN@655 |
| 1 | 1 | 1 | 44µs | 77µs | Moose::Util::TypeConstraints::BEGIN@28 |
| 1 | 1 | 1 | 41µs | 112µs | Moose::Util::TypeConstraints::BEGIN@66 |
| 1 | 1 | 1 | 41µs | 234µs | Moose::Util::TypeConstraints::BEGIN@5 |
| 1 | 1 | 1 | 40µs | 97µs | Moose::Util::TypeConstraints::BEGIN@676 |
| 1 | 1 | 1 | 39µs | 93µs | Moose::Util::TypeConstraints::BEGIN@660 |
| 1 | 1 | 1 | 38µs | 38µs | Moose::Util::TypeConstraints::BEGIN@37 |
| 1 | 1 | 1 | 37µs | 194µs | Moose::Util::TypeConstraints::BEGIN@6 |
| 1 | 1 | 1 | 35µs | 156µs | Moose::Util::TypeConstraints::BEGIN@7 |
| 1 | 1 | 1 | 31µs | 31µs | Moose::Util::TypeConstraints::BEGIN@29 |
| 1 | 1 | 1 | 26µs | 26µs | Moose::Util::TypeConstraints::BEGIN@32 |
| 1 | 1 | 1 | 23µs | 23µs | Moose::Util::TypeConstraints::BEGIN@38 |
| 2 | 2 | 2 | 23µs | 23µs | Moose::Util::TypeConstraints::from |
| 2 | 2 | 2 | 21µs | 21µs | Moose::Util::TypeConstraints::via |
| 0 | 0 | 0 | 0s | 0s | Moose::Util::TypeConstraints::__ANON__[:278] |
| 0 | 0 | 0 | 0s | 0s | Moose::Util::TypeConstraints::__ANON__[:315] |
| 0 | 0 | 0 | 0s | 0s | Moose::Util::TypeConstraints::__ANON__[:327] |
| 0 | 0 | 0 | 0s | 0s | Moose::Util::TypeConstraints::__ANON__[:710] |
| 0 | 0 | 0 | 0s | 0s | Moose::Util::TypeConstraints::__ANON__[:711] |
| 0 | 0 | 0 | 0s | 0s | Moose::Util::TypeConstraints::__ANON__[:716] |
| 0 | 0 | 0 | 0s | 0s | Moose::Util::TypeConstraints::__ANON__[:719] |
| 0 | 0 | 0 | 0s | 0s | Moose::Util::TypeConstraints::__ANON__[:71] |
| 0 | 0 | 0 | 0s | 0s | Moose::Util::TypeConstraints::__ANON__[:722] |
| 0 | 0 | 0 | 0s | 0s | Moose::Util::TypeConstraints::__ANON__[:726] |
| 0 | 0 | 0 | 0s | 0s | Moose::Util::TypeConstraints::__ANON__[:729] |
| 0 | 0 | 0 | 0s | 0s | Moose::Util::TypeConstraints::__ANON__[:732] |
| 0 | 0 | 0 | 0s | 0s | Moose::Util::TypeConstraints::__ANON__[:734] |
| 0 | 0 | 0 | 0s | 0s | Moose::Util::TypeConstraints::__ANON__[:737] |
| 0 | 0 | 0 | 0s | 0s | Moose::Util::TypeConstraints::__ANON__[:745] |
| 0 | 0 | 0 | 0s | 0s | Moose::Util::TypeConstraints::__ANON__[:751] |
| 0 | 0 | 0 | 0s | 0s | Moose::Util::TypeConstraints::__ANON__[:755] |
| 0 | 0 | 0 | 0s | 0s | Moose::Util::TypeConstraints::__ANON__[:758] |
| 0 | 0 | 0 | 0s | 0s | Moose::Util::TypeConstraints::__ANON__[:761] |
| 0 | 0 | 0 | 0s | 0s | Moose::Util::TypeConstraints::__ANON__[:766] |
| 0 | 0 | 0 | 0s | 0s | Moose::Util::TypeConstraints::__ANON__[:777] |
| 0 | 0 | 0 | 0s | 0s | Moose::Util::TypeConstraints::__ANON__[:785] |
| 0 | 0 | 0 | 0s | 0s | Moose::Util::TypeConstraints::__ANON__[:786] |
| 0 | 0 | 0 | 0s | 0s | Moose::Util::TypeConstraints::__ANON__[:795] |
| 0 | 0 | 0 | 0s | 0s | Moose::Util::TypeConstraints::__ANON__[:806] |
| 0 | 0 | 0 | 0s | 0s | Moose::Util::TypeConstraints::__ANON__[:816] |
| 0 | 0 | 0 | 0s | 0s | Moose::Util::TypeConstraints::__ANON__[:827] |
| 0 | 0 | 0 | 0s | 0s | Moose::Util::TypeConstraints::__ANON__[:837] |
| 0 | 0 | 0 | 0s | 0s | Moose::Util::TypeConstraints::__ANON__[:844] |
| 0 | 0 | 0 | 0s | 0s | Moose::Util::TypeConstraints::__ANON__[:845] |
| 0 | 0 | 0 | 0s | 0s | Moose::Util::TypeConstraints::_confess |
| 0 | 0 | 0 | 0s | 0s | Moose::Util::TypeConstraints::_throw_error |
| 0 | 0 | 0 | 0s | 0s | Moose::Util::TypeConstraints::add_parameterizable_type |
| 0 | 0 | 0 | 0s | 0s | Moose::Util::TypeConstraints::create_duck_type_constraint |
| 0 | 0 | 0 | 0s | 0s | Moose::Util::TypeConstraints::create_enum_type_constraint |
| 0 | 0 | 0 | 0s | 0s | Moose::Util::TypeConstraints::duck_type |
| 0 | 0 | 0 | 0s | 0s | Moose::Util::TypeConstraints::enum |
| 0 | 0 | 0 | 0s | 0s | Moose::Util::TypeConstraints::export_type_constraints_as_functions |
| 0 | 0 | 0 | 0s | 0s | Moose::Util::TypeConstraints::get_type_constraint_registry |
| 0 | 0 | 0 | 0s | 0s | Moose::Util::TypeConstraints::list_all_builtin_type_constraints |
| 0 | 0 | 0 | 0s | 0s | Moose::Util::TypeConstraints::match_on_type |
| 0 | 0 | 0 | 0s | 0s | Moose::Util::TypeConstraints::maybe_type |
| 0 | 0 | 0 | 0s | 0s | Moose::Util::TypeConstraints::message |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | |||||
| 2 | package Moose::Util::TypeConstraints; | ||||
| 3 | |||||
| 4 | 3 | 131µs | 1 | 46µs | # spent 46µs within Moose::Util::TypeConstraints::BEGIN@4 which was called:
# once (46µs+0s) by Moose::Meta::Attribute::BEGIN@20 at line 4 # spent 46µs making 1 call to Moose::Util::TypeConstraints::BEGIN@4 |
| 5 | 3 | 114µs | 2 | 428µs | # spent 234µs (41+194) within Moose::Util::TypeConstraints::BEGIN@5 which was called:
# once (41µs+194µs) by Moose::Meta::Attribute::BEGIN@20 at line 5 # spent 234µs making 1 call to Moose::Util::TypeConstraints::BEGIN@5
# spent 194µs making 1 call to Exporter::import |
| 6 | 3 | 98µs | 2 | 352µs | # spent 194µs (37+158) within Moose::Util::TypeConstraints::BEGIN@6 which was called:
# once (37µs+158µs) by Moose::Meta::Attribute::BEGIN@20 at line 6 # spent 194µs making 1 call to Moose::Util::TypeConstraints::BEGIN@6
# spent 158µs making 1 call to Exporter::import |
| 7 | 3 | 311µs | 2 | 277µs | # spent 156µs (35+121) within Moose::Util::TypeConstraints::BEGIN@7 which was called:
# once (35µs+121µs) by Moose::Meta::Attribute::BEGIN@20 at line 7 # spent 156µs making 1 call to Moose::Util::TypeConstraints::BEGIN@7
# spent 121µs making 1 call to Moose::Exporter::import |
| 8 | |||||
| 9 | 1 | 9µs | our $VERSION = '1.19'; | ||
| 10 | 1 | 94µs | $VERSION = eval $VERSION; # spent 12µs executing statements in string eval | ||
| 11 | 1 | 4µs | our $AUTHORITY = 'cpan:STEVAN'; | ||
| 12 | |||||
| 13 | ## -------------------------------------------------------- | ||||
| 14 | # Prototyped subs must be predeclared because we have a | ||||
| 15 | # circular dependency with Moose::Meta::Attribute et. al. | ||||
| 16 | # so in case of us being use'd first the predeclaration | ||||
| 17 | # ensures the prototypes are in scope when consumers are | ||||
| 18 | # compiled. | ||||
| 19 | |||||
| 20 | # dah sugah! | ||||
| 21 | sub where (&); | ||||
| 22 | sub via (&); | ||||
| 23 | sub message (&); | ||||
| 24 | sub optimize_as (&); | ||||
| 25 | |||||
| 26 | ## -------------------------------------------------------- | ||||
| 27 | |||||
| 28 | 3 | 109µs | 2 | 111µs | # spent 77µs (44+34) within Moose::Util::TypeConstraints::BEGIN@28 which was called:
# once (44µs+34µs) by Moose::Meta::Attribute::BEGIN@20 at line 28 # spent 77µs making 1 call to Moose::Util::TypeConstraints::BEGIN@28
# spent 34µs making 1 call to Package::DeprecationManager::__ANON__[Package/DeprecationManager.pm:61] |
| 29 | 3 | 99µs | 1 | 31µs | # spent 31µs within Moose::Util::TypeConstraints::BEGIN@29 which was called:
# once (31µs+0s) by Moose::Meta::Attribute::BEGIN@20 at line 29 # spent 31µs making 1 call to Moose::Util::TypeConstraints::BEGIN@29 |
| 30 | 3 | 495µs | 1 | 15.1ms | # spent 15.1ms (3.67+11.4) within Moose::Util::TypeConstraints::BEGIN@30 which was called:
# once (3.67ms+11.4ms) by Moose::Meta::Attribute::BEGIN@20 at line 30 # spent 15.1ms making 1 call to Moose::Util::TypeConstraints::BEGIN@30 |
| 31 | 3 | 497µs | 1 | 18.5ms | # spent 18.5ms (2.09+16.4) within Moose::Util::TypeConstraints::BEGIN@31 which was called:
# once (2.09ms+16.4ms) by Moose::Meta::Attribute::BEGIN@20 at line 31 # spent 18.5ms making 1 call to Moose::Util::TypeConstraints::BEGIN@31 |
| 32 | 3 | 93µs | 1 | 26µs | # spent 26µs within Moose::Util::TypeConstraints::BEGIN@32 which was called:
# once (26µs+0s) by Moose::Meta::Attribute::BEGIN@20 at line 32 # spent 26µs making 1 call to Moose::Util::TypeConstraints::BEGIN@32 |
| 33 | 3 | 492µs | 1 | 8.91ms | # spent 8.91ms (2.89+6.02) within Moose::Util::TypeConstraints::BEGIN@33 which was called:
# once (2.89ms+6.02ms) by Moose::Meta::Attribute::BEGIN@20 at line 33 # spent 8.91ms making 1 call to Moose::Util::TypeConstraints::BEGIN@33 |
| 34 | 3 | 506µs | 1 | 8.57ms | # spent 8.57ms (2.65+5.93) within Moose::Util::TypeConstraints::BEGIN@34 which was called:
# once (2.65ms+5.93ms) by Moose::Meta::Attribute::BEGIN@20 at line 34 # spent 8.57ms making 1 call to Moose::Util::TypeConstraints::BEGIN@34 |
| 35 | 3 | 482µs | 1 | 8.30ms | # spent 8.30ms (2.46+5.83) within Moose::Util::TypeConstraints::BEGIN@35 which was called:
# once (2.46ms+5.83ms) by Moose::Meta::Attribute::BEGIN@20 at line 35 # spent 8.30ms making 1 call to Moose::Util::TypeConstraints::BEGIN@35 |
| 36 | 3 | 505µs | 1 | 10.1ms | # spent 10.1ms (2.97+7.14) within Moose::Util::TypeConstraints::BEGIN@36 which was called:
# once (2.97ms+7.14ms) by Moose::Meta::Attribute::BEGIN@20 at line 36 # spent 10.1ms making 1 call to Moose::Util::TypeConstraints::BEGIN@36 |
| 37 | 3 | 104µs | 1 | 38µs | # spent 38µs within Moose::Util::TypeConstraints::BEGIN@37 which was called:
# once (38µs+0s) by Moose::Meta::Attribute::BEGIN@20 at line 37 # spent 38µs making 1 call to Moose::Util::TypeConstraints::BEGIN@37 |
| 38 | 3 | 88µs | 1 | 23µs | # spent 23µs within Moose::Util::TypeConstraints::BEGIN@38 which was called:
# once (23µs+0s) by Moose::Meta::Attribute::BEGIN@20 at line 38 # spent 23µs making 1 call to Moose::Util::TypeConstraints::BEGIN@38 |
| 39 | 3 | 511µs | 1 | 12.4ms | # spent 12.4ms (2.01+10.4) within Moose::Util::TypeConstraints::BEGIN@39 which was called:
# once (2.01ms+10.4ms) by Moose::Meta::Attribute::BEGIN@20 at line 39 # spent 12.4ms making 1 call to Moose::Util::TypeConstraints::BEGIN@39 |
| 40 | 3 | 915µs | 1 | 3.05ms | # spent 3.05ms (2.51+532µs) within Moose::Util::TypeConstraints::BEGIN@40 which was called:
# once (2.51ms+532µs) by Moose::Meta::Attribute::BEGIN@20 at line 40 # spent 3.05ms making 1 call to Moose::Util::TypeConstraints::BEGIN@40 |
| 41 | |||||
| 42 | 1 | 104µs | 1 | 5.70ms | Moose::Exporter->setup_import_methods( # spent 5.70ms making 1 call to Moose::Exporter::setup_import_methods |
| 43 | as_is => [ | ||||
| 44 | qw( | ||||
| 45 | type subtype class_type role_type maybe_type duck_type | ||||
| 46 | as where message optimize_as | ||||
| 47 | coerce from via | ||||
| 48 | enum | ||||
| 49 | find_type_constraint | ||||
| 50 | register_type_constraint | ||||
| 51 | match_on_type ) | ||||
| 52 | ], | ||||
| 53 | ); | ||||
| 54 | |||||
| 55 | ## -------------------------------------------------------- | ||||
| 56 | ## type registry and some useful functions for it | ||||
| 57 | ## -------------------------------------------------------- | ||||
| 58 | |||||
| 59 | 1 | 15µs | 1 | 1.54ms | my $REGISTRY = Moose::Meta::TypeConstraint::Registry->new; # spent 1.54ms making 1 call to Moose::Meta::TypeConstraint::Registry::new |
| 60 | |||||
| 61 | sub get_type_constraint_registry {$REGISTRY} | ||||
| 62 | 1 | 51µs | 1 | 11µs | # spent 64µs (53+11) within Moose::Util::TypeConstraints::list_all_type_constraints which was called:
# once (53µs+11µs) by Moose::Meta::Attribute::BEGIN@20 at line 869 # spent 11µs making 1 call to Moose::Meta::TypeConstraint::Registry::type_constraints |
| 63 | |||||
| 64 | sub export_type_constraints_as_functions { | ||||
| 65 | my $pkg = caller(); | ||||
| 66 | 3 | 7.65ms | 2 | 183µs | # spent 112µs (41+71) within Moose::Util::TypeConstraints::BEGIN@66 which was called:
# once (41µs+71µs) by Moose::Meta::Attribute::BEGIN@20 at line 66 # spent 112µs making 1 call to Moose::Util::TypeConstraints::BEGIN@66
# spent 71µs making 1 call to strict::unimport |
| 67 | foreach my $constraint ( keys %{ $REGISTRY->type_constraints } ) { | ||||
| 68 | my $tc = $REGISTRY->get_type_constraint($constraint) | ||||
| 69 | ->_compiled_type_constraint; | ||||
| 70 | *{"${pkg}::${constraint}"} | ||||
| 71 | = sub { $tc->( $_[0] ) ? 1 : undef }; # the undef is for compat | ||||
| 72 | } | ||||
| 73 | } | ||||
| 74 | |||||
| 75 | # spent 9.28ms (908µs+8.37) within Moose::Util::TypeConstraints::create_type_constraint_union which was called 6 times, avg 1.55ms/call:
# 6 times (908µs+8.37ms) by Moose::Util::TypeConstraints::find_or_parse_type_constraint at line 218, avg 1.55ms/call | ||||
| 76 | 6 | 13µs | my @type_constraint_names; | ||
| 77 | |||||
| 78 | 6 | 172µs | 12 | 1.74ms | if ( scalar @_ == 1 && _detect_type_constraint_union( $_[0] ) ) { # spent 1.42ms making 6 calls to Moose::Util::TypeConstraints::_parse_type_constraint_union, avg 236µs/call
# spent 325µs making 6 calls to Moose::Util::TypeConstraints::_detect_type_constraint_union, avg 54µs/call |
| 79 | @type_constraint_names = _parse_type_constraint_union( $_[0] ); | ||||
| 80 | } | ||||
| 81 | else { | ||||
| 82 | @type_constraint_names = @_; | ||||
| 83 | } | ||||
| 84 | |||||
| 85 | 6 | 22µs | ( scalar @type_constraint_names >= 2 ) | ||
| 86 | || __PACKAGE__->_throw_error( | ||||
| 87 | "You must pass in at least 2 type names to make a union"); | ||||
| 88 | |||||
| 89 | 15 | 311µs | 30 | 111µs | my @type_constraints = map { # spent 111µs making 15 calls to Moose::Meta::TypeConstraint::__ANON__[Moose/Meta/TypeConstraint.pm:10], avg 7µs/call
# spent 3.09ms making 15 calls to Moose::Util::TypeConstraints::find_or_parse_type_constraint, avg 206µs/call, recursion: max depth 3, sum of overlapping time 3.09ms |
| 90 | 6 | 86µs | find_or_parse_type_constraint($_) | ||
| 91 | || __PACKAGE__->_throw_error( | ||||
| 92 | "Could not locate type constraint ($_) for the union"); | ||||
| 93 | } @type_constraint_names; | ||||
| 94 | |||||
| 95 | 6 | 163µs | 6 | 3.42ms | return Moose::Meta::TypeConstraint::Union->new( # spent 3.42ms making 6 calls to Moose::Meta::TypeConstraint::Union::new, avg 570µs/call |
| 96 | type_constraints => \@type_constraints ); | ||||
| 97 | } | ||||
| 98 | |||||
| 99 | # spent 58.0ms (852µs+57.2) within Moose::Util::TypeConstraints::create_parameterized_type_constraint which was called 10 times, avg 5.80ms/call:
# 10 times (852µs+57.2ms) by Moose::Util::TypeConstraints::find_or_parse_type_constraint at line 218, avg 5.80ms/call | ||||
| 100 | 10 | 41µs | my $type_constraint_name = shift; | ||
| 101 | 10 | 201µs | 10 | 1.10ms | my ( $base_type, $type_parameter ) # spent 1.10ms making 10 calls to Moose::Util::TypeConstraints::_parse_parameterized_type_constraint, avg 110µs/call |
| 102 | = _parse_parameterized_type_constraint($type_constraint_name); | ||||
| 103 | |||||
| 104 | 10 | 30µs | ( defined $base_type && defined $type_parameter ) | ||
| 105 | || __PACKAGE__->_throw_error( | ||||
| 106 | "Could not parse type name ($type_constraint_name) correctly"); | ||||
| 107 | |||||
| 108 | 10 | 113µs | 10 | 378µs | if ( $REGISTRY->has_type_constraint($base_type) ) { # spent 378µs making 10 calls to Moose::Meta::TypeConstraint::Registry::has_type_constraint, avg 38µs/call |
| 109 | 10 | 115µs | 10 | 376µs | my $base_type_tc = $REGISTRY->get_type_constraint($base_type); # spent 376µs making 10 calls to Moose::Meta::TypeConstraint::Registry::get_type_constraint, avg 38µs/call |
| 110 | 10 | 217µs | 10 | 55.8ms | return _create_parameterized_type_constraint( # spent 70.6ms making 10 calls to Moose::Util::TypeConstraints::_create_parameterized_type_constraint, avg 7.06ms/call, recursion: max depth 1, sum of overlapping time 14.8ms |
| 111 | $base_type_tc, | ||||
| 112 | $type_parameter | ||||
| 113 | ); | ||||
| 114 | } | ||||
| 115 | else { | ||||
| 116 | __PACKAGE__->_throw_error( | ||||
| 117 | "Could not locate the base type ($base_type)"); | ||||
| 118 | } | ||||
| 119 | } | ||||
| 120 | |||||
| 121 | # spent 55.8ms (434µs+55.3) within Moose::Util::TypeConstraints::_create_parameterized_type_constraint which was called 10 times, avg 5.58ms/call:
# 10 times (434µs+55.3ms) by Moose::Util::TypeConstraints::create_parameterized_type_constraint at line 110, avg 5.58ms/call | ||||
| 122 | 10 | 44µs | my ( $base_type_tc, $type_parameter ) = @_; | ||
| 123 | 10 | 428µs | 20 | 55.4ms | if ( $base_type_tc->can('parameterize') ) { # spent 70.1ms making 10 calls to Moose::Meta::TypeConstraint::Parameterizable::parameterize, avg 7.01ms/call, recursion: max depth 1, sum of overlapping time 14.7ms
# spent 73µs making 10 calls to UNIVERSAL::can, avg 7µs/call |
| 124 | return $base_type_tc->parameterize($type_parameter); | ||||
| 125 | } | ||||
| 126 | else { | ||||
| 127 | return Moose::Meta::TypeConstraint::Parameterized->new( | ||||
| 128 | name => $base_type_tc->name . '[' . $type_parameter . ']', | ||||
| 129 | parent => $base_type_tc, | ||||
| 130 | type_parameter => | ||||
| 131 | find_or_create_isa_type_constraint($type_parameter), | ||||
| 132 | ); | ||||
| 133 | } | ||||
| 134 | } | ||||
| 135 | |||||
| 136 | #should we also support optimized checks? | ||||
| 137 | # spent 22.0ms (1.91+20.1) within Moose::Util::TypeConstraints::create_class_type_constraint which was called 34 times, avg 648µs/call:
# 25 times (1.43ms+14.2ms) by Moose::Util::TypeConstraints::class_type at line 362, avg 625µs/call
# 9 times (478µs+5.92ms) by Moose::Util::TypeConstraints::find_or_create_isa_type_constraint at line 204, avg 711µs/call | ||||
| 138 | 34 | 153µs | my ( $class, $options ) = @_; | ||
| 139 | |||||
| 140 | # too early for this check | ||||
| 141 | #find_type_constraint("ClassName")->check($class) | ||||
| 142 | # || __PACKAGE__->_throw_error("Can't create a class type constraint because '$class' is not a class name"); | ||||
| 143 | |||||
| 144 | my %options = ( | ||||
| 145 | class => $class, | ||||
| 146 | name => $class, | ||||
| 147 | 34 | 643µs | %{ $options || {} }, | ||
| 148 | ); | ||||
| 149 | |||||
| 150 | 34 | 92µs | $options{name} ||= "__ANON__"; | ||
| 151 | |||||
| 152 | 34 | 996µs | 34 | 20.1ms | Moose::Meta::TypeConstraint::Class->new(%options); # spent 20.1ms making 34 calls to Moose::Meta::TypeConstraint::Class::new, avg 592µs/call |
| 153 | } | ||||
| 154 | |||||
| 155 | # spent 66.6ms (3.48+63.2) within Moose::Util::TypeConstraints::create_role_type_constraint which was called 70 times, avg 952µs/call:
# 69 times (3.43ms+62.6ms) by Moose::Util::TypeConstraints::role_type at line 371, avg 957µs/call
# once (47µs+551µs) by Moose::Util::TypeConstraints::find_or_create_does_type_constraint at line 210 | ||||
| 156 | 70 | 276µs | my ( $role, $options ) = @_; | ||
| 157 | |||||
| 158 | # too early for this check | ||||
| 159 | #find_type_constraint("ClassName")->check($class) | ||||
| 160 | # || __PACKAGE__->_throw_error("Can't create a class type constraint because '$class' is not a class name"); | ||||
| 161 | |||||
| 162 | my %options = ( | ||||
| 163 | role => $role, | ||||
| 164 | name => $role, | ||||
| 165 | 70 | 1.05ms | %{ $options || {} }, | ||
| 166 | ); | ||||
| 167 | |||||
| 168 | 70 | 183µs | $options{name} ||= "__ANON__"; | ||
| 169 | |||||
| 170 | 70 | 2.05ms | 70 | 63.2ms | Moose::Meta::TypeConstraint::Role->new(%options); # spent 63.2ms making 70 calls to Moose::Meta::TypeConstraint::Role::new, avg 902µs/call |
| 171 | } | ||||
| 172 | |||||
| 173 | # spent 578µs (89+489) within Moose::Util::TypeConstraints::find_or_create_type_constraint which was called 2 times, avg 289µs/call:
# 2 times (89µs+489µs) by Moose::Meta::Attribute::Native::Trait::_check_helper_type at line 93 of Moose/Meta/Attribute/Native/Trait.pm, avg 289µs/call | ||||
| 174 | 2 | 9µs | my ( $type_constraint_name, $options_for_anon_type ) = @_; | ||
| 175 | |||||
| 176 | 2 | 63µs | 4 | 489µs | if ( my $constraint # spent 474µs making 2 calls to Moose::Util::TypeConstraints::find_or_parse_type_constraint, avg 237µs/call
# spent 15µs making 2 calls to Moose::Meta::TypeConstraint::__ANON__[Moose/Meta/TypeConstraint.pm:10], avg 7µs/call |
| 177 | = find_or_parse_type_constraint($type_constraint_name) ) { | ||||
| 178 | return $constraint; | ||||
| 179 | } | ||||
| 180 | elsif ( defined $options_for_anon_type ) { | ||||
| 181 | |||||
| 182 | # NOTE: | ||||
| 183 | # if there is no $options_for_anon_type | ||||
| 184 | # specified, then we assume they don't | ||||
| 185 | # want to create one, and return nothing. | ||||
| 186 | |||||
| 187 | # otherwise assume that we should create | ||||
| 188 | # an ANON type with the $options_for_anon_type | ||||
| 189 | # options which can be passed in. It should | ||||
| 190 | # be noted that these don't get registered | ||||
| 191 | # so we need to return it. | ||||
| 192 | # - SL | ||||
| 193 | return Moose::Meta::TypeConstraint->new( | ||||
| 194 | name => '__ANON__', | ||||
| 195 | %{$options_for_anon_type} | ||||
| 196 | ); | ||||
| 197 | } | ||||
| 198 | |||||
| 199 | return; | ||||
| 200 | } | ||||
| 201 | |||||
| 202 | # spent 100ms (4.76+95.7) within Moose::Util::TypeConstraints::find_or_create_isa_type_constraint which was called 127 times, avg 791µs/call:
# 100 times (3.83ms+92.2ms) by Moose::Meta::Attribute::_process_isa_option at line 325 of Moose/Meta/Attribute.pm, avg 960µs/call
# 17 times (572µs+3.67ms) by Moose::Util::TypeConstraints::_create_type_constraint at line 547, avg 250µs/call
# 10 times (358µs+-116µs) by Moose::Meta::TypeConstraint::Parameterizable::_parse_type_parameter at line 47 of Moose/Meta/TypeConstraint/Parameterizable.pm, avg 24µs/call | ||||
| 203 | 127 | 464µs | my $type_constraint_name = shift; | ||
| 204 | 127 | 3.56ms | 254 | 95.9ms | find_or_parse_type_constraint($type_constraint_name) # spent 112ms making 127 calls to Moose::Util::TypeConstraints::find_or_parse_type_constraint, avg 879µs/call, recursion: max depth 2, sum of overlapping time 23.0ms
# spent 6.40ms making 9 calls to Moose::Util::TypeConstraints::create_class_type_constraint, avg 711µs/call
# spent 899µs making 118 calls to Moose::Meta::TypeConstraint::__ANON__[Moose/Meta/TypeConstraint.pm:10], avg 8µs/call |
| 205 | || create_class_type_constraint($type_constraint_name); | ||||
| 206 | } | ||||
| 207 | |||||
| 208 | # spent 8.45ms (486µs+7.96) within Moose::Util::TypeConstraints::find_or_create_does_type_constraint which was called 11 times, avg 768µs/call:
# 11 times (486µs+7.96ms) by Moose::Meta::Attribute::_process_does_option at line 342 of Moose/Meta/Attribute.pm, avg 768µs/call | ||||
| 209 | 11 | 112µs | my $type_constraint_name = shift; | ||
| 210 | 11 | 303µs | 22 | 7.96ms | find_or_parse_type_constraint($type_constraint_name) # spent 7.29ms making 11 calls to Moose::Util::TypeConstraints::find_or_parse_type_constraint, avg 662µs/call
# spent 598µs making 1 call to Moose::Util::TypeConstraints::create_role_type_constraint
# spent 75µs making 10 calls to Moose::Meta::TypeConstraint::__ANON__[Moose/Meta/TypeConstraint.pm:10], avg 8µs/call |
| 211 | || create_role_type_constraint($type_constraint_name); | ||||
| 212 | } | ||||
| 213 | |||||
| 214 | # spent 96.8ms (8.82+88.0) within Moose::Util::TypeConstraints::find_or_parse_type_constraint which was called 157 times, avg 617µs/call:
# 127 times (7.24ms+81.4ms) by Moose::Util::TypeConstraints::find_or_create_isa_type_constraint at line 204, avg 698µs/call
# 15 times (739µs+-739µs) by Moose::Util::TypeConstraints::create_type_constraint_union at line 89, avg 0s/call
# 11 times (630µs+6.66ms) by Moose::Util::TypeConstraints::find_or_create_does_type_constraint at line 210, avg 662µs/call
# 2 times (103µs+371µs) by Moose::Util::TypeConstraints::find_or_create_type_constraint at line 176, avg 237µs/call
# 2 times (105µs+341µs) by Moose::Meta::TypeCoercion::compile_type_coercion at line 45 of Moose/Meta/TypeCoercion.pm, avg 223µs/call | ||||
| 215 | 157 | 1.76ms | 157 | 4.59ms | my $type_constraint_name = normalize_type_constraint_name(shift); # spent 4.59ms making 157 calls to Moose::Util::TypeConstraints::normalize_type_constraint_name, avg 29µs/call |
| 216 | 157 | 295µs | my $constraint; | ||
| 217 | |||||
| 218 | 157 | 5.27ms | 350 | 92.2ms | if ( $constraint = find_type_constraint($type_constraint_name) ) { # spent 73.3ms making 10 calls to Moose::Util::TypeConstraints::create_parameterized_type_constraint, avg 7.33ms/call, recursion: max depth 1, sum of overlapping time 15.3ms
# spent 19.8ms making 157 calls to Moose::Util::TypeConstraints::find_type_constraint, avg 126µs/call
# spent 9.28ms making 6 calls to Moose::Util::TypeConstraints::create_type_constraint_union, avg 1.55ms/call
# spent 2.41ms making 26 calls to Moose::Util::TypeConstraints::_detect_type_constraint_union, avg 93µs/call
# spent 1.42ms making 20 calls to Moose::Util::TypeConstraints::_detect_parameterized_type_constraint, avg 71µs/call
# spent 1.26ms making 131 calls to Moose::Meta::TypeConstraint::__ANON__[Moose/Meta/TypeConstraint.pm:10], avg 10µs/call |
| 219 | return $constraint; | ||||
| 220 | } | ||||
| 221 | elsif ( _detect_type_constraint_union($type_constraint_name) ) { | ||||
| 222 | $constraint = create_type_constraint_union($type_constraint_name); | ||||
| 223 | } | ||||
| 224 | elsif ( _detect_parameterized_type_constraint($type_constraint_name) ) { | ||||
| 225 | $constraint | ||||
| 226 | = create_parameterized_type_constraint($type_constraint_name); | ||||
| 227 | } | ||||
| 228 | else { | ||||
| 229 | 10 | 124µs | return; | ||
| 230 | } | ||||
| 231 | |||||
| 232 | 16 | 202µs | 16 | 2.08ms | $REGISTRY->add_type_constraint($constraint); # spent 2.08ms making 16 calls to Moose::Meta::TypeConstraint::Registry::add_type_constraint, avg 130µs/call |
| 233 | 16 | 204µs | return $constraint; | ||
| 234 | } | ||||
| 235 | |||||
| 236 | # spent 4.59ms (3.68+913µs) within Moose::Util::TypeConstraints::normalize_type_constraint_name which was called 157 times, avg 29µs/call:
# 157 times (3.68ms+913µs) by Moose::Util::TypeConstraints::find_or_parse_type_constraint at line 215, avg 29µs/call | ||||
| 237 | 157 | 483µs | my $type_constraint_name = shift; | ||
| 238 | 157 | 2.65ms | 157 | 913µs | $type_constraint_name =~ s/\s//g; # spent 913µs making 157 calls to Moose::Util::TypeConstraints::CORE:subst, avg 6µs/call |
| 239 | 157 | 1.94ms | return $type_constraint_name; | ||
| 240 | } | ||||
| 241 | |||||
| 242 | sub _confess { | ||||
| 243 | my $error = shift; | ||||
| 244 | |||||
| 245 | local $Carp::CarpLevel = $Carp::CarpLevel + 1; | ||||
| 246 | Carp::confess($error); | ||||
| 247 | } | ||||
| 248 | |||||
| 249 | ## -------------------------------------------------------- | ||||
| 250 | ## exported functions ... | ||||
| 251 | ## -------------------------------------------------------- | ||||
| 252 | |||||
| 253 | # spent 50.3ms (20.6+29.6) within Moose::Util::TypeConstraints::find_type_constraint which was called 475 times, avg 106µs/call:
# 157 times (7.34ms+12.5ms) by Moose::Util::TypeConstraints::find_or_parse_type_constraint at line 218, avg 126µs/call
# 87 times (2.39ms+896µs) by Moose::Meta::TypeConstraint::equals at line 155 of Moose/Meta/TypeConstraint.pm, avg 38µs/call
# 70 times (3.42ms+5.76ms) by Moose::Meta::TypeConstraint::Role::new at line 23 of Moose/Meta/TypeConstraint/Role.pm, avg 131µs/call
# 69 times (3.13ms+3.80ms) by Moose::Role::init_meta at line 117 of Moose/Role.pm, avg 100µs/call
# 34 times (1.69ms+2.80ms) by Moose::Meta::TypeConstraint::Class::new at line 23 of Moose/Meta/TypeConstraint/Class.pm, avg 132µs/call
# 25 times (1.20ms+1.97ms) by Moose::Meta::TypeConstraint::is_subtype_of at line 186 of Moose/Meta/TypeConstraint.pm, avg 127µs/call
# 25 times (1.09ms+1.28ms) by Moose::init_meta at line 162 of Moose.pm, avg 95µs/call
# 2 times (111µs+181µs) by Moose::Util::TypeConstraints::_install_type_coercions at line 568, avg 146µs/call
# 2 times (86µs+146µs) by Moose::Meta::TypeConstraint::is_a_type_of at line 178 of Moose/Meta/TypeConstraint.pm, avg 116µs/call
# once (48µs+75µs) by Moose::Meta::Attribute::BEGIN@20 at line 809
# once (43µs+74µs) by Moose::Meta::Attribute::BEGIN@20 at line 847
# once (44µs+72µs) by Moose::Meta::Attribute::BEGIN@20 at line 788
# once (44µs+73µs) by Moose::Meta::Attribute::BEGIN@20 at line 830 | ||||
| 254 | 475 | 1.55ms | my $type = shift; | ||
| 255 | |||||
| 256 | 475 | 9.81ms | 562 | 2.85ms | if ( blessed $type and $type->isa("Moose::Meta::TypeConstraint") ) { # spent 2.40ms making 475 calls to Scalar::Util::blessed, avg 5µs/call
# spent 451µs making 87 calls to UNIVERSAL::isa, avg 5µs/call |
| 257 | return $type; | ||||
| 258 | } | ||||
| 259 | else { | ||||
| 260 | 388 | 6.01ms | 388 | 16.3ms | return unless $REGISTRY->has_type_constraint($type); # spent 16.3ms making 388 calls to Moose::Meta::TypeConstraint::Registry::has_type_constraint, avg 42µs/call |
| 261 | 268 | 5.42ms | 268 | 10.5ms | return $REGISTRY->get_type_constraint($type); # spent 10.5ms making 268 calls to Moose::Meta::TypeConstraint::Registry::get_type_constraint, avg 39µs/call |
| 262 | } | ||||
| 263 | } | ||||
| 264 | |||||
| 265 | # spent 17.4ms (4.34+13.1) within Moose::Util::TypeConstraints::register_type_constraint which was called 94 times, avg 186µs/call:
# 69 times (3.20ms+9.59ms) by Moose::Util::TypeConstraints::role_type at line 371, avg 185µs/call
# 25 times (1.14ms+3.51ms) by Moose::Util::TypeConstraints::class_type at line 362, avg 186µs/call | ||||
| 266 | 94 | 325µs | my $constraint = shift; | ||
| 267 | 94 | 1.14ms | 94 | 1.30ms | __PACKAGE__->_throw_error("can't register an unnamed type constraint") # spent 1.30ms making 94 calls to Moose::Meta::TypeConstraint::name, avg 14µs/call |
| 268 | unless defined $constraint->name; | ||||
| 269 | 94 | 1.10ms | 94 | 11.8ms | $REGISTRY->add_type_constraint($constraint); # spent 11.8ms making 94 calls to Moose::Meta::TypeConstraint::Registry::add_type_constraint, avg 126µs/call |
| 270 | 94 | 1.15ms | return $constraint; | ||
| 271 | } | ||||
| 272 | |||||
| 273 | # type constructors | ||||
| 274 | |||||
| 275 | # spent 1.18ms (82µs+1.09) within Moose::Util::TypeConstraints::type which was called:
# once (82µs+1.09ms) by Moose::Meta::Attribute::BEGIN@20 at line 707 | ||||
| 276 | |||||
| 277 | # back-compat version, called without sugar | ||||
| 278 | 3 | 86µs | 3 | 66µs | if ( !any { ( reftype($_) || '' ) eq 'HASH' } @_ ) { # spent 54µs making 1 call to List::MoreUtils::any
# spent 11µs making 2 calls to Scalar::Util::reftype, avg 6µs/call |
| 279 | Moose::Deprecated::deprecated( | ||||
| 280 | feature => 'type without sugar', | ||||
| 281 | message => | ||||
| 282 | 'Calling type() with a simple list of parameters is deprecated' | ||||
| 283 | ); | ||||
| 284 | |||||
| 285 | return _create_type_constraint( $_[0], undef, $_[1] ); | ||||
| 286 | } | ||||
| 287 | |||||
| 288 | 1 | 5µs | my $name = shift; | ||
| 289 | |||||
| 290 | 1 | 13µs | my %p = map { %{$_} } @_; | ||
| 291 | |||||
| 292 | 1 | 41µs | 1 | 1.04ms | return _create_type_constraint( # spent 1.04ms making 1 call to Moose::Util::TypeConstraints::_create_type_constraint |
| 293 | $name, undef, $p{where}, $p{message}, | ||||
| 294 | $p{optimize_as} | ||||
| 295 | ); | ||||
| 296 | } | ||||
| 297 | |||||
| 298 | # spent 19.3ms (1.78+17.5) within Moose::Util::TypeConstraints::subtype which was called 17 times, avg 1.14ms/call:
# once (125µs+1.34ms) by Moose::Meta::Attribute::BEGIN@20 at line 710
# once (104µs+1.35ms) by Moose::Meta::Attribute::BEGIN@20 at line 708
# once (104µs+1.28ms) by Moose::Meta::Attribute::BEGIN@20 at line 711
# once (104µs+1.22ms) by Moose::Meta::Attribute::BEGIN@20 at line 714
# once (112µs+998µs) by Moose::Meta::Attribute::BEGIN@20 at line 723
# once (107µs+982µs) by Moose::Meta::Attribute::BEGIN@20 at line 717
# once (102µs+985µs) by Moose::Meta::Attribute::BEGIN@20 at line 752
# once (107µs+964µs) by Moose::Meta::Attribute::BEGIN@20 at line 761
# once (102µs+953µs) by Moose::Meta::Attribute::BEGIN@20 at line 727
# once (102µs+953µs) by Moose::Meta::Attribute::BEGIN@20 at line 738
# once (99µs+955µs) by Moose::Meta::Attribute::BEGIN@20 at line 745
# once (101µs+940µs) by Moose::Meta::Attribute::BEGIN@20 at line 730
# once (103µs+936µs) by Moose::Meta::Attribute::BEGIN@20 at line 733
# once (102µs+929µs) by Moose::Meta::Attribute::BEGIN@20 at line 756
# once (100µs+930µs) by Moose::Meta::Attribute::BEGIN@20 at line 766
# once (101µs+923µs) by Moose::Meta::Attribute::BEGIN@20 at line 735
# once (100µs+897µs) by Moose::Meta::Attribute::BEGIN@20 at line 720 | ||||
| 299 | |||||
| 300 | # crazy back-compat code for being called without sugar ... | ||||
| 301 | # | ||||
| 302 | # subtype 'Parent', sub { where }; | ||||
| 303 | 17 | 74µs | 1 | 6µs | if ( scalar @_ == 2 && ( reftype( $_[1] ) || '' ) eq 'CODE' ) { # spent 6µs making 1 call to Scalar::Util::reftype |
| 304 | Moose::Deprecated::deprecated( | ||||
| 305 | feature => 'subtype without sugar', | ||||
| 306 | message => | ||||
| 307 | 'Calling subtype() with a simple list of parameters is deprecated' | ||||
| 308 | ); | ||||
| 309 | |||||
| 310 | return _create_type_constraint( undef, @_ ); | ||||
| 311 | } | ||||
| 312 | |||||
| 313 | # subtype 'Parent', sub { where }, sub { message }; | ||||
| 314 | # subtype 'Parent', sub { where }, sub { message }, sub { optimized }; | ||||
| 315 | 33 | 942µs | 32 | 583µs | if ( scalar @_ >= 3 && all { ( reftype($_) || '' ) eq 'CODE' } # spent 487µs making 16 calls to List::MoreUtils::all, avg 30µs/call
# spent 96µs making 16 calls to Scalar::Util::reftype, avg 6µs/call |
| 316 | @_[ 1 .. $#_ ] ) { | ||||
| 317 | Moose::Deprecated::deprecated( | ||||
| 318 | feature => 'subtype without sugar', | ||||
| 319 | message => | ||||
| 320 | 'Calling subtype() with a simple list of parameters is deprecated' | ||||
| 321 | ); | ||||
| 322 | |||||
| 323 | return _create_type_constraint( undef, @_ ); | ||||
| 324 | } | ||||
| 325 | |||||
| 326 | # subtype 'Name', 'Parent', ... | ||||
| 327 | 51 | 677µs | 17 | 320µs | if ( scalar @_ >= 2 && all { !ref } @_[ 0, 1 ] ) { # spent 320µs making 17 calls to List::MoreUtils::all, avg 19µs/call |
| 328 | Moose::Deprecated::deprecated( | ||||
| 329 | feature => 'subtype without sugar', | ||||
| 330 | message => | ||||
| 331 | 'Calling subtype() with a simple list of parameters is deprecated' | ||||
| 332 | ); | ||||
| 333 | |||||
| 334 | return _create_type_constraint(@_); | ||||
| 335 | } | ||||
| 336 | |||||
| 337 | 17 | 51µs | if ( @_ == 1 && !ref $_[0] ) { | ||
| 338 | __PACKAGE__->_throw_error( | ||||
| 339 | 'A subtype cannot consist solely of a name, it must have a parent' | ||||
| 340 | ); | ||||
| 341 | } | ||||
| 342 | |||||
| 343 | # The blessed check is mostly to accommodate MooseX::Types, which | ||||
| 344 | # uses an object which overloads stringification as a type name. | ||||
| 345 | 17 | 83µs | my $name = ref $_[0] && !blessed $_[0] ? undef : shift; | ||
| 346 | |||||
| 347 | 17 | 294µs | my %p = map { %{$_} } @_; | ||
| 348 | |||||
| 349 | # subtype Str => where { ... }; | ||||
| 350 | 17 | 52µs | if ( !exists $p{as} ) { | ||
| 351 | $p{as} = $name; | ||||
| 352 | $name = undef; | ||||
| 353 | } | ||||
| 354 | |||||
| 355 | 17 | 527µs | 17 | 16.7ms | return _create_type_constraint( # spent 16.7ms making 17 calls to Moose::Util::TypeConstraints::_create_type_constraint, avg 983µs/call |
| 356 | $name, $p{as}, $p{where}, $p{message}, | ||||
| 357 | $p{optimize_as} | ||||
| 358 | ); | ||||
| 359 | } | ||||
| 360 | |||||
| 361 | # spent 21.2ms (901µs+20.3) within Moose::Util::TypeConstraints::class_type which was called 25 times, avg 847µs/call:
# 25 times (901µs+20.3ms) by Moose::init_meta at line 162 of Moose.pm, avg 847µs/call | ||||
| 362 | 25 | 745µs | 50 | 20.3ms | register_type_constraint( # spent 15.6ms making 25 calls to Moose::Util::TypeConstraints::create_class_type_constraint, avg 625µs/call
# spent 4.65ms making 25 calls to Moose::Util::TypeConstraints::register_type_constraint, avg 186µs/call |
| 363 | create_class_type_constraint( | ||||
| 364 | $_[0], | ||||
| 365 | ( defined( $_[1] ) ? $_[1] : () ), | ||||
| 366 | ) | ||||
| 367 | ); | ||||
| 368 | } | ||||
| 369 | |||||
| 370 | # spent 81.2ms (2.33+78.8) within Moose::Util::TypeConstraints::role_type which was called 69 times, avg 1.18ms/call:
# 69 times (2.33ms+78.8ms) by Moose::Role::init_meta at line 117 of Moose/Role.pm, avg 1.18ms/call | ||||
| 371 | 69 | 1.96ms | 138 | 78.8ms | register_type_constraint( # spent 66.0ms making 69 calls to Moose::Util::TypeConstraints::create_role_type_constraint, avg 957µs/call
# spent 12.8ms making 69 calls to Moose::Util::TypeConstraints::register_type_constraint, avg 185µs/call |
| 372 | create_role_type_constraint( | ||||
| 373 | $_[0], | ||||
| 374 | ( defined( $_[1] ) ? $_[1] : () ), | ||||
| 375 | ) | ||||
| 376 | ); | ||||
| 377 | } | ||||
| 378 | |||||
| 379 | sub maybe_type { | ||||
| 380 | my ($type_parameter) = @_; | ||||
| 381 | |||||
| 382 | register_type_constraint( | ||||
| 383 | $REGISTRY->get_type_constraint('Maybe')->parameterize($type_parameter) | ||||
| 384 | ); | ||||
| 385 | } | ||||
| 386 | |||||
| 387 | sub duck_type { | ||||
| 388 | my ( $type_name, @methods ) = @_; | ||||
| 389 | if ( ref $type_name eq 'ARRAY' && !@methods ) { | ||||
| 390 | @methods = @$type_name; | ||||
| 391 | $type_name = undef; | ||||
| 392 | } | ||||
| 393 | if ( @methods == 1 && ref $methods[0] eq 'ARRAY' ) { | ||||
| 394 | @methods = @{ $methods[0] }; | ||||
| 395 | } | ||||
| 396 | |||||
| 397 | register_type_constraint( | ||||
| 398 | create_duck_type_constraint( | ||||
| 399 | $type_name, | ||||
| 400 | \@methods, | ||||
| 401 | ) | ||||
| 402 | ); | ||||
| 403 | } | ||||
| 404 | |||||
| 405 | # spent 4.54ms (60µs+4.48) within Moose::Util::TypeConstraints::coerce which was called 2 times, avg 2.27ms/call:
# once (33µs+2.52ms) by KiokuDB::BEGIN@10 at line 24 of KiokuDB/Backend.pm
# once (28µs+1.96ms) by KiokuDB::BEGIN@13 at line 20 of KiokuDB/LiveObjects.pm | ||||
| 406 | 2 | 13µs | my ( $type_name, @coercion_map ) = @_; | ||
| 407 | 2 | 50µs | 2 | 4.48ms | _install_type_coercions( $type_name, \@coercion_map ); # spent 4.48ms making 2 calls to Moose::Util::TypeConstraints::_install_type_coercions, avg 2.24ms/call |
| 408 | } | ||||
| 409 | |||||
| 410 | # The trick of returning @_ lets us avoid having to specify a | ||||
| 411 | # prototype. Perl will parse this: | ||||
| 412 | # | ||||
| 413 | # subtype 'Foo' | ||||
| 414 | # => as 'Str' | ||||
| 415 | # => where { ... } | ||||
| 416 | # | ||||
| 417 | # as this: | ||||
| 418 | # | ||||
| 419 | # subtype( 'Foo', as( 'Str', where { ... } ) ); | ||||
| 420 | # | ||||
| 421 | # If as() returns all it's extra arguments, this just works, and | ||||
| 422 | # preserves backwards compatibility. | ||||
| 423 | 17 | 345µs | # spent 243µs within Moose::Util::TypeConstraints::as which was called 17 times, avg 14µs/call:
# once (29µs+0s) by Moose::Meta::Attribute::BEGIN@20 at line 710
# once (19µs+0s) by Moose::Meta::Attribute::BEGIN@20 at line 761
# once (14µs+0s) by Moose::Meta::Attribute::BEGIN@20 at line 708
# once (14µs+0s) by Moose::Meta::Attribute::BEGIN@20 at line 711
# once (14µs+0s) by Moose::Meta::Attribute::BEGIN@20 at line 738
# once (14µs+0s) by Moose::Meta::Attribute::BEGIN@20 at line 717
# once (13µs+0s) by Moose::Meta::Attribute::BEGIN@20 at line 714
# once (13µs+0s) by Moose::Meta::Attribute::BEGIN@20 at line 727
# once (13µs+0s) by Moose::Meta::Attribute::BEGIN@20 at line 752
# once (13µs+0s) by Moose::Meta::Attribute::BEGIN@20 at line 733
# once (13µs+0s) by Moose::Meta::Attribute::BEGIN@20 at line 766
# once (13µs+0s) by Moose::Meta::Attribute::BEGIN@20 at line 720
# once (13µs+0s) by Moose::Meta::Attribute::BEGIN@20 at line 756
# once (12µs+0s) by Moose::Meta::Attribute::BEGIN@20 at line 745
# once (12µs+0s) by Moose::Meta::Attribute::BEGIN@20 at line 730
# once (12µs+0s) by Moose::Meta::Attribute::BEGIN@20 at line 735
# once (11µs+0s) by Moose::Meta::Attribute::BEGIN@20 at line 723 | ||
| 424 | 17 | 339µs | # spent 190µs within Moose::Util::TypeConstraints::where which was called 17 times, avg 11µs/call:
# once (13µs+0s) by Moose::Meta::Attribute::BEGIN@20 at line 707
# once (12µs+0s) by Moose::Meta::Attribute::BEGIN@20 at line 710
# once (12µs+0s) by Moose::Meta::Attribute::BEGIN@20 at line 714
# once (12µs+0s) by Moose::Meta::Attribute::BEGIN@20 at line 717
# once (11µs+0s) by Moose::Meta::Attribute::BEGIN@20 at line 752
# once (11µs+0s) by Moose::Meta::Attribute::BEGIN@20 at line 761
# once (11µs+0s) by Moose::Meta::Attribute::BEGIN@20 at line 733
# once (11µs+0s) by Moose::Meta::Attribute::BEGIN@20 at line 720
# once (11µs+0s) by Moose::Meta::Attribute::BEGIN@20 at line 727
# once (11µs+0s) by Moose::Meta::Attribute::BEGIN@20 at line 756
# once (11µs+0s) by Moose::Meta::Attribute::BEGIN@20 at line 766
# once (11µs+0s) by Moose::Meta::Attribute::BEGIN@20 at line 711
# once (11µs+0s) by Moose::Meta::Attribute::BEGIN@20 at line 723
# once (11µs+0s) by Moose::Meta::Attribute::BEGIN@20 at line 745
# once (11µs+0s) by Moose::Meta::Attribute::BEGIN@20 at line 730
# once (11µs+0s) by Moose::Meta::Attribute::BEGIN@20 at line 735
# once (11µs+0s) by Moose::Meta::Attribute::BEGIN@20 at line 738 | ||
| 425 | sub message (&) { { message => $_[0] } } | ||||
| 426 | 13 | 208µs | # spent 133µs within Moose::Util::TypeConstraints::optimize_as which was called 13 times, avg 10µs/call:
# once (14µs+0s) by Moose::Meta::Attribute::BEGIN@20 at line 761
# once (11µs+0s) by Moose::Meta::Attribute::BEGIN@20 at line 717
# once (10µs+0s) by Moose::Meta::Attribute::BEGIN@20 at line 738
# once (10µs+0s) by Moose::Meta::Attribute::BEGIN@20 at line 756
# once (10µs+0s) by Moose::Meta::Attribute::BEGIN@20 at line 720
# once (10µs+0s) by Moose::Meta::Attribute::BEGIN@20 at line 727
# once (10µs+0s) by Moose::Meta::Attribute::BEGIN@20 at line 766
# once (10µs+0s) by Moose::Meta::Attribute::BEGIN@20 at line 745
# once (10µs+0s) by Moose::Meta::Attribute::BEGIN@20 at line 733
# once (10µs+0s) by Moose::Meta::Attribute::BEGIN@20 at line 752
# once (10µs+0s) by Moose::Meta::Attribute::BEGIN@20 at line 730
# once (10µs+0s) by Moose::Meta::Attribute::BEGIN@20 at line 723
# once (10µs+0s) by Moose::Meta::Attribute::BEGIN@20 at line 735 | ||
| 427 | |||||
| 428 | 2 | 33µs | # spent 23µs within Moose::Util::TypeConstraints::from which was called 2 times, avg 11µs/call:
# once (11µs+0s) by KiokuDB::BEGIN@13 at line 20 of KiokuDB/LiveObjects.pm
# once (11µs+0s) by KiokuDB::BEGIN@10 at line 24 of KiokuDB/Backend.pm | ||
| 429 | 2 | 34µs | # spent 21µs within Moose::Util::TypeConstraints::via which was called 2 times, avg 11µs/call:
# once (11µs+0s) by KiokuDB::BEGIN@13 at line 20 of KiokuDB/LiveObjects.pm
# once (10µs+0s) by KiokuDB::BEGIN@10 at line 24 of KiokuDB/Backend.pm | ||
| 430 | |||||
| 431 | sub enum { | ||||
| 432 | my ( $type_name, @values ) = @_; | ||||
| 433 | |||||
| 434 | # NOTE: | ||||
| 435 | # if only an array-ref is passed then | ||||
| 436 | # you get an anon-enum | ||||
| 437 | # - SL | ||||
| 438 | if ( ref $type_name eq 'ARRAY' ) { | ||||
| 439 | @values == 0 | ||||
| 440 | || __PACKAGE__->_throw_error("enum called with an array reference and additional arguments. Did you mean to parenthesize the enum call's parameters?"); | ||||
| 441 | |||||
| 442 | @values = @$type_name; | ||||
| 443 | $type_name = undef; | ||||
| 444 | } | ||||
| 445 | if ( @values == 1 && ref $values[0] eq 'ARRAY' ) { | ||||
| 446 | @values = @{ $values[0] }; | ||||
| 447 | } | ||||
| 448 | |||||
| 449 | register_type_constraint( | ||||
| 450 | create_enum_type_constraint( | ||||
| 451 | $type_name, | ||||
| 452 | \@values, | ||||
| 453 | ) | ||||
| 454 | ); | ||||
| 455 | } | ||||
| 456 | |||||
| 457 | sub create_enum_type_constraint { | ||||
| 458 | my ( $type_name, $values ) = @_; | ||||
| 459 | |||||
| 460 | Moose::Meta::TypeConstraint::Enum->new( | ||||
| 461 | name => $type_name || '__ANON__', | ||||
| 462 | values => $values, | ||||
| 463 | ); | ||||
| 464 | } | ||||
| 465 | |||||
| 466 | sub create_duck_type_constraint { | ||||
| 467 | my ( $type_name, $methods ) = @_; | ||||
| 468 | |||||
| 469 | Moose::Meta::TypeConstraint::DuckType->new( | ||||
| 470 | name => $type_name || '__ANON__', | ||||
| 471 | methods => $methods, | ||||
| 472 | ); | ||||
| 473 | } | ||||
| 474 | |||||
| 475 | sub match_on_type { | ||||
| 476 | my ($to_match, @cases) = @_; | ||||
| 477 | my $default; | ||||
| 478 | if (@cases % 2 != 0) { | ||||
| 479 | $default = pop @cases; | ||||
| 480 | (ref $default eq 'CODE') | ||||
| 481 | || __PACKAGE__->_throw_error("Default case must be a CODE ref, not $default"); | ||||
| 482 | } | ||||
| 483 | while (@cases) { | ||||
| 484 | my ($type, $action) = splice @cases, 0, 2; | ||||
| 485 | |||||
| 486 | unless (blessed $type && $type->isa('Moose::Meta::TypeConstraint')) { | ||||
| 487 | $type = find_or_parse_type_constraint($type) | ||||
| 488 | || __PACKAGE__->_throw_error("Cannot find or parse the type '$type'") | ||||
| 489 | } | ||||
| 490 | |||||
| 491 | (ref $action eq 'CODE') | ||||
| 492 | || __PACKAGE__->_throw_error("Match action must be a CODE ref, not $action"); | ||||
| 493 | |||||
| 494 | if ($type->check($to_match)) { | ||||
| 495 | local $_ = $to_match; | ||||
| 496 | return $action->($to_match); | ||||
| 497 | } | ||||
| 498 | } | ||||
| 499 | (defined $default) | ||||
| 500 | || __PACKAGE__->_throw_error("No cases matched for $to_match"); | ||||
| 501 | { | ||||
| 502 | local $_ = $to_match; | ||||
| 503 | return $default->($to_match); | ||||
| 504 | } | ||||
| 505 | } | ||||
| 506 | |||||
| 507 | |||||
| 508 | ## -------------------------------------------------------- | ||||
| 509 | ## desugaring functions ... | ||||
| 510 | ## -------------------------------------------------------- | ||||
| 511 | |||||
| 512 | sub _create_type_constraint ($$$;$$) { | ||||
| 513 | 18 | 56µs | my $name = shift; | ||
| 514 | 18 | 77µs | my $parent = shift; | ||
| 515 | 18 | 41µs | my $check = shift; | ||
| 516 | 18 | 64µs | my $message = shift; | ||
| 517 | 18 | 39µs | my $optimized = shift; | ||
| 518 | |||||
| 519 | 18 | 63µs | my $pkg_defined_in = scalar( caller(1) ); | ||
| 520 | |||||
| 521 | 18 | 72µs | if ( defined $name ) { | ||
| 522 | 18 | 193µs | 18 | 701µs | my $type = $REGISTRY->get_type_constraint($name); # spent 701µs making 18 calls to Moose::Meta::TypeConstraint::Registry::get_type_constraint, avg 39µs/call |
| 523 | |||||
| 524 | 18 | 32µs | ( $type->_package_defined_in eq $pkg_defined_in ) | ||
| 525 | || _confess( | ||||
| 526 | "The type constraint '$name' has already been created in " | ||||
| 527 | . $type->_package_defined_in | ||||
| 528 | . " and cannot be created again in " | ||||
| 529 | . $pkg_defined_in ) | ||||
| 530 | if defined $type; | ||||
| 531 | |||||
| 532 | 18 | 485µs | 18 | 243µs | $name =~ /^[\w:\.]+$/ # spent 243µs making 18 calls to Moose::Util::TypeConstraints::CORE:match, avg 13µs/call |
| 533 | or die qq{$name contains invalid characters for a type name.} | ||||
| 534 | . qq{ Names can contain alphanumeric character, ":", and "."\n}; | ||||
| 535 | } | ||||
| 536 | |||||
| 537 | 18 | 200µs | my %opts = ( | ||
| 538 | name => $name, | ||||
| 539 | package_defined_in => $pkg_defined_in, | ||||
| 540 | |||||
| 541 | ( $check ? ( constraint => $check ) : () ), | ||||
| 542 | ( $message ? ( message => $message ) : () ), | ||||
| 543 | ( $optimized ? ( optimized => $optimized ) : () ), | ||||
| 544 | ); | ||||
| 545 | |||||
| 546 | 18 | 33µs | my $constraint; | ||
| 547 | 18 | 868µs | 68 | 11.5ms | if ( # spent 7.01ms making 17 calls to Moose::Meta::TypeConstraint::create_child_type, avg 413µs/call
# spent 4.25ms making 17 calls to Moose::Util::TypeConstraints::find_or_create_isa_type_constraint, avg 250µs/call
# spent 117µs making 17 calls to Moose::Meta::TypeConstraint::__ANON__[Moose/Meta/TypeConstraint.pm:10], avg 7µs/call
# spent 90µs making 17 calls to Scalar::Util::blessed, avg 5µs/call |
| 548 | defined $parent | ||||
| 549 | and $parent | ||||
| 550 | = blessed $parent | ||||
| 551 | ? $parent | ||||
| 552 | : find_or_create_isa_type_constraint($parent) | ||||
| 553 | ) { | ||||
| 554 | $constraint = $parent->create_child_type(%opts); | ||||
| 555 | } | ||||
| 556 | else { | ||||
| 557 | 1 | 19µs | 1 | 644µs | $constraint = Moose::Meta::TypeConstraint->new(%opts); # spent 644µs making 1 call to Moose::Meta::TypeConstraint::new |
| 558 | } | ||||
| 559 | |||||
| 560 | 18 | 216µs | 18 | 2.15ms | $REGISTRY->add_type_constraint($constraint) # spent 2.15ms making 18 calls to Moose::Meta::TypeConstraint::Registry::add_type_constraint, avg 120µs/call |
| 561 | if defined $name; | ||||
| 562 | |||||
| 563 | 18 | 254µs | return $constraint; | ||
| 564 | } | ||||
| 565 | |||||
| 566 | # spent 4.48ms (269µs+4.21) within Moose::Util::TypeConstraints::_install_type_coercions which was called 2 times, avg 2.24ms/call:
# 2 times (269µs+4.21ms) by Moose::Util::TypeConstraints::coerce at line 407, avg 2.24ms/call | ||||
| 567 | 2 | 7µs | my ( $type_name, $coercion_map ) = @_; | ||
| 568 | 2 | 21µs | 2 | 292µs | my $type = find_type_constraint($type_name); # spent 292µs making 2 calls to Moose::Util::TypeConstraints::find_type_constraint, avg 146µs/call |
| 569 | 2 | 5µs | ( defined $type ) | ||
| 570 | || __PACKAGE__->_throw_error( | ||||
| 571 | "Cannot find type '$type_name', perhaps you forgot to load it"); | ||||
| 572 | 2 | 93µs | 2 | 27µs | if ( $type->has_coercion ) { # spent 27µs making 2 calls to Moose::Meta::TypeConstraint::has_coercion, avg 14µs/call |
| 573 | $type->coercion->add_type_coercions(@$coercion_map); | ||||
| 574 | } | ||||
| 575 | else { | ||||
| 576 | 2 | 34µs | 2 | 3.86ms | my $type_coercion = Moose::Meta::TypeCoercion->new( # spent 3.86ms making 2 calls to Moose::Meta::TypeCoercion::new, avg 1.93ms/call |
| 577 | type_coercion_map => $coercion_map, | ||||
| 578 | type_constraint => $type | ||||
| 579 | ); | ||||
| 580 | 2 | 61µs | 2 | 34µs | $type->coercion($type_coercion); # spent 34µs making 2 calls to Moose::Meta::TypeConstraint::coercion, avg 17µs/call |
| 581 | } | ||||
| 582 | } | ||||
| 583 | |||||
| 584 | ## -------------------------------------------------------- | ||||
| 585 | ## type notation parsing ... | ||||
| 586 | ## -------------------------------------------------------- | ||||
| 587 | |||||
| 588 | { | ||||
| 589 | |||||
| 590 | # All I have to say is mugwump++ cause I know | ||||
| 591 | # do not even have enough regexp-fu to be able | ||||
| 592 | # to have written this (I can only barely | ||||
| 593 | # understand it as it is) | ||||
| 594 | # - SL | ||||
| 595 | |||||
| 596 | 4 | 1.25ms | 6 | 4.03ms | # spent 3.92ms (3.61+304µs) within Moose::Util::TypeConstraints::BEGIN@596 which was called:
# once (3.61ms+304µs) by Moose::Meta::Attribute::BEGIN@20 at line 596 # spent 3.92ms making 1 call to Moose::Util::TypeConstraints::BEGIN@596
# spent 104µs making 1 call to re::import
# spent 15µs making 4 calls to Regexp::DESTROY, avg 4µs/call |
| 597 | |||||
| 598 | 1 | 41µs | 1 | 20µs | my $valid_chars = qr{[\w:\.]}; # spent 20µs making 1 call to Moose::Util::TypeConstraints::CORE:qr |
| 599 | 1 | 174µs | 2 | 140µs | my $type_atom = qr{ (?>$valid_chars+) }x; # spent 132µs making 1 call to Moose::Util::TypeConstraints::CORE:regcomp
# spent 8µs making 1 call to Moose::Util::TypeConstraints::CORE:qr |
| 600 | 1 | 20µs | 1 | 7µs | my $ws = qr{ (?>\s*) }x; # spent 7µs making 1 call to Moose::Util::TypeConstraints::CORE:qr |
| 601 | 1 | 67µs | 2 | 42µs | my $op_union = qr{ $ws \| $ws }x; # spent 36µs making 1 call to Moose::Util::TypeConstraints::CORE:regcomp
# spent 7µs making 1 call to Moose::Util::TypeConstraints::CORE:qr |
| 602 | |||||
| 603 | 1 | 4µs | my ($type, $type_capture_parts, $type_with_parameter, $union, $any); | ||
| 604 | 1 | 79µs | 1 | 6µs | if (Class::MOP::IS_RUNNING_ON_5_10) { # spent 6µs making 1 call to Regexp::DESTROY |
| 605 | 1 | 4µs | my $type_pattern | ||
| 606 | = q{ (?&type_atom) (?: \[ (?&ws) (?&any) (?&ws) \] )? }; | ||||
| 607 | 1 | 4µs | my $type_capture_parts_pattern | ||
| 608 | = q{ ((?&type_atom)) (?: \[ (?&ws) ((?&any)) (?&ws) \] )? }; | ||||
| 609 | 1 | 3µs | my $type_with_parameter_pattern | ||
| 610 | = q{ (?&type_atom) \[ (?&ws) (?&any) (?&ws) \] }; | ||||
| 611 | 1 | 3µs | my $union_pattern | ||
| 612 | = q{ (?&type) (?> (?: (?&op_union) (?&type) )+ ) }; | ||||
| 613 | 1 | 3µs | my $any_pattern | ||
| 614 | = q{ (?&type) | (?&union) }; | ||||
| 615 | |||||
| 616 | 1 | 223µs | 2 | 193µs | my $defines = qr{(?(DEFINE) # spent 186µs making 1 call to Moose::Util::TypeConstraints::CORE:regcomp
# spent 7µs making 1 call to Moose::Util::TypeConstraints::CORE:qr |
| 617 | (?<valid_chars> $valid_chars) | ||||
| 618 | (?<type_atom> $type_atom) | ||||
| 619 | (?<ws> $ws) | ||||
| 620 | (?<op_union> $op_union) | ||||
| 621 | (?<type> $type_pattern) | ||||
| 622 | (?<type_capture_parts> $type_capture_parts_pattern) | ||||
| 623 | (?<type_with_parameter> $type_with_parameter_pattern) | ||||
| 624 | (?<union> $union_pattern) | ||||
| 625 | (?<any> $any_pattern) | ||||
| 626 | )}x; | ||||
| 627 | |||||
| 628 | 1 | 206µs | 2 | 176µs | $type = qr{ $type_pattern $defines }x; # spent 168µs making 1 call to Moose::Util::TypeConstraints::CORE:regcomp
# spent 8µs making 1 call to Moose::Util::TypeConstraints::CORE:qr |
| 629 | 1 | 218µs | 2 | 185µs | $type_capture_parts = qr{ $type_capture_parts_pattern $defines }x; # spent 178µs making 1 call to Moose::Util::TypeConstraints::CORE:regcomp
# spent 8µs making 1 call to Moose::Util::TypeConstraints::CORE:qr |
| 630 | 1 | 198µs | 2 | 168µs | $type_with_parameter = qr{ $type_with_parameter_pattern $defines }x; # spent 161µs making 1 call to Moose::Util::TypeConstraints::CORE:regcomp
# spent 7µs making 1 call to Moose::Util::TypeConstraints::CORE:qr |
| 631 | 1 | 196µs | 2 | 166µs | $union = qr{ $union_pattern $defines }x; # spent 159µs making 1 call to Moose::Util::TypeConstraints::CORE:regcomp
# spent 7µs making 1 call to Moose::Util::TypeConstraints::CORE:qr |
| 632 | 1 | 279µs | 2 | 204µs | $any = qr{ $any_pattern $defines }x; # spent 188µs making 1 call to Moose::Util::TypeConstraints::CORE:regcomp
# spent 16µs making 1 call to Moose::Util::TypeConstraints::CORE:qr |
| 633 | } | ||||
| 634 | else { | ||||
| 635 | $type | ||||
| 636 | = qr{ $type_atom (?: \[ $ws (??{$any}) $ws \] )? }x; | ||||
| 637 | $type_capture_parts | ||||
| 638 | = qr{ ($type_atom) (?: \[ $ws ((??{$any})) $ws \] )? }x; | ||||
| 639 | $type_with_parameter | ||||
| 640 | = qr{ $type_atom \[ $ws (??{$any}) $ws \] }x; | ||||
| 641 | $union | ||||
| 642 | = qr{ $type (?> (?: $op_union $type )+ ) }x; | ||||
| 643 | $any | ||||
| 644 | = qr{ $type | $union }x; | ||||
| 645 | } | ||||
| 646 | |||||
| 647 | |||||
| 648 | # spent 1.10ms (479µs+619µs) within Moose::Util::TypeConstraints::_parse_parameterized_type_constraint which was called 10 times, avg 110µs/call:
# 10 times (479µs+619µs) by Moose::Util::TypeConstraints::create_parameterized_type_constraint at line 101, avg 110µs/call | ||||
| 649 | 23 | 328µs | 2 | 258µs | # spent 157µs (56+101) within Moose::Util::TypeConstraints::BEGIN@649 which was called:
# once (56µs+101µs) by Moose::Meta::Attribute::BEGIN@20 at line 649 # spent 157µs making 1 call to Moose::Util::TypeConstraints::BEGIN@649
# spent 101µs making 1 call to warnings::unimport |
| 650 | 10 | 858µs | 20 | 619µs | $_[0] =~ m{ $type_capture_parts }x; # spent 326µs making 10 calls to Moose::Util::TypeConstraints::CORE:match, avg 33µs/call
# spent 293µs making 10 calls to Moose::Util::TypeConstraints::CORE:regcomp, avg 29µs/call |
| 651 | 10 | 234µs | return ( $1, $2 ); | ||
| 652 | } | ||||
| 653 | |||||
| 654 | # spent 1.42ms (688µs+734µs) within Moose::Util::TypeConstraints::_detect_parameterized_type_constraint which was called 20 times, avg 71µs/call:
# 20 times (688µs+734µs) by Moose::Util::TypeConstraints::find_or_parse_type_constraint at line 218, avg 71µs/call | ||||
| 655 | 43 | 334µs | 2 | 160µs | # spent 102µs (44+58) within Moose::Util::TypeConstraints::BEGIN@655 which was called:
# once (44µs+58µs) by Moose::Meta::Attribute::BEGIN@20 at line 655 # spent 102µs making 1 call to Moose::Util::TypeConstraints::BEGIN@655
# spent 58µs making 1 call to warnings::unimport |
| 656 | 20 | 1.35ms | 40 | 734µs | $_[0] =~ m{ ^ $type_with_parameter $ }x; # spent 399µs making 20 calls to Moose::Util::TypeConstraints::CORE:match, avg 20µs/call
# spent 335µs making 20 calls to Moose::Util::TypeConstraints::CORE:regcomp, avg 17µs/call |
| 657 | } | ||||
| 658 | |||||
| 659 | # spent 1.42ms (833µs+584µs) within Moose::Util::TypeConstraints::_parse_type_constraint_union which was called 6 times, avg 236µs/call:
# 6 times (833µs+584µs) by Moose::Util::TypeConstraints::create_type_constraint_union at line 78, avg 236µs/call | ||||
| 660 | 15 | 422µs | 2 | 147µs | # spent 93µs (39+54) within Moose::Util::TypeConstraints::BEGIN@660 which was called:
# once (39µs+54µs) by Moose::Meta::Attribute::BEGIN@20 at line 660 # spent 93µs making 1 call to Moose::Util::TypeConstraints::BEGIN@660
# spent 54µs making 1 call to warnings::unimport |
| 661 | 6 | 23µs | my $given = shift; | ||
| 662 | 6 | 11µs | my @rv; | ||
| 663 | 6 | 519µs | 12 | 338µs | while ( $given =~ m{ \G (?: $op_union )? ($type) }gcx ) { # spent 259µs making 6 calls to Moose::Util::TypeConstraints::CORE:regcomp, avg 43µs/call
# spent 79µs making 6 calls to Moose::Util::TypeConstraints::CORE:match, avg 13µs/call |
| 664 | 15 | 714µs | 30 | 246µs | push @rv => $1; # spent 142µs making 15 calls to Moose::Util::TypeConstraints::CORE:regcomp, avg 9µs/call
# spent 104µs making 15 calls to Moose::Util::TypeConstraints::CORE:match, avg 7µs/call |
| 665 | } | ||||
| 666 | 6 | 32µs | ( pos($given) eq length($given) ) | ||
| 667 | || __PACKAGE__->_throw_error( "'$given' didn't parse (parse-pos=" | ||||
| 668 | . pos($given) | ||||
| 669 | . " and str-length=" | ||||
| 670 | . length($given) | ||||
| 671 | . ")" ); | ||||
| 672 | 6 | 107µs | @rv; | ||
| 673 | } | ||||
| 674 | |||||
| 675 | # spent 2.73ms (1.12+1.61) within Moose::Util::TypeConstraints::_detect_type_constraint_union which was called 32 times, avg 85µs/call:
# 26 times (952µs+1.46ms) by Moose::Util::TypeConstraints::find_or_parse_type_constraint at line 218, avg 93µs/call
# 6 times (172µs+154µs) by Moose::Util::TypeConstraints::create_type_constraint_union at line 78, avg 54µs/call | ||||
| 676 | 67 | 5.37ms | 2 | 154µs | # spent 97µs (40+57) within Moose::Util::TypeConstraints::BEGIN@676 which was called:
# once (40µs+57µs) by Moose::Meta::Attribute::BEGIN@20 at line 676 # spent 97µs making 1 call to Moose::Util::TypeConstraints::BEGIN@676
# spent 57µs making 1 call to warnings::unimport |
| 677 | 32 | 2.64ms | 64 | 1.61ms | $_[0] =~ m{^ $type $op_union $type ( $op_union .* )? $}x; # spent 865µs making 32 calls to Moose::Util::TypeConstraints::CORE:regcomp, avg 27µs/call
# spent 746µs making 32 calls to Moose::Util::TypeConstraints::CORE:match, avg 23µs/call |
| 678 | } | ||||
| 679 | } | ||||
| 680 | |||||
| 681 | ## -------------------------------------------------------- | ||||
| 682 | # define some basic built-in types | ||||
| 683 | ## -------------------------------------------------------- | ||||
| 684 | |||||
| 685 | # By making these classes immutable before creating all the types we | ||||
| 686 | # below, we avoid repeatedly calling the slow MOP-based accessors. | ||||
| 687 | $_->make_immutable( | ||||
| 688 | 9 | 82µs | 9 | 57µs | inline_constructor => 1, # spent 57µs making 9 calls to Class::MOP::Class::is_mutable, avg 6µs/call |
| 689 | constructor_name => "_new", | ||||
| 690 | |||||
| 691 | # these are Class::MOP accessors, so they need inlining | ||||
| 692 | inline_accessors => 1 | ||||
| 693 | 10 | 290µs | 18 | 127ms | ) for grep { $_->is_mutable } # spent 127ms making 9 calls to Class::MOP::Class::make_immutable, avg 14.1ms/call
# spent 237µs making 9 calls to Class::MOP::class_of, avg 26µs/call |
| 694 | map { Class::MOP::class_of($_) } | ||||
| 695 | qw( | ||||
| 696 | Moose::Meta::TypeConstraint | ||||
| 697 | Moose::Meta::TypeConstraint::Union | ||||
| 698 | Moose::Meta::TypeConstraint::Parameterized | ||||
| 699 | Moose::Meta::TypeConstraint::Parameterizable | ||||
| 700 | Moose::Meta::TypeConstraint::Class | ||||
| 701 | Moose::Meta::TypeConstraint::Role | ||||
| 702 | Moose::Meta::TypeConstraint::Enum | ||||
| 703 | Moose::Meta::TypeConstraint::DuckType | ||||
| 704 | Moose::Meta::TypeConstraint::Registry | ||||
| 705 | 1 | 2µs | ); | ||
| 706 | |||||
| 707 | 6 | 128µs | 2 | 1.19ms | # spent 64µs within Moose::Util::TypeConstraints::__ANON__[/home/doy/perl5/perlbrew/perls/perl-5.10.1/lib/site_perl/5.10.1/x86_64-linux/Moose/Util/TypeConstraints.pm:707] which was called 5 times, avg 13µs/call:
# 5 times (64µs+0s) by Moose::Meta::TypeConstraint::Bool at line 284 of Moose/Meta/TypeConstraint.pm, avg 13µs/call # spent 1.18ms making 1 call to Moose::Util::TypeConstraints::type
# spent 13µs making 1 call to Moose::Util::TypeConstraints::where |
| 708 | 1 | 25µs | 2 | 1.47ms | subtype 'Item' => as 'Any'; # base-type # spent 1.46ms making 1 call to Moose::Util::TypeConstraints::subtype
# spent 14µs making 1 call to Moose::Util::TypeConstraints::as |
| 709 | |||||
| 710 | 1 | 40µs | 3 | 1.50ms | subtype 'Undef' => as 'Item' => where { !defined($_) }; # spent 1.46ms making 1 call to Moose::Util::TypeConstraints::subtype
# spent 29µs making 1 call to Moose::Util::TypeConstraints::as
# spent 12µs making 1 call to Moose::Util::TypeConstraints::where |
| 711 | 1 | 39µs | 3 | 1.40ms | subtype 'Defined' => as 'Item' => where { defined($_) }; # spent 1.38ms making 1 call to Moose::Util::TypeConstraints::subtype
# spent 14µs making 1 call to Moose::Util::TypeConstraints::as
# spent 11µs making 1 call to Moose::Util::TypeConstraints::where |
| 712 | |||||
| 713 | subtype 'Bool' => as 'Item' => | ||||
| 714 | 6 | 133µs | 3 | 1.35ms | # spent 79µs within Moose::Util::TypeConstraints::__ANON__[/home/doy/perl5/perlbrew/perls/perl-5.10.1/lib/site_perl/5.10.1/x86_64-linux/Moose/Util/TypeConstraints.pm:714] which was called 5 times, avg 16µs/call:
# 5 times (79µs+0s) by Moose::Meta::TypeConstraint::Bool at line 284 of Moose/Meta/TypeConstraint.pm, avg 16µs/call # spent 1.32ms making 1 call to Moose::Util::TypeConstraints::subtype
# spent 13µs making 1 call to Moose::Util::TypeConstraints::as
# spent 12µs making 1 call to Moose::Util::TypeConstraints::where |
| 715 | |||||
| 716 | subtype 'Value' => as 'Defined' => where { !ref($_) } => | ||||
| 717 | 1 | 73µs | 4 | 1.13ms | optimize_as \&Moose::Util::TypeConstraints::OptimizedConstraints::Value; # spent 1.09ms making 1 call to Moose::Util::TypeConstraints::subtype
# spent 14µs making 1 call to Moose::Util::TypeConstraints::as
# spent 12µs making 1 call to Moose::Util::TypeConstraints::where
# spent 11µs making 1 call to Moose::Util::TypeConstraints::optimize_as |
| 718 | |||||
| 719 | subtype 'Ref' => as 'Defined' => where { ref($_) } => | ||||
| 720 | 1 | 48µs | 4 | 1.03ms | optimize_as \&Moose::Util::TypeConstraints::OptimizedConstraints::Ref; # spent 997µs making 1 call to Moose::Util::TypeConstraints::subtype
# spent 13µs making 1 call to Moose::Util::TypeConstraints::as
# spent 11µs making 1 call to Moose::Util::TypeConstraints::where
# spent 10µs making 1 call to Moose::Util::TypeConstraints::optimize_as |
| 721 | |||||
| 722 | subtype 'Str' => as 'Value' => where { ref(\$_) eq 'SCALAR' } => | ||||
| 723 | 1 | 47µs | 4 | 1.14ms | optimize_as \&Moose::Util::TypeConstraints::OptimizedConstraints::Str; # spent 1.11ms making 1 call to Moose::Util::TypeConstraints::subtype
# spent 11µs making 1 call to Moose::Util::TypeConstraints::as
# spent 11µs making 1 call to Moose::Util::TypeConstraints::where
# spent 10µs making 1 call to Moose::Util::TypeConstraints::optimize_as |
| 724 | |||||
| 725 | subtype 'Num' => as 'Str' => | ||||
| 726 | where { Scalar::Util::looks_like_number($_) } => | ||||
| 727 | 1 | 48µs | 4 | 1.09ms | optimize_as \&Moose::Util::TypeConstraints::OptimizedConstraints::Num; # spent 1.06ms making 1 call to Moose::Util::TypeConstraints::subtype
# spent 13µs making 1 call to Moose::Util::TypeConstraints::as
# spent 11µs making 1 call to Moose::Util::TypeConstraints::where
# spent 10µs making 1 call to Moose::Util::TypeConstraints::optimize_as |
| 728 | |||||
| 729 | subtype 'Int' => as 'Num' => where { "$_" =~ /^-?[0-9]+$/ } => | ||||
| 730 | 1 | 48µs | 4 | 1.07ms | optimize_as \&Moose::Util::TypeConstraints::OptimizedConstraints::Int; # spent 1.04ms making 1 call to Moose::Util::TypeConstraints::subtype
# spent 12µs making 1 call to Moose::Util::TypeConstraints::as
# spent 11µs making 1 call to Moose::Util::TypeConstraints::where
# spent 10µs making 1 call to Moose::Util::TypeConstraints::optimize_as |
| 731 | |||||
| 732 | subtype 'CodeRef' => as 'Ref' => where { ref($_) eq 'CODE' } => | ||||
| 733 | 1 | 49µs | 4 | 1.07ms | optimize_as \&Moose::Util::TypeConstraints::OptimizedConstraints::CodeRef; # spent 1.04ms making 1 call to Moose::Util::TypeConstraints::subtype
# spent 13µs making 1 call to Moose::Util::TypeConstraints::as
# spent 11µs making 1 call to Moose::Util::TypeConstraints::where
# spent 10µs making 1 call to Moose::Util::TypeConstraints::optimize_as |
| 734 | subtype 'RegexpRef' => as 'Ref' => where { ref($_) eq 'Regexp' } => | ||||
| 735 | 1 | 48µs | 4 | 1.06ms | optimize_as # spent 1.02ms making 1 call to Moose::Util::TypeConstraints::subtype
# spent 12µs making 1 call to Moose::Util::TypeConstraints::as
# spent 11µs making 1 call to Moose::Util::TypeConstraints::where
# spent 10µs making 1 call to Moose::Util::TypeConstraints::optimize_as |
| 736 | \&Moose::Util::TypeConstraints::OptimizedConstraints::RegexpRef; | ||||
| 737 | subtype 'GlobRef' => as 'Ref' => where { ref($_) eq 'GLOB' } => | ||||
| 738 | 1 | 49µs | 4 | 1.09ms | optimize_as \&Moose::Util::TypeConstraints::OptimizedConstraints::GlobRef; # spent 1.06ms making 1 call to Moose::Util::TypeConstraints::subtype
# spent 14µs making 1 call to Moose::Util::TypeConstraints::as
# spent 11µs making 1 call to Moose::Util::TypeConstraints::where
# spent 10µs making 1 call to Moose::Util::TypeConstraints::optimize_as |
| 739 | |||||
| 740 | # NOTE: | ||||
| 741 | # scalar filehandles are GLOB refs, | ||||
| 742 | # but a GLOB ref is not always a filehandle | ||||
| 743 | subtype 'FileHandle' => as 'GlobRef' => where { | ||||
| 744 | Scalar::Util::openhandle($_) || ( blessed($_) && $_->isa("IO::Handle") ); | ||||
| 745 | 1 | 47µs | 4 | 1.09ms | } => optimize_as # spent 1.05ms making 1 call to Moose::Util::TypeConstraints::subtype
# spent 12µs making 1 call to Moose::Util::TypeConstraints::as
# spent 11µs making 1 call to Moose::Util::TypeConstraints::where
# spent 10µs making 1 call to Moose::Util::TypeConstraints::optimize_as |
| 746 | \&Moose::Util::TypeConstraints::OptimizedConstraints::FileHandle; | ||||
| 747 | |||||
| 748 | # NOTE: | ||||
| 749 | # blessed(qr/.../) returns true,.. how odd | ||||
| 750 | subtype 'Object' => as 'Ref' => | ||||
| 751 | where { blessed($_) && blessed($_) ne 'Regexp' } => | ||||
| 752 | 1 | 48µs | 4 | 1.12ms | optimize_as \&Moose::Util::TypeConstraints::OptimizedConstraints::Object; # spent 1.09ms making 1 call to Moose::Util::TypeConstraints::subtype
# spent 13µs making 1 call to Moose::Util::TypeConstraints::as
# spent 11µs making 1 call to Moose::Util::TypeConstraints::where
# spent 10µs making 1 call to Moose::Util::TypeConstraints::optimize_as |
| 753 | |||||
| 754 | # This type is deprecated. | ||||
| 755 | subtype 'Role' => as 'Object' => where { $_->can('does') } => | ||||
| 756 | 1 | 48µs | 4 | 1.07ms | optimize_as \&Moose::Util::TypeConstraints::OptimizedConstraints::Role; # spent 1.03ms making 1 call to Moose::Util::TypeConstraints::subtype
# spent 13µs making 1 call to Moose::Util::TypeConstraints::as
# spent 11µs making 1 call to Moose::Util::TypeConstraints::where
# spent 10µs making 1 call to Moose::Util::TypeConstraints::optimize_as |
| 757 | |||||
| 758 | 1 | 9µs | my $_class_name_checker = sub { }; | ||
| 759 | |||||
| 760 | subtype 'ClassName' => as 'Str' => | ||||
| 761 | 1 | 73µs | 4 | 1.12ms | where { Class::MOP::is_class_loaded($_) } => optimize_as # spent 1.07ms making 1 call to Moose::Util::TypeConstraints::subtype
# spent 19µs making 1 call to Moose::Util::TypeConstraints::as
# spent 14µs making 1 call to Moose::Util::TypeConstraints::optimize_as
# spent 11µs making 1 call to Moose::Util::TypeConstraints::where |
| 762 | \&Moose::Util::TypeConstraints::OptimizedConstraints::ClassName; | ||||
| 763 | |||||
| 764 | subtype 'RoleName' => as 'ClassName' => where { | ||||
| 765 | (Class::MOP::class_of($_) || return)->isa('Moose::Meta::Role'); | ||||
| 766 | 1 | 48µs | 4 | 1.06ms | } => optimize_as # spent 1.03ms making 1 call to Moose::Util::TypeConstraints::subtype
# spent 13µs making 1 call to Moose::Util::TypeConstraints::as
# spent 11µs making 1 call to Moose::Util::TypeConstraints::where
# spent 10µs making 1 call to Moose::Util::TypeConstraints::optimize_as |
| 767 | \&Moose::Util::TypeConstraints::OptimizedConstraints::RoleName; | ||||
| 768 | |||||
| 769 | ## -------------------------------------------------------- | ||||
| 770 | # parameterizable types ... | ||||
| 771 | |||||
| 772 | $REGISTRY->add_type_constraint( | ||||
| 773 | Moose::Meta::TypeConstraint::Parameterizable->new( | ||||
| 774 | name => 'ScalarRef', | ||||
| 775 | package_defined_in => __PACKAGE__, | ||||
| 776 | parent => find_type_constraint('Ref'), | ||||
| 777 | constraint => sub { ref($_) eq 'SCALAR' || ref($_) eq 'REF' }, | ||||
| 778 | optimized => | ||||
| 779 | \&Moose::Util::TypeConstraints::OptimizedConstraints::ScalarRef, | ||||
| 780 | constraint_generator => sub { | ||||
| 781 | my $type_parameter = shift; | ||||
| 782 | my $check = $type_parameter->_compiled_type_constraint; | ||||
| 783 | return sub { | ||||
| 784 | return $check->(${ $_ }); | ||||
| 785 | }; | ||||
| 786 | } | ||||
| 787 | ) | ||||
| 788 | 1 | 68µs | 3 | 985µs | ); # spent 700µs making 1 call to Moose::Meta::TypeConstraint::new
# spent 168µs making 1 call to Moose::Meta::TypeConstraint::Registry::add_type_constraint
# spent 117µs making 1 call to Moose::Util::TypeConstraints::find_type_constraint |
| 789 | |||||
| 790 | $REGISTRY->add_type_constraint( | ||||
| 791 | Moose::Meta::TypeConstraint::Parameterizable->new( | ||||
| 792 | name => 'ArrayRef', | ||||
| 793 | package_defined_in => __PACKAGE__, | ||||
| 794 | parent => find_type_constraint('Ref'), | ||||
| 795 | constraint => sub { ref($_) eq 'ARRAY' }, | ||||
| 796 | optimized => | ||||
| 797 | \&Moose::Util::TypeConstraints::OptimizedConstraints::ArrayRef, | ||||
| 798 | # spent 274µs (211+63) within Moose::Util::TypeConstraints::__ANON__[/home/doy/perl5/perlbrew/perls/perl-5.10.1/lib/site_perl/5.10.1/x86_64-linux/Moose/Util/TypeConstraints.pm:807] which was called 5 times, avg 55µs/call:
# 5 times (211µs+63µs) by Moose::Meta::TypeConstraint::Parameterizable::generate_constraint_for at line 25 of Moose/Meta/TypeConstraint/Parameterizable.pm, avg 55µs/call | ||||
| 799 | 5 | 15µs | my $type_parameter = shift; | ||
| 800 | 5 | 62µs | 5 | 63µs | my $check = $type_parameter->_compiled_type_constraint; # spent 63µs making 5 calls to Moose::Meta::TypeConstraint::_compiled_type_constraint, avg 13µs/call |
| 801 | return sub { | ||||
| 802 | foreach my $x (@$_) { | ||||
| 803 | ( $check->($x) ) || return; | ||||
| 804 | } | ||||
| 805 | 1; | ||||
| 806 | } | ||||
| 807 | 5 | 132µs | } | ||
| 808 | ) | ||||
| 809 | 1 | 47µs | 3 | 516µs | ); # spent 282µs making 1 call to Moose::Meta::TypeConstraint::new
# spent 123µs making 1 call to Moose::Util::TypeConstraints::find_type_constraint
# spent 111µs making 1 call to Moose::Meta::TypeConstraint::Registry::add_type_constraint |
| 810 | |||||
| 811 | $REGISTRY->add_type_constraint( | ||||
| 812 | Moose::Meta::TypeConstraint::Parameterizable->new( | ||||
| 813 | name => 'HashRef', | ||||
| 814 | package_defined_in => __PACKAGE__, | ||||
| 815 | parent => find_type_constraint('Ref'), | ||||
| 816 | constraint => sub { ref($_) eq 'HASH' }, | ||||
| 817 | optimized => | ||||
| 818 | \&Moose::Util::TypeConstraints::OptimizedConstraints::HashRef, | ||||
| 819 | # spent 299µs (240+59) within Moose::Util::TypeConstraints::__ANON__[/home/doy/perl5/perlbrew/perls/perl-5.10.1/lib/site_perl/5.10.1/x86_64-linux/Moose/Util/TypeConstraints.pm:828] which was called 5 times, avg 60µs/call:
# 5 times (240µs+59µs) by Moose::Meta::TypeConstraint::Parameterizable::generate_constraint_for at line 25 of Moose/Meta/TypeConstraint/Parameterizable.pm, avg 60µs/call | ||||
| 820 | 5 | 15µs | my $type_parameter = shift; | ||
| 821 | 5 | 59µs | 5 | 59µs | my $check = $type_parameter->_compiled_type_constraint; # spent 59µs making 5 calls to Moose::Meta::TypeConstraint::_compiled_type_constraint, avg 12µs/call |
| 822 | return sub { | ||||
| 823 | foreach my $x ( values %$_ ) { | ||||
| 824 | ( $check->($x) ) || return; | ||||
| 825 | } | ||||
| 826 | 1; | ||||
| 827 | } | ||||
| 828 | 5 | 151µs | } | ||
| 829 | ) | ||||
| 830 | 1 | 43µs | 3 | 502µs | ); # spent 276µs making 1 call to Moose::Meta::TypeConstraint::new
# spent 117µs making 1 call to Moose::Util::TypeConstraints::find_type_constraint
# spent 109µs making 1 call to Moose::Meta::TypeConstraint::Registry::add_type_constraint |
| 831 | |||||
| 832 | $REGISTRY->add_type_constraint( | ||||
| 833 | Moose::Meta::TypeConstraint::Parameterizable->new( | ||||
| 834 | name => 'Maybe', | ||||
| 835 | package_defined_in => __PACKAGE__, | ||||
| 836 | parent => find_type_constraint('Item'), | ||||
| 837 | constraint => sub {1}, | ||||
| 838 | constraint_generator => sub { | ||||
| 839 | my $type_parameter = shift; | ||||
| 840 | my $check = $type_parameter->_compiled_type_constraint; | ||||
| 841 | return sub { | ||||
| 842 | return 1 if not( defined($_) ) || $check->($_); | ||||
| 843 | return; | ||||
| 844 | } | ||||
| 845 | } | ||||
| 846 | ) | ||||
| 847 | 1 | 59µs | 3 | 923µs | ); # spent 688µs making 1 call to Moose::Meta::TypeConstraint::new
# spent 118µs making 1 call to Moose::Meta::TypeConstraint::Registry::add_type_constraint
# spent 117µs making 1 call to Moose::Util::TypeConstraints::find_type_constraint |
| 848 | |||||
| 849 | my @PARAMETERIZABLE_TYPES | ||||
| 850 | 5 | 59µs | 4 | 139µs | = map { $REGISTRY->get_type_constraint($_) } qw[ScalarRef ArrayRef HashRef Maybe]; # spent 139µs making 4 calls to Moose::Meta::TypeConstraint::Registry::get_type_constraint, avg 35µs/call |
| 851 | |||||
| 852 | 10 | 137µs | # spent 109µs within Moose::Util::TypeConstraints::get_all_parameterizable_types which was called 10 times, avg 11µs/call:
# 10 times (109µs+0s) by Moose::Meta::TypeConstraint::Parameterized::compile_type_constraint at line 51 of Moose/Meta/TypeConstraint/Parameterized.pm, avg 11µs/call | ||
| 853 | |||||
| 854 | sub add_parameterizable_type { | ||||
| 855 | my $type = shift; | ||||
| 856 | ( blessed $type | ||||
| 857 | && $type->isa('Moose::Meta::TypeConstraint::Parameterizable') ) | ||||
| 858 | || __PACKAGE__->_throw_error( | ||||
| 859 | "Type must be a Moose::Meta::TypeConstraint::Parameterizable not $type" | ||||
| 860 | ); | ||||
| 861 | push @PARAMETERIZABLE_TYPES => $type; | ||||
| 862 | } | ||||
| 863 | |||||
| 864 | ## -------------------------------------------------------- | ||||
| 865 | # end of built-in types ... | ||||
| 866 | ## -------------------------------------------------------- | ||||
| 867 | |||||
| 868 | { | ||||
| 869 | 2 | 94µs | 1 | 64µs | my @BUILTINS = list_all_type_constraints(); # spent 64µs making 1 call to Moose::Util::TypeConstraints::list_all_type_constraints |
| 870 | sub list_all_builtin_type_constraints {@BUILTINS} | ||||
| 871 | } | ||||
| 872 | |||||
| 873 | sub _throw_error { | ||||
| 874 | shift; | ||||
| 875 | require Moose; | ||||
| 876 | unshift @_, 'Moose'; | ||||
| 877 | goto &Moose::throw_error; | ||||
| 878 | } | ||||
| 879 | |||||
| 880 | 1 | 291µs | 1; | ||
| 881 | |||||
| 882 | __END__ | ||||
# spent 1.90ms within Moose::Util::TypeConstraints::CORE:match which was called 101 times, avg 19µs/call:
# 32 times (746µs+0s) by Moose::Util::TypeConstraints::_detect_type_constraint_union at line 677, avg 23µs/call
# 20 times (399µs+0s) by Moose::Util::TypeConstraints::_detect_parameterized_type_constraint at line 656, avg 20µs/call
# 18 times (243µs+0s) by Moose::Util::TypeConstraints::_create_type_constraint at line 532, avg 13µs/call
# 15 times (104µs+0s) by Moose::Util::TypeConstraints::_parse_type_constraint_union at line 664, avg 7µs/call
# 10 times (326µs+0s) by Moose::Util::TypeConstraints::_parse_parameterized_type_constraint at line 650, avg 33µs/call
# 6 times (79µs+0s) by Moose::Util::TypeConstraints::_parse_type_constraint_union at line 663, avg 13µs/call | |||||
# spent 94µs within Moose::Util::TypeConstraints::CORE:qr which was called 10 times, avg 9µs/call:
# once (20µs+0s) by Moose::Meta::Attribute::BEGIN@20 at line 598
# once (16µs+0s) by Moose::Meta::Attribute::BEGIN@20 at line 632
# once (8µs+0s) by Moose::Meta::Attribute::BEGIN@20 at line 599
# once (8µs+0s) by Moose::Meta::Attribute::BEGIN@20 at line 628
# once (8µs+0s) by Moose::Meta::Attribute::BEGIN@20 at line 629
# once (7µs+0s) by Moose::Meta::Attribute::BEGIN@20 at line 616
# once (7µs+0s) by Moose::Meta::Attribute::BEGIN@20 at line 600
# once (7µs+0s) by Moose::Meta::Attribute::BEGIN@20 at line 601
# once (7µs+0s) by Moose::Meta::Attribute::BEGIN@20 at line 630
# once (7µs+0s) by Moose::Meta::Attribute::BEGIN@20 at line 631 | |||||
# spent 3.10ms within Moose::Util::TypeConstraints::CORE:regcomp which was called 91 times, avg 34µs/call:
# 32 times (865µs+0s) by Moose::Util::TypeConstraints::_detect_type_constraint_union at line 677, avg 27µs/call
# 20 times (335µs+0s) by Moose::Util::TypeConstraints::_detect_parameterized_type_constraint at line 656, avg 17µs/call
# 15 times (142µs+0s) by Moose::Util::TypeConstraints::_parse_type_constraint_union at line 664, avg 9µs/call
# 10 times (293µs+0s) by Moose::Util::TypeConstraints::_parse_parameterized_type_constraint at line 650, avg 29µs/call
# 6 times (259µs+0s) by Moose::Util::TypeConstraints::_parse_type_constraint_union at line 663, avg 43µs/call
# once (188µs+0s) by Moose::Meta::Attribute::BEGIN@20 at line 632
# once (186µs+0s) by Moose::Meta::Attribute::BEGIN@20 at line 616
# once (178µs+0s) by Moose::Meta::Attribute::BEGIN@20 at line 629
# once (168µs+0s) by Moose::Meta::Attribute::BEGIN@20 at line 628
# once (161µs+0s) by Moose::Meta::Attribute::BEGIN@20 at line 630
# once (159µs+0s) by Moose::Meta::Attribute::BEGIN@20 at line 631
# once (132µs+0s) by Moose::Meta::Attribute::BEGIN@20 at line 599
# once (36µs+0s) by Moose::Meta::Attribute::BEGIN@20 at line 601 | |||||
# spent 913µs within Moose::Util::TypeConstraints::CORE:subst which was called 157 times, avg 6µs/call:
# 157 times (913µs+0s) by Moose::Util::TypeConstraints::normalize_type_constraint_name at line 238, avg 6µs/call |