| Filename | /home/doy/coding/src/Moose/blib/lib//Moose/Meta/TypeConstraint.pm |
| Statements | Executed 3906 statements in 56.7ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1077 | 14 | 7 | 9.20ms | 9.20ms | Moose::Meta::TypeConstraint::__ANON__[:10] |
| 53 | 2 | 1 | 5.35ms | 12.0ms | Moose::Meta::TypeConstraint::equals |
| 125 | 1 | 1 | 5.28ms | 19.1ms | Moose::Meta::TypeConstraint::_actually_compile_type_constraint |
| 98 | 2 | 2 | 4.51ms | 12.9ms | Moose::Meta::TypeConstraint::check |
| 125 | 5 | 5 | 4.48ms | 25.7ms | Moose::Meta::TypeConstraint::compile_type_constraint |
| 36 | 7 | 3 | 3.62ms | 43.0ms | Moose::Meta::TypeConstraint::new |
| 104 | 1 | 1 | 3.16ms | 4.34ms | Moose::Meta::TypeConstraint::_compile_hand_optimized_type_constraint |
| 18 | 2 | 2 | 3.11ms | 17.6ms | Moose::Meta::TypeConstraint::is_subtype_of |
| 20 | 1 | 1 | 2.63ms | 7.36ms | Moose::Meta::TypeConstraint::_compile_subtype |
| 20 | 1 | 1 | 2.27ms | 3.41ms | Moose::Meta::TypeConstraint::_collect_all_parents |
| 106 | 1 | 1 | 1.80ms | 2.25ms | Moose::Meta::TypeConstraint::__ANON__[:8] |
| 1 | 1 | 1 | 1.55ms | 5.45ms | Moose::Meta::TypeConstraint::BEGIN@6 |
| 96 | 2 | 1 | 1.00ms | 1.00ms | Moose::Meta::TypeConstraint::__ANON__[:32] |
| 25 | 2 | 2 | 971µs | 15.0ms | Moose::Meta::TypeConstraint::create_child_type |
| 6 | 1 | 1 | 387µs | 3.46ms | Moose::Meta::TypeConstraint::is_a_type_of |
| 1 | 1 | 1 | 82µs | 109µs | Moose::Meta::TypeConstraint::_compile_type |
| 1 | 1 | 1 | 77µs | 96µs | Moose::Meta::TypeConstraint::BEGIN@4 |
| 1 | 1 | 1 | 52µs | 289µs | Moose::Meta::TypeConstraint::BEGIN@8 |
| 1 | 1 | 1 | 43µs | 112µs | Moose::Meta::TypeConstraint::BEGIN@5 |
| 1 | 1 | 1 | 42µs | 237µs | Moose::Meta::TypeConstraint::BEGIN@13 |
| 1 | 1 | 1 | 39µs | 172µs | Moose::Meta::TypeConstraint::BEGIN@14 |
| 1 | 1 | 1 | 38µs | 269µs | Moose::Meta::TypeConstraint::BEGIN@16 |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::__ANON__[:274] |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::__ANON__[:287] |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::__ANON__[:28] |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::__ANON__[:300] |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::__ANON__[:9] |
| 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::coerce |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::get_message |
| 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 | |||||
| 2 | package Moose::Meta::TypeConstraint; | ||||
| 3 | |||||
| 4 | 3 | 132µs | 2 | 115µs | # spent 96µs (77+19) within Moose::Meta::TypeConstraint::BEGIN@4 which was called:
# once (77µs+19µs) by Moose::BEGIN@20 at line 4 # spent 96µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@4
# spent 19µs making 1 call to strict::import |
| 5 | 3 | 98µs | 2 | 182µs | # spent 112µs (43+70) within Moose::Meta::TypeConstraint::BEGIN@5 which was called:
# once (43µs+70µs) by Moose::BEGIN@20 at line 5 # spent 112µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@5
# spent 70µs making 1 call to warnings::import |
| 6 | 3 | 631µs | 2 | 8.57ms | # spent 5.45ms (1.55+3.90) within Moose::Meta::TypeConstraint::BEGIN@6 which was called:
# once (1.55ms+3.90ms) by Moose::BEGIN@20 at line 6 # spent 5.45ms making 1 call to Moose::Meta::TypeConstraint::BEGIN@6
# spent 3.13ms making 1 call to metaclass::import |
| 7 | |||||
| 8 | 106 | 2.50ms | 106 | 450µs | # spent 2.25ms (1.80+450µs) within Moose::Meta::TypeConstraint::__ANON__[/home/doy/coding/src/Moose/blib/lib//Moose/Meta/TypeConstraint.pm:8] which was called 106 times, avg 21µs/call:
# 106 times (1.80ms+450µs) by Moose::Meta::TypeConstraint::equals at line 157, avg 21µs/call
# spent 289µs (52+237) within Moose::Meta::TypeConstraint::BEGIN@8 which was called:
# once (52µs+237µs) by Moose::BEGIN@20 at line 11 # spent 450µs making 106 calls to Scalar::Util::refaddr, avg 4µs/call |
| 9 | '""' => sub { shift->name }, # stringify to tc name | ||||
| 10 | 1077 | 13.7ms | # spent 9.20ms within Moose::Meta::TypeConstraint::__ANON__[/home/doy/coding/src/Moose/blib/lib//Moose/Meta/TypeConstraint.pm:10] which was called 1077 times, avg 9µs/call:
# 639 times (5.56ms+0s) by MooseX::Types::Base::import at line 83 of MooseX/Types/Base.pm, avg 9µs/call
# 116 times (971µs+0s) by Moose::Meta::TypeConstraint::Registry::add_type_constraint at line 47 of Moose/Meta/TypeConstraint/Registry.pm, avg 8µs/call
# 59 times (526µs+0s) by MooseX::Types::TypeDecorator::new at line 76 of MooseX/Types/TypeDecorator.pm, avg 9µs/call
# 53 times (395µs+0s) by Moose::Meta::TypeConstraint::equals at line 155, avg 7µs/call
# 50 times (365µs+0s) by Moose::Meta::TypeConstraint::is_subtype_of at line 190, avg 7µs/call
# 44 times (404µs+0s) by Moose::Util::TypeConstraints::find_or_parse_type_constraint at line 218 of Moose/Util/TypeConstraints.pm, avg 9µs/call
# 33 times (240µs+0s) by Moose::Util::TypeConstraints::find_or_create_isa_type_constraint at line 204 of Moose/Util/TypeConstraints.pm, avg 7µs/call
# 25 times (279µs+0s) by Moose::Meta::Method::Accessor::_eval_environment at line 46 of Moose/Meta/Method/Accessor.pm, avg 11µs/call
# 18 times (143µs+0s) by Moose::Meta::TypeConstraint::is_subtype_of at line 186, avg 8µs/call
# 17 times (118µs+0s) by Moose::Util::TypeConstraints::_create_type_constraint at line 547 of Moose/Util/TypeConstraints.pm, avg 7µs/call
# 6 times (57µs+0s) by Moose::Meta::TypeConstraint::is_a_type_of at line 178, avg 10µs/call
# 6 times (51µs+0s) by Moose::Meta::TypeConstraint::Parameterizable::parameterize at line 58 of Moose/Meta/TypeConstraint/Parameterizable.pm, avg 8µs/call
# 6 times (48µs+0s) by Moose::Util::TypeConstraints::find_or_create_type_constraint at line 176 of Moose/Util/TypeConstraints.pm, avg 8µs/call
# 5 times (38µs+0s) by Moose::Util::TypeConstraints::find_or_create_does_type_constraint at line 210 of Moose/Util/TypeConstraints.pm, avg 7µs/call | ||
| 11 | 3 | 151µs | 2 | 525µs | fallback => 1; # spent 289µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@8
# spent 237µs making 1 call to overload::import |
| 12 | |||||
| 13 | 3 | 112µs | 2 | 431µs | # spent 237µs (42+194) within Moose::Meta::TypeConstraint::BEGIN@13 which was called:
# once (42µs+194µs) by Moose::BEGIN@20 at line 13 # spent 237µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@13
# spent 194µs making 1 call to Exporter::import |
| 14 | 3 | 104µs | 2 | 305µs | # spent 172µs (39+133) within Moose::Meta::TypeConstraint::BEGIN@14 which was called:
# once (39µs+133µs) by Moose::BEGIN@20 at line 14 # spent 172µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@14
# spent 133µs making 1 call to Exporter::import |
| 15 | |||||
| 16 | 3 | 4.98ms | 2 | 501µs | # spent 269µs (38+232) within Moose::Meta::TypeConstraint::BEGIN@16 which was called:
# once (38µs+232µs) by Moose::BEGIN@20 at line 16 # spent 269µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@16
# spent 232µs making 1 call to base::import |
| 17 | |||||
| 18 | 1 | 5µs | our $VERSION = '1.19'; | ||
| 19 | 1 | 64µs | $VERSION = eval $VERSION; # spent 11µs executing statements in string eval | ||
| 20 | 1 | 4µs | our $AUTHORITY = 'cpan:STEVAN'; | ||
| 21 | |||||
| 22 | 1 | 27µs | 2 | 2.53ms | __PACKAGE__->meta->add_attribute('name' => (reader => 'name')); # spent 2.41ms making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 122µs making 1 call to Moose::Meta::TypeConstraint::meta |
| 23 | 1 | 24µs | 2 | 3.08ms | __PACKAGE__->meta->add_attribute('parent' => ( # spent 3.00ms making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 88µs making 1 call to Moose::Meta::TypeConstraint::meta |
| 24 | reader => 'parent', | ||||
| 25 | predicate => 'has_parent', | ||||
| 26 | )); | ||||
| 27 | |||||
| 28 | 1 | 9µs | my $null_constraint = sub { 1 }; | ||
| 29 | __PACKAGE__->meta->add_attribute('constraint' => ( | ||||
| 30 | reader => 'constraint', | ||||
| 31 | writer => '_set_constraint', | ||||
| 32 | 96 | 1.35ms | # spent 1.00ms within Moose::Meta::TypeConstraint::__ANON__[/home/doy/coding/src/Moose/blib/lib//Moose/Meta/TypeConstraint.pm:32] which was called 96 times, avg 10µs/call:
# 49 times (506µs+0s) by Moose::Meta::TypeConstraint::Enum::_new or Moose::Meta::TypeConstraint::Parameterized::_new or Moose::Meta::TypeConstraint::Role::_new or Moose::Meta::TypeConstraint::_new at line 18 of generated method (unknown origin), avg 10µs/call
# 47 times (497µs+0s) by Moose::Meta::TypeConstraint::Class::_new at line 21 of generated method (unknown origin), avg 11µs/call | ||
| 33 | 1 | 32µs | 2 | 3.08ms | )); # spent 2.99ms making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 89µs making 1 call to Moose::Meta::TypeConstraint::meta |
| 34 | 1 | 23µs | 2 | 3.57ms | __PACKAGE__->meta->add_attribute('message' => ( # spent 3.48ms making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 86µs making 1 call to Moose::Meta::TypeConstraint::meta |
| 35 | accessor => 'message', | ||||
| 36 | predicate => 'has_message' | ||||
| 37 | )); | ||||
| 38 | 1 | 36µs | 2 | 4.50ms | __PACKAGE__->meta->add_attribute('coercion' => ( # spent 4.37ms making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 125µs making 1 call to Moose::Meta::TypeConstraint::meta |
| 39 | accessor => 'coercion', | ||||
| 40 | predicate => 'has_coercion' | ||||
| 41 | )); | ||||
| 42 | |||||
| 43 | 1 | 32µs | 2 | 4.17ms | __PACKAGE__->meta->add_attribute('hand_optimized_type_constraint' => ( # spent 4.05ms making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 120µs making 1 call to Moose::Meta::TypeConstraint::meta |
| 44 | init_arg => 'optimized', | ||||
| 45 | accessor => 'hand_optimized_type_constraint', | ||||
| 46 | predicate => 'has_hand_optimized_type_constraint', | ||||
| 47 | )); | ||||
| 48 | |||||
| 49 | sub parents { | ||||
| 50 | my $self; | ||||
| 51 | $self->parent; | ||||
| 52 | } | ||||
| 53 | |||||
| 54 | # private accessors | ||||
| 55 | |||||
| 56 | 1 | 34µs | 2 | 4.00ms | __PACKAGE__->meta->add_attribute('compiled_type_constraint' => ( # spent 3.89ms making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 117µs making 1 call to Moose::Meta::TypeConstraint::meta |
| 57 | accessor => '_compiled_type_constraint', | ||||
| 58 | predicate => '_has_compiled_type_constraint' | ||||
| 59 | )); | ||||
| 60 | 1 | 32µs | 2 | 2.81ms | __PACKAGE__->meta->add_attribute('package_defined_in' => ( # spent 2.69ms making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 123µs making 1 call to Moose::Meta::TypeConstraint::meta |
| 61 | accessor => '_package_defined_in' | ||||
| 62 | )); | ||||
| 63 | |||||
| 64 | # spent 43.0ms (3.62+39.4) within Moose::Meta::TypeConstraint::new which was called 36 times, avg 1.19ms/call:
# 25 times (2.41ms+11.6ms) by Moose::Meta::TypeConstraint::create_child_type at line 319, avg 560µs/call
# 6 times (739µs+25.6ms) by Moose::Meta::TypeConstraint::Parameterizable::parameterize at line 69 of Moose/Meta/TypeConstraint/Parameterizable.pm, avg 4.39ms/call
# once (95µs+622µs) by Moose::Meta::Attribute::BEGIN@20 at line 847 of Moose/Util/TypeConstraints.pm
# once (113µs+573µs) by Moose::Meta::Attribute::BEGIN@20 at line 788 of Moose/Util/TypeConstraints.pm
# once (101µs+564µs) by Moose::Util::TypeConstraints::_create_type_constraint at line 557 of Moose/Util/TypeConstraints.pm
# once (81µs+233µs) by Moose::Meta::Attribute::BEGIN@20 at line 830 of Moose/Util/TypeConstraints.pm
# once (83µs+219µs) by Moose::Meta::Attribute::BEGIN@20 at line 809 of Moose/Util/TypeConstraints.pm | ||||
| 65 | 36 | 124µs | my $class = shift; | ||
| 66 | 36 | 350µs | my ($first, @rest) = @_; | ||
| 67 | 36 | 384µs | my %args = ref $first ? %$first : $first ? ($first, @rest) : (); | ||
| 68 | 36 | 323µs | 16 | 738µs | $args{name} = $args{name} ? "$args{name}" : "__ANON__"; # spent 680µs making 8 calls to MooseX::Types::TypeDecorator::__ANON__[MooseX/Types/TypeDecorator.pm:26], avg 85µs/call
# spent 57µs making 8 calls to MooseX::Types::TypeDecorator::__ANON__[MooseX/Types/TypeDecorator.pm:27], avg 7µs/call |
| 69 | |||||
| 70 | 36 | 625µs | 36 | 4.83ms | my $self = $class->_new(%args); # spent 2.68ms making 25 calls to Moose::Meta::TypeConstraint::_new, avg 107µs/call
# spent 1.13ms making 6 calls to Moose::Meta::TypeConstraint::Parameterized::_new, avg 188µs/call
# spent 1.03ms making 5 calls to Moose::Meta::TypeConstraint::Parameterizable::_new, avg 206µs/call |
| 71 | 36 | 818µs | 72 | 33.8ms | $self->compile_type_constraint() # spent 24.4ms making 6 calls to Moose::Meta::TypeConstraint::Parameterized::compile_type_constraint, avg 4.06ms/call
# spent 9.01ms making 30 calls to Moose::Meta::TypeConstraint::compile_type_constraint, avg 300µs/call
# spent 414µs making 36 calls to Moose::Meta::TypeConstraint::_has_compiled_type_constraint, avg 11µs/call |
| 72 | unless $self->_has_compiled_type_constraint; | ||||
| 73 | 36 | 656µs | return $self; | ||
| 74 | } | ||||
| 75 | |||||
| - - | |||||
| 78 | sub coerce { | ||||
| 79 | my $self = shift; | ||||
| 80 | |||||
| 81 | my $coercion = $self->coercion; | ||||
| 82 | |||||
| 83 | unless ($coercion) { | ||||
| 84 | require Moose; | ||||
| 85 | Moose->throw_error("Cannot coerce without a type coercion"); | ||||
| 86 | } | ||||
| 87 | |||||
| 88 | return $_[0] if $self->check($_[0]); | ||||
| 89 | |||||
| 90 | return $coercion->coerce(@_); | ||||
| 91 | } | ||||
| 92 | |||||
| 93 | sub assert_coerce { | ||||
| 94 | my $self = shift; | ||||
| 95 | |||||
| 96 | my $coercion = $self->coercion; | ||||
| 97 | |||||
| 98 | unless ($coercion) { | ||||
| 99 | require Moose; | ||||
| 100 | Moose->throw_error("Cannot coerce without a type coercion"); | ||||
| 101 | } | ||||
| 102 | |||||
| 103 | return $_[0] if $self->check($_[0]); | ||||
| 104 | |||||
| 105 | my $result = $coercion->coerce(@_); | ||||
| 106 | |||||
| 107 | $self->assert_valid($result); | ||||
| 108 | |||||
| 109 | return $result; | ||||
| 110 | } | ||||
| 111 | |||||
| 112 | # spent 12.9ms (4.51+8.39) within Moose::Meta::TypeConstraint::check which was called 98 times, avg 132µs/call:
# 92 times (4.26ms+7.62ms) by Moose::Meta::Attribute::verify_against_type_constraint at line 1141 of Moose/Meta/Attribute.pm, avg 129µs/call
# 6 times (259µs+776µs) by MooseX::Types::TypeDecorator::AUTOLOAD at line 206 of MooseX/Types/TypeDecorator.pm, avg 173µs/call | ||||
| 113 | 98 | 499µs | my ($self, @args) = @_; | ||
| 114 | 98 | 1.30ms | 98 | 1.34ms | my $constraint_subref = $self->_compiled_type_constraint; # spent 1.34ms making 98 calls to Moose::Meta::TypeConstraint::_compiled_type_constraint, avg 14µs/call |
| 115 | 98 | 2.22ms | 98 | 7.06ms | return $constraint_subref->(@args) ? 1 : undef; # spent 5.73ms making 84 calls to Moose::Meta::TypeConstraint::Class::__ANON__[Moose/Meta/TypeConstraint/Class.pm:38], avg 68µs/call
# spent 695µs making 6 calls to Moose::Meta::TypeConstraint::ArrayRef[Str], avg 116µs/call
# spent 552µs making 6 calls to Moose::Meta::TypeConstraint::Bool, avg 92µs/call
# spent 80µs making 2 calls to Moose::Util::TypeConstraints::OptimizedConstraints::ClassName, avg 40µs/call |
| 116 | } | ||||
| 117 | |||||
| 118 | sub validate { | ||||
| 119 | my ($self, $value) = @_; | ||||
| 120 | if ($self->_compiled_type_constraint->($value)) { | ||||
| 121 | return undef; | ||||
| 122 | } | ||||
| 123 | else { | ||||
| 124 | $self->get_message($value); | ||||
| 125 | } | ||||
| 126 | } | ||||
| 127 | |||||
| 128 | sub assert_valid { | ||||
| 129 | my ($self, $value) = @_; | ||||
| 130 | |||||
| 131 | my $error = $self->validate($value); | ||||
| 132 | return 1 if ! defined $error; | ||||
| 133 | |||||
| 134 | require Moose; | ||||
| 135 | Moose->throw_error($error); | ||||
| 136 | } | ||||
| 137 | |||||
| 138 | sub get_message { | ||||
| 139 | my ($self, $value) = @_; | ||||
| 140 | if (my $msg = $self->message) { | ||||
| 141 | local $_ = $value; | ||||
| 142 | return $msg->($value); | ||||
| 143 | } | ||||
| 144 | else { | ||||
| 145 | $value = (defined $value ? overload::StrVal($value) : 'undef'); | ||||
| 146 | return "Validation failed for '" . $self->name . "' with value $value"; | ||||
| 147 | } | ||||
| 148 | } | ||||
| 149 | |||||
| 150 | ## type predicates ... | ||||
| 151 | |||||
| 152 | # spent 12.0ms (5.35+6.61) within Moose::Meta::TypeConstraint::equals which was called 53 times, avg 226µs/call:
# 50 times (5.09ms+6.25ms) by Moose::Meta::TypeConstraint::is_subtype_of at line 191, avg 227µs/call
# 3 times (262µs+357µs) by Moose::Meta::TypeConstraint::is_a_type_of at line 180, avg 206µs/call | ||||
| 153 | 53 | 166µs | my ( $self, $type_or_name ) = @_; | ||
| 154 | |||||
| 155 | 53 | 938µs | 106 | 2.42ms | my $other = Moose::Util::TypeConstraints::find_type_constraint($type_or_name) or return; # spent 2.02ms making 53 calls to Moose::Util::TypeConstraints::find_type_constraint, avg 38µs/call
# spent 395µs making 53 calls to Moose::Meta::TypeConstraint::__ANON__[Moose/Meta/TypeConstraint.pm:10], avg 7µs/call |
| 156 | |||||
| 157 | 53 | 1.25ms | 106 | 2.25ms | return 1 if $self == $other; # spent 2.25ms making 106 calls to Moose::Meta::TypeConstraint::__ANON__[Moose/Meta/TypeConstraint.pm:8], avg 21µs/call |
| 158 | |||||
| 159 | 41 | 900µs | 92 | 1.04ms | if ( $self->has_hand_optimized_type_constraint and $other->has_hand_optimized_type_constraint ) { # spent 614µs making 58 calls to Moose::Meta::TypeConstraint::has_hand_optimized_type_constraint, avg 11µs/call
# spent 424µs making 34 calls to Moose::Meta::TypeConstraint::hand_optimized_type_constraint, avg 12µs/call |
| 160 | return 1 if $self->hand_optimized_type_constraint == $other->hand_optimized_type_constraint; | ||||
| 161 | } | ||||
| 162 | |||||
| 163 | 41 | 1.12ms | 82 | 901µs | return unless $self->constraint == $other->constraint; # spent 901µs making 82 calls to Moose::Meta::TypeConstraint::constraint, avg 11µs/call |
| 164 | |||||
| 165 | if ( $self->has_parent ) { | ||||
| 166 | return unless $other->has_parent; | ||||
| 167 | return unless $self->parent->equals( $other->parent ); | ||||
| 168 | } else { | ||||
| 169 | return if $other->has_parent; | ||||
| 170 | } | ||||
| 171 | |||||
| 172 | return; | ||||
| 173 | } | ||||
| 174 | |||||
| 175 | # spent 3.46ms (387µs+3.08) within Moose::Meta::TypeConstraint::is_a_type_of which was called 6 times, avg 577µs/call:
# 6 times (387µs+3.08ms) by MooseX::Types::TypeDecorator::AUTOLOAD at line 206 of MooseX/Types/TypeDecorator.pm, avg 577µs/call | ||||
| 176 | 6 | 26µs | my ($self, $type_or_name) = @_; | ||
| 177 | |||||
| 178 | 6 | 123µs | 12 | 854µs | my $type = Moose::Util::TypeConstraints::find_type_constraint($type_or_name) or return; # spent 796µs making 6 calls to Moose::Util::TypeConstraints::find_type_constraint, avg 133µs/call
# spent 57µs making 6 calls to Moose::Meta::TypeConstraint::__ANON__[Moose/Meta/TypeConstraint.pm:10], avg 10µs/call |
| 179 | |||||
| 180 | 6 | 163µs | 10 | 2.22ms | ($self->equals($type) || $self->is_subtype_of($type)); # spent 1.33ms making 4 calls to Moose::Meta::TypeConstraint::is_subtype_of, avg 332µs/call
# spent 619µs making 3 calls to Moose::Meta::TypeConstraint::equals, avg 206µs/call
# spent 278µs making 3 calls to Moose::Meta::TypeConstraint::Parameterized::equals, avg 93µs/call |
| 181 | } | ||||
| 182 | |||||
| 183 | # spent 17.6ms (3.11+14.5) within Moose::Meta::TypeConstraint::is_subtype_of which was called 18 times, avg 977µs/call:
# 14 times (2.70ms+13.6ms) by Moose::Meta::TypeConstraint::Parameterizable::generate_constraint_for at line 25 of Moose/Meta/TypeConstraint/Parameterizable.pm, avg 1.16ms/call
# 4 times (405µs+923µs) by Moose::Meta::TypeConstraint::is_a_type_of at line 180, avg 332µs/call | ||||
| 184 | 18 | 66µs | my ($self, $type_or_name) = @_; | ||
| 185 | |||||
| 186 | 18 | 355µs | 36 | 2.11ms | my $type = Moose::Util::TypeConstraints::find_type_constraint($type_or_name) or return; # spent 1.97ms making 18 calls to Moose::Util::TypeConstraints::find_type_constraint, avg 109µs/call
# spent 143µs making 18 calls to Moose::Meta::TypeConstraint::__ANON__[Moose/Meta/TypeConstraint.pm:10], avg 8µs/call |
| 187 | |||||
| 188 | 18 | 43µs | my $current = $self; | ||
| 189 | |||||
| 190 | 18 | 1.16ms | 108 | 1.03ms | while (my $parent = $current->parent) { # spent 668µs making 58 calls to Moose::Meta::TypeConstraint::parent, avg 12µs/call
# spent 365µs making 50 calls to Moose::Meta::TypeConstraint::__ANON__[Moose/Meta/TypeConstraint.pm:10], avg 7µs/call |
| 191 | 50 | 669µs | 50 | 11.3ms | return 1 if $parent->equals($type); # spent 11.3ms making 50 calls to Moose::Meta::TypeConstraint::equals, avg 227µs/call |
| 192 | 40 | 136µs | $current = $parent; | ||
| 193 | } | ||||
| 194 | |||||
| 195 | 8 | 96µs | return 0; | ||
| 196 | } | ||||
| 197 | |||||
| 198 | ## compiling the type constraint | ||||
| 199 | |||||
| 200 | # spent 25.7ms (4.48+21.2) within Moose::Meta::TypeConstraint::compile_type_constraint which was called 125 times, avg 206µs/call:
# 47 times (1.76ms+5.01ms) by Moose::Meta::TypeConstraint::Class::new at line 27 of Moose/Meta/TypeConstraint/Class.pm, avg 144µs/call
# 41 times (1.43ms+4.44ms) by Moose::Meta::TypeConstraint::Role::new at line 27 of Moose/Meta/TypeConstraint/Role.pm, avg 143µs/call
# 30 times (985µs+8.03ms) by Moose::Meta::TypeConstraint::new at line 71, avg 300µs/call
# 6 times (251µs+3.02ms) by Moose::Meta::TypeConstraint::Parameterized::compile_type_constraint at line 54 of Moose/Meta/TypeConstraint/Parameterized.pm, avg 546µs/call
# once (51µs+718µs) by Moose::Meta::TypeConstraint::Enum::new at line 42 of Moose/Meta/TypeConstraint/Enum.pm | ||||
| 201 | 125 | 387µs | my $self = shift; | ||
| 202 | 125 | 3.74ms | 250 | 21.2ms | $self->_compiled_type_constraint($self->_actually_compile_type_constraint); # spent 19.1ms making 125 calls to Moose::Meta::TypeConstraint::_actually_compile_type_constraint, avg 153µs/call
# spent 2.08ms making 125 calls to Moose::Meta::TypeConstraint::_compiled_type_constraint, avg 17µs/call |
| 203 | } | ||||
| 204 | |||||
| 205 | ## type compilers ... | ||||
| 206 | |||||
| 207 | # spent 19.1ms (5.28+13.9) within Moose::Meta::TypeConstraint::_actually_compile_type_constraint which was called 125 times, avg 153µs/call:
# 125 times (5.28ms+13.9ms) by Moose::Meta::TypeConstraint::compile_type_constraint at line 202, avg 153µs/call | ||||
| 208 | 125 | 353µs | my $self = shift; | ||
| 209 | |||||
| 210 | 125 | 3.28ms | 229 | 5.84ms | return $self->_compile_hand_optimized_type_constraint # spent 4.34ms making 104 calls to Moose::Meta::TypeConstraint::_compile_hand_optimized_type_constraint, avg 42µs/call
# spent 1.50ms making 125 calls to Moose::Meta::TypeConstraint::has_hand_optimized_type_constraint, avg 12µs/call |
| 211 | if $self->has_hand_optimized_type_constraint; | ||||
| 212 | |||||
| 213 | 21 | 254µs | 21 | 322µs | my $check = $self->constraint; # spent 258µs making 20 calls to Moose::Meta::TypeConstraint::constraint, avg 13µs/call
# spent 65µs making 1 call to Moose::Meta::TypeConstraint::Enum::constraint |
| 214 | 21 | 46µs | unless ( defined $check ) { | ||
| 215 | require Moose; | ||||
| 216 | Moose->throw_error( "Could not compile type constraint '" | ||||
| 217 | . $self->name | ||||
| 218 | . "' because no constraint check" ); | ||||
| 219 | } | ||||
| 220 | |||||
| 221 | 21 | 663µs | 41 | 7.60ms | return $self->_compile_subtype($check) # spent 7.36ms making 20 calls to Moose::Meta::TypeConstraint::_compile_subtype, avg 368µs/call
# spent 233µs making 21 calls to Moose::Meta::TypeConstraint::has_parent, avg 11µs/call |
| 222 | if $self->has_parent; | ||||
| 223 | |||||
| 224 | 1 | 25µs | 1 | 109µs | return $self->_compile_type($check); # spent 109µs making 1 call to Moose::Meta::TypeConstraint::_compile_type |
| 225 | } | ||||
| 226 | |||||
| 227 | # spent 4.34ms (3.16+1.18) within Moose::Meta::TypeConstraint::_compile_hand_optimized_type_constraint which was called 104 times, avg 42µs/call:
# 104 times (3.16ms+1.18ms) by Moose::Meta::TypeConstraint::_actually_compile_type_constraint at line 210, avg 42µs/call | ||||
| 228 | 104 | 278µs | my $self = shift; | ||
| 229 | |||||
| 230 | 104 | 1.14ms | 104 | 1.18ms | my $type_constraint = $self->hand_optimized_type_constraint; # spent 1.18ms making 104 calls to Moose::Meta::TypeConstraint::hand_optimized_type_constraint, avg 11µs/call |
| 231 | |||||
| 232 | 104 | 298µs | unless ( ref $type_constraint ) { | ||
| 233 | require Moose; | ||||
| 234 | Carp::confess ("Hand optimized type constraint for " . $self->name . " is not a code reference"); | ||||
| 235 | Moose->throw_error("Hand optimized type constraint is not a code reference"); | ||||
| 236 | } | ||||
| 237 | |||||
| 238 | 104 | 1.28ms | return $type_constraint; | ||
| 239 | } | ||||
| 240 | |||||
| 241 | # spent 7.36ms (2.63+4.73) within Moose::Meta::TypeConstraint::_compile_subtype which was called 20 times, avg 368µs/call:
# 20 times (2.63ms+4.73ms) by Moose::Meta::TypeConstraint::_actually_compile_type_constraint at line 221, avg 368µs/call | ||||
| 242 | 20 | 76µs | my ($self, $check) = @_; | ||
| 243 | |||||
| 244 | # gather all the parent constraintss in order | ||||
| 245 | 20 | 39µs | my @parents; | ||
| 246 | 20 | 38µs | my $optimized_parent; | ||
| 247 | 20 | 281µs | 20 | 3.41ms | foreach my $parent ($self->_collect_all_parents) { # spent 3.41ms making 20 calls to Moose::Meta::TypeConstraint::_collect_all_parents, avg 171µs/call |
| 248 | # if a parent is optimized, the optimized constraint already includes | ||||
| 249 | # all of its parents tcs, so we can break the loop | ||||
| 250 | 24 | 319µs | 24 | 256µs | if ($parent->has_hand_optimized_type_constraint) { # spent 256µs making 24 calls to Moose::Meta::TypeConstraint::has_hand_optimized_type_constraint, avg 11µs/call |
| 251 | 14 | 176µs | 14 | 183µs | push @parents => $optimized_parent = $parent->hand_optimized_type_constraint; # spent 183µs making 14 calls to Moose::Meta::TypeConstraint::hand_optimized_type_constraint, avg 13µs/call |
| 252 | 14 | 85µs | last; | ||
| 253 | } | ||||
| 254 | else { | ||||
| 255 | 10 | 107µs | 10 | 110µs | push @parents => $parent->constraint; # spent 110µs making 10 calls to Moose::Meta::TypeConstraint::constraint, avg 11µs/call |
| 256 | } | ||||
| 257 | } | ||||
| 258 | |||||
| 259 | 20 | 179µs | @parents = grep { $_ != $null_constraint } reverse @parents; | ||
| 260 | |||||
| 261 | 20 | 83µs | unless ( @parents ) { | ||
| 262 | return $self->_compile_type($check); | ||||
| 263 | } elsif( $optimized_parent and @parents == 1 ) { | ||||
| 264 | # the case of just one optimized parent is optimized to prevent | ||||
| 265 | # looping and the unnecessary localization | ||||
| 266 | 14 | 30µs | if ( $check == $null_constraint ) { | ||
| 267 | return $optimized_parent; | ||||
| 268 | } else { | ||||
| 269 | return subname($self->name, sub { | ||||
| 270 | 6 | 72µs | 6 | 77µs | return undef unless $optimized_parent->($_[0]); # spent 77µs making 6 calls to Moose::Util::TypeConstraints::OptimizedConstraints::ArrayRef, avg 13µs/call |
| 271 | 6 | 26µs | my (@args) = @_; | ||
| 272 | 6 | 19µs | local $_ = $args[0]; | ||
| 273 | 6 | 137µs | 6 | 330µs | $check->(@args); # spent 330µs making 6 calls to Moose::Util::TypeConstraints::__ANON__[Moose/Util/TypeConstraints.pm:806], avg 55µs/call |
| 274 | 14 | 904µs | 29 | 703µs | }); # spent 406µs making 14 calls to Sub::Name::subname, avg 29µs/call
# spent 196µs making 14 calls to Moose::Meta::TypeConstraint::name, avg 14µs/call
# spent 101µs making 1 call to MooseX::Types::TypeDecorator::__ANON__[MooseX/Types/TypeDecorator.pm:26] |
| 275 | } | ||||
| 276 | } else { | ||||
| 277 | # general case, check all the constraints, from the first parent to ourselves | ||||
| 278 | 6 | 23µs | my @checks = @parents; | ||
| 279 | 6 | 16µs | push @checks, $check if $check != $null_constraint; | ||
| 280 | return subname($self->name => sub { | ||||
| 281 | 6 | 27µs | my (@args) = @_; | ||
| 282 | 6 | 22µs | local $_ = $args[0]; | ||
| 283 | 6 | 39µs | foreach my $check (@checks) { | ||
| 284 | 12 | 190µs | 12 | 165µs | return undef unless $check->(@args); # spent 103µs making 6 calls to Moose::Util::TypeConstraints::__ANON__[Moose/Util/TypeConstraints.pm:714], avg 17µs/call
# spent 62µs making 6 calls to Moose::Util::TypeConstraints::__ANON__[Moose/Util/TypeConstraints.pm:707], avg 10µs/call |
| 285 | } | ||||
| 286 | 6 | 77µs | return 1; | ||
| 287 | 6 | 370µs | 12 | 167µs | }); # spent 87µs making 6 calls to Sub::Name::subname, avg 15µs/call
# spent 80µs making 6 calls to Moose::Meta::TypeConstraint::name, avg 13µs/call |
| 288 | } | ||||
| 289 | } | ||||
| 290 | |||||
| 291 | # spent 109µs (82+26) within Moose::Meta::TypeConstraint::_compile_type which was called:
# once (82µs+26µs) by Moose::Meta::TypeConstraint::_actually_compile_type_constraint at line 224 | ||||
| 292 | 1 | 4µs | my ($self, $check) = @_; | ||
| 293 | |||||
| 294 | 1 | 3µs | return $check if $check == $null_constraint; # Item, Any | ||
| 295 | |||||
| 296 | return subname($self->name => sub { | ||||
| 297 | my (@args) = @_; | ||||
| 298 | local $_ = $args[0]; | ||||
| 299 | $check->(@args); | ||||
| 300 | 1 | 86µs | 2 | 26µs | }); # spent 13µs making 1 call to Moose::Meta::TypeConstraint::name
# spent 13µs making 1 call to Sub::Name::subname |
| 301 | } | ||||
| 302 | |||||
| 303 | ## other utils ... | ||||
| 304 | |||||
| 305 | # spent 3.41ms (2.27+1.15) within Moose::Meta::TypeConstraint::_collect_all_parents which was called 20 times, avg 171µs/call:
# 20 times (2.27ms+1.15ms) by Moose::Meta::TypeConstraint::_compile_subtype at line 247, avg 171µs/call | ||||
| 306 | 20 | 55µs | my $self = shift; | ||
| 307 | 20 | 33µs | my @parents; | ||
| 308 | 20 | 214µs | 20 | 233µs | my $current = $self->parent; # spent 233µs making 20 calls to Moose::Meta::TypeConstraint::parent, avg 12µs/call |
| 309 | 20 | 83µs | while (defined $current) { | ||
| 310 | 86 | 246µs | push @parents => $current; | ||
| 311 | 86 | 1.01ms | 86 | 914µs | $current = $current->parent; # spent 914µs making 86 calls to Moose::Meta::TypeConstraint::parent, avg 11µs/call |
| 312 | } | ||||
| 313 | 20 | 302µs | return @parents; | ||
| 314 | } | ||||
| 315 | |||||
| 316 | # spent 15.0ms (971µs+14.0) within Moose::Meta::TypeConstraint::create_child_type which was called 25 times, avg 599µs/call:
# 17 times (664µs+6.81ms) by Moose::Util::TypeConstraints::_create_type_constraint at line 547 of Moose/Util/TypeConstraints.pm, avg 440µs/call
# 8 times (307µs+7.19ms) by MooseX::Types::TypeDecorator::AUTOLOAD at line 206 of MooseX/Types/TypeDecorator.pm, avg 937µs/call | ||||
| 317 | 25 | 268µs | my ($self, %opts) = @_; | ||
| 318 | 25 | 84µs | my $class = ref $self; | ||
| 319 | 25 | 611µs | 25 | 14.0ms | return $class->new(%opts, parent => $self); # spent 14.0ms making 25 calls to Moose::Meta::TypeConstraint::new, avg 560µs/call |
| 320 | } | ||||
| 321 | |||||
| 322 | 1 | 78µs | 1; | ||
| 323 | |||||
| 324 | __END__ |