| Filename | /home/doy/coding/src/Moose/blib/lib//Moose/Meta/TypeConstraint.pm |
| Statements | Executed 3323 statements in 50.9ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 87 | 2 | 1 | 8.90ms | 20.1ms | Moose::Meta::TypeConstraint::equals |
| 780 | 15 | 6 | 6.85ms | 6.85ms | Moose::Meta::TypeConstraint::__ANON__[:10] |
| 25 | 1 | 1 | 4.92ms | 29.7ms | Moose::Meta::TypeConstraint::is_subtype_of |
| 102 | 1 | 1 | 4.38ms | 15.2ms | Moose::Meta::TypeConstraint::_actually_compile_type_constraint |
| 108 | 4 | 4 | 3.85ms | 21.1ms | Moose::Meta::TypeConstraint::compile_type_constraint |
| 38 | 8 | 4 | 3.41ms | 55.9ms | Moose::Meta::TypeConstraint::new |
| 174 | 1 | 1 | 2.89ms | 3.62ms | Moose::Meta::TypeConstraint::__ANON__[:8] |
| 86 | 1 | 1 | 2.66ms | 3.63ms | Moose::Meta::TypeConstraint::_compile_hand_optimized_type_constraint |
| 15 | 1 | 1 | 2.00ms | 5.40ms | Moose::Meta::TypeConstraint::_compile_subtype |
| 15 | 1 | 1 | 1.63ms | 2.46ms | Moose::Meta::TypeConstraint::_collect_all_parents |
| 1 | 1 | 1 | 1.51ms | 5.52ms | Moose::Meta::TypeConstraint::BEGIN@6 |
| 87 | 2 | 1 | 954µs | 954µs | Moose::Meta::TypeConstraint::__ANON__[:32] |
| 17 | 1 | 1 | 632µs | 7.43ms | Moose::Meta::TypeConstraint::create_child_type |
| 9 | 1 | 1 | 367µs | 1.00ms | Moose::Meta::TypeConstraint::check |
| 2 | 1 | 1 | 122µs | 730µs | Moose::Meta::TypeConstraint::is_a_type_of |
| 1 | 1 | 1 | 77µs | 338µs | Moose::Meta::TypeConstraint::BEGIN@8 |
| 1 | 1 | 1 | 72µs | 98µs | Moose::Meta::TypeConstraint::_compile_type |
| 1 | 1 | 1 | 70µs | 88µs | Moose::Meta::TypeConstraint::BEGIN@4 |
| 1 | 1 | 1 | 41µs | 236µs | Moose::Meta::TypeConstraint::BEGIN@13 |
| 1 | 1 | 1 | 39µs | 170µs | Moose::Meta::TypeConstraint::BEGIN@14 |
| 1 | 1 | 1 | 39µs | 108µs | Moose::Meta::TypeConstraint::BEGIN@5 |
| 1 | 1 | 1 | 37µs | 267µ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 | 96µs | 2 | 106µs | # spent 88µs (70+18) within Moose::Meta::TypeConstraint::BEGIN@4 which was called:
# once (70µs+18µs) by Moose::BEGIN@20 at line 4 # spent 88µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@4
# spent 18µs making 1 call to strict::import |
| 5 | 3 | 92µs | 2 | 176µs | # spent 108µs (39+69) within Moose::Meta::TypeConstraint::BEGIN@5 which was called:
# once (39µs+69µs) by Moose::BEGIN@20 at line 5 # spent 108µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@5
# spent 69µs making 1 call to warnings::import |
| 6 | 3 | 651µs | 2 | 8.72ms | # spent 5.52ms (1.51+4.02) within Moose::Meta::TypeConstraint::BEGIN@6 which was called:
# once (1.51ms+4.02ms) by Moose::BEGIN@20 at line 6 # spent 5.52ms making 1 call to Moose::Meta::TypeConstraint::BEGIN@6
# spent 3.20ms making 1 call to metaclass::import |
| 7 | |||||
| 8 | 174 | 3.89ms | 174 | 727µs | # spent 3.62ms (2.89+728µs) within Moose::Meta::TypeConstraint::__ANON__[/home/doy/coding/src/Moose/blib/lib//Moose/Meta/TypeConstraint.pm:8] which was called 174 times, avg 21µs/call:
# 174 times (2.89ms+728µs) by Moose::Meta::TypeConstraint::equals at line 157, avg 21µs/call
# spent 338µs (77+262) within Moose::Meta::TypeConstraint::BEGIN@8 which was called:
# once (77µs+262µs) by Moose::BEGIN@20 at line 11 # spent 727µs making 174 calls to Scalar::Util::refaddr, avg 4µs/call |
| 9 | '""' => sub { shift->name }, # stringify to tc name | ||||
| 10 | 780 | 10.1ms | # spent 6.85ms within Moose::Meta::TypeConstraint::__ANON__[/home/doy/coding/src/Moose/blib/lib//Moose/Meta/TypeConstraint.pm:10] which was called 780 times, avg 9µs/call:
# 170 times (1.82ms+0s) by Moose::Meta::Method::Accessor::_eval_environment at line 46 of Moose/Meta/Method/Accessor.pm, avg 11µs/call
# 131 times (1.29ms+0s) by Moose::Util::TypeConstraints::find_or_parse_type_constraint at line 218 of Moose/Util/TypeConstraints.pm, avg 10µs/call
# 118 times (884µs+0s) by Moose::Util::TypeConstraints::find_or_create_isa_type_constraint at line 204 of Moose/Util/TypeConstraints.pm, avg 7µs/call
# 98 times (836µs+0s) by Moose::Meta::TypeConstraint::Registry::add_type_constraint at line 47 of Moose/Meta/TypeConstraint/Registry.pm, avg 9µs/call
# 87 times (674µs+0s) by Moose::Meta::TypeConstraint::equals at line 155, avg 8µs/call
# 85 times (622µs+0s) by Moose::Meta::TypeConstraint::is_subtype_of at line 190, avg 7µs/call
# 25 times (196µs+0s) by Moose::Meta::TypeConstraint::is_subtype_of at line 186, avg 8µs/call
# 17 times (119µs+0s) by Moose::Util::TypeConstraints::_create_type_constraint at line 547 of Moose/Util/TypeConstraints.pm, avg 7µs/call
# 15 times (118µs+0s) by Moose::Util::TypeConstraints::create_type_constraint_union at line 89 of Moose/Util/TypeConstraints.pm, avg 8µs/call
# 10 times (113µs+0s) by Moose::Util::TypeConstraints::find_or_create_does_type_constraint at line 210 of Moose/Util/TypeConstraints.pm, avg 11µs/call
# 10 times (73µs+0s) by Moose::Meta::TypeConstraint::Parameterizable::parameterize at line 58 of Moose/Meta/TypeConstraint/Parameterizable.pm, avg 7µs/call
# 8 times (58µs+0s) by Moose::Meta::Method::Accessor::Native::Collection::_tc_member_type at line 42 of Moose/Meta/Method/Accessor/Native/Collection.pm, avg 7µs/call
# 2 times (15µs+0s) by Moose::Meta::Method::Accessor::Native::Collection::_tc_member_type at line 39 of Moose/Meta/Method/Accessor/Native/Collection.pm, avg 8µs/call
# 2 times (15µs+0s) by Moose::Meta::TypeConstraint::is_a_type_of at line 178, avg 7µs/call
# 2 times (14µs+0s) by Moose::Util::TypeConstraints::find_or_create_type_constraint at line 176 of Moose/Util/TypeConstraints.pm, avg 7µs/call | ||
| 11 | 3 | 171µs | 2 | 600µs | fallback => 1; # spent 338µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@8
# spent 262µs making 1 call to overload::import |
| 12 | |||||
| 13 | 3 | 115µs | 2 | 431µs | # spent 236µs (41+195) within Moose::Meta::TypeConstraint::BEGIN@13 which was called:
# once (41µs+195µs) by Moose::BEGIN@20 at line 13 # spent 236µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@13
# spent 195µs making 1 call to Exporter::import |
| 14 | 3 | 116µs | 2 | 302µs | # spent 170µs (39+131) within Moose::Meta::TypeConstraint::BEGIN@14 which was called:
# once (39µs+131µs) by Moose::BEGIN@20 at line 14 # spent 170µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@14
# spent 131µs making 1 call to Exporter::import |
| 15 | |||||
| 16 | 3 | 4.92ms | 2 | 497µs | # spent 267µs (37+230) within Moose::Meta::TypeConstraint::BEGIN@16 which was called:
# once (37µs+230µs) by Moose::BEGIN@20 at line 16 # spent 267µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@16
# spent 230µs making 1 call to base::import |
| 17 | |||||
| 18 | 1 | 5µs | our $VERSION = '1.19'; | ||
| 19 | 1 | 145µs | $VERSION = eval $VERSION; # spent 11µs executing statements in string eval | ||
| 20 | 1 | 4µs | our $AUTHORITY = 'cpan:STEVAN'; | ||
| 21 | |||||
| 22 | 1 | 28µs | 2 | 2.51ms | __PACKAGE__->meta->add_attribute('name' => (reader => 'name')); # spent 2.39ms making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 121µs making 1 call to Moose::Meta::TypeConstraint::meta |
| 23 | 1 | 23µs | 2 | 4.74ms | __PACKAGE__->meta->add_attribute('parent' => ( # spent 4.62ms making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 125µs making 1 call to Moose::Meta::TypeConstraint::meta |
| 24 | reader => 'parent', | ||||
| 25 | predicate => 'has_parent', | ||||
| 26 | )); | ||||
| 27 | |||||
| 28 | 1 | 14µs | my $null_constraint = sub { 1 }; | ||
| 29 | __PACKAGE__->meta->add_attribute('constraint' => ( | ||||
| 30 | reader => 'constraint', | ||||
| 31 | writer => '_set_constraint', | ||||
| 32 | 87 | 1.21ms | # spent 954µs within Moose::Meta::TypeConstraint::__ANON__[/home/doy/coding/src/Moose/blib/lib//Moose/Meta/TypeConstraint.pm:32] which was called 87 times, avg 11µs/call:
# 53 times (590µs+0s) by Moose::Meta::TypeConstraint::Parameterized::_new or Moose::Meta::TypeConstraint::Role::_new or Moose::Meta::TypeConstraint::Union::_new or Moose::Meta::TypeConstraint::_new at line 18 of generated method (unknown origin), avg 11µs/call
# 34 times (364µs+0s) by Moose::Meta::TypeConstraint::Class::_new at line 21 of generated method (unknown origin), avg 11µs/call | ||
| 33 | 1 | 46µs | 2 | 4.54ms | )); # spent 4.41ms making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 127µs making 1 call to Moose::Meta::TypeConstraint::meta |
| 34 | 1 | 32µs | 2 | 4.40ms | __PACKAGE__->meta->add_attribute('message' => ( # spent 4.28ms making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 122µs making 1 call to Moose::Meta::TypeConstraint::meta |
| 35 | accessor => 'message', | ||||
| 36 | predicate => 'has_message' | ||||
| 37 | )); | ||||
| 38 | 1 | 33µs | 2 | 4.37ms | __PACKAGE__->meta->add_attribute('coercion' => ( # spent 4.24ms making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 121µs making 1 call to Moose::Meta::TypeConstraint::meta |
| 39 | accessor => 'coercion', | ||||
| 40 | predicate => 'has_coercion' | ||||
| 41 | )); | ||||
| 42 | |||||
| 43 | 1 | 34µs | 2 | 6.66ms | __PACKAGE__->meta->add_attribute('hand_optimized_type_constraint' => ( # spent 6.54ms making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 119µ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 | 31µs | 2 | 3.25ms | __PACKAGE__->meta->add_attribute('compiled_type_constraint' => ( # spent 3.13ms 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 | 24µs | 2 | 2.07ms | __PACKAGE__->meta->add_attribute('package_defined_in' => ( # spent 1.99ms making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 86µs making 1 call to Moose::Meta::TypeConstraint::meta |
| 61 | accessor => '_package_defined_in' | ||||
| 62 | )); | ||||
| 63 | |||||
| 64 | # spent 55.9ms (3.41+52.5) within Moose::Meta::TypeConstraint::new which was called 38 times, avg 1.47ms/call:
# 17 times (1.44ms+5.35ms) by Moose::Meta::TypeConstraint::create_child_type at line 319, avg 400µs/call
# 10 times (944µs+43.1ms) by Moose::Meta::TypeConstraint::Parameterizable::parameterize at line 69 of Moose/Meta/TypeConstraint/Parameterizable.pm, avg 4.40ms/call
# 6 times (543µs+1.80ms) by Moose::Meta::TypeConstraint::Union::new at line 29 of Moose/Meta/TypeConstraint/Union.pm, avg 391µs/call
# once (97µs+697µs) by Moose::Meta::Attribute::BEGIN@20 at line 847 of Moose/Util/TypeConstraints.pm
# once (116µs+602µs) by Moose::Meta::Attribute::BEGIN@20 at line 788 of Moose/Util/TypeConstraints.pm
# once (102µs+556µs) by Moose::Util::TypeConstraints::_create_type_constraint at line 557 of Moose/Util/TypeConstraints.pm
# once (81µs+235µs) by Moose::Meta::Attribute::BEGIN@20 at line 830 of Moose/Util/TypeConstraints.pm
# once (83µs+217µs) by Moose::Meta::Attribute::BEGIN@20 at line 809 of Moose/Util/TypeConstraints.pm | ||||
| 65 | 266 | 3.23ms | my $class = shift; | ||
| 66 | my ($first, @rest) = @_; | ||||
| 67 | my %args = ref $first ? %$first : $first ? ($first, @rest) : (); | ||||
| 68 | $args{name} = $args{name} ? "$args{name}" : "__ANON__"; | ||||
| 69 | |||||
| 70 | 38 | 5.44ms | my $self = $class->_new(%args); # spent 1.92ms making 10 calls to Moose::Meta::TypeConstraint::Parameterized::_new, avg 192µs/call
# spent 1.80ms making 18 calls to Moose::Meta::TypeConstraint::_new, avg 100µs/call
# spent 1.05ms making 6 calls to Moose::Meta::TypeConstraint::Union::_new, avg 176µs/call
# spent 656µs making 4 calls to Moose::Meta::TypeConstraint::Parameterizable::_new, avg 164µs/call | ||
| 71 | 76 | 47.1ms | $self->compile_type_constraint() # spent 41.0ms making 10 calls to Moose::Meta::TypeConstraint::Parameterized::compile_type_constraint, avg 4.10ms/call
# spent 5.63ms making 28 calls to Moose::Meta::TypeConstraint::compile_type_constraint, avg 201µs/call
# spent 439µs making 38 calls to Moose::Meta::TypeConstraint::_has_compiled_type_constraint, avg 12µs/call | ||
| 72 | unless $self->_has_compiled_type_constraint; | ||||
| 73 | 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 1.00ms (367µs+635µs) within Moose::Meta::TypeConstraint::check which was called 9 times, avg 111µs/call:
# 9 times (367µs+635µs) by Moose::Meta::Attribute::verify_against_type_constraint at line 1141 of Moose/Meta/Attribute.pm, avg 111µs/call | ||||
| 113 | 27 | 321µs | my ($self, @args) = @_; | ||
| 114 | 9 | 110µs | my $constraint_subref = $self->_compiled_type_constraint; # spent 110µs making 9 calls to Moose::Meta::TypeConstraint::_compiled_type_constraint, avg 12µs/call | ||
| 115 | 9 | 525µs | return $constraint_subref->(@args) ? 1 : undef; # spent 403µs making 5 calls to Moose::Meta::TypeConstraint::Bool, avg 81µs/call
# spent 92µs making 2 calls to Moose::Util::TypeConstraints::OptimizedConstraints::Int, avg 46µs/call
# spent 30µs making 2 calls to Moose::Util::TypeConstraints::OptimizedConstraints::Str, avg 15µ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 20.1ms (8.90+11.2) within Moose::Meta::TypeConstraint::equals which was called 87 times, avg 231µs/call:
# 85 times (8.75ms+11.0ms) by Moose::Meta::TypeConstraint::is_subtype_of at line 191, avg 232µs/call
# 2 times (149µs+213µs) by Moose::Meta::TypeConstraint::is_a_type_of at line 180, avg 181µs/call | ||||
| 153 | 411 | 5.82ms | my ( $self, $type_or_name ) = @_; | ||
| 154 | |||||
| 155 | 1 | 247µs | 174 | 4.05ms | my $other = Moose::Util::TypeConstraints::find_type_constraint($type_or_name) or return; # spent 3.37ms making 87 calls to Moose::Util::TypeConstraints::find_type_constraint, avg 39µs/call
# spent 674µs making 87 calls to Moose::Meta::TypeConstraint::__ANON__[Moose/Meta/TypeConstraint.pm:10], avg 8µs/call |
| 156 | |||||
| 157 | 1 | 1.19ms | 174 | 3.62ms | return 1 if $self == $other; # spent 3.62ms making 174 calls to Moose::Meta::TypeConstraint::__ANON__[Moose/Meta/TypeConstraint.pm:8], avg 21µs/call |
| 158 | |||||
| 159 | 165 | 1.81ms | if ( $self->has_hand_optimized_type_constraint and $other->has_hand_optimized_type_constraint ) { # spent 1.13ms making 105 calls to Moose::Meta::TypeConstraint::has_hand_optimized_type_constraint, avg 11µs/call
# spent 679µs making 60 calls to Moose::Meta::TypeConstraint::hand_optimized_type_constraint, avg 11µs/call | ||
| 160 | return 1 if $self->hand_optimized_type_constraint == $other->hand_optimized_type_constraint; | ||||
| 161 | } | ||||
| 162 | |||||
| 163 | 150 | 1.74ms | return unless $self->constraint == $other->constraint; # spent 1.74ms making 150 calls to Moose::Meta::TypeConstraint::constraint, avg 12µ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 730µs (122+608) within Moose::Meta::TypeConstraint::is_a_type_of which was called 2 times, avg 365µs/call:
# 2 times (122µs+608µs) by Moose::Meta::Attribute::Native::Trait::_check_helper_type at line 96 of Moose/Meta/Attribute/Native/Trait.pm, avg 365µs/call | ||||
| 176 | 6 | 108µs | my ($self, $type_or_name) = @_; | ||
| 177 | |||||
| 178 | 1 | 6µs | 4 | 245µs | my $type = Moose::Util::TypeConstraints::find_type_constraint($type_or_name) or return; # spent 230µs making 2 calls to Moose::Util::TypeConstraints::find_type_constraint, avg 115µs/call
# spent 15µs making 2 calls to Moose::Meta::TypeConstraint::__ANON__[Moose/Meta/TypeConstraint.pm:10], avg 7µs/call |
| 179 | |||||
| 180 | 2 | 362µs | ($self->equals($type) || $self->is_subtype_of($type)); # spent 362µs making 2 calls to Moose::Meta::TypeConstraint::equals, avg 181µs/call | ||
| 181 | } | ||||
| 182 | |||||
| 183 | # spent 29.7ms (4.92+24.8) within Moose::Meta::TypeConstraint::is_subtype_of which was called 25 times, avg 1.19ms/call:
# 25 times (4.92ms+24.8ms) by Moose::Meta::TypeConstraint::Parameterizable::generate_constraint_for at line 25 of Moose/Meta/TypeConstraint/Parameterizable.pm, avg 1.19ms/call | ||||
| 184 | 275 | 3.61ms | my ($self, $type_or_name) = @_; | ||
| 185 | |||||
| 186 | 1 | 78µs | 50 | 3.31ms | my $type = Moose::Util::TypeConstraints::find_type_constraint($type_or_name) or return; # spent 3.12ms making 25 calls to Moose::Util::TypeConstraints::find_type_constraint, avg 125µs/call
# spent 196µs making 25 calls to Moose::Meta::TypeConstraint::__ANON__[Moose/Meta/TypeConstraint.pm:10], avg 8µs/call |
| 187 | |||||
| 188 | my $current = $self; | ||||
| 189 | |||||
| 190 | 1 | 222µs | 185 | 1.73ms | while (my $parent = $current->parent) { # spent 1.11ms making 100 calls to Moose::Meta::TypeConstraint::parent, avg 11µs/call
# spent 622µs making 85 calls to Moose::Meta::TypeConstraint::__ANON__[Moose/Meta/TypeConstraint.pm:10], avg 7µs/call |
| 191 | 85 | 19.7ms | return 1 if $parent->equals($type); # spent 19.7ms making 85 calls to Moose::Meta::TypeConstraint::equals, avg 232µs/call | ||
| 192 | $current = $parent; | ||||
| 193 | } | ||||
| 194 | |||||
| 195 | return 0; | ||||
| 196 | } | ||||
| 197 | |||||
| 198 | ## compiling the type constraint | ||||
| 199 | |||||
| 200 | # spent 21.1ms (3.85+17.2) within Moose::Meta::TypeConstraint::compile_type_constraint which was called 108 times, avg 195µs/call:
# 36 times (1.28ms+3.88ms) by Moose::Meta::TypeConstraint::Role::new at line 27 of Moose/Meta/TypeConstraint/Role.pm, avg 143µs/call
# 34 times (1.22ms+3.73ms) by Moose::Meta::TypeConstraint::Class::new at line 27 of Moose/Meta/TypeConstraint/Class.pm, avg 145µs/call
# 28 times (998µs+4.63ms) by Moose::Meta::TypeConstraint::new at line 71, avg 201µs/call
# 10 times (355µs+4.98ms) by Moose::Meta::TypeConstraint::Parameterized::compile_type_constraint at line 54 of Moose/Meta/TypeConstraint/Parameterized.pm, avg 533µs/call | ||||
| 201 | 216 | 3.56ms | my $self = shift; | ||
| 202 | 216 | 17.2ms | $self->_compiled_type_constraint($self->_actually_compile_type_constraint); # spent 15.2ms making 102 calls to Moose::Meta::TypeConstraint::_actually_compile_type_constraint, avg 149µs/call
# spent 1.73ms making 108 calls to Moose::Meta::TypeConstraint::_compiled_type_constraint, avg 16µs/call
# spent 341µs making 6 calls to Moose::Meta::TypeConstraint::Union::_actually_compile_type_constraint, avg 57µs/call | ||
| 203 | } | ||||
| 204 | |||||
| 205 | ## type compilers ... | ||||
| 206 | |||||
| 207 | # spent 15.2ms (4.38+10.8) within Moose::Meta::TypeConstraint::_actually_compile_type_constraint which was called 102 times, avg 149µs/call:
# 102 times (4.38ms+10.8ms) by Moose::Meta::TypeConstraint::compile_type_constraint at line 202, avg 149µs/call | ||||
| 208 | 253 | 3.70ms | my $self = shift; | ||
| 209 | |||||
| 210 | 188 | 4.82ms | return $self->_compile_hand_optimized_type_constraint # spent 3.63ms making 86 calls to Moose::Meta::TypeConstraint::_compile_hand_optimized_type_constraint, avg 42µs/call
# spent 1.19ms making 102 calls to Moose::Meta::TypeConstraint::has_hand_optimized_type_constraint, avg 12µs/call | ||
| 211 | if $self->has_hand_optimized_type_constraint; | ||||
| 212 | |||||
| 213 | 16 | 266µs | my $check = $self->constraint; # spent 266µs making 16 calls to Moose::Meta::TypeConstraint::constraint, avg 17µs/call | ||
| 214 | 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 | 31 | 5.59ms | return $self->_compile_subtype($check) # spent 5.40ms making 15 calls to Moose::Meta::TypeConstraint::_compile_subtype, avg 360µs/call
# spent 192µs making 16 calls to Moose::Meta::TypeConstraint::has_parent, avg 12µs/call | ||
| 222 | if $self->has_parent; | ||||
| 223 | |||||
| 224 | 1 | 98µs | return $self->_compile_type($check); # spent 98µs making 1 call to Moose::Meta::TypeConstraint::_compile_type | ||
| 225 | } | ||||
| 226 | |||||
| 227 | # spent 3.63ms (2.66+961µs) within Moose::Meta::TypeConstraint::_compile_hand_optimized_type_constraint which was called 86 times, avg 42µs/call:
# 86 times (2.66ms+961µs) by Moose::Meta::TypeConstraint::_actually_compile_type_constraint at line 210, avg 42µs/call | ||||
| 228 | 344 | 2.52ms | my $self = shift; | ||
| 229 | |||||
| 230 | 86 | 961µs | my $type_constraint = $self->hand_optimized_type_constraint; # spent 961µs making 86 calls to Moose::Meta::TypeConstraint::hand_optimized_type_constraint, avg 11µs/call | ||
| 231 | |||||
| 232 | 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 | return $type_constraint; | ||||
| 239 | } | ||||
| 240 | |||||
| 241 | # spent 5.40ms (2.00+3.40) within Moose::Meta::TypeConstraint::_compile_subtype which was called 15 times, avg 360µs/call:
# 15 times (2.00ms+3.40ms) by Moose::Meta::TypeConstraint::_actually_compile_type_constraint at line 221, avg 360µs/call | ||||
| 242 | 173 | 2.12ms | my ($self, $check) = @_; | ||
| 243 | |||||
| 244 | # gather all the parent constraintss in order | ||||
| 245 | my @parents; | ||||
| 246 | my $optimized_parent; | ||||
| 247 | 15 | 2.46ms | foreach my $parent ($self->_collect_all_parents) { # spent 2.46ms making 15 calls to Moose::Meta::TypeConstraint::_collect_all_parents, avg 164µ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 | 19 | 265µs | if ($parent->has_hand_optimized_type_constraint) { # spent 265µs making 19 calls to Moose::Meta::TypeConstraint::has_hand_optimized_type_constraint, avg 14µs/call | ||
| 251 | 10 | 123µs | push @parents => $optimized_parent = $parent->hand_optimized_type_constraint; # spent 123µs making 10 calls to Moose::Meta::TypeConstraint::hand_optimized_type_constraint, avg 12µs/call | ||
| 252 | last; | ||||
| 253 | } | ||||
| 254 | else { | ||||
| 255 | 9 | 99µs | push @parents => $parent->constraint; # spent 99µs making 9 calls to Moose::Meta::TypeConstraint::constraint, avg 11µs/call | ||
| 256 | } | ||||
| 257 | } | ||||
| 258 | |||||
| 259 | @parents = grep { $_ != $null_constraint } reverse @parents; | ||||
| 260 | |||||
| 261 | 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 | if ( $check == $null_constraint ) { | ||||
| 267 | return $optimized_parent; | ||||
| 268 | } else { | ||||
| 269 | return subname($self->name, sub { | ||||
| 270 | return undef unless $optimized_parent->($_[0]); | ||||
| 271 | my (@args) = @_; | ||||
| 272 | local $_ = $args[0]; | ||||
| 273 | $check->(@args); | ||||
| 274 | 20 | 325µs | }); # spent 187µs making 10 calls to Sub::Name::subname, avg 19µs/call
# spent 139µs making 10 calls to Moose::Meta::TypeConstraint::name, avg 14µs/call | ||
| 275 | } | ||||
| 276 | } else { | ||||
| 277 | # general case, check all the constraints, from the first parent to ourselves | ||||
| 278 | my @checks = @parents; | ||||
| 279 | push @checks, $check if $check != $null_constraint; | ||||
| 280 | return subname($self->name => sub { | ||||
| 281 | 30 | 265µs | my (@args) = @_; | ||
| 282 | local $_ = $args[0]; | ||||
| 283 | foreach my $check (@checks) { | ||||
| 284 | 10 | 115µs | return undef unless $check->(@args); # spent 68µs making 5 calls to Moose::Util::TypeConstraints::__ANON__[Moose/Util/TypeConstraints.pm:714], avg 14µs/call
# spent 47µs making 5 calls to Moose::Util::TypeConstraints::__ANON__[Moose/Util/TypeConstraints.pm:707], avg 9µs/call | ||
| 285 | } | ||||
| 286 | return 1; | ||||
| 287 | 10 | 134µs | }); # spent 68µs making 5 calls to Sub::Name::subname, avg 14µs/call
# spent 66µs making 5 calls to Moose::Meta::TypeConstraint::name, avg 13µs/call | ||
| 288 | } | ||||
| 289 | } | ||||
| 290 | |||||
| 291 | # spent 98µs (72+27) within Moose::Meta::TypeConstraint::_compile_type which was called:
# once (72µs+27µs) by Moose::Meta::TypeConstraint::_actually_compile_type_constraint at line 224 | ||||
| 292 | 3 | 82µs | my ($self, $check) = @_; | ||
| 293 | |||||
| 294 | 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 | 2 | 26µs | }); # spent 14µ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 2.46ms (1.63+824µs) within Moose::Meta::TypeConstraint::_collect_all_parents which was called 15 times, avg 164µs/call:
# 15 times (1.63ms+824µs) by Moose::Meta::TypeConstraint::_compile_subtype at line 247, avg 164µs/call | ||||
| 306 | 193 | 1.40ms | my $self = shift; | ||
| 307 | my @parents; | ||||
| 308 | 15 | 172µs | my $current = $self->parent; # spent 172µs making 15 calls to Moose::Meta::TypeConstraint::parent, avg 11µs/call | ||
| 309 | while (defined $current) { | ||||
| 310 | push @parents => $current; | ||||
| 311 | 59 | 652µs | $current = $current->parent; # spent 652µs making 59 calls to Moose::Meta::TypeConstraint::parent, avg 11µs/call | ||
| 312 | } | ||||
| 313 | return @parents; | ||||
| 314 | } | ||||
| 315 | |||||
| 316 | # spent 7.43ms (632µs+6.80) within Moose::Meta::TypeConstraint::create_child_type which was called 17 times, avg 437µs/call:
# 17 times (632µs+6.80ms) by Moose::Util::TypeConstraints::_create_type_constraint at line 547 of Moose/Util/TypeConstraints.pm, avg 437µs/call | ||||
| 317 | 51 | 621µs | my ($self, %opts) = @_; | ||
| 318 | my $class = ref $self; | ||||
| 319 | 17 | 6.79ms | return $class->new(%opts, parent => $self); # spent 6.79ms making 17 calls to Moose::Meta::TypeConstraint::new, avg 400µs/call | ||
| 320 | } | ||||
| 321 | |||||
| 322 | 1 | 58µs | 1; | ||
| 323 | |||||
| 324 | __END__ |