← Index
NYTProf Performance Profile   « line view »
For fastest.pl
  Run on Fri Jan 31 20:48:16 2014
Reported on Fri Jan 31 20:49:41 2014

Filename/opt/perl-5.18.1/lib/site_perl/5.18.1/darwin-thread-multi-2level/Moose/Meta/TypeConstraint.pm
StatementsExecuted 1135 statements in 10.8ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
25746.00ms13.5msMoose::Meta::TypeConstraint::::newMoose::Meta::TypeConstraint::new
7852629µs936µsMoose::Meta::TypeConstraint::::can_be_inlinedMoose::Meta::TypeConstraint::can_be_inlined (recurses: max depth 1, inclusive time 17µs)
4483627µs1.54msMoose::Meta::TypeConstraint::::_inline_checkMoose::Meta::TypeConstraint::_inline_check (recurses: max depth 2, inclusive time 563µs)
111567µs1.40msMoose::Meta::TypeConstraint::::BEGIN@12Moose::Meta::TypeConstraint::BEGIN@12
2911410µs7.04msMoose::Meta::TypeConstraint::::_actually_compile_type_constraintMoose::Meta::TypeConstraint::_actually_compile_type_constraint
3243285µs415µsMoose::Meta::TypeConstraint::::inline_environmentMoose::Meta::TypeConstraint::inline_environment (recurses: max depth 1, inclusive time 10µs)
2922195µs7.36msMoose::Meta::TypeConstraint::::compile_type_constraintMoose::Meta::TypeConstraint::compile_type_constraint
1611111µs5.18msMoose::Meta::TypeConstraint::::create_child_typeMoose::Meta::TypeConstraint::create_child_type
2511110µs110µsMoose::Meta::TypeConstraint::::__ANON__[:77]Moose::Meta::TypeConstraint::__ANON__[:77]
754287µs87µsMoose::Meta::TypeConstraint::::__ANON__[:16]Moose::Meta::TypeConstraint::__ANON__[:16]
253337µs37µsMoose::Meta::TypeConstraint::::__ANON__[:101]Moose::Meta::TypeConstraint::__ANON__[:101]
11117µs17µsMoose::Meta::TypeConstraint::::BEGIN@3Moose::Meta::TypeConstraint::BEGIN@3
11115µs66µsMoose::Meta::TypeConstraint::::BEGIN@14Moose::Meta::TypeConstraint::BEGIN@14
11110µs37µsMoose::Meta::TypeConstraint::::BEGIN@21Moose::Meta::TypeConstraint::BEGIN@21
11110µs16µsMoose::Meta::TypeConstraint::::BEGIN@11Moose::Meta::TypeConstraint::BEGIN@11
11110µs47µsMoose::Meta::TypeConstraint::::BEGIN@19Moose::Meta::TypeConstraint::BEGIN@19
11110µs46µsMoose::Meta::TypeConstraint::::BEGIN@22Moose::Meta::TypeConstraint::BEGIN@22
11110µs44µsMoose::Meta::TypeConstraint::::BEGIN@24Moose::Meta::TypeConstraint::BEGIN@24
1119µs35µsMoose::Meta::TypeConstraint::::BEGIN@23Moose::Meta::TypeConstraint::BEGIN@23
1119µs37µsMoose::Meta::TypeConstraint::::BEGIN@20Moose::Meta::TypeConstraint::BEGIN@20
1119µs83µsMoose::Meta::TypeConstraint::::BEGIN@26Moose::Meta::TypeConstraint::BEGIN@26
1118µs25µsMoose::Meta::TypeConstraint::::BEGIN@10Moose::Meta::TypeConstraint::BEGIN@10
1112µs2µsMoose::Meta::TypeConstraint::::__ANON__[:42]Moose::Meta::TypeConstraint::__ANON__[:42]
0000s0sMoose::Meta::TypeConstraint::::__ANON__[:14]Moose::Meta::TypeConstraint::__ANON__[:14]
0000s0sMoose::Meta::TypeConstraint::::__ANON__[:15]Moose::Meta::TypeConstraint::__ANON__[:15]
0000s0sMoose::Meta::TypeConstraint::::__ANON__[:378]Moose::Meta::TypeConstraint::__ANON__[:378]
0000s0sMoose::Meta::TypeConstraint::::__ANON__[:38]Moose::Meta::TypeConstraint::__ANON__[:38]
0000s0sMoose::Meta::TypeConstraint::::__ANON__[:391]Moose::Meta::TypeConstraint::__ANON__[:391]
0000s0sMoose::Meta::TypeConstraint::::__ANON__[:404]Moose::Meta::TypeConstraint::__ANON__[:404]
0000s0sMoose::Meta::TypeConstraint::::__ANON__[:68]Moose::Meta::TypeConstraint::__ANON__[:68]
0000s0sMoose::Meta::TypeConstraint::::__ANON__[:76]Moose::Meta::TypeConstraint::__ANON__[:76]
0000s0sMoose::Meta::TypeConstraint::::_collect_all_parentsMoose::Meta::TypeConstraint::_collect_all_parents
0000s0sMoose::Meta::TypeConstraint::::_compile_hand_optimized_type_constraintMoose::Meta::TypeConstraint::_compile_hand_optimized_type_constraint
0000s0sMoose::Meta::TypeConstraint::::_compile_subtypeMoose::Meta::TypeConstraint::_compile_subtype
0000s0sMoose::Meta::TypeConstraint::::_compile_typeMoose::Meta::TypeConstraint::_compile_type
0000s0sMoose::Meta::TypeConstraint::::assert_coerceMoose::Meta::TypeConstraint::assert_coerce
0000s0sMoose::Meta::TypeConstraint::::assert_validMoose::Meta::TypeConstraint::assert_valid
0000s0sMoose::Meta::TypeConstraint::::checkMoose::Meta::TypeConstraint::check
0000s0sMoose::Meta::TypeConstraint::::coerceMoose::Meta::TypeConstraint::coerce
0000s0sMoose::Meta::TypeConstraint::::equalsMoose::Meta::TypeConstraint::equals
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::::is_subtype_ofMoose::Meta::TypeConstraint::is_subtype_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
# spent 17µs within Moose::Meta::TypeConstraint::BEGIN@3 which was called: # once (17µs+0s) by Moose::BEGIN@28 at line 5
BEGIN {
417µs $Moose::Meta::TypeConstraint::AUTHORITY = 'cpan:STEVAN';
5142µs117µs}
# spent 17µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@3
6{
721µs $Moose::Meta::TypeConstraint::VERSION = '2.1005';
8}
9
10230µs242µs
# spent 25µs (8+17) within Moose::Meta::TypeConstraint::BEGIN@10 which was called: # once (8µs+17µs) by Moose::BEGIN@28 at line 10
use strict;
# spent 25µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@10 # spent 17µs making 1 call to strict::import
11229µs221µs
# spent 16µs (10+6) within Moose::Meta::TypeConstraint::BEGIN@11 which was called: # once (10µs+6µs) by Moose::BEGIN@28 at line 11
use warnings;
# spent 16µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@11 # spent 6µs making 1 call to warnings::import
122216µs22.02ms
# spent 1.40ms (567µs+834µs) within Moose::Meta::TypeConstraint::BEGIN@12 which was called: # once (567µs+834µs) by Moose::BEGIN@28 at line 12
use metaclass;
# spent 1.40ms making 1 call to Moose::Meta::TypeConstraint::BEGIN@12 # spent 615µs making 1 call to metaclass::import
13
14
# spent 66µs (15+51) within Moose::Meta::TypeConstraint::BEGIN@14 which was called: # once (15µs+51µs) by Moose::BEGIN@28 at line 17
use overload '0+' => sub { refaddr(shift) }, # id an object
15 '""' => sub { shift->name }, # stringify to tc name
1675170µs
# spent 87µs within Moose::Meta::TypeConstraint::__ANON__[/opt/perl-5.18.1/lib/site_perl/5.18.1/darwin-thread-multi-2level/Moose/Meta/TypeConstraint.pm:16] which was called 75 times, avg 1µs/call: # 25 times (26µs+0s) by Moose::Meta::TypeConstraint::Registry::add_type_constraint at line 51 of Moose/Meta/TypeConstraint/Registry.pm, avg 1µs/call # 17 times (34µs+0s) by Moose::Util::TypeConstraints::find_or_parse_type_constraint at line 274 of Moose/Util/TypeConstraints.pm, avg 2µs/call # 17 times (14µs+0s) by Moose::Util::TypeConstraints::find_or_create_isa_type_constraint at line 260 of Moose/Util/TypeConstraints.pm, avg 841ns/call # 16 times (13µs+0s) by Moose::Util::TypeConstraints::_create_type_constraint at line 565 of Moose/Util/TypeConstraints.pm, avg 806ns/call
bool => sub { 1 },
17241µs2117µs fallback => 1;
# spent 66µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@14 # spent 51µs making 1 call to overload::import
18
19237µs283µs
# spent 47µs (10+37) within Moose::Meta::TypeConstraint::BEGIN@19 which was called: # once (10µs+37µs) by Moose::BEGIN@28 at line 19
use Carp qw(confess);
# spent 47µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@19 # spent 37µs making 1 call to Exporter::import
20233µs265µs
# spent 37µs (9+28) within Moose::Meta::TypeConstraint::BEGIN@20 which was called: # once (9µs+28µs) by Moose::BEGIN@28 at line 20
use Class::Load qw(load_class);
# spent 37µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@20 # spent 28µs making 1 call to Exporter::import
21235µs264µs
# spent 37µs (10+27) within Moose::Meta::TypeConstraint::BEGIN@21 which was called: # once (10µs+27µs) by Moose::BEGIN@28 at line 21
use Eval::Closure;
# spent 37µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@21 # spent 27µs making 1 call to Exporter::import
22235µs282µs
# spent 46µs (10+36) within Moose::Meta::TypeConstraint::BEGIN@22 which was called: # once (10µs+36µs) by Moose::BEGIN@28 at line 22
use Scalar::Util qw(blessed refaddr);
# spent 46µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@22 # spent 36µs making 1 call to Exporter::import
23232µs261µs
# spent 35µs (9+26) within Moose::Meta::TypeConstraint::BEGIN@23 which was called: # once (9µs+26µs) by Moose::BEGIN@28 at line 23
use Sub::Name qw(subname);
# spent 35µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@23 # spent 26µs making 1 call to Exporter::import
24240µs278µs
# spent 44µs (10+34) within Moose::Meta::TypeConstraint::BEGIN@24 which was called: # once (10µs+34µs) by Moose::BEGIN@28 at line 24
use Try::Tiny;
# spent 44µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@24 # spent 34µs making 1 call to Exporter::import
25
2622.45ms2157µs
# spent 83µs (9+74) within Moose::Meta::TypeConstraint::BEGIN@26 which was called: # once (9µs+74µs) by Moose::BEGIN@28 at line 26
use base qw(Class::MOP::Object);
# spent 83µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@26 # spent 74µs making 1 call to base::import
27
2815µs3426µs__PACKAGE__->meta->add_attribute('name' => (
# spent 396µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 22µs making 1 call to Moose::Meta::TypeConstraint::meta # spent 7µs making 1 call to Class::MOP::_definition_context
29 reader => 'name',
30 Class::MOP::_definition_context(),
31));
3214µs3612µs__PACKAGE__->meta->add_attribute('parent' => (
# spent 592µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 13µs making 1 call to Moose::Meta::TypeConstraint::meta # spent 7µs making 1 call to Class::MOP::_definition_context
33 reader => 'parent',
34 predicate => 'has_parent',
35 Class::MOP::_definition_context(),
36));
37
3812µsmy $null_constraint = sub { 1 };
39__PACKAGE__->meta->add_attribute('constraint' => (
40 reader => 'constraint',
41 writer => '_set_constraint',
4214µs
# spent 2µs within Moose::Meta::TypeConstraint::__ANON__[/opt/perl-5.18.1/lib/site_perl/5.18.1/darwin-thread-multi-2level/Moose/Meta/TypeConstraint.pm:42] which was called: # once (2µs+0s) by Moose::Meta::TypeConstraint::_new at line 24 of (eval 88)[Eval/Closure.pm:144]
default => sub { $null_constraint },
4316µs3629µs Class::MOP::_definition_context(),
# spent 609µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 13µs making 1 call to Moose::Meta::TypeConstraint::meta # spent 7µs making 1 call to Class::MOP::_definition_context
44));
45
4614µs3616µs__PACKAGE__->meta->add_attribute('message' => (
# spent 597µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 13µs making 1 call to Moose::Meta::TypeConstraint::meta # spent 7µs making 1 call to Class::MOP::_definition_context
47 accessor => 'message',
48 predicate => 'has_message',
49 Class::MOP::_definition_context(),
50));
51
5214µs3390µs__PACKAGE__->meta->add_attribute('_default_message' => (
# spent 370µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 13µs making 1 call to Moose::Meta::TypeConstraint::meta # spent 7µs making 1 call to Class::MOP::_definition_context
53 accessor => '_default_message',
54 Class::MOP::_definition_context(),
55));
56
57# can't make this a default because it has to close over the type name, and
58# cmop attributes don't have lazy
59
# spent 110µs within Moose::Meta::TypeConstraint::__ANON__[/opt/perl-5.18.1/lib/site_perl/5.18.1/darwin-thread-multi-2level/Moose/Meta/TypeConstraint.pm:77] which was called 25 times, avg 4µs/call: # 25 times (110µs+0s) by Moose::Meta::TypeConstraint::new at line 146, avg 4µs/call
my $_default_message_generator = sub {
602511µs my $name = shift;
61 sub {
62 my $value = shift;
63 # have to load it late like this, since it uses Moose itself
64 my $can_partialdump = try {
65 # versions prior to 0.14 had a potential infinite loop bug
66 load_class('Devel::PartialDump', { -version => 0.14 });
67 1;
68 };
69 if ($can_partialdump) {
70 $value = Devel::PartialDump->new->dump($value);
71 }
72 else {
73 $value = (defined $value ? overload::StrVal($value) : 'undef');
74 }
75 return "Validation failed for '" . $name . "' with value $value";
76 }
77265.37ms};
7815µs3634µs__PACKAGE__->meta->add_attribute('coercion' => (
# spent 610µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 13µs making 1 call to Moose::Meta::TypeConstraint::meta # spent 11µs making 1 call to Class::MOP::_definition_context
79 accessor => 'coercion',
80 predicate => 'has_coercion',
81 Class::MOP::_definition_context(),
82));
83
8415µs3617µs__PACKAGE__->meta->add_attribute('hand_optimized_type_constraint' => (
# spent 597µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 13µs making 1 call to Moose::Meta::TypeConstraint::meta # spent 7µs making 1 call to Class::MOP::_definition_context
85 init_arg => 'optimized',
86 accessor => 'hand_optimized_type_constraint',
87 predicate => 'has_hand_optimized_type_constraint',
88 Class::MOP::_definition_context(),
89));
90
9114µs3613µs__PACKAGE__->meta->add_attribute('inlined' => (
# spent 593µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 13µs making 1 call to Moose::Meta::TypeConstraint::meta # spent 7µs making 1 call to Class::MOP::_definition_context
92 init_arg => 'inlined',
93 accessor => 'inlined',
94 predicate => '_has_inlined_type_constraint',
95 Class::MOP::_definition_context(),
96));
97
98__PACKAGE__->meta->add_attribute('inline_environment' => (
99 init_arg => 'inline_environment',
100 accessor => '_inline_environment',
1012575µs
# spent 37µs within Moose::Meta::TypeConstraint::__ANON__[/opt/perl-5.18.1/lib/site_perl/5.18.1/darwin-thread-multi-2level/Moose/Meta/TypeConstraint.pm:101] which was called 25 times, avg 1µs/call: # 17 times (22µs+0s) by Moose::Meta::TypeConstraint::_new at line 33 of (eval 88)[Eval/Closure.pm:144], avg 1µs/call # 4 times (9µs+0s) by Moose::Meta::TypeConstraint::Class::_new at line 36 of (eval 102)[Eval/Closure.pm:144], avg 2µs/call # 4 times (6µs+0s) by Moose::Meta::TypeConstraint::Parameterizable::_new at line 36 of (eval 100)[Eval/Closure.pm:144], avg 2µs/call
default => sub { {} },
10216µs35.32ms Class::MOP::_definition_context(),
# spent 5.30ms making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 12µs making 1 call to Moose::Meta::TypeConstraint::meta # spent 7µs making 1 call to Class::MOP::_definition_context
103));
104
105sub parents {
106 my $self = shift;
107 $self->parent;
108}
109
110# private accessors
111
11214µs3606µs__PACKAGE__->meta->add_attribute('compiled_type_constraint' => (
# spent 586µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 13µs making 1 call to Moose::Meta::TypeConstraint::meta # spent 7µs making 1 call to Class::MOP::_definition_context
113 accessor => '_compiled_type_constraint',
114 predicate => '_has_compiled_type_constraint',
115 Class::MOP::_definition_context(),
116));
117
11814µs3392µs__PACKAGE__->meta->add_attribute('package_defined_in' => (
# spent 372µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 13µs making 1 call to Moose::Meta::TypeConstraint::meta # spent 7µs making 1 call to Class::MOP::_definition_context
119 accessor => '_package_defined_in',
120 Class::MOP::_definition_context(),
121));
122
123
# spent 13.5ms (6.00+7.52) within Moose::Meta::TypeConstraint::new which was called 25 times, avg 541µs/call: # 16 times (428µs+4.64ms) by Moose::Meta::TypeConstraint::create_child_type at line 423, avg 317µs/call # 4 times (160µs+1.45ms) by Moose::Meta::TypeConstraint::Class::new at line 43 of Moose/Meta/TypeConstraint/Class.pm, avg 402µs/call # once (5.28ms+315µs) by Moose::Util::TypeConstraints::_create_type_constraint at line 575 of Moose/Util/TypeConstraints.pm # once (42µs+383µs) by Moose::Util::TypeConstraints::Builtins::define_builtins at line 204 of Moose/Util/TypeConstraints/Builtins.pm # once (29µs+263µs) by Moose::Util::TypeConstraints::Builtins::define_builtins at line 274 of Moose/Util/TypeConstraints/Builtins.pm # once (34µs+242µs) by Moose::Util::TypeConstraints::Builtins::define_builtins at line 239 of Moose/Util/TypeConstraints/Builtins.pm # once (29µs+233µs) by Moose::Util::TypeConstraints::Builtins::define_builtins at line 300 of Moose/Util/TypeConstraints/Builtins.pm
sub new {
124257µs my $class = shift;
1252542µs my ($first, @rest) = @_;
1262566µs my %args = ref $first ? %$first : $first ? ($first, @rest) : ();
1272522µs $args{name} = $args{name} ? "$args{name}" : "__ANON__";
128
129256µs if ( $args{optimized} ) {
130 Moose::Deprecated::deprecated(
131 feature => 'optimized type constraint sub ref',
132 message =>
133 'Providing an optimized subroutine ref for type constraints is deprecated.'
134 . ' Use the inlining feature (inline_as) instead.'
135 );
136 }
137
138257µs if ( exists $args{message}
139 && (!ref($args{message}) || ref($args{message}) ne 'CODE') ) {
140 confess("The 'message' parameter must be a coderef");
141 }
142
1432562µs25841µs my $self = $class->_new(%args);
# spent 422µs making 17 calls to Moose::Meta::TypeConstraint::_new, avg 25µs/call # spent 232µs making 4 calls to Moose::Meta::TypeConstraint::Class::_new, avg 58µs/call # spent 186µs making 4 calls to Moose::Meta::TypeConstraint::Parameterizable::_new, avg 47µs/call
14425101µs506.40ms $self->compile_type_constraint()
# spent 6.35ms making 25 calls to Moose::Meta::TypeConstraint::compile_type_constraint, avg 254µs/call # spent 51µs making 25 calls to Moose::Meta::TypeConstraint::_has_compiled_type_constraint, avg 2µs/call
145 unless $self->_has_compiled_type_constraint;
14625142µs100273µs $self->_default_message($_default_message_generator->($self->name))
# spent 110µs making 25 calls to Moose::Meta::TypeConstraint::__ANON__[Moose/Meta/TypeConstraint.pm:77], avg 4µs/call # spent 73µs making 25 calls to Moose::Meta::TypeConstraint::_default_message, avg 3µs/call # spent 45µs making 25 calls to Moose::Meta::TypeConstraint::name, avg 2µs/call # spent 44µs making 25 calls to Moose::Meta::TypeConstraint::has_message, avg 2µs/call
147 unless $self->has_message;
14825119µs return $self;
149}
150
- -
153sub coerce {
154 my $self = shift;
155
156 my $coercion = $self->coercion;
157
158 unless ($coercion) {
159 require Moose;
160 Moose->throw_error("Cannot coerce without a type coercion");
161 }
162
163 return $_[0] if $self->check($_[0]);
164
165 return $coercion->coerce(@_);
166}
167
168sub assert_coerce {
169 my $self = shift;
170
171 my $result = $self->coerce(@_);
172
173 $self->assert_valid($result);
174
175 return $result;
176}
177
178sub check {
179 my ($self, @args) = @_;
180 my $constraint_subref = $self->_compiled_type_constraint;
181 return $constraint_subref->(@args) ? 1 : undef;
182}
183
184sub validate {
185 my ($self, $value) = @_;
186 if ($self->_compiled_type_constraint->($value)) {
187 return undef;
188 }
189 else {
190 $self->get_message($value);
191 }
192}
193
194
# spent 936µs (629+307) within Moose::Meta::TypeConstraint::can_be_inlined which was called 78 times, avg 12µs/call: # 44 times (316µs+162µs) by Moose::Meta::TypeConstraint::_inline_check at line 207, avg 11µs/call # 29 times (271µs+140µs) by Moose::Meta::TypeConstraint::_actually_compile_type_constraint at line 311, avg 14µs/call # 2 times (21µs+12µs) by Moose::Meta::Attribute::_inline_check_constraint at line 711 of Moose/Meta/Attribute.pm, avg 16µs/call # 2 times (12µs+-12µs) by Moose::Meta::TypeConstraint::can_be_inlined at line 197, avg 0s/call # once (9µs+5µs) by Moose::Meta::Attribute::_eval_environment at line 789 of Moose/Meta/Attribute.pm
sub can_be_inlined {
1957812µs my $self = shift;
196
19778179µs155201µs if ( $self->has_parent && $self->constraint == $null_constraint ) {
# spent 99µs making 73 calls to Moose::Meta::TypeConstraint::constraint, avg 1µs/call # spent 98µs making 78 calls to Moose::Meta::TypeConstraint::has_parent, avg 1µs/call # spent 3µs making 2 calls to Moose::Meta::TypeConstraint::parent, avg 2µs/call # spent 17µs making 2 calls to Moose::Meta::TypeConstraint::can_be_inlined, avg 8µs/call, recursion: max depth 1, sum of overlapping time 17µs
198 return $self->parent->can_be_inlined;
199 }
200
20176230µs76106µs return $self->_has_inlined_type_constraint;
# spent 106µs making 76 calls to Moose::Meta::TypeConstraint::_has_inlined_type_constraint, avg 1µs/call
202}
203
204
# spent 1.54ms (627µs+908µs) within Moose::Meta::TypeConstraint::_inline_check which was called 44 times, avg 35µs/call: # 29 times (429µs+895µs) by Moose::Meta::TypeConstraint::_actually_compile_type_constraint at line 311, avg 46µs/call # 6 times (80µs+-80µs) by Moose::Util::TypeConstraints::Builtins::__ANON__[/opt/perl-5.18.1/lib/site_perl/5.18.1/darwin-thread-multi-2level/Moose/Util/TypeConstraints/Builtins.pm:66] at line 64 of Moose/Util/TypeConstraints/Builtins.pm, avg 0s/call # 3 times (39µs+-39µs) by Moose::Util::TypeConstraints::Builtins::__ANON__[/opt/perl-5.18.1/lib/site_perl/5.18.1/darwin-thread-multi-2level/Moose/Util/TypeConstraints/Builtins.pm:120] at line 118 of Moose/Util/TypeConstraints/Builtins.pm, avg 0s/call # 2 times (28µs+183µs) by Moose::Meta::Attribute::_inline_check_constraint at line 711 of Moose/Meta/Attribute.pm, avg 106µs/call # once (13µs+-13µs) by Moose::Meta::TypeConstraint::_inline_check at line 212 # once (12µs+-12µs) by Moose::Util::TypeConstraints::Builtins::__ANON__[/opt/perl-5.18.1/lib/site_perl/5.18.1/darwin-thread-multi-2level/Moose/Util/TypeConstraints/Builtins.pm:176] at line 171 of Moose/Util/TypeConstraints/Builtins.pm # once (14µs+-14µs) by Moose::Util::TypeConstraints::Builtins::__ANON__[/opt/perl-5.18.1/lib/site_perl/5.18.1/darwin-thread-multi-2level/Moose/Util/TypeConstraints/Builtins.pm:83] at line 78 of Moose/Util/TypeConstraints/Builtins.pm # once (12µs+-12µs) by Moose::Util::TypeConstraints::Builtins::__ANON__[/opt/perl-5.18.1/lib/site_perl/5.18.1/darwin-thread-multi-2level/Moose/Util/TypeConstraints/Builtins.pm:112] at line 103 of Moose/Util/TypeConstraints/Builtins.pm
sub _inline_check {
205449µs my $self = shift;
206
2074442µs44477µs unless ( $self->can_be_inlined ) {
# spent 477µs making 44 calls to Moose::Meta::TypeConstraint::can_be_inlined, avg 11µs/call
208 require Moose;
209 Moose->throw_error( 'Cannot inline a type constraint check for ' . $self->name );
210 }
211
2124486µs8893µs if ( $self->has_parent && $self->constraint == $null_constraint ) {
# spent 48µs making 44 calls to Moose::Meta::TypeConstraint::has_parent, avg 1µs/call # spent 44µs making 42 calls to Moose::Meta::TypeConstraint::constraint, avg 1µs/call # spent 1µs making 1 call to Moose::Meta::TypeConstraint::parent # spent 24µs making 1 call to Moose::Meta::TypeConstraint::_inline_check, recursion: max depth 1, sum of overlapping time 24µs
213 return $self->parent->_inline_check(@_);
214 }
215
21643245µs86877µs return '( do { ' . $self->inlined->( $self, @_ ) . ' } )';
# spent 243µs making 6 calls to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:66], avg 40µs/call # spent 224µs making 3 calls to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:120], avg 75µs/call # spent 106µs making 8 calls to Moose::Meta::TypeConstraint::Class::__ANON__[Moose/Meta/TypeConstraint/Class.pm:30], avg 13µs/call # spent 83µs making 1 call to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:83] # spent 68µs making 1 call to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:112] # spent 62µs making 43 calls to Moose::Meta::TypeConstraint::inlined, avg 1µs/call # spent 40µs making 1 call to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:176] # spent 13µs making 7 calls to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:46], avg 2µs/call # spent 4µs making 2 calls to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:163], avg 2µs/call # spent 4µs making 1 call to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:152] # spent 4µs making 1 call to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:58] # spent 3µs making 1 call to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:195] # spent 3µs making 1 call to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:125] # spent 2µs making 1 call to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:137] # spent 2µs making 2 calls to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:28], avg 1µs/call # spent 2µs making 1 call to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:223] # spent 2µs making 1 call to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:258] # spent 2µs making 1 call to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:39] # spent 2µs making 1 call to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:72] # spent 2µs making 1 call to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:132] # spent 2µs making 1 call to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:157] # spent 1µs making 1 call to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:291]
217}
218
219
# spent 415µs (285+130) within Moose::Meta::TypeConstraint::inline_environment which was called 32 times, avg 13µs/call: # 29 times (258µs+128µs) by Moose::Meta::TypeConstraint::_actually_compile_type_constraint at line 311, avg 13µs/call # once (10µs+5µs) by Moose::Meta::Attribute::_eval_environment at line 800 of Moose/Meta/Attribute.pm # once (10µs+5µs) by Moose::Meta::Class::_eval_environment at line 543 of Moose/Meta/Class.pm # once (8µs+-8µs) by Moose::Meta::TypeConstraint::inline_environment at line 222
sub inline_environment {
220327µs my $self = shift;
221
2223265µs6480µs if ( $self->has_parent && $self->constraint == $null_constraint ) {
# spent 38µs making 32 calls to Moose::Meta::TypeConstraint::has_parent, avg 1µs/call # spent 35µs making 30 calls to Moose::Meta::TypeConstraint::constraint, avg 1µs/call # spent 7µs making 1 call to Moose::Meta::TypeConstraint::parent # spent 10µs making 1 call to Moose::Meta::TypeConstraint::inline_environment, recursion: max depth 1, sum of overlapping time 10µs
223 return $self->parent->inline_environment;
224 }
225
22631110µs3150µs return $self->_inline_environment;
# spent 50µs making 31 calls to Moose::Meta::TypeConstraint::_inline_environment, avg 2µs/call
227}
228
229sub assert_valid {
230 my ($self, $value) = @_;
231
232 my $error = $self->validate($value);
233 return 1 if ! defined $error;
234
235 require Moose;
236 Moose->throw_error($error);
237}
238
239sub get_message {
240 my ($self, $value) = @_;
241 my $msg = $self->has_message
242 ? $self->message
243 : $self->_default_message;
244 local $_ = $value;
245 return $msg->($value);
246}
247
248## type predicates ...
249
250sub equals {
251 my ( $self, $type_or_name ) = @_;
252
253 my $other = Moose::Util::TypeConstraints::find_type_constraint($type_or_name) or return;
254
255 return 1 if $self == $other;
256
257 if ( $self->has_hand_optimized_type_constraint and $other->has_hand_optimized_type_constraint ) {
258 return 1 if $self->hand_optimized_type_constraint == $other->hand_optimized_type_constraint;
259 }
260
261 return unless $self->constraint == $other->constraint;
262
263 if ( $self->has_parent ) {
264 return unless $other->has_parent;
265 return unless $self->parent->equals( $other->parent );
266 } else {
267 return if $other->has_parent;
268 }
269
270 return;
271}
272
273sub is_a_type_of {
274 my ($self, $type_or_name) = @_;
275
276 my $type = Moose::Util::TypeConstraints::find_type_constraint($type_or_name) or return;
277
278 ($self->equals($type) || $self->is_subtype_of($type));
279}
280
281sub is_subtype_of {
282 my ($self, $type_or_name) = @_;
283
284 my $type = Moose::Util::TypeConstraints::find_type_constraint($type_or_name) or return;
285
286 my $current = $self;
287
288 while (my $parent = $current->parent) {
289 return 1 if $parent->equals($type);
290 $current = $parent;
291 }
292
293 return 0;
294}
295
296## compiling the type constraint
297
298
# spent 7.36ms (195µs+7.17) within Moose::Meta::TypeConstraint::compile_type_constraint which was called 29 times, avg 254µs/call: # 25 times (170µs+6.18ms) by Moose::Meta::TypeConstraint::new at line 144, avg 254µs/call # 4 times (25µs+986µs) by Moose::Meta::TypeConstraint::Class::new at line 45 of Moose/Meta/TypeConstraint/Class.pm, avg 253µs/call
sub compile_type_constraint {
299297µs my $self = shift;
30029141µs587.17ms $self->_compiled_type_constraint($self->_actually_compile_type_constraint);
# spent 7.04ms making 29 calls to Moose::Meta::TypeConstraint::_actually_compile_type_constraint, avg 243µs/call # spent 133µs making 29 calls to Moose::Meta::TypeConstraint::_compiled_type_constraint, avg 5µs/call
301}
302
303## type compilers ...
304
305
# spent 7.04ms (410µs+6.63) within Moose::Meta::TypeConstraint::_actually_compile_type_constraint which was called 29 times, avg 243µs/call: # 29 times (410µs+6.63ms) by Moose::Meta::TypeConstraint::compile_type_constraint at line 300, avg 243µs/call
sub _actually_compile_type_constraint {
306294µs my $self = shift;
307
3082941µs2944µs return $self->_compile_hand_optimized_type_constraint
# spent 44µs making 29 calls to Moose::Meta::TypeConstraint::has_hand_optimized_type_constraint, avg 2µs/call
309 if $self->has_hand_optimized_type_constraint;
310
31129217µs1166.58ms if ( $self->can_be_inlined ) {
# spent 4.46ms making 29 calls to Eval::Closure::eval_closure, avg 154µs/call # spent 1.32ms making 29 calls to Moose::Meta::TypeConstraint::_inline_check, avg 46µs/call # spent 412µs making 29 calls to Moose::Meta::TypeConstraint::can_be_inlined, avg 14µs/call # spent 386µs making 29 calls to Moose::Meta::TypeConstraint::inline_environment, avg 13µs/call
312 return eval_closure(
313 source => 'sub { ' . $self->_inline_check('$_[0]') . ' }',
314 environment => $self->inline_environment,
315 );
316 }
317
318 my $check = $self->constraint;
319 unless ( defined $check ) {
320 require Moose;
321 Moose->throw_error( "Could not compile type constraint '"
322 . $self->name
323 . "' because no constraint check" );
324 }
325
326 return $self->_compile_subtype($check)
327 if $self->has_parent;
328
329 return $self->_compile_type($check);
330}
331
332sub _compile_hand_optimized_type_constraint {
333 my $self = shift;
334
335 my $type_constraint = $self->hand_optimized_type_constraint;
336
337 unless ( ref $type_constraint ) {
338 require Moose;
339 Moose->throw_error("Hand optimized type constraint is not a code reference");
340 }
341
342 return $type_constraint;
343}
344
345sub _compile_subtype {
346 my ($self, $check) = @_;
347
348 # gather all the parent constraints in order
349 my @parents;
350 my $optimized_parent;
351 foreach my $parent ($self->_collect_all_parents) {
352 # if a parent is optimized, the optimized constraint already includes
353 # all of its parents tcs, so we can break the loop
354 if ($parent->has_hand_optimized_type_constraint) {
355 push @parents => $optimized_parent = $parent->hand_optimized_type_constraint;
356 last;
357 }
358 else {
359 push @parents => $parent->constraint;
360 }
361 }
362
363 @parents = grep { $_ != $null_constraint } reverse @parents;
364
365 unless ( @parents ) {
366 return $self->_compile_type($check);
367 } elsif( $optimized_parent and @parents == 1 ) {
368 # the case of just one optimized parent is optimized to prevent
369 # looping and the unnecessary localization
370 if ( $check == $null_constraint ) {
371 return $optimized_parent;
372 } else {
373 return subname($self->name, sub {
374 return undef unless $optimized_parent->($_[0]);
375 my (@args) = @_;
376 local $_ = $args[0];
377 $check->(@args);
378 });
379 }
380 } else {
381 # general case, check all the constraints, from the first parent to ourselves
382 my @checks = @parents;
383 push @checks, $check if $check != $null_constraint;
384 return subname($self->name => sub {
385 my (@args) = @_;
386 local $_ = $args[0];
387 foreach my $check (@checks) {
388 return undef unless $check->(@args);
389 }
390 return 1;
391 });
392 }
393}
394
395sub _compile_type {
396 my ($self, $check) = @_;
397
398 return $check if $check == $null_constraint; # Item, Any
399
400 return subname($self->name => sub {
401 my (@args) = @_;
402 local $_ = $args[0];
403 $check->(@args);
404 });
405}
406
407## other utils ...
408
409sub _collect_all_parents {
410 my $self = shift;
411 my @parents;
412 my $current = $self->parent;
413 while (defined $current) {
414 push @parents => $current;
415 $current = $current->parent;
416 }
417 return @parents;
418}
419
420
# spent 5.18ms (111µs+5.06) within Moose::Meta::TypeConstraint::create_child_type which was called 16 times, avg 323µs/call: # 16 times (111µs+5.06ms) by Moose::Util::TypeConstraints::_create_type_constraint at line 565 of Moose/Util/TypeConstraints.pm, avg 323µs/call
sub create_child_type {
4211621µs my ($self, %opts) = @_;
422169µs my $class = ref $self;
4231672µs165.06ms return $class->new(%opts, parent => $self);
# spent 5.06ms making 16 calls to Moose::Meta::TypeConstraint::new, avg 317µs/call
424}
425
426125µs1;
427
428# ABSTRACT: The Moose Type Constraint metaclass
429
430__END__