| Filename | /home/ss5/perl5/perlbrew/perls/perl-5.22.0/lib/site_perl/5.22.0/x86_64-linux/Moose/Meta/TypeConstraint.pm |
| Statements | Executed 2636 statements in 18.3ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 97 | 9 | 3 | 5.59ms | 6.69ms | Moose::Meta::TypeConstraint::_inline_check (recurses: max depth 2, inclusive time 150µs) |
| 77 | 4 | 4 | 4.89ms | 28.6ms | Moose::Meta::TypeConstraint::compile_type_constraint |
| 77 | 1 | 1 | 4.63ms | 23.4ms | Moose::Meta::TypeConstraint::_actually_compile_type_constraint |
| 50 | 9 | 6 | 880µs | 28.1ms | Moose::Meta::TypeConstraint::new |
| 200 | 6 | 3 | 781µs | 1.10ms | Moose::Meta::TypeConstraint::can_be_inlined (recurses: max depth 1, inclusive time 8µs) |
| 93 | 5 | 4 | 387µs | 528µs | Moose::Meta::TypeConstraint::inline_environment (recurses: max depth 1, inclusive time 4µs) |
| 1 | 1 | 1 | 216µs | 624µs | Moose::Meta::TypeConstraint::BEGIN@6 |
| 21 | 1 | 1 | 152µs | 308µs | Moose::Meta::TypeConstraint::equals |
| 50 | 1 | 1 | 133µs | 133µs | Moose::Meta::TypeConstraint::__ANON__[:72] |
| 7 | 1 | 1 | 114µs | 508µs | Moose::Meta::TypeConstraint::is_subtype_of |
| 155 | 8 | 4 | 76µs | 76µs | Moose::Meta::TypeConstraint::__ANON__[:10] |
| 42 | 1 | 1 | 59µs | 69µs | Moose::Meta::TypeConstraint::__ANON__[:8] |
| 16 | 1 | 1 | 52µs | 6.46ms | Moose::Meta::TypeConstraint::create_child_type |
| 50 | 2 | 1 | 52µs | 52µs | Moose::Meta::TypeConstraint::__ANON__[:89] |
| 1 | 1 | 1 | 11µs | 28µs | Moose::Meta::TypeConstraint::BEGIN@15 |
| 1 | 1 | 1 | 10µs | 12µs | Moose::Meta::TypeConstraint::BEGIN@4 |
| 1 | 1 | 1 | 9µs | 36µs | Moose::Meta::TypeConstraint::BEGIN@8 |
| 1 | 1 | 1 | 6µs | 12µs | Moose::Meta::TypeConstraint::BEGIN@5 |
| 1 | 1 | 1 | 6µs | 26µs | Moose::Meta::TypeConstraint::BEGIN@16 |
| 1 | 1 | 1 | 6µs | 19µs | Moose::Meta::TypeConstraint::BEGIN@14 |
| 1 | 1 | 1 | 6µs | 52µs | Moose::Meta::TypeConstraint::BEGIN@18 |
| 1 | 1 | 1 | 5µs | 31µs | Moose::Meta::TypeConstraint::BEGIN@13 |
| 1 | 1 | 1 | 5µs | 128µs | Moose::Meta::TypeConstraint::BEGIN@20 |
| 3 | 1 | 1 | 4µs | 4µs | Moose::Meta::TypeConstraint::__ANON__[:36] |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::__ANON__[:32] |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::__ANON__[:330] |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::__ANON__[:343] |
| 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 | 300ns | our $VERSION = '2.1605'; | ||
| 3 | |||||
| 4 | 2 | 16µs | 2 | 14µs | # spent 12µs (10+2) within Moose::Meta::TypeConstraint::BEGIN@4 which was called:
# once (10µs+2µs) by Moose::BEGIN@25 at line 4 # spent 12µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@4
# spent 2µs making 1 call to strict::import |
| 5 | 2 | 13µs | 2 | 17µs | # spent 12µs (6+5) within Moose::Meta::TypeConstraint::BEGIN@5 which was called:
# once (6µs+5µs) by Moose::BEGIN@25 at line 5 # spent 12µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@5
# spent 5µs making 1 call to warnings::import |
| 6 | 2 | 99µs | 2 | 997µs | # spent 624µs (216+408) within Moose::Meta::TypeConstraint::BEGIN@6 which was called:
# once (216µs+408µs) by Moose::BEGIN@25 at line 6 # spent 624µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@6
# spent 373µs making 1 call to metaclass::import |
| 7 | |||||
| 8 | 42 | 97µs | 42 | 10µs | # spent 69µs (59+10) within Moose::Meta::TypeConstraint::__ANON__[/home/ss5/perl5/perlbrew/perls/perl-5.22.0/lib/site_perl/5.22.0/x86_64-linux/Moose/Meta/TypeConstraint.pm:8] which was called 42 times, avg 2µs/call:
# 42 times (59µs+10µs) by Moose::Meta::TypeConstraint::equals at line 237, avg 2µs/call
# spent 36µs (9+26) within Moose::Meta::TypeConstraint::BEGIN@8 which was called:
# once (9µs+26µs) by Moose::BEGIN@25 at line 11 # spent 10µs making 42 calls to Scalar::Util::refaddr, avg 243ns/call |
| 9 | '""' => sub { shift->name }, # stringify to tc name | ||||
| 10 | 155 | 193µs | # spent 76µs within Moose::Meta::TypeConstraint::__ANON__[/home/ss5/perl5/perlbrew/perls/perl-5.22.0/lib/site_perl/5.22.0/x86_64-linux/Moose/Meta/TypeConstraint.pm:10] which was called 155 times, avg 490ns/call:
# 50 times (43µs+0s) by Moose::Meta::TypeConstraint::Registry::add_type_constraint at line 47 of Moose/Meta/TypeConstraint/Registry.pm, avg 854ns/call
# 21 times (8µs+0s) by Moose::Meta::TypeConstraint::equals at line 235, avg 367ns/call
# 21 times (7µs+0s) by Moose::Meta::TypeConstraint::is_subtype_of at line 268, avg 343ns/call
# 20 times (4µs+0s) by Moose::Util::TypeConstraints::find_or_create_isa_type_constraint at line 246 of Moose/Util/TypeConstraints.pm, avg 210ns/call
# 18 times (8µs+0s) by Moose::Util::TypeConstraints::find_or_parse_type_constraint at line 260 of Moose/Util/TypeConstraints.pm, avg 417ns/call
# 16 times (3µs+0s) by Moose::Util::TypeConstraints::_create_type_constraint at line 572 of Moose/Util/TypeConstraints.pm, avg 200ns/call
# 7 times (3µs+0s) by Moose::Meta::TypeConstraint::is_subtype_of at line 264, avg 414ns/call
# 2 times (600ns+0s) by Moose::Meta::TypeConstraint::Parameterizable::parameterize at line 78 of Moose/Meta/TypeConstraint/Parameterizable.pm, avg 300ns/call | ||
| 11 | 2 | 20µs | 2 | 62µs | fallback => 1; # spent 36µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@8
# spent 26µs making 1 call to overload::import |
| 12 | |||||
| 13 | 2 | 20µs | 2 | 56µs | # spent 31µs (5+25) within Moose::Meta::TypeConstraint::BEGIN@13 which was called:
# once (5µs+25µs) by Moose::BEGIN@25 at line 13 # spent 31µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@13
# spent 25µs making 1 call to Exporter::import |
| 14 | 2 | 28µs | 2 | 33µs | # spent 19µs (6+14) within Moose::Meta::TypeConstraint::BEGIN@14 which was called:
# once (6µs+14µs) by Moose::BEGIN@25 at line 14 # spent 19µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@14
# spent 14µs making 1 call to Exporter::import |
| 15 | 2 | 26µs | 2 | 45µs | # spent 28µs (11+17) within Moose::Meta::TypeConstraint::BEGIN@15 which was called:
# once (11µs+17µs) by Moose::BEGIN@25 at line 15 # spent 28µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@15
# spent 17µs making 1 call to Exporter::import |
| 16 | 2 | 17µs | 2 | 46µs | # spent 26µs (6+20) within Moose::Meta::TypeConstraint::BEGIN@16 which was called:
# once (6µs+20µs) by Moose::BEGIN@25 at line 16 # spent 26µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@16
# spent 20µs making 1 call to Exporter::import |
| 17 | |||||
| 18 | 2 | 16µs | 2 | 99µs | # spent 52µs (6+47) within Moose::Meta::TypeConstraint::BEGIN@18 which was called:
# once (6µs+47µs) by Moose::BEGIN@25 at line 18 # spent 52µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@18
# spent 47µs making 1 call to base::import |
| 19 | |||||
| 20 | 2 | 868µs | 2 | 251µs | # spent 128µs (5+123) within Moose::Meta::TypeConstraint::BEGIN@20 which was called:
# once (5µs+123µs) by Moose::BEGIN@25 at line 20 # spent 128µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@20
# spent 123µs making 1 call to Sub::Exporter::__ANON__[Sub/Exporter.pm:337] |
| 21 | |||||
| 22 | 1 | 3µs | 3 | 249µs | __PACKAGE__->meta->add_attribute('name' => ( # spent 231µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 14µs making 1 call to Moose::Meta::TypeConstraint::meta
# spent 4µs making 1 call to Class::MOP::_definition_context |
| 23 | reader => 'name', | ||||
| 24 | Class::MOP::_definition_context(), | ||||
| 25 | )); | ||||
| 26 | 1 | 2µs | 3 | 304µs | __PACKAGE__->meta->add_attribute('parent' => ( # spent 294µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 7µs making 1 call to Moose::Meta::TypeConstraint::meta
# spent 4µ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 | 600ns | my $null_constraint = sub { 1 }; | ||
| 33 | __PACKAGE__->meta->add_attribute('constraint' => ( | ||||
| 34 | reader => 'constraint', | ||||
| 35 | writer => '_set_constraint', | ||||
| 36 | 3 | 6µs | # spent 4µs within Moose::Meta::TypeConstraint::__ANON__[/home/ss5/perl5/perlbrew/perls/perl-5.22.0/lib/site_perl/5.22.0/x86_64-linux/Moose/Meta/TypeConstraint.pm:36] which was called 3 times, avg 1µs/call:
# 3 times (4µs+0s) by Moose::Meta::TypeConstraint::Parameterized::_new or Moose::Meta::TypeConstraint::_new at line 24 of (eval 33)[Eval/Closure.pm:142], avg 1µs/call | ||
| 37 | 1 | 3µs | 3 | 290µs | Class::MOP::_definition_context(), # spent 281µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 6µs making 1 call to Moose::Meta::TypeConstraint::meta
# spent 3µs making 1 call to Class::MOP::_definition_context |
| 38 | )); | ||||
| 39 | |||||
| 40 | 1 | 2µs | 3 | 273µs | __PACKAGE__->meta->add_attribute('message' => ( # spent 264µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 6µs making 1 call to Moose::Meta::TypeConstraint::meta
# spent 3µ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 | 2µs | 3 | 200µs | __PACKAGE__->meta->add_attribute('_default_message' => ( # spent 191µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 6µs making 1 call to Moose::Meta::TypeConstraint::meta
# spent 3µ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 133µs within Moose::Meta::TypeConstraint::__ANON__[/home/ss5/perl5/perlbrew/perls/perl-5.22.0/lib/site_perl/5.22.0/x86_64-linux/Moose/Meta/TypeConstraint.pm:72] which was called 50 times, avg 3µs/call:
# 50 times (133µs+0s) by Moose::Meta::TypeConstraint::new at line 127, avg 3µs/call | ||||
| 54 | 50 | 15µ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 | 51 | 147µs | }; | ||
| 73 | 1 | 2µs | 3 | 265µs | __PACKAGE__->meta->add_attribute('coercion' => ( # spent 257µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 6µs making 1 call to Moose::Meta::TypeConstraint::meta
# spent 3µ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 | 2µs | 3 | 272µs | __PACKAGE__->meta->add_attribute('inlined' => ( # spent 264µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 6µs making 1 call to Moose::Meta::TypeConstraint::meta
# spent 3µ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 | 50 | 89µs | # spent 52µs within Moose::Meta::TypeConstraint::__ANON__[/home/ss5/perl5/perlbrew/perls/perl-5.22.0/lib/site_perl/5.22.0/x86_64-linux/Moose/Meta/TypeConstraint.pm:89] which was called 50 times, avg 1µs/call:
# 31 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 33)[Eval/Closure.pm:142], avg 942ns/call
# 19 times (23µs+0s) by Moose::Meta::TypeConstraint::Class::_new or Moose::Meta::TypeConstraint::Parameterizable::_new at line 33 of (eval 33)[Eval/Closure.pm:142], avg 1µs/call | ||
| 90 | 1 | 2µs | 3 | 176µs | Class::MOP::_definition_context(), # spent 167µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 5µs making 1 call to Moose::Meta::TypeConstraint::meta
# spent 3µ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 | 2µs | 3 | 328µs | __PACKAGE__->meta->add_attribute('compiled_type_constraint' => ( # spent 309µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 17µs making 1 call to Moose::Meta::TypeConstraint::meta
# spent 3µ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 | 2µs | 3 | 221µs | __PACKAGE__->meta->add_attribute('package_defined_in' => ( # spent 212µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 6µs making 1 call to Moose::Meta::TypeConstraint::meta
# spent 3µs making 1 call to Class::MOP::_definition_context |
| 107 | accessor => '_package_defined_in', | ||||
| 108 | Class::MOP::_definition_context(), | ||||
| 109 | )); | ||||
| 110 | |||||
| 111 | # spent 28.1ms (880µs+27.2) within Moose::Meta::TypeConstraint::new which was called 50 times, avg 561µs/call:
# 16 times (202µs+6.21ms) by Moose::Meta::TypeConstraint::create_child_type at line 362, avg 401µs/call
# 15 times (316µs+11.7ms) by Moose::Meta::TypeConstraint::Class::new at line 38 of Moose/Meta/TypeConstraint/Class.pm, avg 801µs/call
# 12 times (231µs+6.92ms) by Moose::Meta::TypeConstraint::Role::new at line 39 of Moose/Meta/TypeConstraint/Role.pm, avg 596µs/call
# 2 times (43µs+1.23ms) by Moose::Meta::TypeConstraint::Parameterizable::parameterize at line 90 of Moose/Meta/TypeConstraint/Parameterizable.pm, avg 637µs/call
# once (25µs+613µs) by Moose::Util::TypeConstraints::_create_type_constraint at line 582 of Moose/Util/TypeConstraints.pm
# once (23µs+174µs) by Moose::Util::TypeConstraints::Builtins::define_builtins at line 198 of Moose/Util/TypeConstraints/Builtins.pm
# once (14µs+117µs) by Moose::Util::TypeConstraints::Builtins::define_builtins at line 233 of Moose/Util/TypeConstraints/Builtins.pm
# once (14µs+115µs) by Moose::Util::TypeConstraints::Builtins::define_builtins at line 294 of Moose/Util/TypeConstraints/Builtins.pm
# once (13µs+112µs) by Moose::Util::TypeConstraints::Builtins::define_builtins at line 268 of Moose/Util/TypeConstraints/Builtins.pm | ||||
| 112 | 50 | 9µs | my $class = shift; | ||
| 113 | 50 | 33µs | my ($first, @rest) = @_; | ||
| 114 | 50 | 90µs | my %args = ref $first ? %$first : $first ? ($first, @rest) : (); | ||
| 115 | 50 | 45µs | $args{name} = $args{name} ? "$args{name}" : "__ANON__"; | ||
| 116 | |||||
| 117 | 50 | 12µ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 | 50 | 91µs | 50 | 903µs | my $self = $class->_new(%args); # spent 315µs making 15 calls to Moose::Meta::TypeConstraint::Class::_new, avg 21µs/call
# spent 231µs making 12 calls to Moose::Meta::TypeConstraint::Role::_new, avg 19µs/call
# spent 203µs making 17 calls to Moose::Meta::TypeConstraint::_new, avg 12µs/call
# spent 86µs making 4 calls to Moose::Meta::TypeConstraint::Parameterizable::_new, avg 22µs/call
# spent 67µs making 2 calls to Moose::Meta::TypeConstraint::Parameterized::_new, avg 34µs/call |
| 125 | 50 | 133µs | 100 | 26.0ms | $self->compile_type_constraint() # spent 24.8ms making 48 calls to Moose::Meta::TypeConstraint::compile_type_constraint, avg 516µs/call
# spent 1.15ms making 2 calls to Moose::Meta::TypeConstraint::Parameterized::compile_type_constraint, avg 575µs/call
# spent 53µs making 50 calls to Moose::Meta::TypeConstraint::_has_compiled_type_constraint, avg 1µs/call |
| 126 | unless $self->_has_compiled_type_constraint; | ||||
| 127 | 50 | 209µs | 200 | 302µs | $self->_default_message($_default_message_generator->($self->name)) # spent 133µs making 50 calls to Moose::Meta::TypeConstraint::__ANON__[Moose/Meta/TypeConstraint.pm:72], avg 3µs/call
# spent 69µs making 50 calls to Moose::Meta::TypeConstraint::_default_message, avg 1µs/call
# spent 53µs making 50 calls to Moose::Meta::TypeConstraint::name, avg 1µs/call
# spent 46µs making 50 calls to Moose::Meta::TypeConstraint::has_message, avg 924ns/call |
| 128 | unless $self->has_message; | ||||
| 129 | 50 | 139µ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 1.10ms (781µs+323µs) within Moose::Meta::TypeConstraint::can_be_inlined which was called 200 times, avg 6µs/call:
# 97 times (307µs+112µs) by Moose::Meta::TypeConstraint::_inline_check at line 187, avg 4µs/call
# 75 times (370µs+177µs) by Moose::Meta::TypeConstraint::_actually_compile_type_constraint at line 288, avg 7µs/call
# 15 times (54µs+20µs) by Moose::Meta::TypeConstraint::Parameterized::can_be_inlined at line 72 of Moose/Meta/TypeConstraint/Parameterized.pm, avg 5µs/call
# 8 times (33µs+15µs) by Moose::Meta::Attribute::_inline_check_constraint at line 686 of Moose/Meta/Attribute.pm, avg 6µs/call
# 3 times (12µs+5µs) by Moose::Meta::Attribute::_eval_environment at line 766 of Moose/Meta/Attribute.pm, avg 6µs/call
# 2 times (6µs+-6µs) by Moose::Meta::TypeConstraint::can_be_inlined at line 177, avg 0s/call | ||||
| 175 | 200 | 27µs | my $self = shift; | ||
| 176 | |||||
| 177 | 200 | 273µs | 399 | 222µs | if ( $self->has_parent && $self->constraint == $null_constraint ) { # spent 115µs making 195 calls to Moose::Meta::TypeConstraint::constraint, avg 592ns/call
# spent 105µs making 200 calls to Moose::Meta::TypeConstraint::has_parent, avg 523ns/call
# spent 2µs making 2 calls to Moose::Meta::TypeConstraint::parent, avg 1µs/call
# spent 8µs making 2 calls to Moose::Meta::TypeConstraint::can_be_inlined, avg 4µs/call, recursion: max depth 1, sum of overlapping time 8µs |
| 178 | return $self->parent->can_be_inlined; | ||||
| 179 | } | ||||
| 180 | |||||
| 181 | 198 | 4.45ms | 198 | 101µs | return $self->_has_inlined_type_constraint; # spent 101µs making 198 calls to Moose::Meta::TypeConstraint::_has_inlined_type_constraint, avg 512ns/call |
| 182 | } | ||||
| 183 | |||||
| 184 | # spent 6.69ms (5.59+1.11) within Moose::Meta::TypeConstraint::_inline_check which was called 97 times, avg 69µs/call:
# 75 times (5.44ms+1.04ms) by Moose::Meta::TypeConstraint::_actually_compile_type_constraint at line 288, avg 86µs/call
# 8 times (60µs+79µs) by Moose::Meta::Attribute::_inline_check_constraint at line 686 of Moose/Meta/Attribute.pm, avg 17µs/call
# 5 times (32µs+38µs) by Moose::Util::TypeConstraints::Builtins::__ANON__[/home/ss5/perl5/perlbrew/perls/perl-5.22.0/lib/site_perl/5.22.0/x86_64-linux/Moose/Util/TypeConstraints/Builtins.pm:266] at line 258 of Moose/Util/TypeConstraints/Builtins.pm, avg 14µs/call
# 4 times (24µs+-24µs) by Moose::Util::TypeConstraints::Builtins::__ANON__[/home/ss5/perl5/perlbrew/perls/perl-5.22.0/lib/site_perl/5.22.0/x86_64-linux/Moose/Util/TypeConstraints/Builtins.pm:60] at line 58 of Moose/Util/TypeConstraints/Builtins.pm, avg 0s/call
# once (6µs+-6µs) by Moose::Meta::TypeConstraint::_inline_check at line 191
# once (6µs+-6µs) by Moose::Util::TypeConstraints::Builtins::__ANON__[/home/ss5/perl5/perlbrew/perls/perl-5.22.0/lib/site_perl/5.22.0/x86_64-linux/Moose/Util/TypeConstraints/Builtins.pm:170] at line 165 of Moose/Util/TypeConstraints/Builtins.pm
# once (6µs+-6µs) by Moose::Util::TypeConstraints::Builtins::__ANON__[/home/ss5/perl5/perlbrew/perls/perl-5.22.0/lib/site_perl/5.22.0/x86_64-linux/Moose/Util/TypeConstraints/Builtins.pm:106] at line 97 of Moose/Util/TypeConstraints/Builtins.pm
# once (5µs+-5µs) by Moose::Util::TypeConstraints::Builtins::__ANON__[/home/ss5/perl5/perlbrew/perls/perl-5.22.0/lib/site_perl/5.22.0/x86_64-linux/Moose/Util/TypeConstraints/Builtins.pm:114] at line 112 of Moose/Util/TypeConstraints/Builtins.pm
# once (6µs+-6µs) by Moose::Util::TypeConstraints::Builtins::__ANON__[/home/ss5/perl5/perlbrew/perls/perl-5.22.0/lib/site_perl/5.22.0/x86_64-linux/Moose/Util/TypeConstraints/Builtins.pm:77] at line 72 of Moose/Util/TypeConstraints/Builtins.pm | ||||
| 185 | 97 | 14µs | my $self = shift; | ||
| 186 | |||||
| 187 | 97 | 48µs | 97 | 420µs | unless ( $self->can_be_inlined ) { # spent 420µs making 97 calls to Moose::Meta::TypeConstraint::can_be_inlined, avg 4µs/call |
| 188 | throw_exception( CannotInlineTypeConstraintCheck => type_name => $self->name ); | ||||
| 189 | } | ||||
| 190 | |||||
| 191 | 97 | 4.97ms | 194 | 66µs | if ( $self->has_parent && $self->constraint == $null_constraint ) { # spent 36µs making 95 calls to Moose::Meta::TypeConstraint::constraint, avg 375ns/call
# spent 30µs making 97 calls to Moose::Meta::TypeConstraint::has_parent, avg 306ns/call
# spent 200ns making 1 call to Moose::Meta::TypeConstraint::parent
# spent 10µs making 1 call to Moose::Meta::TypeConstraint::_inline_check, recursion: max depth 1, sum of overlapping time 10µs |
| 192 | return $self->parent->_inline_check(@_); | ||||
| 193 | } | ||||
| 194 | |||||
| 195 | 96 | 308µs | 192 | 761µs | return '( do { ' . $self->inlined->( $self, @_ ) . ' } )'; # spent 290µs making 35 calls to Moose::Meta::TypeConstraint::Class::__ANON__[Moose/Meta/TypeConstraint/Class.pm:25], avg 8µs/call
# spent 181µs making 24 calls to Moose::Meta::TypeConstraint::Role::__ANON__[Moose/Meta/TypeConstraint/Role.pm:27], avg 8µs/call
# spent 66µs making 4 calls to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:60], avg 17µs/call
# spent 66µs making 96 calls to Moose::Meta::TypeConstraint::inlined, avg 682ns/call
# spent 33µs making 1 call to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:77]
# spent 32µs making 1 call to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:114]
# spent 31µs making 1 call to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:106]
# spent 20µs making 1 call to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:170]
# spent 16µs making 9 calls to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:52], avg 2µs/call
# spent 4µs making 5 calls to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:40], avg 880ns/call
# spent 3µs making 1 call to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:146]
# spent 2µs making 2 calls to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:157], avg 1µs/call
# 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:189]
# 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:252]
# spent 1µs making 1 call to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:119]
# spent 1µs making 1 call to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:131]
# spent 1µs making 1 call to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:217]
# spent 1µs making 2 calls to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:22], avg 600ns/call
# spent 1µs making 1 call to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:33]
# spent 1µs making 1 call to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:66]
# spent 1µs making 1 call to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:285] |
| 196 | } | ||||
| 197 | |||||
| 198 | # spent 528µs (387+141) within Moose::Meta::TypeConstraint::inline_environment which was called 93 times, avg 6µs/call:
# 75 times (321µs+122µs) by Moose::Meta::TypeConstraint::_actually_compile_type_constraint at line 288, avg 6µs/call
# 11 times (40µs+15µs) by Moose::Meta::TypeConstraint::Parameterized::inline_environment at line 85 of Moose/Meta/TypeConstraint/Parameterized.pm, avg 5µs/call
# 3 times (12µs+4µs) by Moose::Meta::Attribute::_eval_environment at line 777 of Moose/Meta/Attribute.pm, avg 5µs/call
# 3 times (11µs+4µs) by Moose::Meta::Class::_eval_environment at line 542 of Moose/Meta/Class.pm, avg 5µs/call
# once (3µs+-3µs) by Moose::Meta::TypeConstraint::inline_environment at line 201 | ||||
| 199 | 93 | 14µs | my $self = shift; | ||
| 200 | |||||
| 201 | 93 | 102µs | 186 | 69µs | if ( $self->has_parent && $self->constraint == $null_constraint ) { # spent 36µs making 91 calls to Moose::Meta::TypeConstraint::constraint, avg 395ns/call
# spent 33µs making 93 calls to Moose::Meta::TypeConstraint::has_parent, avg 355ns/call
# spent 300ns making 1 call to Moose::Meta::TypeConstraint::parent
# spent 4µs making 1 call to Moose::Meta::TypeConstraint::inline_environment, recursion: max depth 1, sum of overlapping time 4µs |
| 202 | return $self->parent->inline_environment; | ||||
| 203 | } | ||||
| 204 | |||||
| 205 | 92 | 158µs | 92 | 72µs | return $self->_inline_environment; # spent 72µs making 92 calls to Moose::Meta::TypeConstraint::_inline_environment, avg 783ns/call |
| 206 | } | ||||
| 207 | |||||
| 208 | sub assert_valid { | ||||
| 209 | my ( $self, $value ) = @_; | ||||
| 210 | |||||
| 211 | return 1 if $self->check($value); | ||||
| 212 | |||||
| 213 | throw_exception( | ||||
| 214 | 'ValidationFailedForTypeConstraint', | ||||
| 215 | type => $self, | ||||
| 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 308µs (152+156) within Moose::Meta::TypeConstraint::equals which was called 21 times, avg 15µs/call:
# 21 times (152µs+156µs) by Moose::Meta::TypeConstraint::is_subtype_of at line 269, avg 15µs/call | ||||
| 232 | 21 | 3µs | my ( $self, $type_or_name ) = @_; | ||
| 233 | |||||
| 234 | 21 | 11µs | 21 | 59µs | my $other = Moose::Util::TypeConstraints::find_type_constraint($type_or_name); # spent 59µs making 21 calls to Moose::Util::TypeConstraints::find_type_constraint, avg 3µs/call |
| 235 | 21 | 12µs | 21 | 8µs | return if not $other; # spent 8µs making 21 calls to Moose::Meta::TypeConstraint::__ANON__[Moose/Meta/TypeConstraint.pm:10], avg 367ns/call |
| 236 | |||||
| 237 | 21 | 28µs | 42 | 69µs | return 1 if $self == $other; # spent 69µs making 42 calls to Moose::Meta::TypeConstraint::__ANON__[Moose/Meta/TypeConstraint.pm:8], avg 2µs/call |
| 238 | |||||
| 239 | 19 | 36µs | 38 | 20µs | return unless $self->constraint == $other->constraint; # spent 20µs making 38 calls to Moose::Meta::TypeConstraint::constraint, avg 516ns/call |
| 240 | |||||
| 241 | if ( $self->has_parent ) { | ||||
| 242 | return unless $other->has_parent; | ||||
| 243 | return unless $self->parent->equals( $other->parent ); | ||||
| 244 | } else { | ||||
| 245 | return if $other->has_parent; | ||||
| 246 | } | ||||
| 247 | |||||
| 248 | return; | ||||
| 249 | } | ||||
| 250 | |||||
| 251 | sub is_a_type_of { | ||||
| 252 | my ($self, $type_or_name) = @_; | ||||
| 253 | |||||
| 254 | my $type = Moose::Util::TypeConstraints::find_type_constraint($type_or_name); | ||||
| 255 | return if not $type; | ||||
| 256 | |||||
| 257 | ($self->equals($type) || $self->is_subtype_of($type)); | ||||
| 258 | } | ||||
| 259 | |||||
| 260 | # spent 508µs (114+394) within Moose::Meta::TypeConstraint::is_subtype_of which was called 7 times, avg 73µs/call:
# 7 times (114µs+394µs) by Moose::Meta::TypeConstraint::Parameterizable::generate_constraint_for at line 33 of Moose/Meta/TypeConstraint/Parameterizable.pm, avg 73µs/call | ||||
| 261 | 7 | 1µs | my ($self, $type_or_name) = @_; | ||
| 262 | |||||
| 263 | 7 | 4µs | 7 | 62µs | my $type = Moose::Util::TypeConstraints::find_type_constraint($type_or_name); # spent 62µs making 7 calls to Moose::Util::TypeConstraints::find_type_constraint, avg 9µs/call |
| 264 | 7 | 5µs | 7 | 3µs | return if not $type; # spent 3µs making 7 calls to Moose::Meta::TypeConstraint::__ANON__[Moose/Meta/TypeConstraint.pm:10], avg 414ns/call |
| 265 | |||||
| 266 | 7 | 900ns | my $current = $self; | ||
| 267 | |||||
| 268 | 7 | 29µs | 47 | 20µs | while (my $parent = $current->parent) { # spent 13µs making 26 calls to Moose::Meta::TypeConstraint::parent, avg 500ns/call
# spent 7µs making 21 calls to Moose::Meta::TypeConstraint::__ANON__[Moose/Meta/TypeConstraint.pm:10], avg 343ns/call |
| 269 | 21 | 17µs | 21 | 308µs | return 1 if $parent->equals($type); # spent 308µs making 21 calls to Moose::Meta::TypeConstraint::equals, avg 15µs/call |
| 270 | 19 | 3µs | $current = $parent; | ||
| 271 | } | ||||
| 272 | |||||
| 273 | 5 | 6µs | return 0; | ||
| 274 | } | ||||
| 275 | |||||
| 276 | ## compiling the type constraint | ||||
| 277 | |||||
| 278 | # spent 28.6ms (4.89+23.7) within Moose::Meta::TypeConstraint::compile_type_constraint which was called 77 times, avg 371µs/call:
# 48 times (4.80ms+20.0ms) by Moose::Meta::TypeConstraint::new at line 125, avg 516µs/call
# 15 times (45µs+1.83ms) by Moose::Meta::TypeConstraint::Class::new at line 40 of Moose/Meta/TypeConstraint/Class.pm, avg 125µs/call
# 12 times (33µs+1.40ms) by Moose::Meta::TypeConstraint::Role::new at line 41 of Moose/Meta/TypeConstraint/Role.pm, avg 120µs/call
# 2 times (10µs+487µs) by Moose::Meta::TypeConstraint::Parameterized::compile_type_constraint at line 57 of Moose/Meta/TypeConstraint/Parameterized.pm, avg 249µs/call | ||||
| 279 | 77 | 12µs | my $self = shift; | ||
| 280 | 77 | 231µs | 154 | 23.7ms | $self->_compiled_type_constraint($self->_actually_compile_type_constraint); # spent 23.4ms making 77 calls to Moose::Meta::TypeConstraint::_actually_compile_type_constraint, avg 304µs/call
# spent 277µs making 77 calls to Moose::Meta::TypeConstraint::_compiled_type_constraint, avg 4µs/call |
| 281 | } | ||||
| 282 | |||||
| 283 | ## type compilers ... | ||||
| 284 | |||||
| 285 | # spent 23.4ms (4.63+18.8) within Moose::Meta::TypeConstraint::_actually_compile_type_constraint which was called 77 times, avg 304µs/call:
# 77 times (4.63ms+18.8ms) by Moose::Meta::TypeConstraint::compile_type_constraint at line 280, avg 304µs/call | ||||
| 286 | 77 | 10µs | my $self = shift; | ||
| 287 | |||||
| 288 | 77 | 4.98ms | 308 | 18.8ms | if ( $self->can_be_inlined ) { # spent 11.1ms making 77 calls to Eval::Closure::eval_closure, avg 144µs/call
# spent 6.49ms making 75 calls to Moose::Meta::TypeConstraint::_inline_check, avg 86µs/call
# spent 547µs making 75 calls to Moose::Meta::TypeConstraint::can_be_inlined, avg 7µs/call
# spent 443µs making 75 calls to Moose::Meta::TypeConstraint::inline_environment, avg 6µs/call
# spent 146µs making 2 calls to Moose::Meta::TypeConstraint::Parameterized::_inline_check, avg 73µs/call
# spent 65µs making 2 calls to Moose::Meta::TypeConstraint::Parameterized::inline_environment, avg 32µs/call
# spent 49µs making 2 calls to Moose::Meta::TypeConstraint::Parameterized::can_be_inlined, avg 25µs/call |
| 289 | return eval_closure( | ||||
| 290 | source => 'sub { ' . $self->_inline_check('$_[0]') . ' }', | ||||
| 291 | environment => $self->inline_environment, | ||||
| 292 | ); | ||||
| 293 | } | ||||
| 294 | |||||
| 295 | my $check = $self->constraint; | ||||
| 296 | unless ( defined $check ) { | ||||
| 297 | throw_exception( NoConstraintCheckForTypeConstraint => type_name => $self->name ); | ||||
| 298 | } | ||||
| 299 | |||||
| 300 | return $self->_compile_subtype($check) | ||||
| 301 | if $self->has_parent; | ||||
| 302 | |||||
| 303 | return $self->_compile_type($check); | ||||
| 304 | } | ||||
| 305 | |||||
| 306 | sub _compile_subtype { | ||||
| 307 | my ($self, $check) = @_; | ||||
| 308 | |||||
| 309 | # gather all the parent constraints in order | ||||
| 310 | my @parents; | ||||
| 311 | foreach my $parent ($self->_collect_all_parents) { | ||||
| 312 | push @parents => $parent->constraint; | ||||
| 313 | } | ||||
| 314 | |||||
| 315 | @parents = grep { $_ != $null_constraint } reverse @parents; | ||||
| 316 | |||||
| 317 | unless ( @parents ) { | ||||
| 318 | return $self->_compile_type($check); | ||||
| 319 | } else { | ||||
| 320 | # general case, check all the constraints, from the first parent to ourselves | ||||
| 321 | my @checks = @parents; | ||||
| 322 | push @checks, $check if $check != $null_constraint; | ||||
| 323 | return subname($self->name => sub { | ||||
| 324 | my (@args) = @_; | ||||
| 325 | local $_ = $args[0]; | ||||
| 326 | foreach my $check (@checks) { | ||||
| 327 | return undef unless $check->(@args); | ||||
| 328 | } | ||||
| 329 | return 1; | ||||
| 330 | }); | ||||
| 331 | } | ||||
| 332 | } | ||||
| 333 | |||||
| 334 | sub _compile_type { | ||||
| 335 | my ($self, $check) = @_; | ||||
| 336 | |||||
| 337 | return $check if $check == $null_constraint; # Item, Any | ||||
| 338 | |||||
| 339 | return subname($self->name => sub { | ||||
| 340 | my (@args) = @_; | ||||
| 341 | local $_ = $args[0]; | ||||
| 342 | $check->(@args); | ||||
| 343 | }); | ||||
| 344 | } | ||||
| 345 | |||||
| 346 | ## other utils ... | ||||
| 347 | |||||
| 348 | sub _collect_all_parents { | ||||
| 349 | my $self = shift; | ||||
| 350 | my @parents; | ||||
| 351 | my $current = $self->parent; | ||||
| 352 | while (defined $current) { | ||||
| 353 | push @parents => $current; | ||||
| 354 | $current = $current->parent; | ||||
| 355 | } | ||||
| 356 | return @parents; | ||||
| 357 | } | ||||
| 358 | |||||
| 359 | # spent 6.46ms (52µs+6.41) within Moose::Meta::TypeConstraint::create_child_type which was called 16 times, avg 404µs/call:
# 16 times (52µs+6.41ms) by Moose::Util::TypeConstraints::_create_type_constraint at line 572 of Moose/Util/TypeConstraints.pm, avg 404µs/call | ||||
| 360 | 16 | 12µs | my ($self, %opts) = @_; | ||
| 361 | 16 | 4µs | my $class = ref $self; | ||
| 362 | 16 | 40µs | 16 | 6.41ms | return $class->new(%opts, parent => $self); # spent 6.41ms making 16 calls to Moose::Meta::TypeConstraint::new, avg 401µs/call |
| 363 | } | ||||
| 364 | |||||
| 365 | 1 | 10µs | 1; | ||
| 366 | |||||
| 367 | # ABSTRACT: The Moose Type Constraint metaclass | ||||
| 368 | |||||
| 369 | __END__ |