← Index
NYTProf Performance Profile   « block view • line view • sub view »
For /usr/bin/epoll_server.pl
  Run on Wed Jan 5 05:34:33 2011
Reported on Wed Jan 5 05:40:41 2011

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
Subroutines — ordered by exclusive time
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
3551498.78ms12.6msMoose::Meta::TypeConstraint::::__ANON__[:8]Moose::Meta::TypeConstraint::__ANON__[:8]
35113.85ms7.72msMoose::Meta::TypeConstraint::::equalsMoose::Meta::TypeConstraint::equals
88112.94ms11.2msMoose::Meta::TypeConstraint::::_actually_compile_type_constraintMoose::Meta::TypeConstraint::_actually_compile_type_constraint
88442.74ms15.2msMoose::Meta::TypeConstraint::::compile_type_constraintMoose::Meta::TypeConstraint::compile_type_constraint
11112.33ms12.9msMoose::Meta::TypeConstraint::::is_subtype_ofMoose::Meta::TypeConstraint::is_subtype_of
27732.16ms31.2msMoose::Meta::TypeConstraint::::newMoose::Meta::TypeConstraint::new
1112.16ms3.62msMoose::Meta::TypeConstraint::::BEGIN@6Moose::Meta::TypeConstraint::BEGIN@6
77112.03ms2.76msMoose::Meta::TypeConstraint::::_compile_hand_optimized_type_constraintMoose::Meta::TypeConstraint::_compile_hand_optimized_type_constraint
10111.90ms2.25msMoose::Meta::TypeConstraint::::_collect_all_parentsMoose::Meta::TypeConstraint::_collect_all_parents
10111.34ms4.15msMoose::Meta::TypeConstraint::::_compile_subtypeMoose::Meta::TypeConstraint::_compile_subtype
6744711µs711µsMoose::Meta::TypeConstraint::::__ANON__[:30]Moose::Meta::TypeConstraint::__ANON__[:30]
1711529µs6.80msMoose::Meta::TypeConstraint::::create_child_typeMoose::Meta::TypeConstraint::create_child_type
111284µs306µsMoose::Meta::TypeConstraint::::_compile_typeMoose::Meta::TypeConstraint::_compile_type
522145µs7.31msMoose::Meta::TypeConstraint::::checkMoose::Meta::TypeConstraint::check
11156µs70µsMoose::Meta::TypeConstraint::::BEGIN@4Moose::Meta::TypeConstraint::BEGIN@4
11143µs4.00msMoose::Meta::TypeConstraint::::BEGIN@8Moose::Meta::TypeConstraint::BEGIN@8
11137µs239µsMoose::Meta::TypeConstraint::::BEGIN@11Moose::Meta::TypeConstraint::BEGIN@11
11132µs137µsMoose::Meta::TypeConstraint::::BEGIN@12Moose::Meta::TypeConstraint::BEGIN@12
11131µs91µsMoose::Meta::TypeConstraint::::BEGIN@5Moose::Meta::TypeConstraint::BEGIN@5
11131µs215µsMoose::Meta::TypeConstraint::::BEGIN@14Moose::Meta::TypeConstraint::BEGIN@14
0000s0sMoose::Meta::TypeConstraint::::__ANON__[:253]Moose::Meta::TypeConstraint::__ANON__[:253]
0000s0sMoose::Meta::TypeConstraint::::__ANON__[:266]Moose::Meta::TypeConstraint::__ANON__[:266]
0000s0sMoose::Meta::TypeConstraint::::__ANON__[:26]Moose::Meta::TypeConstraint::__ANON__[:26]
0000s0sMoose::Meta::TypeConstraint::::__ANON__[:279]Moose::Meta::TypeConstraint::__ANON__[:279]
0000s0sMoose::Meta::TypeConstraint::::assert_validMoose::Meta::TypeConstraint::assert_valid
0000s0sMoose::Meta::TypeConstraint::::coerceMoose::Meta::TypeConstraint::coerce
0000s0sMoose::Meta::TypeConstraint::::get_messageMoose::Meta::TypeConstraint::get_message
0000s0sMoose::Meta::TypeConstraint::::is_a_type_ofMoose::Meta::TypeConstraint::is_a_type_of
0000s0sMoose::Meta::TypeConstraint::::parentsMoose::Meta::TypeConstraint::parents
0000s0sMoose::Meta::TypeConstraint::::validateMoose::Meta::TypeConstraint::validate
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1
2package Moose::Meta::TypeConstraint;
3
4385µs285µ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
use strict;
# spent 70µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@4 # spent 14µs making 1 call to strict::import
5380µs2151µ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
use warnings;
# spent 91µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@5 # spent 60µs making 1 call to warnings::import
631.12ms24.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
use metaclass;
# spent 3.62ms making 1 call to Moose::Meta::TypeConstraint::BEGIN@6 # spent 899µs making 1 call to metaclass::import
7
83556.17ms3553.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
use overload '""' => sub { shift->name }, # stringify to tc name
# spent 3.83ms making 355 calls to Moose::Meta::TypeConstraint::name, avg 11µs/call
93275µs27.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
11399µs2440µ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
use Scalar::Util qw(blessed refaddr);
# spent 239µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@11 # spent 202µs making 1 call to Exporter::import
12392µs2242µ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
use Sub::Name qw(subname);
# spent 137µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@12 # spent 105µs making 1 call to Exporter::import
13
1435.22ms2399µ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
use base qw(Class::MOP::Object);
# spent 215µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@14 # spent 184µs making 1 call to base::import
15
1614µsour $VERSION = '1.01';
17156µs$VERSION = eval $VERSION;
1812µsour $AUTHORITY = 'cpan:STEVAN';
19
20123µs23.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
21115µs22.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
2618µsmy $null_constraint = sub { 1 };
27__PACKAGE__->meta->add_attribute('constraint' => (
28 reader => 'constraint',
29 writer => '_set_constraint',
30671.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
default => sub { $null_constraint }
31121µs22.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
32118µs22.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));
36118µs22.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
41118µs22.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
47sub parents {
48 my $self;
49 $self->parent;
50}
51
52# private accessors
53
541127µs22.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));
58118µs21.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
sub new {
632761µs my $class = shift;
6427231µs my ($first, @rest) = @_;
6527285µs my %args = ref $first ? %$first : $first ? ($first, @rest) : ();
6627103µs $args{name} = $args{name} ? "$args{name}" : "__ANON__";
67
6827493µs274.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
6927549µs5425.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;
7127360µs return $self;
72}
73
74
75
76sub 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
sub check {
92514µs my ($self, @args) = @_;
93534µs587µ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
94573µs57.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
97sub 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
107sub 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
117sub 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
sub equals {
1323587µs my ( $self, $type_or_name ) = @_;
133
13435478µs702.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
136351.58ms70283µs return 1 if refaddr($self) == refaddr($other);
# spent 283µs making 70 calls to Scalar::Util::refaddr, avg 4µs/call
137
13830467µs66661µ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
14230777µs60566µ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
154sub 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
sub is_subtype_of {
1631131µs my ($self, $type_or_name) = @_;
164
16511162µs221.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
16711123µs my $current = $self;
168
169111.10ms761.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
17035322µs357.72ms return 1 if $parent->equals($type);
# spent 7.72ms making 35 calls to Moose::Meta::TypeConstraint::equals, avg 221µs/call
1713063µs $current = $parent;
172 }
173
174665µ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
sub compile_type_constraint {
18088176µs my $self = shift;
181882.40ms17612.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
sub _actually_compile_type_constraint {
18788154µs my $self = shift;
188
189882.01ms1653.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
19211239µs11158µs my $check = $self->constraint;
# spent 158µs making 11 calls to Moose::Meta::TypeConstraint::constraint, avg 14µs/call
1931117µ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
20011235µs214.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
203179µs1306µ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
sub _compile_hand_optimized_type_constraint {
20777158µs my $self = shift;
208
20977659µs77728µ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
21177160µ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
21777898µ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
sub _compile_subtype {
2211028µs my ($self, $check) = @_;
222
223 # gather all the parent constraintss in order
2241014µs my @parents;
2251013µs my $optimized_parent;
22610194µs102.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
22914148µs14106µ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
230539µs5145µ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
231520µs last;
232 }
233 else {
234970µs973µs push @parents => $parent->constraint;
# spent 73µs making 9 calls to Moose::Meta::TypeConstraint::constraint, avg 8µs/call
235 }
236 }
237
2381059µs @parents = grep { $_ != $null_constraint } reverse @parents;
239
2401030µ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
24558µs if ( $check == $null_constraint ) {
246 return $optimized_parent;
247 } else {
248 return subname($self->name, sub {
24921148µs21193µ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
2502154µs my (@args) = @_;
2512138µs local $_ = $args[0];
25221637µs217.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
2535294µs10119µ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
257581µs my @checks = @parents;
258513µs push @checks, $check if $check != $null_constraint;
259 return subname($self->name => sub {
26014µs my (@args) = @_;
26113µs local $_ = $args[0];
26215µs foreach my $check (@checks) {
263227µs223µs return undef unless $check->(@args);
264 }
265120µs return 1;
2665222µs10108µ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
sub _compile_type {
27113µs my ($self, $check) = @_;
272
27313µ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);
2791324µs223µ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
sub _collect_all_parents {
2851019µs my $self = shift;
2861013µs my @parents;
28710131µs1084µs my $current = $self->parent;
# spent 84µs making 10 calls to Moose::Meta::TypeConstraint::parent, avg 8µs/call
2881033µs while (defined $current) {
2893465µs push @parents => $current;
290341.22ms34270µs $current = $current->parent;
# spent 270µs making 34 calls to Moose::Meta::TypeConstraint::parent, avg 8µs/call
291 }
29210107µ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
sub create_child_type {
29617113µs my ($self, %opts) = @_;
2971743µs my $class = ref $self;
29817299µs176.27ms return $class->new(%opts, parent => $self);
# spent 6.27ms making 17 calls to Moose::Meta::TypeConstraint::new, avg 369µs/call
299}
300
301154µs1;
302
303__END__
304
305=pod
306
307=head1 NAME
308
309Moose::Meta::TypeConstraint - The Moose Type Constraint metaclass
310
311=head1 DESCRIPTION
312
313This class represents a single type constraint. Moose's built-in type
314constraints, as well as constraints you define, are all stored in a
315L<Moose::Meta::TypeConstraint::Registry> object as objects of this
316class.
317
318=head1 INHERITANCE
319
320C<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
328This creates a new type constraint based on the provided C<%options>:
329
330=over 8
331
332=item * name
333
334The constraint name. If a name is not provided, it will be set to
335"__ANON__".
336
337=item * parent
338
339A C<Moose::Meta::TypeConstraint> object which is the parent type for
340the type being created. This is optional.
341
342=item * constraint
343
344This is the subroutine reference that implements the actual constraint
345check. This defaults to a subroutine which always returns true.
346
347=item * message
348
349A subroutine reference which is used to generate an error message when
350the constraint fails. This is optional.
351
352=item * coercion
353
354A L<Moose::Meta::TypeCoercion> object representing the coercions to
355the type. This is optional.
356
357=item * optimized
358
359This is a variant of the C<constraint> parameter that is somehow
360optimized. Typically, this means incorporating both the type's
361constraint and all of its parents' constraints into a single
362subroutine reference.
363
364=back
365
366=item B<< $constraint->equals($type_name_or_object) >>
367
368Returns true if the supplied name or type object is the same as the
369current type.
370
371=item B<< $constraint->is_subtype_of($type_name_or_object) >>
372
373Returns true if the supplied name or type object is a parent of the
374current type.
375
376=item B<< $constraint->is_a_type_of($type_name_or_object) >>
377
378Returns true if the given type is the same as the current type, or is
379a parent of the current type. This is a shortcut for checking
380C<equals> and C<is_subtype_of>.
381
382=item B<< $constraint->coerce($value) >>
383
384This will attempt to coerce the value to the type. If the type does
385have any defined coercions this will throw an error.
386
387=item B<< $constraint->check($value) >>
388
389Returns true if the given value passes the constraint for the type.
390
391=item B<< $constraint->validate($value) >>
392
393This is similar to C<check>. However, if the type I<is valid> then the
394method returns an explicit C<undef>. If the type is not valid, we call
395C<< $self->get_message($value) >> internally to generate an error
396message.
397
398=item B<< $constraint->assert_valid($value) >>
399
400Like C<check> and C<validate>, this method checks whether C<$value> is
401valid under the constraint. If it is, it will return true. If it is not,
402an exception will be thrown with the results of
403C<< $self->get_message($value) >>.
404
405=item B<< $constraint->name >>
406
407Returns the type's name, as provided to the constructor.
408
409=item B<< $constraint->parent >>
410
411Returns the type's parent, as provided to the constructor, if any.
412
413=item B<< $constraint->has_parent >>
414
415Returns true if the type has a parent type.
416
417=item B<< $constraint->parents >>
418
419A synonym for C<parent>. This is useful for polymorphism with types
420that can have more than one parent.
421
422=item B<< $constraint->constraint >>
423
424Returns the type's constraint, as provided to the constructor.
425
426=item B<< $constraint->get_message($value) >>
427
428This generates a method for the given value. If the type does not have
429an explicit message, we generate a default message.
430
431=item B<< $constraint->has_message >>
432
433Returns true if the type has a message.
434
435=item B<< $constraint->message >>
436
437Returns the type's message as a subroutine reference.
438
439=item B<< $constraint->coercion >>
440
441Returns the type's L<Moose::Meta::TypeCoercion> object, if one
442exists.
443
444=item B<< $constraint->has_coercion >>
445
446Returns true if the type has a coercion.
447
448=item B<< $constraint->hand_optimized_type_constraint >>
449
450Returns the type's hand optimized constraint, as provided to the
451constructor via the C<optimized> option.
452
453=item B<< $constraint->has_hand_optimized_type_constraint >>
454
455Returns true if the type has an optimized constraint.
456
457=item B<< $constraint->create_child_type(%options) >>
458
459This returns a new type constraint of the same class using the
460provided C<%options>. The C<parent> option will be the current type.
461
462This method exists so that subclasses of this class can override this
463behavior and change how child types are created.
464
465=back
466
467=head1 BUGS
468
469See L<Moose/BUGS> for details on reporting bugs.
470
471=head1 AUTHOR
472
473Stevan Little E<lt>stevan@iinteractive.comE<gt>
474
475=head1 COPYRIGHT AND LICENSE
476
477Copyright 2006-2010 by Infinity Interactive, Inc.
478
479L<http://www.iinteractive.com>
480
481This library is free software; you can redistribute it and/or modify
482it under the same terms as Perl itself.
483
484=cut