← Index
NYTProf Performance Profile   « block view • line view • sub view »
For xt/tapper-mcp-scheduler-with-db-longrun.t
  Run on Tue May 22 17:18:39 2012
Reported on Tue May 22 17:22:47 2012

Filename/2home/ss5/perl5/perlbrew/perls/perl-5.12.3/lib/site_perl/5.12.3/x86_64-linux/Moose/Meta/TypeConstraint.pm
StatementsExecuted 1556 statements in 5.96ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
33851.06ms11.6msMoose::Meta::TypeConstraint::::newMoose::Meta::TypeConstraint::new
11052895µs1.38msMoose::Meta::TypeConstraint::::can_be_inlinedMoose::Meta::TypeConstraint::can_be_inlined (recurses: max depth 1, inclusive time 19µs)
5683776µs2.12msMoose::Meta::TypeConstraint::::_inline_checkMoose::Meta::TypeConstraint::_inline_check (recurses: max depth 2, inclusive time 307µs)
4511641µs9.66msMoose::Meta::TypeConstraint::::_actually_compile_type_constraintMoose::Meta::TypeConstraint::_actually_compile_type_constraint
111417µs1.28msMoose::Meta::TypeConstraint::::BEGIN@12Moose::Meta::TypeConstraint::BEGIN@12
4732411µs608µsMoose::Meta::TypeConstraint::::inline_environmentMoose::Meta::TypeConstraint::inline_environment (recurses: max depth 1, inclusive time 8µs)
4533301µs10.2msMoose::Meta::TypeConstraint::::compile_type_constraintMoose::Meta::TypeConstraint::compile_type_constraint
3311156µs156µsMoose::Meta::TypeConstraint::::__ANON__[:77]Moose::Meta::TypeConstraint::__ANON__[:77]
9142102µs102µsMoose::Meta::TypeConstraint::::__ANON__[:16]Moose::Meta::TypeConstraint::__ANON__[:16]
161193µs4.32msMoose::Meta::TypeConstraint::::create_child_typeMoose::Meta::TypeConstraint::create_child_type
334466µs66µsMoose::Meta::TypeConstraint::::__ANON__[:101]Moose::Meta::TypeConstraint::__ANON__[:101]
31135µs85µsMoose::Meta::TypeConstraint::::checkMoose::Meta::TypeConstraint::check
41122µs27µsMoose::Meta::TypeConstraint::::_compile_hand_optimized_type_constraintMoose::Meta::TypeConstraint::_compile_hand_optimized_type_constraint
11116µs68µsMoose::Meta::TypeConstraint::::BEGIN@14Moose::Meta::TypeConstraint::BEGIN@14
11110µs10µsMoose::Meta::TypeConstraint::::BEGIN@3Moose::Meta::TypeConstraint::BEGIN@3
1119µs14µsMoose::Meta::TypeConstraint::::BEGIN@10Moose::Meta::TypeConstraint::BEGIN@10
1119µs270µsMoose::Meta::TypeConstraint::::BEGIN@21Moose::Meta::TypeConstraint::BEGIN@21
1119µs41µsMoose::Meta::TypeConstraint::::BEGIN@19Moose::Meta::TypeConstraint::BEGIN@19
1118µs83µsMoose::Meta::TypeConstraint::::BEGIN@26Moose::Meta::TypeConstraint::BEGIN@26
1118µs24µsMoose::Meta::TypeConstraint::::BEGIN@11Moose::Meta::TypeConstraint::BEGIN@11
1118µs33µsMoose::Meta::TypeConstraint::::BEGIN@22Moose::Meta::TypeConstraint::BEGIN@22
1118µs27µsMoose::Meta::TypeConstraint::::BEGIN@20Moose::Meta::TypeConstraint::BEGIN@20
1117µs36µsMoose::Meta::TypeConstraint::::BEGIN@24Moose::Meta::TypeConstraint::BEGIN@24
1117µs26µsMoose::Meta::TypeConstraint::::BEGIN@23Moose::Meta::TypeConstraint::BEGIN@23
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__[:387]Moose::Meta::TypeConstraint::__ANON__[:387]
0000s0sMoose::Meta::TypeConstraint::::__ANON__[:38]Moose::Meta::TypeConstraint::__ANON__[:38]
0000s0sMoose::Meta::TypeConstraint::::__ANON__[:400]Moose::Meta::TypeConstraint::__ANON__[:400]
0000s0sMoose::Meta::TypeConstraint::::__ANON__[:413]Moose::Meta::TypeConstraint::__ANON__[:413]
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_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::::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 10µs within Moose::Meta::TypeConstraint::BEGIN@3 which was called: # once (10µs+0s) by Moose::BEGIN@29 at line 5
BEGIN {
414µs $Moose::Meta::TypeConstraint::AUTHORITY = 'cpan:STEVAN';
5124µs110µs}
# spent 10µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@3
6{
722µs $Moose::Meta::TypeConstraint::VERSION = '2.0602';
8}
9
10320µs219µs
# spent 14µs (9+5) within Moose::Meta::TypeConstraint::BEGIN@10 which was called: # once (9µs+5µs) by Moose::BEGIN@29 at line 10
use strict;
# spent 14µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@10 # spent 5µs making 1 call to strict::import
11319µs240µs
# spent 24µs (8+16) within Moose::Meta::TypeConstraint::BEGIN@11 which was called: # once (8µs+16µs) by Moose::BEGIN@29 at line 11
use warnings;
# spent 24µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@11 # spent 16µs making 1 call to warnings::import
123156µs21.96ms
# spent 1.28ms (417µs+861µs) within Moose::Meta::TypeConstraint::BEGIN@12 which was called: # once (417µs+861µs) by Moose::BEGIN@29 at line 12
use metaclass;
# spent 1.28ms making 1 call to Moose::Meta::TypeConstraint::BEGIN@12 # spent 681µs making 1 call to metaclass::import
13
14
# spent 68µs (16+53) within Moose::Meta::TypeConstraint::BEGIN@14 which was called: # once (16µs+53µs) by Moose::BEGIN@29 at line 17
use overload '0+' => sub { refaddr(shift) }, # id an object
15 '""' => sub { shift->name }, # stringify to tc name
1691225µs
# spent 102µs within Moose::Meta::TypeConstraint::__ANON__[/2home/ss5/perl5/perlbrew/perls/perl-5.12.3/lib/site_perl/5.12.3/x86_64-linux/Moose/Meta/TypeConstraint.pm:16] which was called 91 times, avg 1µs/call: # 33 times (42µs+0s) by Moose::Meta::TypeConstraint::Registry::add_type_constraint at line 51 of Moose/Meta/TypeConstraint/Registry.pm, avg 1µs/call # 21 times (30µs+0s) by Moose::Util::TypeConstraints::find_or_parse_type_constraint at line 274 of Moose/Util/TypeConstraints.pm, avg 1µs/call # 21 times (19µs+0s) by Moose::Util::TypeConstraints::find_or_create_isa_type_constraint at line 260 of Moose/Util/TypeConstraints.pm, avg 905ns/call # 16 times (11µs+0s) by Moose::Util::TypeConstraints::_create_type_constraint at line 565 of Moose/Util/TypeConstraints.pm, avg 675ns/call
bool => sub { 1 },
17331µs2121µs fallback => 1;
# spent 68µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@14 # spent 53µs making 1 call to overload::import
18
19321µs274µs
# spent 41µs (9+33) within Moose::Meta::TypeConstraint::BEGIN@19 which was called: # once (9µs+33µs) by Moose::BEGIN@29 at line 19
use Carp qw(confess);
# spent 41µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@19 # spent 33µs making 1 call to Exporter::import
20322µs246µs
# spent 27µs (8+19) within Moose::Meta::TypeConstraint::BEGIN@20 which was called: # once (8µs+19µs) by Moose::BEGIN@29 at line 20
use Class::Load qw(load_class);
# spent 27µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@20 # spent 19µs making 1 call to Exporter::import
21325µs2531µs
# spent 270µs (9+261) within Moose::Meta::TypeConstraint::BEGIN@21 which was called: # once (9µs+261µs) by Moose::BEGIN@29 at line 21
use Eval::Closure;
# spent 270µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@21 # spent 261µs making 1 call to Sub::Exporter::__ANON__[Sub/Exporter.pm:756]
22320µs259µs
# spent 33µs (8+26) within Moose::Meta::TypeConstraint::BEGIN@22 which was called: # once (8µs+26µs) by Moose::BEGIN@29 at line 22
use Scalar::Util qw(blessed refaddr);
# spent 33µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@22 # spent 26µs making 1 call to Exporter::import
23318µs245µs
# spent 26µs (7+19) within Moose::Meta::TypeConstraint::BEGIN@23 which was called: # once (7µs+19µs) by Moose::BEGIN@29 at line 23
use Sub::Name qw(subname);
# spent 26µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@23 # spent 19µs making 1 call to Exporter::import
24318µs266µs
# spent 36µs (7+29) within Moose::Meta::TypeConstraint::BEGIN@24 which was called: # once (7µs+29µs) by Moose::BEGIN@29 at line 24
use Try::Tiny;
# spent 36µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@24 # spent 29µs making 1 call to Exporter::import
25
2631.59ms2158µs
# spent 83µs (8+75) within Moose::Meta::TypeConstraint::BEGIN@26 which was called: # once (8µs+75µs) by Moose::BEGIN@29 at line 26
use base qw(Class::MOP::Object);
# spent 83µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@26 # spent 75µs making 1 call to base::import
27
2817µs3679µs__PACKAGE__->meta->add_attribute('name' => (
# spent 637µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 32µs making 1 call to Moose::Meta::TypeConstraint::meta # spent 10µs making 1 call to Class::MOP::_definition_context
29 reader => 'name',
30 Class::MOP::_definition_context(),
31));
3214µs3468µs__PACKAGE__->meta->add_attribute('parent' => (
# spent 450µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 12µs making 1 call to Moose::Meta::TypeConstraint::meta # spent 6µ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',
4217µs
# spent 2µs within Moose::Meta::TypeConstraint::__ANON__[/2home/ss5/perl5/perlbrew/perls/perl-5.12.3/lib/site_perl/5.12.3/x86_64-linux/Moose/Meta/TypeConstraint.pm:42] which was called: # once (2µs+0s) by Moose::Meta::TypeConstraint::_new at line 24 of (eval 87)[Eval/Closure.pm:125]
default => sub { $null_constraint },
4315µs3455µs Class::MOP::_definition_context(),
# spent 440µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 11µs making 1 call to Moose::Meta::TypeConstraint::meta # spent 5µs making 1 call to Class::MOP::_definition_context
44));
45
4614µs3435µs__PACKAGE__->meta->add_attribute('message' => (
# spent 418µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 10µ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µs3288µs__PACKAGE__->meta->add_attribute('_default_message' => (
# spent 274µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 10µs making 1 call to Moose::Meta::TypeConstraint::meta # spent 4µ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 156µs within Moose::Meta::TypeConstraint::__ANON__[/2home/ss5/perl5/perlbrew/perls/perl-5.12.3/lib/site_perl/5.12.3/x86_64-linux/Moose/Meta/TypeConstraint.pm:77] which was called 33 times, avg 5µs/call: # 33 times (156µs+0s) by Moose::Meta::TypeConstraint::new at line 146, avg 5µs/call
my $_default_message_generator = sub {
6066182µ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 }
7712µs};
7814µs3421µs__PACKAGE__->meta->add_attribute('coercion' => (
# spent 406µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 10µs making 1 call to Moose::Meta::TypeConstraint::meta # spent 5µs making 1 call to Class::MOP::_definition_context
79 accessor => 'coercion',
80 predicate => 'has_coercion',
81 Class::MOP::_definition_context(),
82));
83
8414µs3458µs__PACKAGE__->meta->add_attribute('hand_optimized_type_constraint' => (
# spent 444µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 10µs making 1 call to Moose::Meta::TypeConstraint::meta # spent 4µ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µs3434µs__PACKAGE__->meta->add_attribute('inlined' => (
# spent 419µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 10µs making 1 call to Moose::Meta::TypeConstraint::meta # spent 4µ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',
10133108µs
# spent 66µs within Moose::Meta::TypeConstraint::__ANON__[/2home/ss5/perl5/perlbrew/perls/perl-5.12.3/lib/site_perl/5.12.3/x86_64-linux/Moose/Meta/TypeConstraint.pm:101] which was called 33 times, avg 2µs/call: # 17 times (27µs+0s) by Moose::Meta::TypeConstraint::_new at line 33 of (eval 87)[Eval/Closure.pm:125], avg 2µs/call # 8 times (23µs+0s) by Moose::Meta::TypeConstraint::Class::_new at line 36 of (eval 101)[Eval/Closure.pm:125], avg 3µs/call # 4 times (10µs+0s) by Moose::Meta::TypeConstraint::Role::_new at line 33 of (eval 103)[Eval/Closure.pm:125], avg 2µs/call # 4 times (6µs+0s) by Moose::Meta::TypeConstraint::Parameterizable::_new at line 36 of (eval 99)[Eval/Closure.pm:125], avg 1µs/call
default => sub { {} },
10217µs3461µs Class::MOP::_definition_context(),
# spent 446µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 10µs making 1 call to Moose::Meta::TypeConstraint::meta # spent 5µ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
11218µs3539µs__PACKAGE__->meta->add_attribute('compiled_type_constraint' => (
# spent 507µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 22µs making 1 call to Moose::Meta::TypeConstraint::meta # spent 10µ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µs3289µs__PACKAGE__->meta->add_attribute('package_defined_in' => (
# spent 274µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 10µs making 1 call to Moose::Meta::TypeConstraint::meta # spent 5µs making 1 call to Class::MOP::_definition_context
119 accessor => '_package_defined_in',
120 Class::MOP::_definition_context(),
121));
122
123
# spent 11.6ms (1.06+10.6) within Moose::Meta::TypeConstraint::new which was called 33 times, avg 352µs/call: # 16 times (360µs+3.87ms) by Moose::Meta::TypeConstraint::create_child_type at line 432, avg 264µs/call # 8 times (374µs+3.85ms) by Moose::Meta::TypeConstraint::Class::new at line 43 of Moose/Meta/TypeConstraint/Class.pm, avg 528µs/call # 4 times (167µs+1.61ms) by Moose::Meta::TypeConstraint::Role::new at line 44 of Moose/Meta/TypeConstraint/Role.pm, avg 444µs/call # once (40µs+376µs) by Moose::Util::TypeConstraints::Builtins::define_builtins at line 185 of Moose/Util/TypeConstraints/Builtins.pm # once (42µs+330µs) by Moose::Util::TypeConstraints::_create_type_constraint at line 575 of Moose/Util/TypeConstraints.pm # once (24µs+180µs) by Moose::Util::TypeConstraints::Builtins::define_builtins at line 255 of Moose/Util/TypeConstraints/Builtins.pm # once (24µs+180µs) by Moose::Util::TypeConstraints::Builtins::define_builtins at line 220 of Moose/Util/TypeConstraints/Builtins.pm # once (24µs+171µs) by Moose::Util::TypeConstraints::Builtins::define_builtins at line 281 of Moose/Util/TypeConstraints/Builtins.pm
sub new {
124330921µs my $class = shift;
125 my ($first, @rest) = @_;
126 my %args = ref $first ? %$first : $first ? ($first, @rest) : ();
127 $args{name} = $args{name} ? "$args{name}" : "__ANON__";
128
129 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
138 if ( exists $args{message}
139 && (!ref($args{message}) || ref($args{message}) ne 'CODE') ) {
140 confess("The 'message' parameter must be a coderef");
141 }
142
143331.89ms my $self = $class->_new(%args);
# spent 904µs making 8 calls to Moose::Meta::TypeConstraint::Class::_new, avg 113µs/call # spent 410µs making 4 calls to Moose::Meta::TypeConstraint::Role::_new, avg 102µs/call # spent 389µs making 17 calls to Moose::Meta::TypeConstraint::_new, avg 23µs/call # spent 190µs making 4 calls to Moose::Meta::TypeConstraint::Parameterizable::_new, avg 47µs/call
144668.30ms $self->compile_type_constraint()
# spent 8.22ms making 33 calls to Moose::Meta::TypeConstraint::compile_type_constraint, avg 249µs/call # spent 74µs making 33 calls to Moose::Meta::TypeConstraint::_has_compiled_type_constraint, avg 2µs/call
145 unless $self->_has_compiled_type_constraint;
146132375µs $self->_default_message($_default_message_generator->($self->name))
# spent 156µs making 33 calls to Moose::Meta::TypeConstraint::__ANON__[Moose/Meta/TypeConstraint.pm:77], avg 5µs/call # spent 89µs making 33 calls to Moose::Meta::TypeConstraint::_default_message, avg 3µs/call # spent 69µs making 33 calls to Moose::Meta::TypeConstraint::name, avg 2µs/call # spent 60µs making 33 calls to Moose::Meta::TypeConstraint::has_message, avg 2µs/call
147 unless $self->has_message;
148 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 $coercion = $self->coercion;
172
173 unless ($coercion) {
174 require Moose;
175 Moose->throw_error("Cannot coerce without a type coercion");
176 }
177
178 return $_[0] if $self->check($_[0]);
179
180 my $result = $coercion->coerce(@_);
181
182 $self->assert_valid($result);
183
184 return $result;
185}
186
187
# spent 85µs (35+51) within Moose::Meta::TypeConstraint::check which was called 3 times, avg 28µs/call: # 3 times (35µs+51µs) by Moose::Meta::Attribute::verify_against_type_constraint at line 1275 of Moose/Meta/Attribute.pm, avg 28µs/call
sub check {
188928µs my ($self, @args) = @_;
18938µs my $constraint_subref = $self->_compiled_type_constraint;
# spent 8µs making 3 calls to Moose::Meta::TypeConstraint::_compiled_type_constraint, avg 3µs/call
190343µs return $constraint_subref->(@args) ? 1 : undef;
191}
192
193sub validate {
194 my ($self, $value) = @_;
195 if ($self->_compiled_type_constraint->($value)) {
196 return undef;
197 }
198 else {
199 $self->get_message($value);
200 }
201}
202
203
# spent 1.38ms (895µs+485µs) within Moose::Meta::TypeConstraint::can_be_inlined which was called 110 times, avg 13µs/call: # 56 times (361µs+200µs) by Moose::Meta::TypeConstraint::_inline_check at line 216, avg 10µs/call # 41 times (405µs+226µs) by Moose::Meta::TypeConstraint::_actually_compile_type_constraint at line 320, avg 15µs/call # 6 times (78µs+47µs) by Moose::Meta::Attribute::_inline_check_constraint at line 707 of Moose/Meta/Attribute.pm, avg 21µs/call # 5 times (40µs+22µs) by Moose::Meta::Attribute::_eval_environment at line 785 of Moose/Meta/Attribute.pm, avg 12µs/call # 2 times (11µs+-11µs) by Moose::Meta::TypeConstraint::can_be_inlined at line 206, avg 0s/call
sub can_be_inlined {
204328686µs my $self = shift;
205
206219329µs if ( $self->has_parent && $self->constraint == $null_constraint ) {
# spent 164µs making 105 calls to Moose::Meta::TypeConstraint::constraint, avg 2µs/call # spent 161µs making 110 calls to Moose::Meta::TypeConstraint::has_parent, avg 1µs/call # spent 4µs making 2 calls to Moose::Meta::TypeConstraint::parent, avg 2µs/call # spent 19µs making 2 calls to Moose::Meta::TypeConstraint::can_be_inlined, avg 10µs/call, recursion: max depth 1, sum of overlapping time 19µs
207 return $self->parent->can_be_inlined;
208 }
209
210108156µs return $self->_has_inlined_type_constraint;
# spent 156µs making 108 calls to Moose::Meta::TypeConstraint::_has_inlined_type_constraint, avg 1µs/call
211}
212
213
# spent 2.12ms (776µs+1.34) within Moose::Meta::TypeConstraint::_inline_check which was called 56 times, avg 38µs/call: # 41 times (591µs+1.27ms) by Moose::Meta::TypeConstraint::_actually_compile_type_constraint at line 320, avg 45µs/call # 6 times (91µs+167µs) by Moose::Meta::Attribute::_inline_check_constraint at line 707 of Moose/Meta/Attribute.pm, avg 43µs/call # 4 times (44µs+-44µs) by Moose::Util::TypeConstraints::Builtins::__ANON__[/2home/ss5/perl5/perlbrew/perls/perl-5.12.3/lib/site_perl/5.12.3/x86_64-linux/Moose/Util/TypeConstraints/Builtins.pm:66] at line 64 of Moose/Util/TypeConstraints/Builtins.pm, avg 0s/call # once (10µs+-10µs) by Moose::Meta::TypeConstraint::_inline_check at line 221 # once (10µs+-10µs) by Moose::Util::TypeConstraints::Builtins::__ANON__[/2home/ss5/perl5/perlbrew/perls/perl-5.12.3/lib/site_perl/5.12.3/x86_64-linux/Moose/Util/TypeConstraints/Builtins.pm:157] at line 152 of Moose/Util/TypeConstraints/Builtins.pm # once (10µs+-10µs) by Moose::Util::TypeConstraints::Builtins::__ANON__[/2home/ss5/perl5/perlbrew/perls/perl-5.12.3/lib/site_perl/5.12.3/x86_64-linux/Moose/Util/TypeConstraints/Builtins.pm:101] at line 99 of Moose/Util/TypeConstraints/Builtins.pm # once (10µs+-10µs) by Moose::Util::TypeConstraints::Builtins::__ANON__[/2home/ss5/perl5/perlbrew/perls/perl-5.12.3/lib/site_perl/5.12.3/x86_64-linux/Moose/Util/TypeConstraints/Builtins.pm:93] at line 91 of Moose/Util/TypeConstraints/Builtins.pm # once (11µs+-11µs) by Moose::Util::TypeConstraints::Builtins::__ANON__[/2home/ss5/perl5/perlbrew/perls/perl-5.12.3/lib/site_perl/5.12.3/x86_64-linux/Moose/Util/TypeConstraints/Builtins.pm:83] at line 78 of Moose/Util/TypeConstraints/Builtins.pm
sub _inline_check {
214223565µs my $self = shift;
215
21656562µs unless ( $self->can_be_inlined ) {
# spent 562µs making 56 calls to Moose::Meta::TypeConstraint::can_be_inlined, avg 10µs/call
217 require Moose;
218 Moose->throw_error( 'Cannot inline a type constraint check for ' . $self->name );
219 }
220
221112123µs if ( $self->has_parent && $self->constraint == $null_constraint ) {
# spent 62µs making 56 calls to Moose::Meta::TypeConstraint::has_parent, avg 1µs/call # spent 61µs making 54 calls to Moose::Meta::TypeConstraint::constraint, avg 1µs/call # spent 1µs making 1 call to Moose::Meta::TypeConstraint::parent # spent 20µs making 1 call to Moose::Meta::TypeConstraint::_inline_check, recursion: max depth 1, sum of overlapping time 20µs
222 return $self->parent->_inline_check(@_);
223 }
224
225110942µs return '( do { ' . $self->inlined->( $self, @_ ) . ' } )';
# spent 366µs making 20 calls to Moose::Meta::TypeConstraint::Class::__ANON__[Moose/Meta/TypeConstraint/Class.pm:30], avg 18µs/call # spent 133µs making 4 calls to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:66], avg 33µs/call # spent 94µs making 55 calls to Moose::Meta::TypeConstraint::inlined, avg 2µs/call # spent 73µs making 4 calls to Moose::Meta::TypeConstraint::Role::__ANON__[Moose/Meta/TypeConstraint/Role.pm:32], avg 18µs/call # spent 68µs making 1 call to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:83] # spent 60µs making 1 call to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:93] # spent 59µs making 1 call to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:101] # spent 36µs making 1 call to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:157] # spent 9µs making 5 calls to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:46], avg 2µs/call # spent 6µs making 2 calls to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:239], avg 3µs/call # spent 5µs making 2 calls to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:204], avg 3µs/call # spent 4µs making 1 call to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:58] # spent 4µs making 1 call to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:133] # spent 4µs making 1 call to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:176] # spent 4µs making 2 calls to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:144], avg 2µs/call # spent 3µs making 2 calls to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:28], avg 1µs/call # spent 3µs making 1 call to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:113] # spent 2µs making 1 call to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:106] # 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:138] # 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:118] # spent 1µs making 1 call to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:272]
226}
227
228
# spent 608µs (411+197) within Moose::Meta::TypeConstraint::inline_environment which was called 47 times, avg 13µs/call: # 41 times (354µs+180µs) by Moose::Meta::TypeConstraint::_actually_compile_type_constraint at line 320, avg 13µs/call # 5 times (52µs+23µs) by Moose::Meta::Attribute::_eval_environment at line 796 of Moose/Meta/Attribute.pm, avg 15µs/call # once (6µs+-6µs) by Moose::Meta::TypeConstraint::inline_environment at line 231
sub inline_environment {
229140304µs my $self = shift;
230
23194111µs if ( $self->has_parent && $self->constraint == $null_constraint ) {
# spent 56µs making 45 calls to Moose::Meta::TypeConstraint::constraint, avg 1µs/call # spent 54µs making 47 calls to Moose::Meta::TypeConstraint::has_parent, avg 1µs/call # spent 1µs making 1 call to Moose::Meta::TypeConstraint::parent # spent 8µs making 1 call to Moose::Meta::TypeConstraint::inline_environment, recursion: max depth 1, sum of overlapping time 8µs
232 return $self->parent->inline_environment;
233 }
234
2354686µs return $self->_inline_environment;
# spent 86µs making 46 calls to Moose::Meta::TypeConstraint::_inline_environment, avg 2µs/call
236}
237
238sub assert_valid {
239 my ($self, $value) = @_;
240
241 my $error = $self->validate($value);
242 return 1 if ! defined $error;
243
244 require Moose;
245 Moose->throw_error($error);
246}
247
248sub get_message {
249 my ($self, $value) = @_;
250 my $msg = $self->has_message
251 ? $self->message
252 : $self->_default_message;
253 local $_ = $value;
254 return $msg->($value);
255}
256
257## type predicates ...
258
259sub equals {
260 my ( $self, $type_or_name ) = @_;
261
262 my $other = Moose::Util::TypeConstraints::find_type_constraint($type_or_name) or return;
263
264 return 1 if $self == $other;
265
266 if ( $self->has_hand_optimized_type_constraint and $other->has_hand_optimized_type_constraint ) {
267 return 1 if $self->hand_optimized_type_constraint == $other->hand_optimized_type_constraint;
268 }
269
270 return unless $self->constraint == $other->constraint;
271
272 if ( $self->has_parent ) {
273 return unless $other->has_parent;
274 return unless $self->parent->equals( $other->parent );
275 } else {
276 return if $other->has_parent;
277 }
278
279 return;
280}
281
282sub is_a_type_of {
283 my ($self, $type_or_name) = @_;
284
285 my $type = Moose::Util::TypeConstraints::find_type_constraint($type_or_name) or return;
286
287 ($self->equals($type) || $self->is_subtype_of($type));
288}
289
290sub is_subtype_of {
291 my ($self, $type_or_name) = @_;
292
293 my $type = Moose::Util::TypeConstraints::find_type_constraint($type_or_name) or return;
294
295 my $current = $self;
296
297 while (my $parent = $current->parent) {
298 return 1 if $parent->equals($type);
299 $current = $parent;
300 }
301
302 return 0;
303}
304
305## compiling the type constraint
306
307
# spent 10.2ms (301µs+9.86) within Moose::Meta::TypeConstraint::compile_type_constraint which was called 45 times, avg 226µs/call: # 33 times (234µs+7.99ms) by Moose::Meta::TypeConstraint::new at line 144, avg 249µs/call # 8 times (49µs+1.79ms) by Moose::Meta::TypeConstraint::Class::new at line 45 of Moose/Meta/TypeConstraint/Class.pm, avg 230µs/call # 4 times (18µs+83µs) by Moose::Meta::TypeConstraint::Role::new at line 47 of Moose/Meta/TypeConstraint/Role.pm, avg 25µs/call
sub compile_type_constraint {
30890260µs my $self = shift;
309909.86ms $self->_compiled_type_constraint($self->_actually_compile_type_constraint);
# spent 9.66ms making 45 calls to Moose::Meta::TypeConstraint::_actually_compile_type_constraint, avg 215µs/call # spent 200µs making 45 calls to Moose::Meta::TypeConstraint::_compiled_type_constraint, avg 4µs/call
310}
311
312## type compilers ...
313
314
# spent 9.66ms (641µs+9.02) within Moose::Meta::TypeConstraint::_actually_compile_type_constraint which was called 45 times, avg 215µs/call: # 45 times (641µs+9.02ms) by Moose::Meta::TypeConstraint::compile_type_constraint at line 309, avg 215µs/call
sub _actually_compile_type_constraint {
315131502µs my $self = shift;
316
31749114µs return $self->_compile_hand_optimized_type_constraint
# spent 88µs making 45 calls to Moose::Meta::TypeConstraint::has_hand_optimized_type_constraint, avg 2µs/call # spent 27µs making 4 calls to Moose::Meta::TypeConstraint::_compile_hand_optimized_type_constraint, avg 7µs/call
318 if $self->has_hand_optimized_type_constraint;
319
3201648.91ms if ( $self->can_be_inlined ) {
# spent 5.88ms making 41 calls to Eval::Closure::eval_closure, avg 143µs/call # spent 1.86ms making 41 calls to Moose::Meta::TypeConstraint::_inline_check, avg 45µs/call # spent 632µs making 41 calls to Moose::Meta::TypeConstraint::can_be_inlined, avg 15µs/call # spent 534µs making 41 calls to Moose::Meta::TypeConstraint::inline_environment, avg 13µs/call
321 return eval_closure(
322 source => 'sub { ' . $self->_inline_check('$_[0]') . ' }',
323 environment => $self->inline_environment,
324 );
325 }
326
327 my $check = $self->constraint;
328 unless ( defined $check ) {
329 require Moose;
330 Moose->throw_error( "Could not compile type constraint '"
331 . $self->name
332 . "' because no constraint check" );
333 }
334
335 return $self->_compile_subtype($check)
336 if $self->has_parent;
337
338 return $self->_compile_type($check);
339}
340
341
# spent 27µs (22+5) within Moose::Meta::TypeConstraint::_compile_hand_optimized_type_constraint which was called 4 times, avg 7µs/call: # 4 times (22µs+5µs) by Moose::Meta::TypeConstraint::_actually_compile_type_constraint at line 317, avg 7µs/call
sub _compile_hand_optimized_type_constraint {
3421620µs my $self = shift;
343
34445µs my $type_constraint = $self->hand_optimized_type_constraint;
# spent 5µs making 4 calls to Moose::Meta::TypeConstraint::hand_optimized_type_constraint, avg 1µs/call
345
346 unless ( ref $type_constraint ) {
347 require Moose;
348 Moose->throw_error("Hand optimized type constraint is not a code reference");
349 }
350
351 return $type_constraint;
352}
353
354sub _compile_subtype {
355 my ($self, $check) = @_;
356
357 # gather all the parent constraintss in order
358 my @parents;
359 my $optimized_parent;
360 foreach my $parent ($self->_collect_all_parents) {
361 # if a parent is optimized, the optimized constraint already includes
362 # all of its parents tcs, so we can break the loop
363 if ($parent->has_hand_optimized_type_constraint) {
364 push @parents => $optimized_parent = $parent->hand_optimized_type_constraint;
365 last;
366 }
367 else {
368 push @parents => $parent->constraint;
369 }
370 }
371
372 @parents = grep { $_ != $null_constraint } reverse @parents;
373
374 unless ( @parents ) {
375 return $self->_compile_type($check);
376 } elsif( $optimized_parent and @parents == 1 ) {
377 # the case of just one optimized parent is optimized to prevent
378 # looping and the unnecessary localization
379 if ( $check == $null_constraint ) {
380 return $optimized_parent;
381 } else {
382 return subname($self->name, sub {
383 return undef unless $optimized_parent->($_[0]);
384 my (@args) = @_;
385 local $_ = $args[0];
386 $check->(@args);
387 });
388 }
389 } else {
390 # general case, check all the constraints, from the first parent to ourselves
391 my @checks = @parents;
392 push @checks, $check if $check != $null_constraint;
393 return subname($self->name => sub {
394 my (@args) = @_;
395 local $_ = $args[0];
396 foreach my $check (@checks) {
397 return undef unless $check->(@args);
398 }
399 return 1;
400 });
401 }
402}
403
404sub _compile_type {
405 my ($self, $check) = @_;
406
407 return $check if $check == $null_constraint; # Item, Any
408
409 return subname($self->name => sub {
410 my (@args) = @_;
411 local $_ = $args[0];
412 $check->(@args);
413 });
414}
415
416## other utils ...
417
418sub _collect_all_parents {
419 my $self = shift;
420 my @parents;
421 my $current = $self->parent;
422 while (defined $current) {
423 push @parents => $current;
424 $current = $current->parent;
425 }
426 return @parents;
427}
428
429
# spent 4.32ms (93µs+4.23) within Moose::Meta::TypeConstraint::create_child_type which was called 16 times, avg 270µs/call: # 16 times (93µs+4.23ms) by Moose::Util::TypeConstraints::_create_type_constraint at line 565 of Moose/Util/TypeConstraints.pm, avg 270µs/call
sub create_child_type {
4304891µs my ($self, %opts) = @_;
431 my $class = ref $self;
432164.23ms return $class->new(%opts, parent => $self);
# spent 4.23ms making 16 calls to Moose::Meta::TypeConstraint::new, avg 264µs/call
433}
434
435134µs1;
436
437# ABSTRACT: The Moose Type Constraint metaclass
438
- -
441=pod
442
443=head1 NAME
444
445Moose::Meta::TypeConstraint - The Moose Type Constraint metaclass
446
447=head1 VERSION
448
449version 2.0602
450
451=head1 DESCRIPTION
452
453This class represents a single type constraint. Moose's built-in type
454constraints, as well as constraints you define, are all stored in a
455L<Moose::Meta::TypeConstraint::Registry> object as objects of this
456class.
457
458=head1 INHERITANCE
459
460C<Moose::Meta::TypeConstraint> is a subclass of L<Class::MOP::Object>.
461
462=head1 METHODS
463
464=over 4
465
466=item B<< Moose::Meta::TypeConstraint->new(%options) >>
467
468This creates a new type constraint based on the provided C<%options>:
469
470=over 8
471
472=item * name
473
474The constraint name. If a name is not provided, it will be set to
475"__ANON__".
476
477=item * parent
478
479A C<Moose::Meta::TypeConstraint> object which is the parent type for
480the type being created. This is optional.
481
482=item * constraint
483
484This is the subroutine reference that implements the actual constraint
485check. This defaults to a subroutine which always returns true.
486
487=item * message
488
489A subroutine reference which is used to generate an error message when
490the constraint fails. This is optional.
491
492=item * coercion
493
494A L<Moose::Meta::TypeCoercion> object representing the coercions to
495the type. This is optional.
496
497=item * inlined
498
499A subroutine which returns a string suitable for inlining this type
500constraint. It will be called as a method on the type constraint object, and
501will receive a single additional parameter, a variable name to be tested
502(usually C<"$_"> or C<"$_[0]">.
503
504This is optional.
505
506=item * inline_environment
507
508A hash reference of variables to close over. The keys are variables names, and
509the values are I<references> to the variables.
510
511=item * optimized
512
513B<This option is deprecated.>
514
515This is a variant of the C<constraint> parameter that is somehow
516optimized. Typically, this means incorporating both the type's
517constraint and all of its parents' constraints into a single
518subroutine reference.
519
520=back
521
522=item B<< $constraint->equals($type_name_or_object) >>
523
524Returns true if the supplied name or type object is the same as the
525current type.
526
527=item B<< $constraint->is_subtype_of($type_name_or_object) >>
528
529Returns true if the supplied name or type object is a parent of the
530current type.
531
532=item B<< $constraint->is_a_type_of($type_name_or_object) >>
533
534Returns true if the given type is the same as the current type, or is
535a parent of the current type. This is a shortcut for checking
536C<equals> and C<is_subtype_of>.
537
538=item B<< $constraint->coerce($value) >>
539
540This will attempt to coerce the value to the type. If the type does not
541have any defined coercions this will throw an error.
542
543If no coercion can produce a value matching C<$constraint>, the original
544value is returned.
545
546=item B<< $constraint->assert_coerce($value) >>
547
548This method behaves just like C<coerce>, but if the result is not valid
549according to C<$constraint>, an error is thrown.
550
551=item B<< $constraint->check($value) >>
552
553Returns true if the given value passes the constraint for the type.
554
555=item B<< $constraint->validate($value) >>
556
557This is similar to C<check>. However, if the type I<is valid> then the
558method returns an explicit C<undef>. If the type is not valid, we call
559C<< $self->get_message($value) >> internally to generate an error
560message.
561
562=item B<< $constraint->assert_valid($value) >>
563
564Like C<check> and C<validate>, this method checks whether C<$value> is
565valid under the constraint. If it is, it will return true. If it is not,
566an exception will be thrown with the results of
567C<< $self->get_message($value) >>.
568
569=item B<< $constraint->name >>
570
571Returns the type's name, as provided to the constructor.
572
573=item B<< $constraint->parent >>
574
575Returns the type's parent, as provided to the constructor, if any.
576
577=item B<< $constraint->has_parent >>
578
579Returns true if the type has a parent type.
580
581=item B<< $constraint->parents >>
582
583Returns all of the types parents as an list of type constraint objects.
584
585=item B<< $constraint->constraint >>
586
587Returns the type's constraint, as provided to the constructor.
588
589=item B<< $constraint->get_message($value) >>
590
591This generates a method for the given value. If the type does not have
592an explicit message, we generate a default message.
593
594=item B<< $constraint->has_message >>
595
596Returns true if the type has a message.
597
598=item B<< $constraint->message >>
599
600Returns the type's message as a subroutine reference.
601
602=item B<< $constraint->coercion >>
603
604Returns the type's L<Moose::Meta::TypeCoercion> object, if one
605exists.
606
607=item B<< $constraint->has_coercion >>
608
609Returns true if the type has a coercion.
610
611=item B<< $constraint->can_be_inlined >>
612
613Returns true if this type constraint can be inlined. A type constraint which
614subtypes an inlinable constraint and does not add an additional constraint
615"inherits" its parent type's inlining.
616
617=item B<< $constraint->hand_optimized_type_constraint >>
618
619B<This method is deprecated.>
620
621Returns the type's hand optimized constraint, as provided to the
622constructor via the C<optimized> option.
623
624=item B<< $constraint->has_hand_optimized_type_constraint >>
625
626B<This method is deprecated.>
627
628Returns true if the type has an optimized constraint.
629
630=item B<< $constraint->create_child_type(%options) >>
631
632This returns a new type constraint of the same class using the
633provided C<%options>. The C<parent> option will be the current type.
634
635This method exists so that subclasses of this class can override this
636behavior and change how child types are created.
637
638=back
639
640=head1 BUGS
641
642See L<Moose/BUGS> for details on reporting bugs.
643
644=head1 AUTHOR
645
646Moose is maintained by the Moose Cabal, along with the help of many contributors. See L<Moose/CABAL> and L<Moose/CONTRIBUTORS> for details.
647
648=head1 COPYRIGHT AND LICENSE
649
650This software is copyright (c) 2012 by Infinity Interactive, Inc..
651
652This is free software; you can redistribute it and/or modify it under
653the same terms as the Perl 5 programming language system itself.
654
655=cut
656
657
658__END__