| Filename | /Users/ap13/perl5/lib/perl5/darwin-2level/Moose/Meta/TypeConstraint.pm |
| Statements | Executed 10400 statements in 22.9ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1417 | 6 | 3 | 10.3ms | 16.4ms | Moose::Meta::TypeConstraint::can_be_inlined (recurses: max depth 1, inclusive time 16µs) |
| 796 | 9 | 3 | 9.29ms | 25.1ms | Moose::Meta::TypeConstraint::_inline_check (recurses: max depth 2, inclusive time 15.7ms) |
| 444 | 5 | 4 | 3.70ms | 5.67ms | Moose::Meta::TypeConstraint::inline_environment (recurses: max depth 1, inclusive time 8µs) |
| 48 | 9 | 6 | 1.54ms | 17.4ms | Moose::Meta::TypeConstraint::new |
| 73 | 1 | 1 | 806µs | 15.8ms | Moose::Meta::TypeConstraint::_actually_compile_type_constraint |
| 1 | 1 | 1 | 578µs | 1.70ms | Moose::Meta::TypeConstraint::BEGIN@6 |
| 490 | 8 | 4 | 565µs | 565µs | Moose::Meta::TypeConstraint::__ANON__[:10] |
| 73 | 4 | 4 | 478µs | 16.7ms | Moose::Meta::TypeConstraint::compile_type_constraint |
| 20 | 1 | 1 | 276µs | 597µs | Moose::Meta::TypeConstraint::equals |
| 48 | 1 | 1 | 234µs | 234µs | Moose::Meta::TypeConstraint::__ANON__[:72] |
| 8 | 1 | 1 | 226µs | 1.03ms | Moose::Meta::TypeConstraint::is_subtype_of |
| 16 | 1 | 1 | 117µs | 4.15ms | Moose::Meta::TypeConstraint::create_child_type |
| 40 | 1 | 1 | 108µs | 134µs | Moose::Meta::TypeConstraint::__ANON__[:8] |
| 48 | 2 | 1 | 87µs | 87µs | Moose::Meta::TypeConstraint::__ANON__[:89] |
| 1 | 1 | 1 | 26µs | 55µs | Moose::Meta::TypeConstraint::BEGIN@4 |
| 1 | 1 | 1 | 23µs | 73µs | Moose::Meta::TypeConstraint::BEGIN@8 |
| 1 | 1 | 1 | 14µs | 25µs | Moose::Meta::TypeConstraint::BEGIN@5 |
| 1 | 1 | 1 | 11µs | 47µs | Moose::Meta::TypeConstraint::BEGIN@14 |
| 1 | 1 | 1 | 11µs | 283µs | Moose::Meta::TypeConstraint::BEGIN@13 |
| 1 | 1 | 1 | 10µs | 40µs | Moose::Meta::TypeConstraint::BEGIN@16 |
| 1 | 1 | 1 | 10µs | 92µs | Moose::Meta::TypeConstraint::BEGIN@18 |
| 1 | 1 | 1 | 10µs | 31µs | Moose::Meta::TypeConstraint::BEGIN@15 |
| 1 | 1 | 1 | 9µs | 153µs | Moose::Meta::TypeConstraint::BEGIN@20 |
| 3 | 1 | 1 | 6µs | 6µs | Moose::Meta::TypeConstraint::__ANON__[:36] |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::__ANON__[:327] |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::__ANON__[:32] |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::__ANON__[:340] |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::__ANON__[:63] |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::__ANON__[:71] |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::__ANON__[:9] |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::_collect_all_parents |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::_compile_subtype |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::_compile_type |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::assert_coerce |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::assert_valid |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::check |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::coerce |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::get_message |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::is_a_type_of |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::parents |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::validate |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package Moose::Meta::TypeConstraint; | ||||
| 2 | 1 | 2µs | our $VERSION = '2.1403'; | ||
| 3 | |||||
| 4 | 2 | 44µs | 2 | 84µs | # spent 55µs (26+29) within Moose::Meta::TypeConstraint::BEGIN@4 which was called:
# once (26µs+29µs) by Moose::BEGIN@25 at line 4 # spent 55µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@4
# spent 29µs making 1 call to strict::import |
| 5 | 2 | 39µs | 2 | 36µs | # spent 25µs (14+11) within Moose::Meta::TypeConstraint::BEGIN@5 which was called:
# once (14µs+11µs) by Moose::BEGIN@25 at line 5 # spent 25µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@5
# spent 11µs making 1 call to warnings::import |
| 6 | 2 | 253µs | 2 | 2.71ms | # spent 1.70ms (578µs+1.12) within Moose::Meta::TypeConstraint::BEGIN@6 which was called:
# once (578µs+1.12ms) by Moose::BEGIN@25 at line 6 # spent 1.70ms making 1 call to Moose::Meta::TypeConstraint::BEGIN@6
# spent 1.00ms making 1 call to metaclass::import |
| 7 | |||||
| 8 | 40 | 160µs | 40 | 25µs | # spent 134µs (108+25) within Moose::Meta::TypeConstraint::__ANON__[/Users/ap13/perl5/lib/perl5/darwin-2level/Moose/Meta/TypeConstraint.pm:8] which was called 40 times, avg 3µs/call:
# 40 times (108µs+25µs) by Moose::Meta::TypeConstraint::equals at line 236, avg 3µs/call
# spent 73µs (23+50) within Moose::Meta::TypeConstraint::BEGIN@8 which was called:
# once (23µs+50µs) by Moose::BEGIN@25 at line 11 # spent 25µs making 40 calls to Scalar::Util::refaddr, avg 635ns/call |
| 9 | '""' => sub { shift->name }, # stringify to tc name | ||||
| 10 | 490 | 1.02ms | # spent 565µs within Moose::Meta::TypeConstraint::__ANON__[/Users/ap13/perl5/lib/perl5/darwin-2level/Moose/Meta/TypeConstraint.pm:10] which was called 490 times, avg 1µs/call:
# 189 times (166µs+0s) by Moose::Util::TypeConstraints::find_or_create_isa_type_constraint at line 246 of Moose/Util/TypeConstraints.pm, avg 878ns/call
# 187 times (266µs+0s) by Moose::Util::TypeConstraints::find_or_parse_type_constraint at line 260 of Moose/Util/TypeConstraints.pm, avg 1µs/call
# 48 times (76µs+0s) by Moose::Meta::TypeConstraint::Registry::add_type_constraint at line 47 of Moose/Meta/TypeConstraint/Registry.pm, avg 2µs/call
# 20 times (17µs+0s) by Moose::Meta::TypeConstraint::equals at line 234, avg 865ns/call
# 20 times (17µs+0s) by Moose::Meta::TypeConstraint::is_subtype_of at line 265, avg 860ns/call
# 16 times (12µs+0s) by Moose::Util::TypeConstraints::_create_type_constraint at line 572 of Moose/Util/TypeConstraints.pm, avg 756ns/call
# 8 times (8µs+0s) by Moose::Meta::TypeConstraint::is_subtype_of at line 261, avg 1µs/call
# 2 times (2µs+0s) by Moose::Meta::TypeConstraint::Parameterizable::parameterize at line 78 of Moose/Meta/TypeConstraint/Parameterizable.pm, avg 800ns/call | ||
| 11 | 2 | 43µs | 2 | 123µs | fallback => 1; # spent 73µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@8
# spent 50µs making 1 call to overload::import |
| 12 | |||||
| 13 | 2 | 37µs | 2 | 555µs | # spent 283µs (11+272) within Moose::Meta::TypeConstraint::BEGIN@13 which was called:
# once (11µs+272µs) by Moose::BEGIN@25 at line 13 # spent 283µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@13
# spent 272µs making 1 call to Sub::Exporter::__ANON__[Sub/Exporter.pm:337] |
| 14 | 2 | 30µs | 2 | 83µs | # spent 47µs (11+36) within Moose::Meta::TypeConstraint::BEGIN@14 which was called:
# once (11µs+36µs) by Moose::BEGIN@25 at line 14 # spent 47µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@14
# spent 36µs making 1 call to Exporter::import |
| 15 | 2 | 26µs | 2 | 52µs | # spent 31µs (10+21) within Moose::Meta::TypeConstraint::BEGIN@15 which was called:
# once (10µs+21µs) by Moose::BEGIN@25 at line 15 # spent 31µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@15
# spent 21µs making 1 call to Exporter::import |
| 16 | 2 | 32µs | 2 | 71µs | # spent 40µs (10+30) within Moose::Meta::TypeConstraint::BEGIN@16 which was called:
# once (10µs+30µs) by Moose::BEGIN@25 at line 16 # spent 40µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@16
# spent 30µs making 1 call to Exporter::import |
| 17 | |||||
| 18 | 2 | 29µs | 2 | 174µs | # spent 92µs (10+82) within Moose::Meta::TypeConstraint::BEGIN@18 which was called:
# once (10µs+82µs) by Moose::BEGIN@25 at line 18 # spent 92µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@18
# spent 82µs making 1 call to base::import |
| 19 | |||||
| 20 | 2 | 2.05ms | 2 | 297µs | # spent 153µs (9+144) within Moose::Meta::TypeConstraint::BEGIN@20 which was called:
# once (9µs+144µs) by Moose::BEGIN@25 at line 20 # spent 153µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@20
# spent 144µs making 1 call to Sub::Exporter::__ANON__[Sub/Exporter.pm:337] |
| 21 | |||||
| 22 | 1 | 19µs | 3 | 1.07ms | __PACKAGE__->meta->add_attribute('name' => ( # spent 1.00ms making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 54µs making 1 call to Moose::Meta::TypeConstraint::meta
# spent 17µs making 1 call to Class::MOP::_definition_context |
| 23 | reader => 'name', | ||||
| 24 | Class::MOP::_definition_context(), | ||||
| 25 | )); | ||||
| 26 | 1 | 9µs | 3 | 936µs | __PACKAGE__->meta->add_attribute('parent' => ( # spent 907µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 20µs making 1 call to Moose::Meta::TypeConstraint::meta
# spent 10µs making 1 call to Class::MOP::_definition_context |
| 27 | reader => 'parent', | ||||
| 28 | predicate => 'has_parent', | ||||
| 29 | Class::MOP::_definition_context(), | ||||
| 30 | )); | ||||
| 31 | |||||
| 32 | 1 | 3µs | my $null_constraint = sub { 1 }; | ||
| 33 | __PACKAGE__->meta->add_attribute('constraint' => ( | ||||
| 34 | reader => 'constraint', | ||||
| 35 | writer => '_set_constraint', | ||||
| 36 | 3 | 9µs | # spent 6µs within Moose::Meta::TypeConstraint::__ANON__[/Users/ap13/perl5/lib/perl5/darwin-2level/Moose/Meta/TypeConstraint.pm:36] which was called 3 times, avg 2µs/call:
# 3 times (6µs+0s) by Moose::Meta::TypeConstraint::Parameterized::_new or Moose::Meta::TypeConstraint::_new at line 24 of (eval 25)[Eval/Closure.pm:125], avg 2µs/call | ||
| 37 | 1 | 13µs | 3 | 1.04ms | Class::MOP::_definition_context(), # spent 1.01ms making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 22µs making 1 call to Moose::Meta::TypeConstraint::meta
# spent 10µs making 1 call to Class::MOP::_definition_context |
| 38 | )); | ||||
| 39 | |||||
| 40 | 1 | 7µs | 3 | 580µs | __PACKAGE__->meta->add_attribute('message' => ( # spent 555µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 18µs making 1 call to Moose::Meta::TypeConstraint::meta
# spent 8µs making 1 call to Class::MOP::_definition_context |
| 41 | accessor => 'message', | ||||
| 42 | predicate => 'has_message', | ||||
| 43 | Class::MOP::_definition_context(), | ||||
| 44 | )); | ||||
| 45 | |||||
| 46 | 1 | 5µs | 3 | 321µs | __PACKAGE__->meta->add_attribute('_default_message' => ( # spent 296µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 21µs making 1 call to Moose::Meta::TypeConstraint::meta
# spent 5µs making 1 call to Class::MOP::_definition_context |
| 47 | accessor => '_default_message', | ||||
| 48 | Class::MOP::_definition_context(), | ||||
| 49 | )); | ||||
| 50 | |||||
| 51 | # can't make this a default because it has to close over the type name, and | ||||
| 52 | # cmop attributes don't have lazy | ||||
| 53 | # spent 234µs within Moose::Meta::TypeConstraint::__ANON__[/Users/ap13/perl5/lib/perl5/darwin-2level/Moose/Meta/TypeConstraint.pm:72] which was called 48 times, avg 5µs/call:
# 48 times (234µs+0s) by Moose::Meta::TypeConstraint::new at line 127, avg 5µs/call | ||||
| 54 | 48 | 31µs | my $name = shift; | ||
| 55 | sub { | ||||
| 56 | my $value = shift; | ||||
| 57 | # have to load it late like this, since it uses Moose itself | ||||
| 58 | my $can_partialdump = try { | ||||
| 59 | # versions prior to 0.14 had a potential infinite loop bug | ||||
| 60 | require Devel::PartialDump; | ||||
| 61 | Devel::PartialDump->VERSION(0.14); | ||||
| 62 | 1; | ||||
| 63 | }; | ||||
| 64 | if ($can_partialdump) { | ||||
| 65 | $value = Devel::PartialDump->new->dump($value); | ||||
| 66 | } | ||||
| 67 | else { | ||||
| 68 | $value = (defined $value ? overload::StrVal($value) : 'undef'); | ||||
| 69 | } | ||||
| 70 | return "Validation failed for '" . $name . "' with value $value"; | ||||
| 71 | } | ||||
| 72 | 49 | 227µs | }; | ||
| 73 | 1 | 6µs | 3 | 699µs | __PACKAGE__->meta->add_attribute('coercion' => ( # spent 684µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 10µs making 1 call to Moose::Meta::TypeConstraint::meta
# spent 5µs making 1 call to Class::MOP::_definition_context |
| 74 | accessor => 'coercion', | ||||
| 75 | predicate => 'has_coercion', | ||||
| 76 | Class::MOP::_definition_context(), | ||||
| 77 | )); | ||||
| 78 | |||||
| 79 | 1 | 6µs | 3 | 514µs | __PACKAGE__->meta->add_attribute('inlined' => ( # spent 488µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 17µs making 1 call to Moose::Meta::TypeConstraint::meta
# spent 8µs making 1 call to Class::MOP::_definition_context |
| 80 | init_arg => 'inlined', | ||||
| 81 | accessor => 'inlined', | ||||
| 82 | predicate => '_has_inlined_type_constraint', | ||||
| 83 | Class::MOP::_definition_context(), | ||||
| 84 | )); | ||||
| 85 | |||||
| 86 | __PACKAGE__->meta->add_attribute('inline_environment' => ( | ||||
| 87 | init_arg => 'inline_environment', | ||||
| 88 | accessor => '_inline_environment', | ||||
| 89 | 48 | 135µs | # spent 87µs within Moose::Meta::TypeConstraint::__ANON__[/Users/ap13/perl5/lib/perl5/darwin-2level/Moose/Meta/TypeConstraint.pm:89] which was called 48 times, avg 2µs/call:
# 26 times (58µs+0s) by Moose::Meta::TypeConstraint::Class::_new or Moose::Meta::TypeConstraint::Parameterizable::_new at line 33 of (eval 25)[Eval/Closure.pm:125], avg 2µs/call
# 22 times (29µs+0s) by Moose::Meta::TypeConstraint::Parameterized::_new or Moose::Meta::TypeConstraint::Role::_new or Moose::Meta::TypeConstraint::_new at line 30 of (eval 25)[Eval/Closure.pm:125], avg 1µs/call | ||
| 90 | 1 | 7µs | 3 | 315µs | Class::MOP::_definition_context(), # spent 299µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 10µs making 1 call to Moose::Meta::TypeConstraint::meta
# spent 5µs making 1 call to Class::MOP::_definition_context |
| 91 | )); | ||||
| 92 | |||||
| 93 | sub parents { | ||||
| 94 | my $self = shift; | ||||
| 95 | $self->parent; | ||||
| 96 | } | ||||
| 97 | |||||
| 98 | # private accessors | ||||
| 99 | |||||
| 100 | 1 | 5µs | 3 | 500µs | __PACKAGE__->meta->add_attribute('compiled_type_constraint' => ( # spent 484µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 10µs making 1 call to Moose::Meta::TypeConstraint::meta
# spent 5µs making 1 call to Class::MOP::_definition_context |
| 101 | accessor => '_compiled_type_constraint', | ||||
| 102 | predicate => '_has_compiled_type_constraint', | ||||
| 103 | Class::MOP::_definition_context(), | ||||
| 104 | )); | ||||
| 105 | |||||
| 106 | 1 | 5µs | 3 | 308µs | __PACKAGE__->meta->add_attribute('package_defined_in' => ( # spent 292µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 10µs making 1 call to Moose::Meta::TypeConstraint::meta
# spent 5µs making 1 call to Class::MOP::_definition_context |
| 107 | accessor => '_package_defined_in', | ||||
| 108 | Class::MOP::_definition_context(), | ||||
| 109 | )); | ||||
| 110 | |||||
| 111 | # spent 17.4ms (1.54+15.9) within Moose::Meta::TypeConstraint::new which was called 48 times, avg 363µs/call:
# 22 times (820µs+7.43ms) by Moose::Meta::TypeConstraint::Class::new at line 38 of Moose/Meta/TypeConstraint/Class.pm, avg 375µs/call
# 16 times (373µs+3.66ms) by Moose::Meta::TypeConstraint::create_child_type at line 359, avg 252µs/call
# 3 times (119µs+1.13ms) by Moose::Meta::TypeConstraint::Role::new at line 39 of Moose/Meta/TypeConstraint/Role.pm, avg 417µs/call
# 2 times (79µs+2.40ms) by Moose::Meta::TypeConstraint::Parameterizable::parameterize at line 90 of Moose/Meta/TypeConstraint/Parameterizable.pm, avg 1.24ms/call
# once (36µs+342µs) by Moose::Util::TypeConstraints::Builtins::define_builtins at line 198 of Moose/Util/TypeConstraints/Builtins.pm
# once (38µs+309µs) by Moose::Util::TypeConstraints::_create_type_constraint at line 582 of Moose/Util/TypeConstraints.pm
# once (23µs+239µs) by Moose::Util::TypeConstraints::Builtins::define_builtins at line 294 of Moose/Util/TypeConstraints/Builtins.pm
# once (27µs+182µs) by Moose::Util::TypeConstraints::Builtins::define_builtins at line 233 of Moose/Util/TypeConstraints/Builtins.pm
# once (27µs+182µs) by Moose::Util::TypeConstraints::Builtins::define_builtins at line 268 of Moose/Util/TypeConstraints/Builtins.pm | ||||
| 112 | 48 | 24µs | my $class = shift; | ||
| 113 | 48 | 72µs | my ($first, @rest) = @_; | ||
| 114 | 48 | 134µs | my %args = ref $first ? %$first : $first ? ($first, @rest) : (); | ||
| 115 | 48 | 53µs | $args{name} = $args{name} ? "$args{name}" : "__ANON__"; | ||
| 116 | |||||
| 117 | 48 | 15µs | if ( exists $args{message} | ||
| 118 | && (!ref($args{message}) || ref($args{message}) ne 'CODE') ) { | ||||
| 119 | throw_exception( MessageParameterMustBeCodeRef => params => \%args, | ||||
| 120 | class => $class | ||||
| 121 | ); | ||||
| 122 | } | ||||
| 123 | |||||
| 124 | 48 | 188µs | 48 | 2.31ms | my $self = $class->_new(%args); # spent 1.23ms making 22 calls to Moose::Meta::TypeConstraint::Class::_new, avg 56µs/call
# spent 361µs making 17 calls to Moose::Meta::TypeConstraint::_new, avg 21µs/call
# spent 336µs making 3 calls to Moose::Meta::TypeConstraint::Role::_new, avg 112µs/call
# spent 223µs making 2 calls to Moose::Meta::TypeConstraint::Parameterized::_new, avg 112µs/call
# spent 162µs making 4 calls to Moose::Meta::TypeConstraint::Parameterizable::_new, avg 40µs/call |
| 125 | 48 | 227µs | 96 | 13.0ms | $self->compile_type_constraint() # spent 10.7ms making 46 calls to Moose::Meta::TypeConstraint::compile_type_constraint, avg 233µs/call
# spent 2.14ms making 2 calls to Moose::Meta::TypeConstraint::Parameterized::compile_type_constraint, avg 1.07ms/call
# spent 112µs making 48 calls to Moose::Meta::TypeConstraint::_has_compiled_type_constraint, avg 2µs/call |
| 126 | unless $self->_has_compiled_type_constraint; | ||||
| 127 | 48 | 356µs | 192 | 566µs | $self->_default_message($_default_message_generator->($self->name)) # spent 234µs making 48 calls to Moose::Meta::TypeConstraint::__ANON__[Moose/Meta/TypeConstraint.pm:72], avg 5µs/call
# spent 126µs making 48 calls to Moose::Meta::TypeConstraint::_default_message, avg 3µs/call
# spent 106µs making 48 calls to Moose::Meta::TypeConstraint::name, avg 2µs/call
# spent 100µs making 48 calls to Moose::Meta::TypeConstraint::has_message, avg 2µs/call |
| 128 | unless $self->has_message; | ||||
| 129 | 48 | 212µs | return $self; | ||
| 130 | } | ||||
| 131 | |||||
| - - | |||||
| 134 | sub coerce { | ||||
| 135 | my $self = shift; | ||||
| 136 | |||||
| 137 | my $coercion = $self->coercion; | ||||
| 138 | |||||
| 139 | unless ($coercion) { | ||||
| 140 | throw_exception( CoercingWithoutCoercions => type_name => $self->name ); | ||||
| 141 | } | ||||
| 142 | |||||
| 143 | return $_[0] if $self->check($_[0]); | ||||
| 144 | |||||
| 145 | return $coercion->coerce(@_); | ||||
| 146 | } | ||||
| 147 | |||||
| 148 | sub assert_coerce { | ||||
| 149 | my $self = shift; | ||||
| 150 | |||||
| 151 | my $result = $self->coerce(@_); | ||||
| 152 | |||||
| 153 | $self->assert_valid($result); | ||||
| 154 | |||||
| 155 | return $result; | ||||
| 156 | } | ||||
| 157 | |||||
| 158 | sub check { | ||||
| 159 | my ($self, @args) = @_; | ||||
| 160 | my $constraint_subref = $self->_compiled_type_constraint; | ||||
| 161 | return $constraint_subref->(@args) ? 1 : undef; | ||||
| 162 | } | ||||
| 163 | |||||
| 164 | sub validate { | ||||
| 165 | my ($self, $value) = @_; | ||||
| 166 | if ($self->_compiled_type_constraint->($value)) { | ||||
| 167 | return undef; | ||||
| 168 | } | ||||
| 169 | else { | ||||
| 170 | $self->get_message($value); | ||||
| 171 | } | ||||
| 172 | } | ||||
| 173 | |||||
| 174 | # spent 16.4ms (10.3+6.09) within Moose::Meta::TypeConstraint::can_be_inlined which was called 1417 times, avg 12µs/call:
# 796 times (5.20ms+2.98ms) by Moose::Meta::TypeConstraint::_inline_check at line 187, avg 10µs/call
# 350 times (2.72ms+1.66ms) by Moose::Meta::Attribute::_inline_check_constraint at line 686 of Moose/Meta/Attribute.pm, avg 13µs/call
# 182 times (1.55ms+994µs) by Moose::Meta::Attribute::_eval_environment at line 766 of Moose/Meta/Attribute.pm, avg 14µs/call
# 71 times (652µs+388µs) by Moose::Meta::TypeConstraint::_actually_compile_type_constraint at line 285, avg 15µs/call
# 16 times (142µs+79µs) by Moose::Meta::TypeConstraint::Parameterized::can_be_inlined at line 72 of Moose/Meta/TypeConstraint/Parameterized.pm, avg 14µs/call
# 2 times (11µs+-11µs) by Moose::Meta::TypeConstraint::can_be_inlined at line 177, avg 0s/call | ||||
| 175 | 1417 | 211µs | my $self = shift; | ||
| 176 | |||||
| 177 | 1417 | 3.13ms | 2833 | 4.04ms | if ( $self->has_parent && $self->constraint == $null_constraint ) { # spent 2.08ms making 1412 calls to Moose::Meta::TypeConstraint::constraint, avg 1µs/call
# spent 1.95ms making 1417 calls to Moose::Meta::TypeConstraint::has_parent, avg 1µs/call
# spent 4µs making 2 calls to Moose::Meta::TypeConstraint::parent, avg 2µs/call
# spent 16µs making 2 calls to Moose::Meta::TypeConstraint::can_be_inlined, avg 8µs/call, recursion: max depth 1, sum of overlapping time 16µs |
| 178 | return $self->parent->can_be_inlined; | ||||
| 179 | } | ||||
| 180 | |||||
| 181 | 1415 | 3.76ms | 1415 | 2.05ms | return $self->_has_inlined_type_constraint; # spent 2.05ms making 1415 calls to Moose::Meta::TypeConstraint::_has_inlined_type_constraint, avg 1µs/call |
| 182 | } | ||||
| 183 | |||||
| 184 | # spent 25.1ms (9.29+15.8) within Moose::Meta::TypeConstraint::_inline_check which was called 796 times, avg 32µs/call:
# 350 times (4.11ms+17.6ms) by Moose::Meta::Attribute::_inline_check_constraint at line 686 of Moose/Meta/Attribute.pm, avg 62µs/call
# 184 times (2.06ms+-2.06ms) by Moose::Util::TypeConstraints::Builtins::__ANON__[/Users/ap13/perl5/lib/perl5/darwin-2level/Moose/Util/TypeConstraints/Builtins.pm:60] at line 58 of Moose/Util/TypeConstraints/Builtins.pm, avg 0s/call
# 125 times (1.39ms+-1.39ms) by Moose::Util::TypeConstraints::Builtins::__ANON__[/Users/ap13/perl5/lib/perl5/darwin-2level/Moose/Util/TypeConstraints/Builtins.pm:77] at line 72 of Moose/Util/TypeConstraints/Builtins.pm, avg 0s/call
# 71 times (982µs+2.15ms) by Moose::Meta::TypeConstraint::_actually_compile_type_constraint at line 285, avg 44µs/call
# 36 times (413µs+-413µs) by Moose::Util::TypeConstraints::Builtins::__ANON__[/Users/ap13/perl5/lib/perl5/darwin-2level/Moose/Util/TypeConstraints/Builtins.pm:114] at line 112 of Moose/Util/TypeConstraints/Builtins.pm, avg 0s/call
# 22 times (236µs+-236µs) by Moose::Util::TypeConstraints::Builtins::__ANON__[/Users/ap13/perl5/lib/perl5/darwin-2level/Moose/Util/TypeConstraints/Builtins.pm:106] at line 97 of Moose/Util/TypeConstraints/Builtins.pm, avg 0s/call
# 6 times (78µs+242µs) by Moose::Util::TypeConstraints::Builtins::__ANON__[/Users/ap13/perl5/lib/perl5/darwin-2level/Moose/Util/TypeConstraints/Builtins.pm:292] at line 290 of Moose/Util/TypeConstraints/Builtins.pm, avg 53µs/call
# once (10µs+-10µs) by Moose::Util::TypeConstraints::Builtins::__ANON__[/Users/ap13/perl5/lib/perl5/darwin-2level/Moose/Util/TypeConstraints/Builtins.pm:170] at line 165 of Moose/Util/TypeConstraints/Builtins.pm
# once (10µs+-10µs) by Moose::Meta::TypeConstraint::_inline_check at line 191 | ||||
| 185 | 796 | 172µs | my $self = shift; | ||
| 186 | |||||
| 187 | 796 | 710µs | 796 | 8.17ms | unless ( $self->can_be_inlined ) { # spent 8.17ms making 796 calls to Moose::Meta::TypeConstraint::can_be_inlined, avg 10µs/call |
| 188 | throw_exception( CannotInlineTypeConstraintCheck => type_name => $self->name ); | ||||
| 189 | } | ||||
| 190 | |||||
| 191 | 796 | 1.65ms | 1592 | 1.96ms | if ( $self->has_parent && $self->constraint == $null_constraint ) { # spent 1.01ms making 796 calls to Moose::Meta::TypeConstraint::has_parent, avg 1µs/call
# spent 949µs making 794 calls to Moose::Meta::TypeConstraint::constraint, avg 1µs/call
# spent 1µs making 1 call to Moose::Meta::TypeConstraint::parent
# spent 20µs making 1 call to Moose::Meta::TypeConstraint::_inline_check, recursion: max depth 1, sum of overlapping time 20µs |
| 192 | return $self->parent->_inline_check(@_); | ||||
| 193 | } | ||||
| 194 | |||||
| 195 | 795 | 3.80ms | 1590 | 21.4ms | return '( do { ' . $self->inlined->( $self, @_ ) . ' } )'; # spent 8.36ms making 125 calls to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:77], avg 67µs/call
# spent 6.26ms making 184 calls to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:60], avg 34µs/call
# spent 2.40ms making 36 calls to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:114], avg 67µs/call
# spent 1.37ms making 22 calls to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:106], avg 62µs/call
# spent 1.14ms making 83 calls to Moose::Meta::TypeConstraint::Class::__ANON__[Moose/Meta/TypeConstraint/Class.pm:25], avg 14µs/call
# spent 1.09ms making 795 calls to Moose::Meta::TypeConstraint::inlined, avg 1µs/call
# spent 326µs making 185 calls to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:40], avg 2µs/call
# spent 135µs making 45 calls to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:52], avg 3µs/call
# spent 122µs making 55 calls to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:252], avg 2µs/call
# spent 93µs making 40 calls to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:217], avg 2µs/call
# spent 81µs making 6 calls to Moose::Meta::TypeConstraint::Role::__ANON__[Moose/Meta/TypeConstraint/Role.pm:27], avg 13µs/call
# spent 37µs making 1 call to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:170]
# spent 4µs making 2 calls to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:157], avg 2µs/call
# spent 4µs making 1 call to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:146]
# spent 3µs making 1 call to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:119]
# spent 3µs making 1 call to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:189]
# spent 2µs making 2 calls to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:22], avg 1µs/call
# spent 2µs making 1 call to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:131]
# spent 2µs making 1 call to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:151]
# spent 2µs making 1 call to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:126]
# spent 2µs making 1 call to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:66]
# spent 2µs making 1 call to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:285]
# spent 2µs making 1 call to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:33] |
| 196 | } | ||||
| 197 | |||||
| 198 | # spent 5.67ms (3.70+1.96) within Moose::Meta::TypeConstraint::inline_environment which was called 444 times, avg 13µs/call:
# 182 times (1.56ms+795µs) by Moose::Meta::Attribute::_eval_environment at line 777 of Moose/Meta/Attribute.pm, avg 13µs/call
# 170 times (1.39ms+773µs) by Moose::Meta::Class::_eval_environment at line 535 of Moose/Meta/Class.pm, avg 13µs/call
# 71 times (588µs+307µs) by Moose::Meta::TypeConstraint::_actually_compile_type_constraint at line 285, avg 13µs/call
# 20 times (161µs+95µs) by Moose::Meta::TypeConstraint::Parameterized::inline_environment at line 85 of Moose/Meta/TypeConstraint/Parameterized.pm, avg 13µs/call
# once (6µs+-6µs) by Moose::Meta::TypeConstraint::inline_environment at line 201 | ||||
| 199 | 444 | 128µs | my $self = shift; | ||
| 200 | |||||
| 201 | 444 | 958µs | 888 | 1.19ms | if ( $self->has_parent && $self->constraint == $null_constraint ) { # spent 598µs making 444 calls to Moose::Meta::TypeConstraint::has_parent, avg 1µs/call
# spent 588µs making 442 calls to Moose::Meta::TypeConstraint::constraint, avg 1µs/call
# spent 1µs making 1 call to Moose::Meta::TypeConstraint::parent
# spent 8µs making 1 call to Moose::Meta::TypeConstraint::inline_environment, recursion: max depth 1, sum of overlapping time 8µs |
| 202 | return $self->parent->inline_environment; | ||||
| 203 | } | ||||
| 204 | |||||
| 205 | 443 | 1.39ms | 443 | 777µs | return $self->_inline_environment; # spent 777µs making 443 calls to Moose::Meta::TypeConstraint::_inline_environment, avg 2µs/call |
| 206 | } | ||||
| 207 | |||||
| 208 | sub assert_valid { | ||||
| 209 | my ($self, $value) = @_; | ||||
| 210 | |||||
| 211 | my $error = $self->validate($value); | ||||
| 212 | return 1 if ! defined $error; | ||||
| 213 | |||||
| 214 | throw_exception( ValidationFailedForTypeConstraint => type => $self, | ||||
| 215 | error_message => $error, | ||||
| 216 | value => $value | ||||
| 217 | ); | ||||
| 218 | } | ||||
| 219 | |||||
| 220 | sub get_message { | ||||
| 221 | my ($self, $value) = @_; | ||||
| 222 | my $msg = $self->has_message | ||||
| 223 | ? $self->message | ||||
| 224 | : $self->_default_message; | ||||
| 225 | local $_ = $value; | ||||
| 226 | return $msg->($value); | ||||
| 227 | } | ||||
| 228 | |||||
| 229 | ## type predicates ... | ||||
| 230 | |||||
| 231 | # spent 597µs (276+321) within Moose::Meta::TypeConstraint::equals which was called 20 times, avg 30µs/call:
# 20 times (276µs+321µs) by Moose::Meta::TypeConstraint::is_subtype_of at line 266, avg 30µs/call | ||||
| 232 | 20 | 10µs | my ( $self, $type_or_name ) = @_; | ||
| 233 | |||||
| 234 | 20 | 42µs | 40 | 133µs | my $other = Moose::Util::TypeConstraints::find_type_constraint($type_or_name) or return; # spent 116µs making 20 calls to Moose::Util::TypeConstraints::find_type_constraint, avg 6µs/call
# spent 17µs making 20 calls to Moose::Meta::TypeConstraint::__ANON__[Moose/Meta/TypeConstraint.pm:10], avg 865ns/call |
| 235 | |||||
| 236 | 20 | 50µs | 40 | 134µs | return 1 if $self == $other; # spent 134µs making 40 calls to Moose::Meta::TypeConstraint::__ANON__[Moose/Meta/TypeConstraint.pm:8], avg 3µs/call |
| 237 | |||||
| 238 | 18 | 73µs | 36 | 54µs | return unless $self->constraint == $other->constraint; # spent 54µs making 36 calls to Moose::Meta::TypeConstraint::constraint, avg 2µs/call |
| 239 | |||||
| 240 | if ( $self->has_parent ) { | ||||
| 241 | return unless $other->has_parent; | ||||
| 242 | return unless $self->parent->equals( $other->parent ); | ||||
| 243 | } else { | ||||
| 244 | return if $other->has_parent; | ||||
| 245 | } | ||||
| 246 | |||||
| 247 | return; | ||||
| 248 | } | ||||
| 249 | |||||
| 250 | sub is_a_type_of { | ||||
| 251 | my ($self, $type_or_name) = @_; | ||||
| 252 | |||||
| 253 | my $type = Moose::Util::TypeConstraints::find_type_constraint($type_or_name) or return; | ||||
| 254 | |||||
| 255 | ($self->equals($type) || $self->is_subtype_of($type)); | ||||
| 256 | } | ||||
| 257 | |||||
| 258 | # spent 1.03ms (226µs+802µs) within Moose::Meta::TypeConstraint::is_subtype_of which was called 8 times, avg 128µs/call:
# 8 times (226µs+802µs) by Moose::Meta::TypeConstraint::Parameterizable::generate_constraint_for at line 33 of Moose/Meta/TypeConstraint/Parameterizable.pm, avg 128µs/call | ||||
| 259 | 8 | 5µs | my ($self, $type_or_name) = @_; | ||
| 260 | |||||
| 261 | 8 | 20µs | 16 | 150µs | my $type = Moose::Util::TypeConstraints::find_type_constraint($type_or_name) or return; # spent 142µs making 8 calls to Moose::Util::TypeConstraints::find_type_constraint, avg 18µs/call
# spent 8µs making 8 calls to Moose::Meta::TypeConstraint::__ANON__[Moose/Meta/TypeConstraint.pm:10], avg 1µs/call |
| 262 | |||||
| 263 | 8 | 1µs | my $current = $self; | ||
| 264 | |||||
| 265 | 8 | 62µs | 46 | 55µs | while (my $parent = $current->parent) { # spent 38µs making 26 calls to Moose::Meta::TypeConstraint::parent, avg 1µs/call
# spent 17µs making 20 calls to Moose::Meta::TypeConstraint::__ANON__[Moose/Meta/TypeConstraint.pm:10], avg 860ns/call |
| 266 | 20 | 28µs | 20 | 597µs | return 1 if $parent->equals($type); # spent 597µs making 20 calls to Moose::Meta::TypeConstraint::equals, avg 30µs/call |
| 267 | 18 | 7µs | $current = $parent; | ||
| 268 | } | ||||
| 269 | |||||
| 270 | 6 | 15µs | return 0; | ||
| 271 | } | ||||
| 272 | |||||
| 273 | ## compiling the type constraint | ||||
| 274 | |||||
| 275 | # spent 16.7ms (478µs+16.3) within Moose::Meta::TypeConstraint::compile_type_constraint which was called 73 times, avg 229µs/call:
# 46 times (325µs+10.4ms) by Moose::Meta::TypeConstraint::new at line 125, avg 233µs/call
# 22 times (120µs+4.56ms) by Moose::Meta::TypeConstraint::Class::new at line 40 of Moose/Meta/TypeConstraint/Class.pm, avg 213µs/call
# 3 times (15µs+540µs) by Moose::Meta::TypeConstraint::Role::new at line 41 of Moose/Meta/TypeConstraint/Role.pm, avg 185µs/call
# 2 times (18µs+762µs) by Moose::Meta::TypeConstraint::Parameterized::compile_type_constraint at line 57 of Moose/Meta/TypeConstraint/Parameterized.pm, avg 390µs/call | ||||
| 276 | 73 | 20µs | my $self = shift; | ||
| 277 | 73 | 384µs | 146 | 16.3ms | $self->_compiled_type_constraint($self->_actually_compile_type_constraint); # spent 15.8ms making 73 calls to Moose::Meta::TypeConstraint::_actually_compile_type_constraint, avg 217µs/call
# spent 450µs making 73 calls to Moose::Meta::TypeConstraint::_compiled_type_constraint, avg 6µs/call |
| 278 | } | ||||
| 279 | |||||
| 280 | ## type compilers ... | ||||
| 281 | |||||
| 282 | # spent 15.8ms (806µs+15.0) within Moose::Meta::TypeConstraint::_actually_compile_type_constraint which was called 73 times, avg 217µs/call:
# 73 times (806µs+15.0ms) by Moose::Meta::TypeConstraint::compile_type_constraint at line 277, avg 217µs/call | ||||
| 283 | 73 | 12µs | my $self = shift; | ||
| 284 | |||||
| 285 | 73 | 557µs | 292 | 15.0ms | if ( $self->can_be_inlined ) { # spent 9.51ms making 73 calls to Eval::Closure::eval_closure, avg 130µs/call
# spent 3.13ms making 71 calls to Moose::Meta::TypeConstraint::_inline_check, avg 44µs/call
# spent 1.04ms making 71 calls to Moose::Meta::TypeConstraint::can_be_inlined, avg 15µs/call
# spent 895µs making 71 calls to Moose::Meta::TypeConstraint::inline_environment, avg 13µs/call
# spent 268µs making 2 calls to Moose::Meta::TypeConstraint::Parameterized::_inline_check, avg 134µs/call
# spent 91µs making 2 calls to Moose::Meta::TypeConstraint::Parameterized::inline_environment, avg 46µs/call
# spent 77µs making 2 calls to Moose::Meta::TypeConstraint::Parameterized::can_be_inlined, avg 38µs/call |
| 286 | return eval_closure( | ||||
| 287 | source => 'sub { ' . $self->_inline_check('$_[0]') . ' }', | ||||
| 288 | environment => $self->inline_environment, | ||||
| 289 | ); | ||||
| 290 | } | ||||
| 291 | |||||
| 292 | my $check = $self->constraint; | ||||
| 293 | unless ( defined $check ) { | ||||
| 294 | throw_exception( NoConstraintCheckForTypeConstraint => type_name => $self->name ); | ||||
| 295 | } | ||||
| 296 | |||||
| 297 | return $self->_compile_subtype($check) | ||||
| 298 | if $self->has_parent; | ||||
| 299 | |||||
| 300 | return $self->_compile_type($check); | ||||
| 301 | } | ||||
| 302 | |||||
| 303 | sub _compile_subtype { | ||||
| 304 | my ($self, $check) = @_; | ||||
| 305 | |||||
| 306 | # gather all the parent constraints in order | ||||
| 307 | my @parents; | ||||
| 308 | foreach my $parent ($self->_collect_all_parents) { | ||||
| 309 | push @parents => $parent->constraint; | ||||
| 310 | } | ||||
| 311 | |||||
| 312 | @parents = grep { $_ != $null_constraint } reverse @parents; | ||||
| 313 | |||||
| 314 | unless ( @parents ) { | ||||
| 315 | return $self->_compile_type($check); | ||||
| 316 | } else { | ||||
| 317 | # general case, check all the constraints, from the first parent to ourselves | ||||
| 318 | my @checks = @parents; | ||||
| 319 | push @checks, $check if $check != $null_constraint; | ||||
| 320 | return subname($self->name => sub { | ||||
| 321 | my (@args) = @_; | ||||
| 322 | local $_ = $args[0]; | ||||
| 323 | foreach my $check (@checks) { | ||||
| 324 | return undef unless $check->(@args); | ||||
| 325 | } | ||||
| 326 | return 1; | ||||
| 327 | }); | ||||
| 328 | } | ||||
| 329 | } | ||||
| 330 | |||||
| 331 | sub _compile_type { | ||||
| 332 | my ($self, $check) = @_; | ||||
| 333 | |||||
| 334 | return $check if $check == $null_constraint; # Item, Any | ||||
| 335 | |||||
| 336 | return subname($self->name => sub { | ||||
| 337 | my (@args) = @_; | ||||
| 338 | local $_ = $args[0]; | ||||
| 339 | $check->(@args); | ||||
| 340 | }); | ||||
| 341 | } | ||||
| 342 | |||||
| 343 | ## other utils ... | ||||
| 344 | |||||
| 345 | sub _collect_all_parents { | ||||
| 346 | my $self = shift; | ||||
| 347 | my @parents; | ||||
| 348 | my $current = $self->parent; | ||||
| 349 | while (defined $current) { | ||||
| 350 | push @parents => $current; | ||||
| 351 | $current = $current->parent; | ||||
| 352 | } | ||||
| 353 | return @parents; | ||||
| 354 | } | ||||
| 355 | |||||
| 356 | # spent 4.15ms (117µs+4.03) within Moose::Meta::TypeConstraint::create_child_type which was called 16 times, avg 259µs/call:
# 16 times (117µs+4.03ms) by Moose::Util::TypeConstraints::_create_type_constraint at line 572 of Moose/Util/TypeConstraints.pm, avg 259µs/call | ||||
| 357 | 16 | 24µs | my ($self, %opts) = @_; | ||
| 358 | 16 | 9µs | my $class = ref $self; | ||
| 359 | 16 | 84µs | 16 | 4.03ms | return $class->new(%opts, parent => $self); # spent 4.03ms making 16 calls to Moose::Meta::TypeConstraint::new, avg 252µs/call |
| 360 | } | ||||
| 361 | |||||
| 362 | 1 | 44µs | 1; | ||
| 363 | |||||
| 364 | # ABSTRACT: The Moose Type Constraint metaclass | ||||
| 365 | |||||
| 366 | __END__ |