| Filename | /home/doy/perl5/perlbrew/perls/perl-5.10.1/lib/site_perl/5.10.1/x86_64-linux/Moose/Meta/TypeConstraint.pm |
| Statements | Executed 4335 statements in 67.1ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1119 | 14 | 7 | 9.40ms | 9.40ms | Moose::Meta::TypeConstraint::__ANON__[:10] |
| 168 | 1 | 1 | 7.01ms | 23.3ms | Moose::Meta::TypeConstraint::_actually_compile_type_constraint |
| 168 | 5 | 5 | 6.02ms | 32.1ms | Moose::Meta::TypeConstraint::compile_type_constraint |
| 53 | 2 | 1 | 5.44ms | 12.1ms | Moose::Meta::TypeConstraint::equals |
| 147 | 1 | 1 | 4.74ms | 6.39ms | Moose::Meta::TypeConstraint::_compile_hand_optimized_type_constraint |
| 98 | 2 | 2 | 4.53ms | 13.1ms | Moose::Meta::TypeConstraint::check |
| 36 | 7 | 3 | 3.70ms | 42.8ms | Moose::Meta::TypeConstraint::new |
| 18 | 2 | 2 | 3.07ms | 17.8ms | Moose::Meta::TypeConstraint::is_subtype_of |
| 20 | 1 | 1 | 2.58ms | 7.44ms | Moose::Meta::TypeConstraint::_compile_subtype |
| 20 | 1 | 1 | 2.34ms | 3.57ms | Moose::Meta::TypeConstraint::_collect_all_parents |
| 1 | 1 | 1 | 2.31ms | 8.61ms | Moose::Meta::TypeConstraint::BEGIN@6 |
| 106 | 1 | 1 | 1.81ms | 2.31ms | Moose::Meta::TypeConstraint::__ANON__[:8] |
| 139 | 4 | 1 | 1.54ms | 1.54ms | Moose::Meta::TypeConstraint::__ANON__[:32] |
| 25 | 2 | 2 | 975µs | 14.7ms | Moose::Meta::TypeConstraint::create_child_type |
| 6 | 1 | 1 | 409µs | 3.49ms | Moose::Meta::TypeConstraint::is_a_type_of |
| 1 | 1 | 1 | 136µs | 162µs | Moose::Meta::TypeConstraint::BEGIN@4 |
| 1 | 1 | 1 | 93µs | 439µs | Moose::Meta::TypeConstraint::BEGIN@8 |
| 1 | 1 | 1 | 84µs | 109µs | Moose::Meta::TypeConstraint::_compile_type |
| 1 | 1 | 1 | 72µs | 164µs | Moose::Meta::TypeConstraint::BEGIN@5 |
| 1 | 1 | 1 | 57µs | 310µs | Moose::Meta::TypeConstraint::BEGIN@13 |
| 1 | 1 | 1 | 55µs | 378µs | Moose::Meta::TypeConstraint::BEGIN@16 |
| 1 | 1 | 1 | 53µs | 257µs | Moose::Meta::TypeConstraint::BEGIN@14 |
| 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 | 157µs | 2 | 188µs | # spent 162µs (136+26) within Moose::Meta::TypeConstraint::BEGIN@4 which was called:
# once (136µs+26µs) by Moose::BEGIN@20 at line 4 # spent 162µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@4
# spent 26µs making 1 call to strict::import |
| 5 | 3 | 157µs | 2 | 255µs | # spent 164µs (72+91) within Moose::Meta::TypeConstraint::BEGIN@5 which was called:
# once (72µs+91µs) by Moose::BEGIN@20 at line 5 # spent 164µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@5
# spent 91µs making 1 call to warnings::import |
| 6 | 3 | 962µs | 2 | 13.6ms | # spent 8.61ms (2.31+6.29) within Moose::Meta::TypeConstraint::BEGIN@6 which was called:
# once (2.31ms+6.29ms) by Moose::BEGIN@20 at line 6 # spent 8.61ms making 1 call to Moose::Meta::TypeConstraint::BEGIN@6
# spent 5.03ms making 1 call to metaclass::import |
| 7 | |||||
| 8 | 106 | 2.52ms | 106 | 498µs | # spent 439µs (93+346) within Moose::Meta::TypeConstraint::BEGIN@8 which was called:
# once (93µs+346µs) by Moose::BEGIN@20 at line 11
# spent 2.31ms (1.81+498µs) within Moose::Meta::TypeConstraint::__ANON__[/home/doy/perl5/perlbrew/perls/perl-5.10.1/lib/site_perl/5.10.1/x86_64-linux/Moose/Meta/TypeConstraint.pm:8] which was called 106 times, avg 22µs/call:
# 106 times (1.81ms+498µs) by Moose::Meta::TypeConstraint::equals at line 157, avg 22µs/call # spent 498µs making 106 calls to Scalar::Util::refaddr, avg 5µs/call |
| 9 | '""' => sub { shift->name }, # stringify to tc name | ||||
| 10 | 1119 | 14.4ms | # spent 9.40ms within Moose::Meta::TypeConstraint::__ANON__[/home/doy/perl5/perlbrew/perls/perl-5.10.1/lib/site_perl/5.10.1/x86_64-linux/Moose/Meta/TypeConstraint.pm:10] which was called 1119 times, avg 8µs/call:
# 639 times (5.35ms+0s) by MooseX::Types::Base::import at line 83 of MooseX/Types/Base.pm, avg 8µs/call
# 159 times (1.35ms+0s) by Moose::Meta::TypeConstraint::Registry::add_type_constraint at line 47 of Moose/Meta/TypeConstraint/Registry.pm, avg 8µs/call
# 59 times (532µs+0s) by MooseX::Types::TypeDecorator::new at line 76 of MooseX/Types/TypeDecorator.pm, avg 9µs/call
# 53 times (452µs+0s) by Moose::Meta::TypeConstraint::equals at line 155, avg 9µs/call
# 50 times (364µs+0s) by Moose::Meta::TypeConstraint::is_subtype_of at line 190, avg 7µs/call
# 44 times (402µ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 (248µs+0s) by Moose::Util::TypeConstraints::find_or_create_isa_type_constraint at line 204 of Moose/Util/TypeConstraints.pm, avg 8µs/call
# 24 times (270µs+0s) by Moose::Meta::Method::Accessor::_eval_environment at line 41 of Moose/Meta/Method/Accessor.pm, avg 11µs/call
# 18 times (144µs+0s) by Moose::Meta::TypeConstraint::is_subtype_of at line 186, avg 8µs/call
# 17 times (112µs+0s) by Moose::Util::TypeConstraints::_create_type_constraint at line 547 of Moose/Util/TypeConstraints.pm, avg 7µs/call
# 6 times (54µs+0s) by Moose::Meta::TypeConstraint::is_a_type_of at line 178, avg 9µs/call
# 6 times (47µs+0s) by Moose::Meta::TypeConstraint::Parameterizable::parameterize at line 58 of Moose/Meta/TypeConstraint/Parameterizable.pm, avg 8µs/call
# 6 times (43µs+0s) by Moose::Util::TypeConstraints::find_or_create_type_constraint at line 176 of Moose/Util/TypeConstraints.pm, avg 7µs/call
# 5 times (36µ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 | 317µs | 2 | 785µs | fallback => 1; # spent 439µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@8
# spent 346µs making 1 call to overload::import |
| 12 | |||||
| 13 | 3 | 172µs | 2 | 563µs | # spent 310µs (57+253) within Moose::Meta::TypeConstraint::BEGIN@13 which was called:
# once (57µs+253µs) by Moose::BEGIN@20 at line 13 # spent 310µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@13
# spent 253µs making 1 call to Exporter::import |
| 14 | 3 | 175µs | 2 | 462µs | # spent 257µs (53+205) within Moose::Meta::TypeConstraint::BEGIN@14 which was called:
# once (53µs+205µs) by Moose::BEGIN@20 at line 14 # spent 257µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@14
# spent 205µs making 1 call to Exporter::import |
| 15 | |||||
| 16 | 3 | 8.70ms | 2 | 702µs | # spent 378µs (55+324) within Moose::Meta::TypeConstraint::BEGIN@16 which was called:
# once (55µs+324µs) by Moose::BEGIN@20 at line 16 # spent 378µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@16
# spent 324µs making 1 call to base::import |
| 17 | |||||
| 18 | 1 | 7µs | our $VERSION = '1.19'; | ||
| 19 | 1 | 91µs | $VERSION = eval $VERSION; # spent 15µs executing statements in string eval | ||
| 20 | 1 | 6µs | our $AUTHORITY = 'cpan:STEVAN'; | ||
| 21 | |||||
| 22 | 1 | 34µs | 2 | 2.86ms | __PACKAGE__->meta->add_attribute('name' => (reader => 'name')); # spent 2.72ms making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 147µs making 1 call to Moose::Meta::TypeConstraint::meta |
| 23 | 1 | 23µs | 2 | 3.70ms | __PACKAGE__->meta->add_attribute('parent' => ( # spent 3.58ms making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 123µ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 | 139 | 2.10ms | # spent 1.54ms within Moose::Meta::TypeConstraint::__ANON__[/home/doy/perl5/perlbrew/perls/perl-5.10.1/lib/site_perl/5.10.1/x86_64-linux/Moose/Meta/TypeConstraint.pm:32] which was called 139 times, avg 11µs/call:
# 84 times (955µs+0s) by Moose::Meta::TypeConstraint::Role::_new at line 32 of (eval 76)[Class/MOP/Method/Generated.pm:53], avg 11µs/call
# 48 times (516µs+0s) by Moose::Meta::TypeConstraint::Class::_new or Moose::Meta::TypeConstraint::Enum::_new at line 35 of (eval 76)[Class/MOP/Method/Generated.pm:53], avg 11µs/call
# 6 times (61µs+0s) by Moose::Meta::TypeConstraint::Parameterized::_new at line 29 of (eval 76)[Class/MOP/Method/Generated.pm:53], avg 10µs/call
# once (9µs+0s) by Moose::Meta::TypeConstraint::_new at line 26 of (eval 76)[Class/MOP/Method/Generated.pm:53] | ||
| 33 | 1 | 31µs | 2 | 3.29ms | )); # spent 3.20ms making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 86µs making 1 call to Moose::Meta::TypeConstraint::meta |
| 34 | 1 | 24µs | 2 | 3.25ms | __PACKAGE__->meta->add_attribute('message' => ( # spent 3.16ms making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 85µs making 1 call to Moose::Meta::TypeConstraint::meta |
| 35 | accessor => 'message', | ||||
| 36 | predicate => 'has_message' | ||||
| 37 | )); | ||||
| 38 | 1 | 24µs | 2 | 3.21ms | __PACKAGE__->meta->add_attribute('coercion' => ( # spent 3.12ms making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 90µs making 1 call to Moose::Meta::TypeConstraint::meta |
| 39 | accessor => 'coercion', | ||||
| 40 | predicate => 'has_coercion' | ||||
| 41 | )); | ||||
| 42 | |||||
| 43 | 1 | 25µs | 2 | 3.88ms | __PACKAGE__->meta->add_attribute('hand_optimized_type_constraint' => ( # spent 3.80ms making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 85µ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 | 35µs | 2 | 4.89ms | __PACKAGE__->meta->add_attribute('compiled_type_constraint' => ( # spent 4.76ms making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 133µ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.14ms | __PACKAGE__->meta->add_attribute('package_defined_in' => ( # spent 2.04ms making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 91µs making 1 call to Moose::Meta::TypeConstraint::meta |
| 61 | accessor => '_package_defined_in' | ||||
| 62 | )); | ||||
| 63 | |||||
| 64 | # spent 42.8ms (3.70+39.1) within Moose::Meta::TypeConstraint::new which was called 36 times, avg 1.19ms/call:
# 25 times (2.51ms+11.3ms) by Moose::Meta::TypeConstraint::create_child_type at line 319, avg 551µs/call
# 6 times (721µs+25.7ms) by Moose::Meta::TypeConstraint::Parameterizable::parameterize at line 69 of Moose/Meta/TypeConstraint/Parameterizable.pm, avg 4.40ms/call
# once (81µs+627µs) by Moose::Meta::Attribute::BEGIN@20 at line 847 of Moose/Util/TypeConstraints.pm
# once (118µs+586µs) by Moose::Meta::Attribute::BEGIN@20 at line 788 of Moose/Util/TypeConstraints.pm
# once (104µs+555µs) by Moose::Util::TypeConstraints::_create_type_constraint at line 557 of Moose/Util/TypeConstraints.pm
# once (87µs+201µs) by Moose::Meta::Attribute::BEGIN@20 at line 809 of Moose/Util/TypeConstraints.pm
# once (82µs+197µs) by Moose::Meta::Attribute::BEGIN@20 at line 830 of Moose/Util/TypeConstraints.pm | ||||
| 65 | 252 | 3.24ms | my $class = shift; | ||
| 66 | my ($first, @rest) = @_; | ||||
| 67 | my %args = ref $first ? %$first : $first ? ($first, @rest) : (); | ||||
| 68 | 1 | 137µs | 16 | 792µs | $args{name} = $args{name} ? "$args{name}" : "__ANON__"; # spent 700µs making 8 calls to MooseX::Types::TypeDecorator::__ANON__[MooseX/Types/TypeDecorator.pm:26], avg 88µs/call
# spent 92µs making 8 calls to MooseX::Types::TypeDecorator::__ANON__[MooseX/Types/TypeDecorator.pm:27], avg 12µs/call |
| 69 | |||||
| 70 | 36 | 4.08ms | my $self = $class->_new(%args); # spent 2.17ms making 25 calls to Moose::Meta::TypeConstraint::_new, avg 87µs/call
# spent 988µs making 6 calls to Moose::Meta::TypeConstraint::Parameterized::_new, avg 165µs/call
# spent 921µs making 5 calls to Moose::Meta::TypeConstraint::Parameterizable::_new, avg 184µs/call | ||
| 71 | 72 | 34.3ms | $self->compile_type_constraint() # spent 24.6ms making 6 calls to Moose::Meta::TypeConstraint::Parameterized::compile_type_constraint, avg 4.11ms/call
# spent 9.20ms making 30 calls to Moose::Meta::TypeConstraint::compile_type_constraint, avg 307µs/call
# spent 415µs making 36 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 13.1ms (4.53+8.58) within Moose::Meta::TypeConstraint::check which was called 98 times, avg 134µs/call:
# 92 times (4.26ms+7.74ms) by Moose::Meta::Attribute::verify_against_type_constraint at line 896 of Moose/Meta/Attribute.pm, avg 131µs/call
# 6 times (262µs+834µs) by MooseX::Types::TypeDecorator::AUTOLOAD at line 206 of MooseX/Types/TypeDecorator.pm, avg 183µs/call | ||||
| 113 | 294 | 4.03ms | my ($self, @args) = @_; | ||
| 114 | 98 | 1.44ms | my $constraint_subref = $self->_compiled_type_constraint; # spent 1.44ms making 98 calls to Moose::Meta::TypeConstraint::_compiled_type_constraint, avg 15µs/call | ||
| 115 | 98 | 7.14ms | return $constraint_subref->(@args) ? 1 : undef; # spent 5.77ms making 84 calls to Moose::Meta::TypeConstraint::Class::__ANON__[Moose/Meta/TypeConstraint/Class.pm:38], avg 69µs/call
# spent 748µs making 6 calls to Moose::Meta::TypeConstraint::ArrayRef[Str], avg 125µs/call
# spent 541µs making 6 calls to Moose::Meta::TypeConstraint::Bool, avg 90µ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.1ms (5.44+6.71) within Moose::Meta::TypeConstraint::equals which was called 53 times, avg 229µs/call:
# 50 times (5.18ms+6.37ms) by Moose::Meta::TypeConstraint::is_subtype_of at line 191, avg 231µs/call
# 3 times (259µs+342µs) by Moose::Meta::TypeConstraint::is_a_type_of at line 180, avg 200µs/call | ||||
| 153 | 241 | 3.54ms | my ( $self, $type_or_name ) = @_; | ||
| 154 | |||||
| 155 | 1 | 150µs | 106 | 2.46ms | my $other = Moose::Util::TypeConstraints::find_type_constraint($type_or_name) or return; # spent 2.01ms making 53 calls to Moose::Util::TypeConstraints::find_type_constraint, avg 38µs/call
# spent 452µs making 53 calls to Moose::Meta::TypeConstraint::__ANON__[Moose/Meta/TypeConstraint.pm:10], avg 9µs/call |
| 156 | |||||
| 157 | 1 | 792µs | 106 | 2.31ms | return 1 if $self == $other; # spent 2.31ms making 106 calls to Moose::Meta::TypeConstraint::__ANON__[Moose/Meta/TypeConstraint.pm:8], avg 22µs/call |
| 158 | |||||
| 159 | 92 | 1.05ms | if ( $self->has_hand_optimized_type_constraint and $other->has_hand_optimized_type_constraint ) { # spent 595µs making 58 calls to Moose::Meta::TypeConstraint::has_hand_optimized_type_constraint, avg 10µs/call
# spent 450µs making 34 calls to Moose::Meta::TypeConstraint::hand_optimized_type_constraint, avg 13µs/call | ||
| 160 | return 1 if $self->hand_optimized_type_constraint == $other->hand_optimized_type_constraint; | ||||
| 161 | } | ||||
| 162 | |||||
| 163 | 82 | 895µs | return unless $self->constraint == $other->constraint; # spent 895µ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.49ms (409µs+3.08) within Moose::Meta::TypeConstraint::is_a_type_of which was called 6 times, avg 582µs/call:
# 6 times (409µs+3.08ms) by MooseX::Types::TypeDecorator::AUTOLOAD at line 206 of MooseX/Types/TypeDecorator.pm, avg 582µs/call | ||||
| 176 | 18 | 300µs | my ($self, $type_or_name) = @_; | ||
| 177 | |||||
| 178 | 1 | 19µs | 12 | 917µs | my $type = Moose::Util::TypeConstraints::find_type_constraint($type_or_name) or return; # spent 862µs making 6 calls to Moose::Util::TypeConstraints::find_type_constraint, avg 144µs/call
# spent 54µs making 6 calls to Moose::Meta::TypeConstraint::__ANON__[Moose/Meta/TypeConstraint.pm:10], avg 9µs/call |
| 179 | |||||
| 180 | 10 | 2.16ms | ($self->equals($type) || $self->is_subtype_of($type)); # spent 1.28ms making 4 calls to Moose::Meta::TypeConstraint::is_subtype_of, avg 319µs/call
# spent 601µs making 3 calls to Moose::Meta::TypeConstraint::equals, avg 200µs/call
# spent 285µs making 3 calls to Moose::Meta::TypeConstraint::Parameterized::equals, avg 95µs/call | ||
| 181 | } | ||||
| 182 | |||||
| 183 | # spent 17.8ms (3.07+14.7) within Moose::Meta::TypeConstraint::is_subtype_of which was called 18 times, avg 989µs/call:
# 14 times (2.74ms+13.8ms) by Moose::Meta::TypeConstraint::Parameterizable::generate_constraint_for at line 25 of Moose/Meta/TypeConstraint/Parameterizable.pm, avg 1.18ms/call
# 4 times (332µs+946µs) by Moose::Meta::TypeConstraint::is_a_type_of at line 180, avg 319µs/call | ||||
| 184 | 80 | 1.54ms | my ($self, $type_or_name) = @_; | ||
| 185 | |||||
| 186 | 1 | 56µs | 36 | 2.16ms | my $type = Moose::Util::TypeConstraints::find_type_constraint($type_or_name) or return; # spent 2.02ms making 18 calls to Moose::Util::TypeConstraints::find_type_constraint, avg 112µs/call
# spent 144µs making 18 calls to Moose::Meta::TypeConstraint::__ANON__[Moose/Meta/TypeConstraint.pm:10], avg 8µs/call |
| 187 | |||||
| 188 | my $current = $self; | ||||
| 189 | |||||
| 190 | 90 | 903µs | 108 | 1.02ms | while (my $parent = $current->parent) { # spent 659µs making 58 calls to Moose::Meta::TypeConstraint::parent, avg 11µs/call
# spent 364µs making 50 calls to Moose::Meta::TypeConstraint::__ANON__[Moose/Meta/TypeConstraint.pm:10], avg 7µs/call |
| 191 | 50 | 11.5ms | return 1 if $parent->equals($type); # spent 11.5ms making 50 calls to Moose::Meta::TypeConstraint::equals, avg 231µs/call | ||
| 192 | $current = $parent; | ||||
| 193 | } | ||||
| 194 | |||||
| 195 | return 0; | ||||
| 196 | } | ||||
| 197 | |||||
| 198 | ## compiling the type constraint | ||||
| 199 | |||||
| 200 | # spent 32.1ms (6.02+26.1) within Moose::Meta::TypeConstraint::compile_type_constraint which was called 168 times, avg 191µs/call:
# 84 times (3.07ms+8.97ms) by Moose::Meta::TypeConstraint::Role::new at line 27 of Moose/Meta/TypeConstraint/Role.pm, avg 143µs/call
# 47 times (1.68ms+5.19ms) by Moose::Meta::TypeConstraint::Class::new at line 27 of Moose/Meta/TypeConstraint/Class.pm, avg 146µs/call
# 30 times (993µs+8.21ms) by Moose::Meta::TypeConstraint::new at line 71, avg 307µs/call
# 6 times (224µs+2.98ms) by Moose::Meta::TypeConstraint::Parameterized::compile_type_constraint at line 54 of Moose/Meta/TypeConstraint/Parameterized.pm, avg 534µs/call
# once (52µs+745µs) by Moose::Meta::TypeConstraint::Enum::new at line 42 of Moose/Meta/TypeConstraint/Enum.pm | ||||
| 201 | 336 | 5.51ms | my $self = shift; | ||
| 202 | 336 | 26.1ms | $self->_compiled_type_constraint($self->_actually_compile_type_constraint); # spent 23.3ms making 168 calls to Moose::Meta::TypeConstraint::_actually_compile_type_constraint, avg 139µs/call
# spent 2.75ms making 168 calls to Moose::Meta::TypeConstraint::_compiled_type_constraint, avg 16µs/call | ||
| 203 | } | ||||
| 204 | |||||
| 205 | ## type compilers ... | ||||
| 206 | |||||
| 207 | # spent 23.3ms (7.01+16.3) within Moose::Meta::TypeConstraint::_actually_compile_type_constraint which was called 168 times, avg 139µs/call:
# 168 times (7.01ms+16.3ms) by Moose::Meta::TypeConstraint::compile_type_constraint at line 202, avg 139µs/call | ||||
| 208 | 400 | 6.15ms | my $self = shift; | ||
| 209 | |||||
| 210 | 315 | 8.21ms | return $self->_compile_hand_optimized_type_constraint # spent 6.39ms making 147 calls to Moose::Meta::TypeConstraint::_compile_hand_optimized_type_constraint, avg 43µs/call
# spent 1.82ms making 168 calls to Moose::Meta::TypeConstraint::has_hand_optimized_type_constraint, avg 11µs/call | ||
| 211 | if $self->has_hand_optimized_type_constraint; | ||||
| 212 | |||||
| 213 | 21 | 324µs | my $check = $self->constraint; # spent 259µ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 | 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 | 41 | 7.69ms | return $self->_compile_subtype($check) # spent 7.44ms making 20 calls to Moose::Meta::TypeConstraint::_compile_subtype, avg 372µs/call
# spent 250µs making 21 calls to Moose::Meta::TypeConstraint::has_parent, avg 12µs/call | ||
| 222 | if $self->has_parent; | ||||
| 223 | |||||
| 224 | 1 | 109µs | return $self->_compile_type($check); # spent 109µs making 1 call to Moose::Meta::TypeConstraint::_compile_type | ||
| 225 | } | ||||
| 226 | |||||
| 227 | # spent 6.39ms (4.74+1.65) within Moose::Meta::TypeConstraint::_compile_hand_optimized_type_constraint which was called 147 times, avg 43µs/call:
# 147 times (4.74ms+1.65ms) by Moose::Meta::TypeConstraint::_actually_compile_type_constraint at line 210, avg 43µs/call | ||||
| 228 | 588 | 4.26ms | my $self = shift; | ||
| 229 | |||||
| 230 | 147 | 1.65ms | my $type_constraint = $self->hand_optimized_type_constraint; # spent 1.65ms making 147 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 7.44ms (2.58+4.86) within Moose::Meta::TypeConstraint::_compile_subtype which was called 20 times, avg 372µs/call:
# 20 times (2.58ms+4.86ms) by Moose::Meta::TypeConstraint::_actually_compile_type_constraint at line 221, avg 372µs/call | ||||
| 242 | 120 | 674µs | my ($self, $check) = @_; | ||
| 243 | |||||
| 244 | # gather all the parent constraintss in order | ||||
| 245 | my @parents; | ||||
| 246 | my $optimized_parent; | ||||
| 247 | 20 | 3.57ms | foreach my $parent ($self->_collect_all_parents) { # spent 3.57ms making 20 calls to Moose::Meta::TypeConstraint::_collect_all_parents, avg 178µ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 | 62 | 677µs | 24 | 248µs | if ($parent->has_hand_optimized_type_constraint) { # spent 248µs making 24 calls to Moose::Meta::TypeConstraint::has_hand_optimized_type_constraint, avg 10µs/call |
| 251 | 14 | 172µs | push @parents => $optimized_parent = $parent->hand_optimized_type_constraint; # spent 172µs making 14 calls to Moose::Meta::TypeConstraint::hand_optimized_type_constraint, avg 12µs/call | ||
| 252 | last; | ||||
| 253 | } | ||||
| 254 | else { | ||||
| 255 | 10 | 106µs | push @parents => $parent->constraint; # spent 106µs making 10 calls to Moose::Meta::TypeConstraint::constraint, avg 11µs/call | ||
| 256 | } | ||||
| 257 | } | ||||
| 258 | |||||
| 259 | @parents = grep { $_ != $null_constraint } reverse @parents; | ||||
| 260 | |||||
| 261 | 32 | 417µ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 | 874µs | if ( $check == $null_constraint ) { | ||
| 267 | return $optimized_parent; | ||||
| 268 | } else { | ||||
| 269 | return subname($self->name, sub { | ||||
| 270 | 24 | 306µs | 6 | 75µs | return undef unless $optimized_parent->($_[0]); # spent 75µs making 6 calls to Moose::Util::TypeConstraints::OptimizedConstraints::ArrayRef, avg 12µs/call |
| 271 | my (@args) = @_; | ||||
| 272 | local $_ = $args[0]; | ||||
| 273 | 6 | 354µs | $check->(@args); # spent 354µs making 6 calls to Moose::Util::TypeConstraints::__ANON__[Moose/Util/TypeConstraints.pm:806], avg 59µs/call | ||
| 274 | 1 | 36µs | 29 | 706µs | }); # spent 414µs making 14 calls to Sub::Name::subname, avg 30µs/call
# spent 186µs making 14 calls to Moose::Meta::TypeConstraint::name, avg 13µs/call
# spent 105µ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 | my @checks = @parents; | ||||
| 279 | push @checks, $check if $check != $null_constraint; | ||||
| 280 | return subname($self->name => sub { | ||||
| 281 | 24 | 167µs | my (@args) = @_; | ||
| 282 | local $_ = $args[0]; | ||||
| 283 | foreach my $check (@checks) { | ||||
| 284 | 12 | 188µs | 12 | 158µs | return undef unless $check->(@args); # spent 97µs making 6 calls to Moose::Util::TypeConstraints::__ANON__[Moose/Util/TypeConstraints.pm:714], avg 16µs/call
# spent 61µs making 6 calls to Moose::Util::TypeConstraints::__ANON__[Moose/Util/TypeConstraints.pm:707], avg 10µs/call |
| 285 | } | ||||
| 286 | return 1; | ||||
| 287 | 12 | 164µs | }); # spent 89µs making 6 calls to Sub::Name::subname, avg 15µs/call
# spent 74µs making 6 calls to Moose::Meta::TypeConstraint::name, avg 12µs/call | ||
| 288 | } | ||||
| 289 | } | ||||
| 290 | |||||
| 291 | # spent 109µs (84+25) within Moose::Meta::TypeConstraint::_compile_type which was called:
# once (84µs+25µs) by Moose::Meta::TypeConstraint::_actually_compile_type_constraint at line 224 | ||||
| 292 | 3 | 95µ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 | 25µs | }); # spent 13µs making 1 call to Sub::Name::subname
# spent 12µs making 1 call to Moose::Meta::TypeConstraint::name | ||
| 301 | } | ||||
| 302 | |||||
| 303 | ## other utils ... | ||||
| 304 | |||||
| 305 | # spent 3.57ms (2.34+1.23) within Moose::Meta::TypeConstraint::_collect_all_parents which was called 20 times, avg 178µs/call:
# 20 times (2.34ms+1.23ms) by Moose::Meta::TypeConstraint::_compile_subtype at line 247, avg 178µs/call | ||||
| 306 | 100 | 695µs | my $self = shift; | ||
| 307 | my @parents; | ||||
| 308 | 20 | 306µs | my $current = $self->parent; # spent 306µs making 20 calls to Moose::Meta::TypeConstraint::parent, avg 15µs/call | ||
| 309 | while (defined $current) { | ||||
| 310 | 172 | 1.33ms | push @parents => $current; | ||
| 311 | 86 | 923µs | $current = $current->parent; # spent 923µs making 86 calls to Moose::Meta::TypeConstraint::parent, avg 11µs/call | ||
| 312 | } | ||||
| 313 | return @parents; | ||||
| 314 | } | ||||
| 315 | |||||
| 316 | # spent 14.7ms (975µs+13.8) within Moose::Meta::TypeConstraint::create_child_type which was called 25 times, avg 590µs/call:
# 17 times (669µs+6.55ms) by Moose::Util::TypeConstraints::_create_type_constraint at line 547 of Moose/Util/TypeConstraints.pm, avg 425µs/call
# 8 times (306µs+7.22ms) by MooseX::Types::TypeDecorator::AUTOLOAD at line 206 of MooseX/Types/TypeDecorator.pm, avg 940µs/call | ||||
| 317 | 75 | 968µs | my ($self, %opts) = @_; | ||
| 318 | my $class = ref $self; | ||||
| 319 | 25 | 13.8ms | return $class->new(%opts, parent => $self); # spent 13.8ms making 25 calls to Moose::Meta::TypeConstraint::new, avg 551µs/call | ||
| 320 | } | ||||
| 321 | |||||
| 322 | 1 | 57µs | 1; | ||
| 323 | |||||
| 324 | __END__ |