← Index
NYTProf Performance Profile   « block view • line view • sub view »
For mentat.storage.mongo.pl
  Run on Tue Jun 24 10:04:38 2014
Reported on Tue Jun 24 10:05:07 2014

Filename/usr/local/lib/perl/5.14.2/Moose/Meta/TypeConstraint.pm
StatementsExecuted 4036 statements in 9.14ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
480733.07ms4.71msMoose::Meta::TypeConstraint::::can_be_inlinedMoose::Meta::TypeConstraint::can_be_inlined (recurses: max depth 1, inclusive time 147µs)
2621042.68ms7.11msMoose::Meta::TypeConstraint::::_inline_checkMoose::Meta::TypeConstraint::_inline_check (recurses: max depth 3, inclusive time 4.70ms)
14654964µs1.44msMoose::Meta::TypeConstraint::::inline_environmentMoose::Meta::TypeConstraint::inline_environment (recurses: max depth 1, inclusive time 44µs)
3685837µs10.7msMoose::Meta::TypeConstraint::::newMoose::Meta::TypeConstraint::new
4611494µs9.98msMoose::Meta::TypeConstraint::::_actually_compile_type_constraintMoose::Meta::TypeConstraint::_actually_compile_type_constraint
111398µs1.03msMoose::Meta::TypeConstraint::::BEGIN@12Moose::Meta::TypeConstraint::BEGIN@12
4722248µs10.5msMoose::Meta::TypeConstraint::::compile_type_constraintMoose::Meta::TypeConstraint::compile_type_constraint
19963173µs173µsMoose::Meta::TypeConstraint::::__ANON__[:16]Moose::Meta::TypeConstraint::__ANON__[:16]
3611146µs146µsMoose::Meta::TypeConstraint::::__ANON__[:77]Moose::Meta::TypeConstraint::__ANON__[:77]
1911104µs5.10msMoose::Meta::TypeConstraint::::create_child_typeMoose::Meta::TypeConstraint::create_child_type
11151µs94µsMoose::Meta::TypeConstraint::::_compile_subtypeMoose::Meta::TypeConstraint::_compile_subtype
362150µs50µsMoose::Meta::TypeConstraint::::__ANON__[:101]Moose::Meta::TypeConstraint::__ANON__[:101]
51140µs91µsMoose::Meta::TypeConstraint::::checkMoose::Meta::TypeConstraint::check
11120µs26µsMoose::Meta::TypeConstraint::::_collect_all_parentsMoose::Meta::TypeConstraint::_collect_all_parents
11117µs60µsMoose::Meta::TypeConstraint::::BEGIN@14Moose::Meta::TypeConstraint::BEGIN@14
1119µs9µsMoose::Meta::TypeConstraint::::BEGIN@3Moose::Meta::TypeConstraint::BEGIN@3
1118µs11µsMoose::Meta::TypeConstraint::::BEGIN@10Moose::Meta::TypeConstraint::BEGIN@10
4117µs7µsMoose::Meta::TypeConstraint::::__ANON__[:42]Moose::Meta::TypeConstraint::__ANON__[:42]
1117µs35µsMoose::Meta::TypeConstraint::::BEGIN@24Moose::Meta::TypeConstraint::BEGIN@24
1117µs12µsMoose::Meta::TypeConstraint::::BEGIN@11Moose::Meta::TypeConstraint::BEGIN@11
1117µs28µsMoose::Meta::TypeConstraint::::BEGIN@21Moose::Meta::TypeConstraint::BEGIN@21
1117µs45µsMoose::Meta::TypeConstraint::::BEGIN@26Moose::Meta::TypeConstraint::BEGIN@26
1117µs32µsMoose::Meta::TypeConstraint::::BEGIN@19Moose::Meta::TypeConstraint::BEGIN@19
1116µs32µsMoose::Meta::TypeConstraint::::BEGIN@22Moose::Meta::TypeConstraint::BEGIN@22
1116µs32µsMoose::Meta::TypeConstraint::::BEGIN@20Moose::Meta::TypeConstraint::BEGIN@20
1116µs26µsMoose::Meta::TypeConstraint::::BEGIN@23Moose::Meta::TypeConstraint::BEGIN@23
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::::_compile_hand_optimized_type_constraintMoose::Meta::TypeConstraint::_compile_hand_optimized_type_constraint
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 9µs within Moose::Meta::TypeConstraint::BEGIN@3 which was called: # once (9µs+0s) by Moose::BEGIN@28 at line 5
BEGIN {
415µs $Moose::Meta::TypeConstraint::AUTHORITY = 'cpan:STEVAN';
5130µs19µs}
# spent 9µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@3
6{
721µs $Moose::Meta::TypeConstraint::VERSION = '2.1005';
8}
9
10222µs214µs
# spent 11µs (8+3) within Moose::Meta::TypeConstraint::BEGIN@10 which was called: # once (8µs+3µs) by Moose::BEGIN@28 at line 10
use strict;
# spent 11µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@10 # spent 3µs making 1 call to strict::import
11221µs217µs
# spent 12µs (7+5) within Moose::Meta::TypeConstraint::BEGIN@11 which was called: # once (7µs+5µs) by Moose::BEGIN@28 at line 11
use warnings;
# spent 12µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@11 # spent 5µs making 1 call to warnings::import
122156µs21.51ms
# spent 1.03ms (398µs+635µs) within Moose::Meta::TypeConstraint::BEGIN@12 which was called: # once (398µs+635µs) by Moose::BEGIN@28 at line 12
use metaclass;
# spent 1.03ms making 1 call to Moose::Meta::TypeConstraint::BEGIN@12 # spent 480µs making 1 call to metaclass::import
13
14
# spent 60µs (17+43) within Moose::Meta::TypeConstraint::BEGIN@14 which was called: # once (17µs+43µ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
16199361µs
# spent 173µs within Moose::Meta::TypeConstraint::__ANON__[/usr/local/lib/perl/5.14.2/Moose/Meta/TypeConstraint.pm:16] which was called 199 times, avg 870ns/call: # 72 times (77µs+0s) by Moose::Util::TypeConstraints::find_or_parse_type_constraint at line 274 of Moose/Util/TypeConstraints.pm, avg 1µs/call # 69 times (49µs+0s) by Moose::Util::TypeConstraints::find_or_create_isa_type_constraint at line 260 of Moose/Util/TypeConstraints.pm, avg 706ns/call # 35 times (32µs+0s) by Moose::Meta::TypeConstraint::Registry::add_type_constraint at line 51 of Moose/Meta/TypeConstraint/Registry.pm, avg 914ns/call # 19 times (12µs+0s) by Moose::Util::TypeConstraints::_create_type_constraint at line 565 of Moose/Util/TypeConstraints.pm, avg 611ns/call # 2 times (3µs+0s) by Moose::init_meta at line 165 of Moose.pm, avg 1µs/call # 2 times (1µs+0s) by Moose::Util::TypeConstraints::_create_type_constraint_union at line 104 of Moose/Util/TypeConstraints.pm, avg 700ns/call
bool => sub { 1 },
17236µs2102µs fallback => 1;
# spent 60µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@14 # spent 42µs making 1 call to overload::import
18
19225µs257µs
# spent 32µs (7+25) within Moose::Meta::TypeConstraint::BEGIN@19 which was called: # once (7µs+25µs) by Moose::BEGIN@28 at line 19
use Carp qw(confess);
# spent 32µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@19 # spent 25µs making 1 call to Exporter::import
20227µs258µs
# spent 32µs (6+26) within Moose::Meta::TypeConstraint::BEGIN@20 which was called: # once (6µs+26µs) by Moose::BEGIN@28 at line 20
use Class::Load qw(load_class);
# spent 32µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@20 # spent 26µs making 1 call to Exporter::import
21224µs250µs
# spent 28µs (7+22) within Moose::Meta::TypeConstraint::BEGIN@21 which was called: # once (7µs+22µs) by Moose::BEGIN@28 at line 21
use Eval::Closure;
# spent 28µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@21 # spent 22µs making 1 call to Exporter::import
22223µs257µs
# spent 32µs (6+25) within Moose::Meta::TypeConstraint::BEGIN@22 which was called: # once (6µs+25µs) by Moose::BEGIN@28 at line 22
use Scalar::Util qw(blessed refaddr);
# spent 32µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@22 # spent 25µs making 1 call to Exporter::import
23222µs246µs
# spent 26µs (6+20) within Moose::Meta::TypeConstraint::BEGIN@23 which was called: # once (6µs+20µs) by Moose::BEGIN@28 at line 23
use Sub::Name qw(subname);
# spent 26µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@23 # spent 20µs making 1 call to Exporter::import
24231µs263µs
# spent 35µs (7+28) within Moose::Meta::TypeConstraint::BEGIN@24 which was called: # once (7µs+28µs) by Moose::BEGIN@28 at line 24
use Try::Tiny;
# spent 35µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@24 # spent 28µs making 1 call to Exporter::import
25
2621.70ms283µs
# spent 45µs (7+38) within Moose::Meta::TypeConstraint::BEGIN@26 which was called: # once (7µs+38µs) by Moose::BEGIN@28 at line 26
use base qw(Class::MOP::Object);
# spent 45µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@26 # spent 38µs making 1 call to base::import
27
2815µs3451µs__PACKAGE__->meta->add_attribute('name' => (
# spent 426µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 19µs making 1 call to Moose::Meta::TypeConstraint::meta # spent 6µs making 1 call to Class::MOP::_definition_context
29 reader => 'name',
30 Class::MOP::_definition_context(),
31));
3213µs3528µs__PACKAGE__->meta->add_attribute('parent' => (
# spent 512µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 12µs making 1 call to Moose::Meta::TypeConstraint::meta # spent 5µ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',
42412µs
# spent 7µs within Moose::Meta::TypeConstraint::__ANON__[/usr/local/lib/perl/5.14.2/Moose/Meta/TypeConstraint.pm:42] which was called 4 times, avg 2µs/call: # 4 times (7µs+0s) by Moose::Meta::TypeConstraint::Union::_new or Moose::Meta::TypeConstraint::_new at line 24 of (eval 62)[Eval/Closure.pm:144], avg 2µs/call
default => sub { $null_constraint },
4315µs3511µs Class::MOP::_definition_context(),
# spent 494µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 12µs making 1 call to Moose::Meta::TypeConstraint::meta # spent 5µs making 1 call to Class::MOP::_definition_context
44));
45
4613µs3482µs__PACKAGE__->meta->add_attribute('message' => (
# spent 466µ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
47 accessor => 'message',
48 predicate => 'has_message',
49 Class::MOP::_definition_context(),
50));
51
5214µs3313µs__PACKAGE__->meta->add_attribute('_default_message' => (
# spent 296µ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
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 146µs within Moose::Meta::TypeConstraint::__ANON__[/usr/local/lib/perl/5.14.2/Moose/Meta/TypeConstraint.pm:77] which was called 36 times, avg 4µs/call: # 36 times (146µs+0s) by Moose::Meta::TypeConstraint::new at line 146, avg 4µs/call
my $_default_message_generator = sub {
6072173µ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µs3561µs__PACKAGE__->meta->add_attribute('coercion' => (
# spent 545µ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
79 accessor => 'coercion',
80 predicate => 'has_coercion',
81 Class::MOP::_definition_context(),
82));
83
84116µs3514µs__PACKAGE__->meta->add_attribute('hand_optimized_type_constraint' => (
# spent 485µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 17µs making 1 call to Class::MOP::_definition_context # spent 12µs making 1 call to Moose::Meta::TypeConstraint::meta
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µs3538µs__PACKAGE__->meta->add_attribute('inlined' => (
# spent 521µ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
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',
10136101µs
# spent 50µs within Moose::Meta::TypeConstraint::__ANON__[/usr/local/lib/perl/5.14.2/Moose/Meta/TypeConstraint.pm:101] which was called 36 times, avg 1µs/call: # 21 times (29µs+0s) by Moose::Meta::TypeConstraint::Union::_new or Moose::Meta::TypeConstraint::_new at line 33 of (eval 62)[Eval/Closure.pm:144], avg 1µs/call # 15 times (21µs+0s) by Moose::Meta::TypeConstraint::Class::_new or Moose::Meta::TypeConstraint::Parameterizable::_new at line 36 of (eval 62)[Eval/Closure.pm:144], avg 1µs/call
default => sub { {} },
10215µs3313µs Class::MOP::_definition_context(),
# spent 293µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 11µs making 1 call to Moose::Meta::TypeConstraint::meta # spent 9µ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µs3495µs__PACKAGE__->meta->add_attribute('compiled_type_constraint' => (
# spent 479µ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
113 accessor => '_compiled_type_constraint',
114 predicate => '_has_compiled_type_constraint',
115 Class::MOP::_definition_context(),
116));
117
11814µs3309µs__PACKAGE__->meta->add_attribute('package_defined_in' => (
# spent 293µ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
119 accessor => '_package_defined_in',
120 Class::MOP::_definition_context(),
121));
122
123
# spent 10.7ms (837µs+9.87) within Moose::Meta::TypeConstraint::new which was called 36 times, avg 298µs/call: # 19 times (392µs+4.60ms) by Moose::Meta::TypeConstraint::create_child_type at line 423, avg 263µs/call # 11 times (262µs+3.97ms) by Moose::Meta::TypeConstraint::Class::new at line 43 of Moose/Meta/TypeConstraint/Class.pm, avg 385µs/call # once (38µs+301µs) by Moose::Util::TypeConstraints::Builtins::define_builtins at line 204 of Moose/Util/TypeConstraints/Builtins.pm # once (29µs+245µs) by Moose::Util::TypeConstraints::_create_type_constraint at line 575 of Moose/Util/TypeConstraints.pm # once (29µs+210µs) by Moose::Util::TypeConstraints::Builtins::define_builtins at line 274 of Moose/Util/TypeConstraints/Builtins.pm # once (22µs+204µs) by Moose::Util::TypeConstraints::Builtins::define_builtins at line 239 of Moose/Util/TypeConstraints/Builtins.pm # once (22µs+193µs) by Moose::Util::TypeConstraints::Builtins::define_builtins at line 300 of Moose/Util/TypeConstraints/Builtins.pm # once (43µs+147µs) by Moose::Meta::TypeConstraint::Union::new at line 33 of Moose/Meta/TypeConstraint/Union.pm
sub new {
124360699µ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
143361.20ms my $self = $class->_new(%args);
# spent 482µs making 20 calls to Moose::Meta::TypeConstraint::_new, avg 24µs/call # spent 460µs making 11 calls to Moose::Meta::TypeConstraint::Class::_new, avg 42µs/call # spent 153µs making 4 calls to Moose::Meta::TypeConstraint::Parameterizable::_new, avg 38µs/call # spent 108µs making 1 call to Moose::Meta::TypeConstraint::Union::_new
144728.34ms $self->compile_type_constraint()
# spent 8.29ms making 36 calls to Moose::Meta::TypeConstraint::compile_type_constraint, avg 230µs/call # spent 57µs making 36 calls to Moose::Meta::TypeConstraint::_has_compiled_type_constraint, avg 2µs/call
145 unless $self->_has_compiled_type_constraint;
146144327µs $self->_default_message($_default_message_generator->($self->name))
# spent 146µs making 36 calls to Moose::Meta::TypeConstraint::__ANON__[Moose/Meta/TypeConstraint.pm:77], avg 4µs/call # spent 80µs making 36 calls to Moose::Meta::TypeConstraint::_default_message, avg 2µs/call # spent 51µs making 36 calls to Moose::Meta::TypeConstraint::name, avg 1µs/call # spent 50µs making 36 calls to Moose::Meta::TypeConstraint::has_message, avg 1µ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 $result = $self->coerce(@_);
172
173 $self->assert_valid($result);
174
175 return $result;
176}
177
178
# spent 91µs (40+51) within Moose::Meta::TypeConstraint::check which was called 5 times, avg 18µs/call: # 5 times (40µs+51µs) by Moose::Meta::Attribute::verify_against_type_constraint at line 1279 of Moose/Meta/Attribute.pm, avg 18µs/call
sub check {
1791536µs my ($self, @args) = @_;
180510µs my $constraint_subref = $self->_compiled_type_constraint;
# spent 10µs making 5 calls to Moose::Meta::TypeConstraint::_compiled_type_constraint, avg 2µs/call
181542µs 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 4.71ms (3.07+1.65) within Moose::Meta::TypeConstraint::can_be_inlined which was called 480 times, avg 10µs/call: # 262 times (1.53ms+881µs) by Moose::Meta::TypeConstraint::_inline_check at line 207, avg 9µs/call # 90 times (636µs+354µs) by Moose::Meta::Attribute::_inline_check_constraint at line 711 of Moose/Meta/Attribute.pm, avg 11µs/call # 56 times (408µs+249µs) by Moose::Meta::Attribute::_eval_environment at line 789 of Moose/Meta/Attribute.pm, avg 12µs/call # 46 times (335µs+200µs) by Moose::Meta::TypeConstraint::_actually_compile_type_constraint at line 311, avg 12µs/call # 16 times (95µs+-95µs) by Moose::Meta::TypeConstraint::can_be_inlined at line 198, avg 0s/call # 8 times (51µs+31µs) by Moose::Meta::TypeConstraint::Union::can_be_inlined at line 87 of Moose/Meta/TypeConstraint/Union.pm, avg 10µs/call # 2 times (17µs+26µs) by Moose::Meta::Attribute::_inline_check_coercion at line 687 of Moose/Meta/Attribute.pm, avg 22µs/call
sub can_be_inlined {
19514402.28ms my $self = shift;
196
1979551.07ms if ( $self->has_parent && $self->constraint == $null_constraint ) {
# spent 545µs making 475 calls to Moose::Meta::TypeConstraint::constraint, avg 1µs/call # spent 528µs making 480 calls to Moose::Meta::TypeConstraint::has_parent, avg 1µs/call
1983218µs return $self->parent->can_be_inlined;
# spent 18µs making 16 calls to Moose::Meta::TypeConstraint::parent, avg 1µs/call # spent 147µs making 16 calls to Moose::Meta::TypeConstraint::can_be_inlined, avg 9µs/call, recursion: max depth 1, sum of overlapping time 147µs
199 }
200
201464555µs return $self->_has_inlined_type_constraint;
# spent 555µs making 464 calls to Moose::Meta::TypeConstraint::_has_inlined_type_constraint, avg 1µs/call
202}
203
204
# spent 7.11ms (2.68+4.43) within Moose::Meta::TypeConstraint::_inline_check which was called 262 times, avg 27µs/call: # 88 times (932µs+3.72ms) by Moose::Meta::Attribute::_inline_check_constraint at line 713 of Moose/Meta/Attribute.pm, avg 53µs/call # 57 times (563µs+-563µs) by Moose::Util::TypeConstraints::Builtins::__ANON__[/usr/local/lib/perl/5.14.2/Moose/Util/TypeConstraints/Builtins.pm:66] at line 64 of Moose/Util/TypeConstraints/Builtins.pm, avg 0s/call # 45 times (493µs+1.29ms) by Moose::Meta::TypeConstraint::_actually_compile_type_constraint at line 312, avg 40µs/call # 29 times (271µs+-271µs) by Moose::Util::TypeConstraints::Builtins::__ANON__[/usr/local/lib/perl/5.14.2/Moose/Util/TypeConstraints/Builtins.pm:120] at line 118 of Moose/Util/TypeConstraints/Builtins.pm, avg 0s/call # 26 times (249µs+-249µs) by Moose::Util::TypeConstraints::Builtins::__ANON__[/usr/local/lib/perl/5.14.2/Moose/Util/TypeConstraints/Builtins.pm:83] at line 78 of Moose/Util/TypeConstraints/Builtins.pm, avg 0s/call # 7 times (70µs+-70µs) by Moose::Meta::TypeConstraint::_inline_check at line 213, avg 0s/call # 6 times (61µs+392µs) by Moose::Meta::TypeConstraint::Union::_inline_check at line 97 of Moose/Meta/TypeConstraint/Union.pm, avg 75µs/call # 2 times (18µs+201µs) by Moose::Meta::Attribute::_inline_check_coercion at line 689 of Moose/Meta/Attribute.pm, avg 110µs/call # once (9µs+-9µs) by Moose::Util::TypeConstraints::Builtins::__ANON__[/usr/local/lib/perl/5.14.2/Moose/Util/TypeConstraints/Builtins.pm:112] at line 103 of Moose/Util/TypeConstraints/Builtins.pm # once (10µs+-10µs) by Moose::Util::TypeConstraints::Builtins::__ANON__[/usr/local/lib/perl/5.14.2/Moose/Util/TypeConstraints/Builtins.pm:176] at line 171 of Moose/Util/TypeConstraints/Builtins.pm
sub _inline_check {
20510481.87ms my $self = shift;
206
2072622.41ms unless ( $self->can_be_inlined ) {
# spent 2.41ms making 262 calls to Moose::Meta::TypeConstraint::can_be_inlined, avg 9µs/call
208 require Moose;
209 Moose->throw_error( 'Cannot inline a type constraint check for ' . $self->name );
210 }
211
212522540µs if ( $self->has_parent && $self->constraint == $null_constraint ) {
# spent 286µs making 262 calls to Moose::Meta::TypeConstraint::has_parent, avg 1µs/call # spent 254µs making 260 calls to Moose::Meta::TypeConstraint::constraint, avg 977ns/call
213147µs return $self->parent->_inline_check(@_);
# spent 7µs making 7 calls to Moose::Meta::TypeConstraint::parent, avg 1µs/call # spent 488µs making 7 calls to Moose::Meta::TypeConstraint::_inline_check, avg 70µs/call, recursion: max depth 1, sum of overlapping time 488µs
214 }
215
2165105.70ms return '( do { ' . $self->inlined->( $self, @_ ) . ' } )';
# spent 1.70ms making 57 calls to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:66], avg 30µs/call # spent 1.61ms making 29 calls to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:120], avg 55µs/call # spent 1.50ms making 26 calls to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:83], avg 58µs/call # spent 306µs making 255 calls to Moose::Meta::TypeConstraint::inlined, avg 1µs/call # spent 292µs making 28 calls to Moose::Meta::TypeConstraint::Class::__ANON__[Moose/Meta/TypeConstraint/Class.pm:30], avg 10µs/call # spent 91µs making 37 calls to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:58], avg 2µs/call # spent 79µs making 58 calls to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:46], avg 1µs/call # spent 58µs making 1 call to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:112] # spent 34µs making 1 call to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:176] # spent 8µs making 4 calls to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:258], avg 2µs/call # spent 3µs making 2 calls to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:163], avg 2µs/call # spent 3µs making 1 call to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:152] # spent 3µs making 1 call to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:195] # 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:137] # spent 2µ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:132] # spent 2µs making 1 call to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:157] # 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:39] # spent 2µs making 1 call to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:72] # spent 900ns making 1 call to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:291]
217}
218
219
# spent 1.44ms (964µs+475µs) within Moose::Meta::TypeConstraint::inline_environment which was called 146 times, avg 10µs/call: # 56 times (382µs+198µs) by Moose::Meta::Attribute::_eval_environment at line 800 of Moose/Meta/Attribute.pm, avg 10µs/call # 45 times (301µs+178µs) by Moose::Meta::TypeConstraint::_actually_compile_type_constraint at line 312, avg 11µs/call # 36 times (227µs+117µs) by Moose::Meta::Class::_eval_environment at line 543 of Moose/Meta/Class.pm, avg 10µs/call # 5 times (29µs+-29µs) by Moose::Meta::TypeConstraint::inline_environment at line 223, avg 0s/call # 4 times (25µs+12µs) by Moose::Meta::TypeConstraint::Union::inline_environment at line 108 of Moose/Meta/TypeConstraint/Union.pm, avg 9µs/call
sub inline_environment {
220438675µs my $self = shift;
221
222290297µs if ( $self->has_parent && $self->constraint == $null_constraint ) {
# spent 153µs making 144 calls to Moose::Meta::TypeConstraint::constraint, avg 1µs/call # spent 144µs making 146 calls to Moose::Meta::TypeConstraint::has_parent, avg 984ns/call
223105µs return $self->parent->inline_environment;
# spent 5µs making 5 calls to Moose::Meta::TypeConstraint::parent, avg 1µs/call # spent 44µs making 5 calls to Moose::Meta::TypeConstraint::inline_environment, avg 9µs/call, recursion: max depth 1, sum of overlapping time 44µs
224 }
225
226141173µs return $self->_inline_environment;
# spent 173µs making 141 calls to Moose::Meta::TypeConstraint::_inline_environment, avg 1µ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 10.5ms (248µs+10.2) within Moose::Meta::TypeConstraint::compile_type_constraint which was called 47 times, avg 222µs/call: # 36 times (196µs+8.09ms) by Moose::Meta::TypeConstraint::new at line 144, avg 230µs/call # 11 times (52µs+2.11ms) by Moose::Meta::TypeConstraint::Class::new at line 45 of Moose/Meta/TypeConstraint/Class.pm, avg 197µs/call
sub compile_type_constraint {
29994195µs my $self = shift;
3009410.2ms $self->_compiled_type_constraint($self->_actually_compile_type_constraint);
# spent 9.98ms making 46 calls to Moose::Meta::TypeConstraint::_actually_compile_type_constraint, avg 217µs/call # spent 208µs making 47 calls to Moose::Meta::TypeConstraint::_compiled_type_constraint, avg 4µs/call # spent 17µs making 1 call to Moose::Meta::TypeConstraint::Union::_actually_compile_type_constraint
301}
302
303## type compilers ...
304
305
# spent 9.98ms (494µs+9.48) within Moose::Meta::TypeConstraint::_actually_compile_type_constraint which was called 46 times, avg 217µs/call: # 46 times (494µs+9.48ms) by Moose::Meta::TypeConstraint::compile_type_constraint at line 300, avg 217µs/call
sub _actually_compile_type_constraint {
306186350µs my $self = shift;
307
3084661µs return $self->_compile_hand_optimized_type_constraint
# spent 61µs making 46 calls to Moose::Meta::TypeConstraint::has_hand_optimized_type_constraint, avg 1µs/call
309 if $self->has_hand_optimized_type_constraint;
310
31146535µs if ( $self->can_be_inlined ) {
# spent 535µs making 46 calls to Moose::Meta::TypeConstraint::can_be_inlined, avg 12µs/call
3121358.79ms return eval_closure(
# spent 6.53ms making 45 calls to Eval::Closure::eval_closure, avg 145µs/call # spent 1.78ms making 45 calls to Moose::Meta::TypeConstraint::_inline_check, avg 40µs/call # spent 480µs making 45 calls to Moose::Meta::TypeConstraint::inline_environment, avg 11µs/call
313 source => 'sub { ' . $self->_inline_check('$_[0]') . ' }',
314 environment => $self->inline_environment,
315 );
316 }
317
31811µs my $check = $self->constraint;
# spent 1µs making 1 call to Moose::Meta::TypeConstraint::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
326295µs return $self->_compile_subtype($check)
# spent 94µs making 1 call to Moose::Meta::TypeConstraint::_compile_subtype # spent 1µs making 1 call to Moose::Meta::TypeConstraint::has_parent
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
345
# spent 94µs (51+43) within Moose::Meta::TypeConstraint::_compile_subtype which was called: # once (51µs+43µs) by Moose::Meta::TypeConstraint::_actually_compile_type_constraint at line 326
sub _compile_subtype {
3462444µs my ($self, $check) = @_;
347
348 # gather all the parent constraints in order
349 my @parents;
350 my $optimized_parent;
351126µs 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
35456µs if ($parent->has_hand_optimized_type_constraint) {
# spent 6µs making 5 calls to Moose::Meta::TypeConstraint::has_hand_optimized_type_constraint, avg 1µs/call
355 push @parents => $optimized_parent = $parent->hand_optimized_type_constraint;
356 last;
357 }
358 else {
35956µs push @parents => $parent->constraint;
# spent 6µs making 5 calls to Moose::Meta::TypeConstraint::constraint, avg 1µs/call
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 {
385920µs my (@args) = @_;
386 local $_ = $args[0];
387 foreach my $check (@checks) {
388519µs return undef unless $check->(@args);
389 }
390 return 1;
39125µs });
# spent 3µs making 1 call to Sub::Name::subname # spent 1µs making 1 call to Moose::Meta::TypeConstraint::name
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
409
# spent 26µs (20+6) within Moose::Meta::TypeConstraint::_collect_all_parents which was called: # once (20µs+6µs) by Moose::Meta::TypeConstraint::_compile_subtype at line 351
sub _collect_all_parents {
4101514µs my $self = shift;
411 my @parents;
41211µs my $current = $self->parent;
# spent 1µs making 1 call to Moose::Meta::TypeConstraint::parent
413 while (defined $current) {
414 push @parents => $current;
41555µs $current = $current->parent;
# spent 5µs making 5 calls to Moose::Meta::TypeConstraint::parent, avg 1µs/call
416 }
417 return @parents;
418}
419
420
# spent 5.10ms (104µs+5.00) within Moose::Meta::TypeConstraint::create_child_type which was called 19 times, avg 268µs/call: # 19 times (104µs+5.00ms) by Moose::Util::TypeConstraints::_create_type_constraint at line 572 of Moose/Util/TypeConstraints.pm, avg 268µs/call
sub create_child_type {
42157103µs my ($self, %opts) = @_;
422 my $class = ref $self;
423195.00ms return $class->new(%opts, parent => $self);
# spent 5.00ms making 19 calls to Moose::Meta::TypeConstraint::new, avg 263µs/call
424}
425
426118µs1;
427
428# ABSTRACT: The Moose Type Constraint metaclass
429
430__END__