| File | /usr/lib/perl5/vendor_perl/5.10.1/i386-linux-thread-multi/Moose/Meta/TypeConstraint.pm |
| Statements Executed | 2014 |
| Statement Execution Time | 33.8ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 355 | 14 | 9 | 8.78ms | 12.6ms | Moose::Meta::TypeConstraint::__ANON__[:8] |
| 35 | 1 | 1 | 3.85ms | 7.72ms | Moose::Meta::TypeConstraint::equals |
| 88 | 1 | 1 | 2.94ms | 11.2ms | Moose::Meta::TypeConstraint::_actually_compile_type_constraint |
| 88 | 4 | 4 | 2.74ms | 15.2ms | Moose::Meta::TypeConstraint::compile_type_constraint |
| 11 | 1 | 1 | 2.33ms | 12.9ms | Moose::Meta::TypeConstraint::is_subtype_of |
| 27 | 7 | 3 | 2.16ms | 31.2ms | Moose::Meta::TypeConstraint::new |
| 1 | 1 | 1 | 2.16ms | 3.62ms | Moose::Meta::TypeConstraint::BEGIN@6 |
| 77 | 1 | 1 | 2.03ms | 2.76ms | Moose::Meta::TypeConstraint::_compile_hand_optimized_type_constraint |
| 10 | 1 | 1 | 1.90ms | 2.25ms | Moose::Meta::TypeConstraint::_collect_all_parents |
| 10 | 1 | 1 | 1.34ms | 4.15ms | Moose::Meta::TypeConstraint::_compile_subtype |
| 67 | 4 | 4 | 711µs | 711µs | Moose::Meta::TypeConstraint::__ANON__[:30] |
| 17 | 1 | 1 | 529µs | 6.80ms | Moose::Meta::TypeConstraint::create_child_type |
| 1 | 1 | 1 | 284µs | 306µs | Moose::Meta::TypeConstraint::_compile_type |
| 5 | 2 | 2 | 145µs | 7.31ms | Moose::Meta::TypeConstraint::check |
| 1 | 1 | 1 | 56µs | 70µs | Moose::Meta::TypeConstraint::BEGIN@4 |
| 1 | 1 | 1 | 43µs | 4.00ms | Moose::Meta::TypeConstraint::BEGIN@8 |
| 1 | 1 | 1 | 37µs | 239µs | Moose::Meta::TypeConstraint::BEGIN@11 |
| 1 | 1 | 1 | 32µs | 137µs | Moose::Meta::TypeConstraint::BEGIN@12 |
| 1 | 1 | 1 | 31µs | 91µs | Moose::Meta::TypeConstraint::BEGIN@5 |
| 1 | 1 | 1 | 31µs | 215µs | Moose::Meta::TypeConstraint::BEGIN@14 |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::__ANON__[:253] |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::__ANON__[:266] |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::__ANON__[:26] |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::__ANON__[:279] |
| 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::is_a_type_of |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::parents |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeConstraint::validate |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | |||||
| 2 | package Moose::Meta::TypeConstraint; | ||||
| 3 | |||||
| 4 | 3 | 85µs | 2 | 85µs | # spent 70µs (56+14) within Moose::Meta::TypeConstraint::BEGIN@4 which was called
# once (56µs+14µs) by Moose::BEGIN@19 at line 4 # spent 70µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@4
# spent 14µs making 1 call to strict::import |
| 5 | 3 | 80µs | 2 | 151µs | # spent 91µs (31+60) within Moose::Meta::TypeConstraint::BEGIN@5 which was called
# once (31µs+60µs) by Moose::BEGIN@19 at line 5 # spent 91µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@5
# spent 60µs making 1 call to warnings::import |
| 6 | 3 | 1.12ms | 2 | 4.51ms | # spent 3.62ms (2.16+1.46) within Moose::Meta::TypeConstraint::BEGIN@6 which was called
# once (2.16ms+1.46ms) by Moose::BEGIN@19 at line 6 # spent 3.62ms making 1 call to Moose::Meta::TypeConstraint::BEGIN@6
# spent 899µs making 1 call to metaclass::import |
| 7 | |||||
| 8 | 355 | 6.17ms | 355 | 3.83ms | # spent 12.6ms (8.78+3.83) within Moose::Meta::TypeConstraint::__ANON__[/usr/lib/perl5/vendor_perl/5.10.1/i386-linux-thread-multi/Moose/Meta/TypeConstraint.pm:8] which was called 355 times, avg 36µs/call:
# 82 times (1.74ms+889µs) by Moose::Meta::TypeConstraint::Registry::add_type_constraint at line 47 of Moose/Meta/TypeConstraint/Registry.pm, avg 32µs/call
# 66 times (1.64ms+862µs) by MooseX::Types::Base::import at line 83 of MooseX/Types/Base.pm, avg 38µs/call
# 37 times (847µs+389µs) by Moose::Util::TypeConstraints::find_or_parse_type_constraint at line 217 of Moose/Util/TypeConstraints.pm, avg 33µs/call
# 35 times (842µs+353µs) by Moose::Meta::TypeConstraint::equals at line 134, avg 34µs/call
# 35 times (608µs+409µs) by Moose::Meta::TypeConstraint::is_subtype_of at line 169, avg 29µs/call
# 32 times (586µs+356µs) by Moose::Util::TypeConstraints::find_or_create_isa_type_constraint at line 203 of Moose/Util/TypeConstraints.pm, avg 29µs/call
# 18 times (430µs+140µs) by Moose::Meta::Method::Accessor::_eval_code at line 26 of Moose/Meta/Method/Accessor.pm, avg 32µs/call
# 17 times (1.35ms+145µs) by Moose::Util::TypeConstraints::_create_type_constraint at line 523 of Moose/Util/TypeConstraints.pm, avg 88µs/call
# 11 times (189µs+99µs) by Moose::Meta::TypeConstraint::is_subtype_of at line 165, avg 26µs/call
# 9 times (159µs+78µs) by MooseX::Types::TypeDecorator::new at line 70 of MooseX/Types/TypeDecorator.pm, avg 26µs/call
# 5 times (258µs+46µs) by Moose::Meta::TypeConstraint::Parameterizable::parameterize at line 58 of Moose/Meta/TypeConstraint/Parameterizable.pm, avg 61µs/call
# 5 times (84µs+41µs) by Moose::Util::TypeConstraints::find_or_create_type_constraint at line 175 of Moose/Util/TypeConstraints.pm, avg 25µs/call
# 2 times (35µs+15µs) by Moose::Role::init_meta at line 116 of Moose/Role.pm, avg 25µs/call
# once (12µs+6µs) by Moose::init_meta at line 155 of Moose.pm
# spent 4.00ms (43µs+3.96) within Moose::Meta::TypeConstraint::BEGIN@8 which was called
# once (43µs+3.96ms) by Moose::BEGIN@19 at line 9 # spent 3.83ms making 355 calls to Moose::Meta::TypeConstraint::name, avg 11µs/call |
| 9 | 3 | 275µs | 2 | 7.96ms | fallback => 1; # spent 4.00ms making 1 call to Moose::Meta::TypeConstraint::BEGIN@8
# spent 3.96ms making 1 call to overload::import |
| 10 | |||||
| 11 | 3 | 99µs | 2 | 440µs | # spent 239µs (37+202) within Moose::Meta::TypeConstraint::BEGIN@11 which was called
# once (37µs+202µs) by Moose::BEGIN@19 at line 11 # spent 239µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@11
# spent 202µs making 1 call to Exporter::import |
| 12 | 3 | 92µs | 2 | 242µs | # spent 137µs (32+105) within Moose::Meta::TypeConstraint::BEGIN@12 which was called
# once (32µs+105µs) by Moose::BEGIN@19 at line 12 # spent 137µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@12
# spent 105µs making 1 call to Exporter::import |
| 13 | |||||
| 14 | 3 | 5.22ms | 2 | 399µs | # spent 215µs (31+184) within Moose::Meta::TypeConstraint::BEGIN@14 which was called
# once (31µs+184µs) by Moose::BEGIN@19 at line 14 # spent 215µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@14
# spent 184µs making 1 call to base::import |
| 15 | |||||
| 16 | 1 | 4µs | our $VERSION = '1.01'; | ||
| 17 | 1 | 56µs | $VERSION = eval $VERSION; | ||
| 18 | 1 | 2µs | our $AUTHORITY = 'cpan:STEVAN'; | ||
| 19 | |||||
| 20 | 1 | 23µs | 2 | 3.59ms | __PACKAGE__->meta->add_attribute('name' => (reader => 'name')); # spent 3.51ms making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 85µs making 1 call to Moose::Meta::TypeConstraint::meta |
| 21 | 1 | 15µs | 2 | 2.68ms | __PACKAGE__->meta->add_attribute('parent' => ( # spent 2.62ms making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 61µs making 1 call to Moose::Meta::TypeConstraint::meta |
| 22 | reader => 'parent', | ||||
| 23 | predicate => 'has_parent', | ||||
| 24 | )); | ||||
| 25 | |||||
| 26 | 1 | 8µs | my $null_constraint = sub { 1 }; | ||
| 27 | __PACKAGE__->meta->add_attribute('constraint' => ( | ||||
| 28 | reader => 'constraint', | ||||
| 29 | writer => '_set_constraint', | ||||
| 30 | 67 | 1.05ms | # spent 711µs within Moose::Meta::TypeConstraint::__ANON__[/usr/lib/perl5/vendor_perl/5.10.1/i386-linux-thread-multi/Moose/Meta/TypeConstraint.pm:30] which was called 67 times, avg 11µs/call:
# 34 times (257µs+0s) by Moose::Meta::TypeConstraint::Class::_new at line 35 of (eval 0)[Class/MOP/Method/Generated.pm:54] at line 54 of Class/MOP/Method/Generated.pm, avg 8µs/call
# 27 times (407µs+0s) by Moose::Meta::TypeConstraint::Role::_new at line 32 of (eval 0)[Class/MOP/Method/Generated.pm:54] at line 54 of Class/MOP/Method/Generated.pm, avg 15µs/call
# 5 times (38µs+0s) by Moose::Meta::TypeConstraint::Parameterized::_new at line 29 of (eval 0)[Class/MOP/Method/Generated.pm:54] at line 54 of Class/MOP/Method/Generated.pm, avg 8µs/call
# once (10µs+0s) by Moose::Meta::TypeConstraint::_new at line 26 of (eval 0)[Class/MOP/Method/Generated.pm:54] at line 54 of Class/MOP/Method/Generated.pm | ||
| 31 | 1 | 21µs | 2 | 2.78ms | )); # spent 2.72ms making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 57µs making 1 call to Moose::Meta::TypeConstraint::meta |
| 32 | 1 | 18µs | 2 | 2.53ms | __PACKAGE__->meta->add_attribute('message' => ( # spent 2.45ms making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 78µs making 1 call to Moose::Meta::TypeConstraint::meta |
| 33 | accessor => 'message', | ||||
| 34 | predicate => 'has_message' | ||||
| 35 | )); | ||||
| 36 | 1 | 18µs | 2 | 2.38ms | __PACKAGE__->meta->add_attribute('coercion' => ( # spent 2.32ms making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 68µs making 1 call to Moose::Meta::TypeConstraint::meta |
| 37 | accessor => 'coercion', | ||||
| 38 | predicate => 'has_coercion' | ||||
| 39 | )); | ||||
| 40 | |||||
| 41 | 1 | 18µs | 2 | 2.86ms | __PACKAGE__->meta->add_attribute('hand_optimized_type_constraint' => ( # spent 2.60ms making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 255µs making 1 call to Moose::Meta::TypeConstraint::meta |
| 42 | init_arg => 'optimized', | ||||
| 43 | accessor => 'hand_optimized_type_constraint', | ||||
| 44 | predicate => 'has_hand_optimized_type_constraint', | ||||
| 45 | )); | ||||
| 46 | |||||
| 47 | sub parents { | ||||
| 48 | my $self; | ||||
| 49 | $self->parent; | ||||
| 50 | } | ||||
| 51 | |||||
| 52 | # private accessors | ||||
| 53 | |||||
| 54 | 1 | 127µs | 2 | 2.78ms | __PACKAGE__->meta->add_attribute('compiled_type_constraint' => ( # spent 2.61ms making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 174µs making 1 call to Moose::Meta::TypeConstraint::meta |
| 55 | accessor => '_compiled_type_constraint', | ||||
| 56 | predicate => '_has_compiled_type_constraint' | ||||
| 57 | )); | ||||
| 58 | 1 | 18µs | 2 | 1.83ms | __PACKAGE__->meta->add_attribute('package_defined_in' => ( # spent 1.66ms making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 171µs making 1 call to Moose::Meta::TypeConstraint::meta |
| 59 | accessor => '_package_defined_in' | ||||
| 60 | )); | ||||
| 61 | |||||
| 62 | # spent 31.2ms (2.16+29.1) within Moose::Meta::TypeConstraint::new which was called 27 times, avg 1.16ms/call:
# 17 times (1.26ms+5.01ms) by Moose::Meta::TypeConstraint::create_child_type at line 298, avg 369µs/call
# 5 times (455µs+21.6ms) by Moose::Meta::TypeConstraint::Parameterizable::parameterize at line 69 of Moose/Meta/TypeConstraint/Parameterizable.pm, avg 4.42ms/call
# once (140µs+854µs) by Moose::Util::TypeConstraints::_create_type_constraint at line 533 of Moose/Util/TypeConstraints.pm
# once (94µs+604µs) by Moose::Meta::Attribute::BEGIN@18 at line 731 of Moose/Util/TypeConstraints.pm
# once (65µs+555µs) by Moose::Meta::Attribute::BEGIN@18 at line 790 of Moose/Util/TypeConstraints.pm
# once (77µs+221µs) by Moose::Meta::Attribute::BEGIN@18 at line 773 of Moose/Util/TypeConstraints.pm
# once (72µs+165µs) by Moose::Meta::Attribute::BEGIN@18 at line 752 of Moose/Util/TypeConstraints.pm | ||||
| 63 | 27 | 61µs | my $class = shift; | ||
| 64 | 27 | 231µs | my ($first, @rest) = @_; | ||
| 65 | 27 | 285µs | my %args = ref $first ? %$first : $first ? ($first, @rest) : (); | ||
| 66 | 27 | 103µs | $args{name} = $args{name} ? "$args{name}" : "__ANON__"; | ||
| 67 | |||||
| 68 | 27 | 493µs | 27 | 4.04ms | my $self = $class->_new(%args); # spent 1.90ms making 18 calls to Moose::Meta::TypeConstraint::_new, avg 106µs/call
# spent 1.57ms making 5 calls to Moose::Meta::TypeConstraint::Parameterized::_new, avg 313µs/call
# spent 569µs making 4 calls to Moose::Meta::TypeConstraint::Parameterizable::_new, avg 142µs/call |
| 69 | 27 | 549µs | 54 | 25.0ms | $self->compile_type_constraint() # spent 20.0ms making 5 calls to Moose::Meta::TypeConstraint::Parameterized::compile_type_constraint, avg 3.99ms/call
# spent 4.71ms making 22 calls to Moose::Meta::TypeConstraint::compile_type_constraint, avg 214µs/call
# spent 331µs making 27 calls to Moose::Meta::TypeConstraint::_has_compiled_type_constraint, avg 12µs/call |
| 70 | unless $self->_has_compiled_type_constraint; | ||||
| 71 | 27 | 360µs | return $self; | ||
| 72 | } | ||||
| 73 | |||||
| 74 | |||||
| 75 | |||||
| 76 | sub coerce { | ||||
| 77 | my $self = shift; | ||||
| 78 | |||||
| 79 | my $coercion = $self->coercion; | ||||
| 80 | |||||
| 81 | unless ($coercion) { | ||||
| 82 | require Moose; | ||||
| 83 | Moose->throw_error("Cannot coerce without a type coercion"); | ||||
| 84 | } | ||||
| 85 | |||||
| 86 | return $_[0] if $self->check($_[0]); | ||||
| 87 | |||||
| 88 | return $coercion->coerce(@_); | ||||
| 89 | } | ||||
| 90 | |||||
| 91 | # spent 7.31ms (145µs+7.16) within Moose::Meta::TypeConstraint::check which was called 5 times, avg 1.46ms/call:
# 4 times (124µs+7.15ms) by MooseX::Types::TypeDecorator::AUTOLOAD at line 200 of MooseX/Types/TypeDecorator.pm, avg 1.82ms/call
# once (21µs+13µs) by Moose::Meta::Attribute::verify_against_type_constraint at line 759 of Moose/Meta/Attribute.pm | ||||
| 92 | 5 | 14µs | my ($self, @args) = @_; | ||
| 93 | 5 | 34µs | 5 | 87µs | my $constraint_subref = $self->_compiled_type_constraint; # spent 87µs making 5 calls to Moose::Meta::TypeConstraint::_compiled_type_constraint, avg 17µs/call |
| 94 | 5 | 73µs | 5 | 7.08ms | return $constraint_subref->(@args) ? 1 : undef; # spent 7.07ms making 4 calls to Moose::Meta::TypeConstraint::ArrayRef[Str], avg 1.77ms/call
# spent 6µs making 1 call to Moose::Util::TypeConstraints::OptimizedConstraints::Str |
| 95 | } | ||||
| 96 | |||||
| 97 | sub validate { | ||||
| 98 | my ($self, $value) = @_; | ||||
| 99 | if ($self->_compiled_type_constraint->($value)) { | ||||
| 100 | return undef; | ||||
| 101 | } | ||||
| 102 | else { | ||||
| 103 | $self->get_message($value); | ||||
| 104 | } | ||||
| 105 | } | ||||
| 106 | |||||
| 107 | sub assert_valid { | ||||
| 108 | my ($self, $value) = @_; | ||||
| 109 | |||||
| 110 | my $error = $self->validate($value); | ||||
| 111 | return 1 if ! defined $error; | ||||
| 112 | |||||
| 113 | require Moose; | ||||
| 114 | Moose->throw_error($error); | ||||
| 115 | } | ||||
| 116 | |||||
| 117 | sub get_message { | ||||
| 118 | my ($self, $value) = @_; | ||||
| 119 | if (my $msg = $self->message) { | ||||
| 120 | local $_ = $value; | ||||
| 121 | return $msg->($value); | ||||
| 122 | } | ||||
| 123 | else { | ||||
| 124 | $value = (defined $value ? overload::StrVal($value) : 'undef'); | ||||
| 125 | return "Validation failed for '" . $self->name . "' failed with value $value"; | ||||
| 126 | } | ||||
| 127 | } | ||||
| 128 | |||||
| 129 | ## type predicates ... | ||||
| 130 | |||||
| 131 | # spent 7.72ms (3.85+3.87) within Moose::Meta::TypeConstraint::equals which was called 35 times, avg 221µs/call:
# 35 times (3.85ms+3.87ms) by Moose::Meta::TypeConstraint::is_subtype_of at line 170, avg 221µs/call | ||||
| 132 | 35 | 87µs | my ( $self, $type_or_name ) = @_; | ||
| 133 | |||||
| 134 | 35 | 478µs | 70 | 2.36ms | my $other = Moose::Util::TypeConstraints::find_type_constraint($type_or_name) or return; # spent 1.19ms making 35 calls to Moose::Meta::TypeConstraint::__ANON__[Moose/Meta/TypeConstraint.pm:8], avg 34µs/call
# spent 1.16ms making 35 calls to Moose::Util::TypeConstraints::find_type_constraint, avg 33µs/call |
| 135 | |||||
| 136 | 35 | 1.58ms | 70 | 283µs | return 1 if refaddr($self) == refaddr($other); # spent 283µs making 70 calls to Scalar::Util::refaddr, avg 4µs/call |
| 137 | |||||
| 138 | 30 | 467µs | 66 | 661µs | if ( $self->has_hand_optimized_type_constraint and $other->has_hand_optimized_type_constraint ) { # spent 384µs making 42 calls to Moose::Meta::TypeConstraint::has_hand_optimized_type_constraint, avg 9µs/call
# spent 277µs making 24 calls to Moose::Meta::TypeConstraint::hand_optimized_type_constraint, avg 12µs/call |
| 139 | return 1 if $self->hand_optimized_type_constraint == $other->hand_optimized_type_constraint; | ||||
| 140 | } | ||||
| 141 | |||||
| 142 | 30 | 777µs | 60 | 566µs | return unless $self->constraint == $other->constraint; # spent 566µs making 60 calls to Moose::Meta::TypeConstraint::constraint, avg 9µs/call |
| 143 | |||||
| 144 | if ( $self->has_parent ) { | ||||
| 145 | return unless $other->has_parent; | ||||
| 146 | return unless $self->parent->equals( $other->parent ); | ||||
| 147 | } else { | ||||
| 148 | return if $other->has_parent; | ||||
| 149 | } | ||||
| 150 | |||||
| 151 | return 1; | ||||
| 152 | } | ||||
| 153 | |||||
| 154 | sub is_a_type_of { | ||||
| 155 | my ($self, $type_or_name) = @_; | ||||
| 156 | |||||
| 157 | my $type = Moose::Util::TypeConstraints::find_type_constraint($type_or_name) or return; | ||||
| 158 | |||||
| 159 | ($self->equals($type) || $self->is_subtype_of($type)); | ||||
| 160 | } | ||||
| 161 | |||||
| 162 | # spent 12.9ms (2.33+10.6) within Moose::Meta::TypeConstraint::is_subtype_of which was called 11 times, avg 1.17ms/call:
# 11 times (2.33ms+10.6ms) by Moose::Meta::TypeConstraint::Parameterizable::generate_constraint_for at line 25 of Moose/Meta/TypeConstraint/Parameterizable.pm, avg 1.17ms/call | ||||
| 163 | 11 | 31µs | my ($self, $type_or_name) = @_; | ||
| 164 | |||||
| 165 | 11 | 162µs | 22 | 1.45ms | my $type = Moose::Util::TypeConstraints::find_type_constraint($type_or_name) or return; # spent 1.16ms making 11 calls to Moose::Util::TypeConstraints::find_type_constraint, avg 106µs/call
# spent 288µs making 11 calls to Moose::Meta::TypeConstraint::__ANON__[Moose/Meta/TypeConstraint.pm:8], avg 26µs/call |
| 166 | |||||
| 167 | 11 | 123µs | my $current = $self; | ||
| 168 | |||||
| 169 | 11 | 1.10ms | 76 | 1.38ms | while (my $parent = $current->parent) { # spent 1.02ms making 35 calls to Moose::Meta::TypeConstraint::__ANON__[Moose/Meta/TypeConstraint.pm:8], avg 29µs/call
# spent 365µs making 41 calls to Moose::Meta::TypeConstraint::parent, avg 9µs/call |
| 170 | 35 | 322µs | 35 | 7.72ms | return 1 if $parent->equals($type); # spent 7.72ms making 35 calls to Moose::Meta::TypeConstraint::equals, avg 221µs/call |
| 171 | 30 | 63µs | $current = $parent; | ||
| 172 | } | ||||
| 173 | |||||
| 174 | 6 | 65µs | return 0; | ||
| 175 | } | ||||
| 176 | |||||
| 177 | ## compiling the type constraint | ||||
| 178 | |||||
| 179 | # spent 15.2ms (2.74+12.5) within Moose::Meta::TypeConstraint::compile_type_constraint which was called 88 times, avg 173µs/call:
# 34 times (988µs+3.03ms) by Moose::Meta::TypeConstraint::Class::new at line 27 of Moose/Meta/TypeConstraint/Class.pm, avg 118µs/call
# 27 times (982µs+2.16ms) by Moose::Meta::TypeConstraint::Role::new at line 27 of Moose/Meta/TypeConstraint/Role.pm, avg 116µs/call
# 22 times (643µs+4.07ms) by Moose::Meta::TypeConstraint::new at line 69, avg 214µs/call
# 5 times (129µs+3.21ms) by Moose::Meta::TypeConstraint::Parameterized::compile_type_constraint at line 54 of Moose/Meta/TypeConstraint/Parameterized.pm, avg 667µs/call | ||||
| 180 | 88 | 176µs | my $self = shift; | ||
| 181 | 88 | 2.40ms | 176 | 12.5ms | $self->_compiled_type_constraint($self->_actually_compile_type_constraint); # spent 11.2ms making 88 calls to Moose::Meta::TypeConstraint::_actually_compile_type_constraint, avg 127µs/call
# spent 1.26ms making 88 calls to Moose::Meta::TypeConstraint::_compiled_type_constraint, avg 14µs/call |
| 182 | } | ||||
| 183 | |||||
| 184 | ## type compilers ... | ||||
| 185 | |||||
| 186 | # spent 11.2ms (2.94+8.26) within Moose::Meta::TypeConstraint::_actually_compile_type_constraint which was called 88 times, avg 127µs/call:
# 88 times (2.94ms+8.26ms) by Moose::Meta::TypeConstraint::compile_type_constraint at line 181, avg 127µs/call | ||||
| 187 | 88 | 154µs | my $self = shift; | ||
| 188 | |||||
| 189 | 88 | 2.01ms | 165 | 3.56ms | return $self->_compile_hand_optimized_type_constraint # spent 2.76ms making 77 calls to Moose::Meta::TypeConstraint::_compile_hand_optimized_type_constraint, avg 36µs/call
# spent 803µs making 88 calls to Moose::Meta::TypeConstraint::has_hand_optimized_type_constraint, avg 9µs/call |
| 190 | if $self->has_hand_optimized_type_constraint; | ||||
| 191 | |||||
| 192 | 11 | 239µs | 11 | 158µs | my $check = $self->constraint; # spent 158µs making 11 calls to Moose::Meta::TypeConstraint::constraint, avg 14µs/call |
| 193 | 11 | 17µs | unless ( defined $check ) { | ||
| 194 | require Moose; | ||||
| 195 | Moose->throw_error( "Could not compile type constraint '" | ||||
| 196 | . $self->name | ||||
| 197 | . "' because no constraint check" ); | ||||
| 198 | } | ||||
| 199 | |||||
| 200 | 11 | 235µs | 21 | 4.23ms | return $self->_compile_subtype($check) # spent 4.15ms making 10 calls to Moose::Meta::TypeConstraint::_compile_subtype, avg 415µs/call
# spent 86µs making 11 calls to Moose::Meta::TypeConstraint::has_parent, avg 8µs/call |
| 201 | if $self->has_parent; | ||||
| 202 | |||||
| 203 | 1 | 79µs | 1 | 306µs | return $self->_compile_type($check); # spent 306µs making 1 call to Moose::Meta::TypeConstraint::_compile_type |
| 204 | } | ||||
| 205 | |||||
| 206 | # spent 2.76ms (2.03+728µs) within Moose::Meta::TypeConstraint::_compile_hand_optimized_type_constraint which was called 77 times, avg 36µs/call:
# 77 times (2.03ms+728µs) by Moose::Meta::TypeConstraint::_actually_compile_type_constraint at line 189, avg 36µs/call | ||||
| 207 | 77 | 158µs | my $self = shift; | ||
| 208 | |||||
| 209 | 77 | 659µs | 77 | 728µs | my $type_constraint = $self->hand_optimized_type_constraint; # spent 728µs making 77 calls to Moose::Meta::TypeConstraint::hand_optimized_type_constraint, avg 9µs/call |
| 210 | |||||
| 211 | 77 | 160µs | unless ( ref $type_constraint ) { | ||
| 212 | require Moose; | ||||
| 213 | Carp::confess ("Hand optimized type constraint for " . $self->name . " is not a code reference"); | ||||
| 214 | Moose->throw_error("Hand optimized type constraint is not a code reference"); | ||||
| 215 | } | ||||
| 216 | |||||
| 217 | 77 | 898µs | return $type_constraint; | ||
| 218 | } | ||||
| 219 | |||||
| 220 | # spent 4.15ms (1.34+2.81) within Moose::Meta::TypeConstraint::_compile_subtype which was called 10 times, avg 415µs/call:
# 10 times (1.34ms+2.81ms) by Moose::Meta::TypeConstraint::_actually_compile_type_constraint at line 200, avg 415µs/call | ||||
| 221 | 10 | 28µs | my ($self, $check) = @_; | ||
| 222 | |||||
| 223 | # gather all the parent constraintss in order | ||||
| 224 | 10 | 14µs | my @parents; | ||
| 225 | 10 | 13µs | my $optimized_parent; | ||
| 226 | 10 | 194µs | 10 | 2.25ms | foreach my $parent ($self->_collect_all_parents) { # spent 2.25ms making 10 calls to Moose::Meta::TypeConstraint::_collect_all_parents, avg 225µs/call |
| 227 | # if a parent is optimized, the optimized constraint already includes | ||||
| 228 | # all of its parents tcs, so we can break the loop | ||||
| 229 | 14 | 148µs | 14 | 106µs | if ($parent->has_hand_optimized_type_constraint) { # spent 106µs making 14 calls to Moose::Meta::TypeConstraint::has_hand_optimized_type_constraint, avg 8µs/call |
| 230 | 5 | 39µs | 5 | 145µs | push @parents => $optimized_parent = $parent->hand_optimized_type_constraint; # spent 145µs making 5 calls to Moose::Meta::TypeConstraint::hand_optimized_type_constraint, avg 29µs/call |
| 231 | 5 | 20µs | last; | ||
| 232 | } | ||||
| 233 | else { | ||||
| 234 | 9 | 70µs | 9 | 73µs | push @parents => $parent->constraint; # spent 73µs making 9 calls to Moose::Meta::TypeConstraint::constraint, avg 8µs/call |
| 235 | } | ||||
| 236 | } | ||||
| 237 | |||||
| 238 | 10 | 59µs | @parents = grep { $_ != $null_constraint } reverse @parents; | ||
| 239 | |||||
| 240 | 10 | 30µs | unless ( @parents ) { | ||
| 241 | return $self->_compile_type($check); | ||||
| 242 | } elsif( $optimized_parent and @parents == 1 ) { | ||||
| 243 | # the case of just one optimized parent is optimized to prevent | ||||
| 244 | # looping and the unnecessary localization | ||||
| 245 | 5 | 8µs | if ( $check == $null_constraint ) { | ||
| 246 | return $optimized_parent; | ||||
| 247 | } else { | ||||
| 248 | return subname($self->name, sub { | ||||
| 249 | 21 | 148µs | 21 | 193µs | return undef unless $optimized_parent->($_[0]); # spent 147µs making 13 calls to Moose::Util::TypeConstraints::OptimizedConstraints::ArrayRef, avg 11µs/call
# spent 46µs making 8 calls to Moose::Util::TypeConstraints::OptimizedConstraints::HashRef, avg 6µs/call |
| 250 | 21 | 54µs | my (@args) = @_; | ||
| 251 | 21 | 38µs | local $_ = $args[0]; | ||
| 252 | 21 | 637µs | 21 | 7.37ms | $check->(@args); # spent 7.27ms making 13 calls to Moose::Util::TypeConstraints::__ANON__[Moose/Util/TypeConstraints.pm:749], avg 559µs/call
# spent 102µs making 8 calls to Moose::Util::TypeConstraints::__ANON__[Moose/Util/TypeConstraints.pm:770], avg 13µs/call |
| 253 | 5 | 294µs | 10 | 119µs | }); # spent 75µs making 5 calls to Sub::Name::subname, avg 15µs/call
# spent 44µs making 5 calls to Moose::Meta::TypeConstraint::name, avg 9µs/call |
| 254 | } | ||||
| 255 | } else { | ||||
| 256 | # general case, check all the constraints, from the first parent to ourselves | ||||
| 257 | 5 | 81µs | my @checks = @parents; | ||
| 258 | 5 | 13µs | push @checks, $check if $check != $null_constraint; | ||
| 259 | return subname($self->name => sub { | ||||
| 260 | 1 | 4µs | my (@args) = @_; | ||
| 261 | 1 | 3µs | local $_ = $args[0]; | ||
| 262 | 1 | 5µs | foreach my $check (@checks) { | ||
| 263 | 2 | 27µs | 2 | 23µs | return undef unless $check->(@args); # spent 13µs making 1 call to Moose::Util::TypeConstraints::__ANON__[Moose/Util/TypeConstraints.pm:657]
# spent 10µs making 1 call to Moose::Util::TypeConstraints::__ANON__[Moose/Util/TypeConstraints.pm:650] |
| 264 | } | ||||
| 265 | 1 | 20µs | return 1; | ||
| 266 | 5 | 222µs | 10 | 108µs | }); # spent 62µs making 5 calls to Sub::Name::subname, avg 12µs/call
# spent 47µs making 5 calls to Moose::Meta::TypeConstraint::name, avg 9µs/call |
| 267 | } | ||||
| 268 | } | ||||
| 269 | |||||
| 270 | # spent 306µs (284+23) within Moose::Meta::TypeConstraint::_compile_type which was called
# once (284µs+23µs) by Moose::Meta::TypeConstraint::_actually_compile_type_constraint at line 203 | ||||
| 271 | 1 | 3µs | my ($self, $check) = @_; | ||
| 272 | |||||
| 273 | 1 | 3µs | return $check if $check == $null_constraint; # Item, Any | ||
| 274 | |||||
| 275 | return subname($self->name => sub { | ||||
| 276 | my (@args) = @_; | ||||
| 277 | local $_ = $args[0]; | ||||
| 278 | $check->(@args); | ||||
| 279 | 1 | 324µs | 2 | 23µs | }); # spent 13µs making 1 call to Sub::Name::subname
# spent 10µs making 1 call to Moose::Meta::TypeConstraint::name |
| 280 | } | ||||
| 281 | |||||
| 282 | ## other utils ... | ||||
| 283 | |||||
| 284 | # spent 2.25ms (1.90+354µs) within Moose::Meta::TypeConstraint::_collect_all_parents which was called 10 times, avg 225µs/call:
# 10 times (1.90ms+354µs) by Moose::Meta::TypeConstraint::_compile_subtype at line 226, avg 225µs/call | ||||
| 285 | 10 | 19µs | my $self = shift; | ||
| 286 | 10 | 13µs | my @parents; | ||
| 287 | 10 | 131µs | 10 | 84µs | my $current = $self->parent; # spent 84µs making 10 calls to Moose::Meta::TypeConstraint::parent, avg 8µs/call |
| 288 | 10 | 33µs | while (defined $current) { | ||
| 289 | 34 | 65µs | push @parents => $current; | ||
| 290 | 34 | 1.22ms | 34 | 270µs | $current = $current->parent; # spent 270µs making 34 calls to Moose::Meta::TypeConstraint::parent, avg 8µs/call |
| 291 | } | ||||
| 292 | 10 | 107µs | return @parents; | ||
| 293 | } | ||||
| 294 | |||||
| 295 | # spent 6.80ms (529µs+6.27) within Moose::Meta::TypeConstraint::create_child_type which was called 17 times, avg 400µs/call:
# 17 times (529µs+6.27ms) by Moose::Util::TypeConstraints::_create_type_constraint at line 523 of Moose/Util/TypeConstraints.pm, avg 400µs/call | ||||
| 296 | 17 | 113µs | my ($self, %opts) = @_; | ||
| 297 | 17 | 43µs | my $class = ref $self; | ||
| 298 | 17 | 299µs | 17 | 6.27ms | return $class->new(%opts, parent => $self); # spent 6.27ms making 17 calls to Moose::Meta::TypeConstraint::new, avg 369µs/call |
| 299 | } | ||||
| 300 | |||||
| 301 | 1 | 54µs | 1; | ||
| 302 | |||||
| 303 | __END__ | ||||
| 304 | |||||
| 305 | =pod | ||||
| 306 | |||||
| 307 | =head1 NAME | ||||
| 308 | |||||
| 309 | Moose::Meta::TypeConstraint - The Moose Type Constraint metaclass | ||||
| 310 | |||||
| 311 | =head1 DESCRIPTION | ||||
| 312 | |||||
| 313 | This class represents a single type constraint. Moose's built-in type | ||||
| 314 | constraints, as well as constraints you define, are all stored in a | ||||
| 315 | L<Moose::Meta::TypeConstraint::Registry> object as objects of this | ||||
| 316 | class. | ||||
| 317 | |||||
| 318 | =head1 INHERITANCE | ||||
| 319 | |||||
| 320 | C<Moose::Meta::TypeConstraint> is a subclass of L<Class::MOP::Object>. | ||||
| 321 | |||||
| 322 | =head1 METHODS | ||||
| 323 | |||||
| 324 | =over 4 | ||||
| 325 | |||||
| 326 | =item B<< Moose::Meta::TypeConstraint->new(%options) >> | ||||
| 327 | |||||
| 328 | This creates a new type constraint based on the provided C<%options>: | ||||
| 329 | |||||
| 330 | =over 8 | ||||
| 331 | |||||
| 332 | =item * name | ||||
| 333 | |||||
| 334 | The constraint name. If a name is not provided, it will be set to | ||||
| 335 | "__ANON__". | ||||
| 336 | |||||
| 337 | =item * parent | ||||
| 338 | |||||
| 339 | A C<Moose::Meta::TypeConstraint> object which is the parent type for | ||||
| 340 | the type being created. This is optional. | ||||
| 341 | |||||
| 342 | =item * constraint | ||||
| 343 | |||||
| 344 | This is the subroutine reference that implements the actual constraint | ||||
| 345 | check. This defaults to a subroutine which always returns true. | ||||
| 346 | |||||
| 347 | =item * message | ||||
| 348 | |||||
| 349 | A subroutine reference which is used to generate an error message when | ||||
| 350 | the constraint fails. This is optional. | ||||
| 351 | |||||
| 352 | =item * coercion | ||||
| 353 | |||||
| 354 | A L<Moose::Meta::TypeCoercion> object representing the coercions to | ||||
| 355 | the type. This is optional. | ||||
| 356 | |||||
| 357 | =item * optimized | ||||
| 358 | |||||
| 359 | This is a variant of the C<constraint> parameter that is somehow | ||||
| 360 | optimized. Typically, this means incorporating both the type's | ||||
| 361 | constraint and all of its parents' constraints into a single | ||||
| 362 | subroutine reference. | ||||
| 363 | |||||
| 364 | =back | ||||
| 365 | |||||
| 366 | =item B<< $constraint->equals($type_name_or_object) >> | ||||
| 367 | |||||
| 368 | Returns true if the supplied name or type object is the same as the | ||||
| 369 | current type. | ||||
| 370 | |||||
| 371 | =item B<< $constraint->is_subtype_of($type_name_or_object) >> | ||||
| 372 | |||||
| 373 | Returns true if the supplied name or type object is a parent of the | ||||
| 374 | current type. | ||||
| 375 | |||||
| 376 | =item B<< $constraint->is_a_type_of($type_name_or_object) >> | ||||
| 377 | |||||
| 378 | Returns true if the given type is the same as the current type, or is | ||||
| 379 | a parent of the current type. This is a shortcut for checking | ||||
| 380 | C<equals> and C<is_subtype_of>. | ||||
| 381 | |||||
| 382 | =item B<< $constraint->coerce($value) >> | ||||
| 383 | |||||
| 384 | This will attempt to coerce the value to the type. If the type does | ||||
| 385 | have any defined coercions this will throw an error. | ||||
| 386 | |||||
| 387 | =item B<< $constraint->check($value) >> | ||||
| 388 | |||||
| 389 | Returns true if the given value passes the constraint for the type. | ||||
| 390 | |||||
| 391 | =item B<< $constraint->validate($value) >> | ||||
| 392 | |||||
| 393 | This is similar to C<check>. However, if the type I<is valid> then the | ||||
| 394 | method returns an explicit C<undef>. If the type is not valid, we call | ||||
| 395 | C<< $self->get_message($value) >> internally to generate an error | ||||
| 396 | message. | ||||
| 397 | |||||
| 398 | =item B<< $constraint->assert_valid($value) >> | ||||
| 399 | |||||
| 400 | Like C<check> and C<validate>, this method checks whether C<$value> is | ||||
| 401 | valid under the constraint. If it is, it will return true. If it is not, | ||||
| 402 | an exception will be thrown with the results of | ||||
| 403 | C<< $self->get_message($value) >>. | ||||
| 404 | |||||
| 405 | =item B<< $constraint->name >> | ||||
| 406 | |||||
| 407 | Returns the type's name, as provided to the constructor. | ||||
| 408 | |||||
| 409 | =item B<< $constraint->parent >> | ||||
| 410 | |||||
| 411 | Returns the type's parent, as provided to the constructor, if any. | ||||
| 412 | |||||
| 413 | =item B<< $constraint->has_parent >> | ||||
| 414 | |||||
| 415 | Returns true if the type has a parent type. | ||||
| 416 | |||||
| 417 | =item B<< $constraint->parents >> | ||||
| 418 | |||||
| 419 | A synonym for C<parent>. This is useful for polymorphism with types | ||||
| 420 | that can have more than one parent. | ||||
| 421 | |||||
| 422 | =item B<< $constraint->constraint >> | ||||
| 423 | |||||
| 424 | Returns the type's constraint, as provided to the constructor. | ||||
| 425 | |||||
| 426 | =item B<< $constraint->get_message($value) >> | ||||
| 427 | |||||
| 428 | This generates a method for the given value. If the type does not have | ||||
| 429 | an explicit message, we generate a default message. | ||||
| 430 | |||||
| 431 | =item B<< $constraint->has_message >> | ||||
| 432 | |||||
| 433 | Returns true if the type has a message. | ||||
| 434 | |||||
| 435 | =item B<< $constraint->message >> | ||||
| 436 | |||||
| 437 | Returns the type's message as a subroutine reference. | ||||
| 438 | |||||
| 439 | =item B<< $constraint->coercion >> | ||||
| 440 | |||||
| 441 | Returns the type's L<Moose::Meta::TypeCoercion> object, if one | ||||
| 442 | exists. | ||||
| 443 | |||||
| 444 | =item B<< $constraint->has_coercion >> | ||||
| 445 | |||||
| 446 | Returns true if the type has a coercion. | ||||
| 447 | |||||
| 448 | =item B<< $constraint->hand_optimized_type_constraint >> | ||||
| 449 | |||||
| 450 | Returns the type's hand optimized constraint, as provided to the | ||||
| 451 | constructor via the C<optimized> option. | ||||
| 452 | |||||
| 453 | =item B<< $constraint->has_hand_optimized_type_constraint >> | ||||
| 454 | |||||
| 455 | Returns true if the type has an optimized constraint. | ||||
| 456 | |||||
| 457 | =item B<< $constraint->create_child_type(%options) >> | ||||
| 458 | |||||
| 459 | This returns a new type constraint of the same class using the | ||||
| 460 | provided C<%options>. The C<parent> option will be the current type. | ||||
| 461 | |||||
| 462 | This method exists so that subclasses of this class can override this | ||||
| 463 | behavior and change how child types are created. | ||||
| 464 | |||||
| 465 | =back | ||||
| 466 | |||||
| 467 | =head1 BUGS | ||||
| 468 | |||||
| 469 | See L<Moose/BUGS> for details on reporting bugs. | ||||
| 470 | |||||
| 471 | =head1 AUTHOR | ||||
| 472 | |||||
| 473 | Stevan Little E<lt>stevan@iinteractive.comE<gt> | ||||
| 474 | |||||
| 475 | =head1 COPYRIGHT AND LICENSE | ||||
| 476 | |||||
| 477 | Copyright 2006-2010 by Infinity Interactive, Inc. | ||||
| 478 | |||||
| 479 | L<http://www.iinteractive.com> | ||||
| 480 | |||||
| 481 | This library is free software; you can redistribute it and/or modify | ||||
| 482 | it under the same terms as Perl itself. | ||||
| 483 | |||||
| 484 | =cut |