← Index
NYTProf Performance Profile   « line view »
For examples/Atom-timer.pl
  Run on Mon Aug 12 14:45:28 2013
Reported on Mon Aug 12 14:46:14 2013

Filename/Users/dde/perl5/perlbrew/perls/5.18.0t/lib/site_perl/5.18.0/darwin-thread-multi-2level/Moose/Meta/TypeConstraint.pm
StatementsExecuted 4390 statements in 7.88ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
73444.31ms13.9msMoose::Meta::TypeConstraint::::compile_type_constraintMoose::Meta::TypeConstraint::compile_type_constraint
444852.41ms3.62msMoose::Meta::TypeConstraint::::can_be_inlinedMoose::Meta::TypeConstraint::can_be_inlined (recurses: max depth 1, inclusive time 12µs)
2191252.01ms5.10msMoose::Meta::TypeConstraint::::_inline_checkMoose::Meta::TypeConstraint::_inline_check (recurses: max depth 2, inclusive time 2.30ms)
49107983µs12.4msMoose::Meta::TypeConstraint::::newMoose::Meta::TypeConstraint::new
15776885µs1.30msMoose::Meta::TypeConstraint::::inline_environmentMoose::Meta::TypeConstraint::inline_environment (recurses: max depth 1, inclusive time 7µs)
7211587µs9.34msMoose::Meta::TypeConstraint::::_actually_compile_type_constraintMoose::Meta::TypeConstraint::_actually_compile_type_constraint
111387µs967µsMoose::Meta::TypeConstraint::::BEGIN@12Moose::Meta::TypeConstraint::BEGIN@12
2721312µs630µsMoose::Meta::TypeConstraint::::equalsMoose::Meta::TypeConstraint::equals
288145201µs201µsMoose::Meta::TypeConstraint::::__ANON__[:16]Moose::Meta::TypeConstraint::__ANON__[:16]
822185µs891µsMoose::Meta::TypeConstraint::::is_subtype_ofMoose::Meta::TypeConstraint::is_subtype_of
4911152µs152µsMoose::Meta::TypeConstraint::::__ANON__[:77]Moose::Meta::TypeConstraint::__ANON__[:77]
5411107µs126µsMoose::Meta::TypeConstraint::::__ANON__[:14]Moose::Meta::TypeConstraint::__ANON__[:14]
161174µs3.55msMoose::Meta::TypeConstraint::::create_child_typeMoose::Meta::TypeConstraint::create_child_type
492160µs60µsMoose::Meta::TypeConstraint::::__ANON__[:101]Moose::Meta::TypeConstraint::__ANON__[:101]
191158µs74µsMoose::Meta::TypeConstraint::::_compile_hand_optimized_type_constraintMoose::Meta::TypeConstraint::_compile_hand_optimized_type_constraint
41138µs57µsMoose::Meta::TypeConstraint::::checkMoose::Meta::TypeConstraint::check
41136µs208µsMoose::Meta::TypeConstraint::::is_a_type_ofMoose::Meta::TypeConstraint::is_a_type_of
1119µs48µsMoose::Meta::TypeConstraint::::BEGIN@14Moose::Meta::TypeConstraint::BEGIN@14
1118µs8µsMoose::Meta::TypeConstraint::::BEGIN@3Moose::Meta::TypeConstraint::BEGIN@3
1117µs23µsMoose::Meta::TypeConstraint::::BEGIN@23Moose::Meta::TypeConstraint::BEGIN@23
1116µs24µsMoose::Meta::TypeConstraint::::BEGIN@21Moose::Meta::TypeConstraint::BEGIN@21
5116µs6µsMoose::Meta::TypeConstraint::::__ANON__[:42]Moose::Meta::TypeConstraint::__ANON__[:42]
1116µs25µsMoose::Meta::TypeConstraint::::BEGIN@19Moose::Meta::TypeConstraint::BEGIN@19
1116µs16µsMoose::Meta::TypeConstraint::::BEGIN@10Moose::Meta::TypeConstraint::BEGIN@10
1116µs9µsMoose::Meta::TypeConstraint::::BEGIN@11Moose::Meta::TypeConstraint::BEGIN@11
1116µs28µsMoose::Meta::TypeConstraint::::BEGIN@24Moose::Meta::TypeConstraint::BEGIN@24
1116µs24µsMoose::Meta::TypeConstraint::::BEGIN@20Moose::Meta::TypeConstraint::BEGIN@20
1116µs27µsMoose::Meta::TypeConstraint::::BEGIN@22Moose::Meta::TypeConstraint::BEGIN@22
1115µs52µsMoose::Meta::TypeConstraint::::BEGIN@26Moose::Meta::TypeConstraint::BEGIN@26
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_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::::get_messageMoose::Meta::TypeConstraint::get_message
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 8µs within Moose::Meta::TypeConstraint::BEGIN@3 which was called: # once (8µs+0s) by Moose::BEGIN@28 at line 5
BEGIN {
414µs $Moose::Meta::TypeConstraint::AUTHORITY = 'cpan:STEVAN';
5128µs18µs}
# spent 8µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@3
6{
72900ns $Moose::Meta::TypeConstraint::VERSION = '2.1005';
8}
9
10223µs226µs
# spent 16µs (6+10) within Moose::Meta::TypeConstraint::BEGIN@10 which was called: # once (6µs+10µs) by Moose::BEGIN@28 at line 10
use strict;
# spent 16µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@10 # spent 10µs making 1 call to strict::import
11219µs212µs
# spent 9µs (6+3) within Moose::Meta::TypeConstraint::BEGIN@11 which was called: # once (6µs+3µs) by Moose::BEGIN@28 at line 11
use warnings;
# spent 9µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@11 # spent 3µs making 1 call to warnings::import
122139µs21.40ms
# spent 967µs (387+580) within Moose::Meta::TypeConstraint::BEGIN@12 which was called: # once (387µs+580µs) by Moose::BEGIN@28 at line 12
use metaclass;
# spent 967µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@12 # spent 436µs making 1 call to metaclass::import
13
1454164µs5419µs
# spent 126µs (107+19) within Moose::Meta::TypeConstraint::__ANON__[/Users/dde/perl5/perlbrew/perls/5.18.0t/lib/site_perl/5.18.0/darwin-thread-multi-2level/Moose/Meta/TypeConstraint.pm:14] which was called 54 times, avg 2µs/call: # 54 times (107µs+19µs) by Moose::Meta::TypeConstraint::equals at line 255, avg 2µs/call # spent 48µs (9+39) within Moose::Meta::TypeConstraint::BEGIN@14 which was called: # once (9µs+39µs) by Moose::BEGIN@28 at line 17
use overload '0+' => sub { refaddr(shift) }, # id an object
# spent 19µs making 54 calls to Scalar::Util::refaddr, avg 348ns/call
15 '""' => sub { shift->name }, # stringify to tc name
16288474µs
# spent 201µs within Moose::Meta::TypeConstraint::__ANON__[/Users/dde/perl5/perlbrew/perls/5.18.0t/lib/site_perl/5.18.0/darwin-thread-multi-2level/Moose/Meta/TypeConstraint.pm:16] which was called 288 times, avg 699ns/call: # 49 times (38µs+0s) by Moose::Meta::TypeConstraint::Registry::add_type_constraint at line 51 of Moose/Meta/TypeConstraint/Registry.pm, avg 786ns/call # 48 times (40µs+0s) by Moose::Util::TypeConstraints::find_or_parse_type_constraint at line 274 of Moose/Util/TypeConstraints.pm, avg 827ns/call # 46 times (29µs+0s) by Moose::Util::TypeConstraints::find_or_create_isa_type_constraint at line 260 of Moose/Util/TypeConstraints.pm, avg 635ns/call # 36 times (22µs+0s) by Moose::Meta::Method::Accessor::Native::Collection::_tc_member_type at line 44 of Moose/Meta/Method/Accessor/Native/Collection.pm, avg 606ns/call # 27 times (17µs+0s) by Moose::Meta::TypeConstraint::equals at line 253, avg 619ns/call # 24 times (14µs+0s) by Moose::Meta::TypeConstraint::is_subtype_of at line 288, avg 600ns/call # 17 times (14µs+0s) by Moose::Meta::Method::Accessor::Native::Collection::_tc_member_type at line 41 of Moose/Meta/Method/Accessor/Native/Collection.pm, avg 835ns/call # 16 times (10µs+0s) by Moose::Util::TypeConstraints::_create_type_constraint at line 565 of Moose/Util/TypeConstraints.pm, avg 600ns/call # 8 times (6µs+0s) by Moose::Meta::TypeConstraint::is_subtype_of at line 284, avg 712ns/call # 4 times (3µs+0s) by Moose::Meta::TypeConstraint::is_a_type_of at line 276, avg 725ns/call # 4 times (3µs+0s) by Moose::Util::TypeConstraints::find_or_create_type_constraint at line 232 of Moose/Util/TypeConstraints.pm, avg 675ns/call # 4 times (3µs+0s) by Class::MOP::Class:::around at line 149 of Moose/Meta/Method/Accessor/Native/Collection.pm, avg 675ns/call # 3 times (2µs+0s) by Moose::Meta::TypeConstraint::Parameterizable::parameterize at line 79 of Moose/Meta/TypeConstraint/Parameterizable.pm, avg 667ns/call # 2 times (1µs+0s) by Moose::Util::TypeConstraints::_create_type_constraint_union at line 104 of Moose/Util/TypeConstraints.pm, avg 650ns/call
bool => sub { 1 },
17225µs287µs fallback => 1;
# spent 48µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@14 # spent 39µs making 1 call to overload::import
18
19225µs244µs
# spent 25µs (6+19) within Moose::Meta::TypeConstraint::BEGIN@19 which was called: # once (6µs+19µs) by Moose::BEGIN@28 at line 19
use Carp qw(confess);
# spent 25µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@19 # spent 19µs making 1 call to Exporter::import
20219µs241µs
# spent 24µs (6+18) within Moose::Meta::TypeConstraint::BEGIN@20 which was called: # once (6µs+18µs) by Moose::BEGIN@28 at line 20
use Class::Load qw(load_class);
# spent 24µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@20 # spent 18µs making 1 call to Exporter::import
21221µs241µs
# spent 24µs (6+17) within Moose::Meta::TypeConstraint::BEGIN@21 which was called: # once (6µs+17µs) by Moose::BEGIN@28 at line 21
use Eval::Closure;
# spent 24µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@21 # spent 17µs making 1 call to Exporter::import
22221µs249µs
# spent 27µs (6+22) within Moose::Meta::TypeConstraint::BEGIN@22 which was called: # once (6µs+22µs) by Moose::BEGIN@28 at line 22
use Scalar::Util qw(blessed refaddr);
# spent 27µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@22 # spent 22µs making 1 call to Exporter::import
23219µs239µs
# spent 23µs (7+16) within Moose::Meta::TypeConstraint::BEGIN@23 which was called: # once (7µs+16µs) by Moose::BEGIN@28 at line 23
use Sub::Name qw(subname);
# spent 23µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@23 # spent 16µs making 1 call to Exporter::import
24220µs250µs
# spent 28µs (6+22) within Moose::Meta::TypeConstraint::BEGIN@24 which was called: # once (6µs+22µs) by Moose::BEGIN@28 at line 24
use Try::Tiny;
# spent 28µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@24 # spent 22µs making 1 call to Exporter::import
25
2621.59ms299µs
# spent 52µs (5+47) within Moose::Meta::TypeConstraint::BEGIN@26 which was called: # once (5µs+47µs) by Moose::BEGIN@28 at line 26
use base qw(Class::MOP::Object);
# spent 52µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@26 # spent 47µs making 1 call to base::import
27
2814µs3302µs__PACKAGE__->meta->add_attribute('name' => (
# spent 282µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 15µs making 1 call to Moose::Meta::TypeConstraint::meta # spent 5µs making 1 call to Class::MOP::_definition_context
29 reader => 'name',
30 Class::MOP::_definition_context(),
31));
3213µs3417µs__PACKAGE__->meta->add_attribute('parent' => (
# spent 404µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 8µ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
3811µsmy $null_constraint = sub { 1 };
39__PACKAGE__->meta->add_attribute('constraint' => (
40 reader => 'constraint',
41 writer => '_set_constraint',
42513µs
# spent 6µs within Moose::Meta::TypeConstraint::__ANON__[/Users/dde/perl5/perlbrew/perls/5.18.0t/lib/site_perl/5.18.0/darwin-thread-multi-2level/Moose/Meta/TypeConstraint.pm:42] which was called 5 times, avg 1µs/call: # 5 times (6µs+0s) by Moose::Meta::TypeConstraint::Parameterized::_new or Moose::Meta::TypeConstraint::Union::_new or Moose::Meta::TypeConstraint::_new at line 24 of (eval 74)[Eval/Closure.pm:135], avg 1µs/call
default => sub { $null_constraint },
4314µs3421µs Class::MOP::_definition_context(),
# spent 408µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 8µs making 1 call to Moose::Meta::TypeConstraint::meta # spent 4µs making 1 call to Class::MOP::_definition_context
44));
45
4613µs3414µs__PACKAGE__->meta->add_attribute('message' => (
# spent 401µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 8µs making 1 call to Moose::Meta::TypeConstraint::meta # spent 4µs making 1 call to Class::MOP::_definition_context
47 accessor => 'message',
48 predicate => 'has_message',
49 Class::MOP::_definition_context(),
50));
51
5213µs3259µs__PACKAGE__->meta->add_attribute('_default_message' => (
# spent 246µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 8µ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 152µs within Moose::Meta::TypeConstraint::__ANON__[/Users/dde/perl5/perlbrew/perls/5.18.0t/lib/site_perl/5.18.0/darwin-thread-multi-2level/Moose/Meta/TypeConstraint.pm:77] which was called 49 times, avg 3µs/call: # 49 times (152µs+0s) by Moose::Meta::TypeConstraint::new at line 146, avg 3µs/call
my $_default_message_generator = sub {
604916µ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 }
7750177µs};
7813µs3400µs__PACKAGE__->meta->add_attribute('coercion' => (
# spent 388µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 8µs making 1 call to Moose::Meta::TypeConstraint::meta # spent 4µs making 1 call to Class::MOP::_definition_context
79 accessor => 'coercion',
80 predicate => 'has_coercion',
81 Class::MOP::_definition_context(),
82));
83
8413µs3395µs__PACKAGE__->meta->add_attribute('hand_optimized_type_constraint' => (
# spent 383µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 8µ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
9113µs3402µs__PACKAGE__->meta->add_attribute('inlined' => (
# spent 390µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 8µ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',
10149104µs
# spent 60µs within Moose::Meta::TypeConstraint::__ANON__[/Users/dde/perl5/perlbrew/perls/5.18.0t/lib/site_perl/5.18.0/darwin-thread-multi-2level/Moose/Meta/TypeConstraint.pm:101] which was called 49 times, avg 1µs/call: # 40 times (49µs+0s) by Moose::Meta::TypeConstraint::Parameterized::_new or Moose::Meta::TypeConstraint::Role::_new or Moose::Meta::TypeConstraint::Union::_new or Moose::Meta::TypeConstraint::_new at line 33 of (eval 74)[Eval/Closure.pm:135], avg 1µs/call # 9 times (11µs+0s) by Moose::Meta::TypeConstraint::Class::_new or Moose::Meta::TypeConstraint::Parameterizable::_new at line 36 of (eval 74)[Eval/Closure.pm:135], avg 1µs/call
default => sub { {} },
10214µs3279µs Class::MOP::_definition_context(),
# spent 266µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 8µs making 1 call to Moose::Meta::TypeConstraint::meta # spent 4µ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
11213µs3415µs__PACKAGE__->meta->add_attribute('compiled_type_constraint' => (
# spent 401µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 9µ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
11813µs3283µs__PACKAGE__->meta->add_attribute('package_defined_in' => (
# spent 260µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 18µ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 12.4ms (983µs+11.4) within Moose::Meta::TypeConstraint::new which was called 49 times, avg 254µs/call: # 19 times (366µs+3.83ms) by Moose::Meta::TypeConstraint::Role::new at line 44 of Moose/Meta/TypeConstraint/Role.pm, avg 221µs/call # 16 times (284µs+3.19ms) by Moose::Meta::TypeConstraint::create_child_type at line 423, avg 217µs/call # 5 times (114µs+1.10ms) by Moose::Meta::TypeConstraint::Class::new at line 43 of Moose/Meta/TypeConstraint/Class.pm, avg 242µs/call # 3 times (75µs+2.28ms) by Moose::Meta::TypeConstraint::Parameterizable::parameterize at line 90 of Moose/Meta/TypeConstraint/Parameterizable.pm, avg 785µs/call # once (29µs+243µs) by Moose::Util::TypeConstraints::Builtins::define_builtins at line 204 of Moose/Util/TypeConstraints/Builtins.pm # once (29µs+212µs) by Moose::Util::TypeConstraints::_create_type_constraint at line 575 of Moose/Util/TypeConstraints.pm # once (19µs+165µs) by Moose::Util::TypeConstraints::Builtins::define_builtins at line 274 of Moose/Util/TypeConstraints/Builtins.pm # once (19µs+164µs) by Moose::Util::TypeConstraints::Builtins::define_builtins at line 239 of Moose/Util/TypeConstraints/Builtins.pm # once (19µs+159µs) by Moose::Util::TypeConstraints::Builtins::define_builtins at line 300 of Moose/Util/TypeConstraints/Builtins.pm # once (29µs+106µs) by Moose::Meta::TypeConstraint::Union::new at line 33 of Moose/Meta/TypeConstraint/Union.pm
sub new {
124498µs my $class = shift;
1254936µs my ($first, @rest) = @_;
1264974µs my %args = ref $first ? %$first : $first ? ($first, @rest) : ();
1274926µs $args{name} = $args{name} ? "$args{name}" : "__ANON__";
128
129496µ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
138498µ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
1434989µs491.18ms my $self = $class->_new(%args);
# spent 421µs making 19 calls to Moose::Meta::TypeConstraint::Role::_new, avg 22µs/call # spent 288µs making 17 calls to Moose::Meta::TypeConstraint::_new, avg 17µs/call # spent 152µs making 5 calls to Moose::Meta::TypeConstraint::Class::_new, avg 30µs/call # spent 127µs making 3 calls to Moose::Meta::TypeConstraint::Parameterized::_new, avg 42µs/call # spent 114µs making 4 calls to Moose::Meta::TypeConstraint::Parameterizable::_new, avg 28µs/call # spent 78µs making 1 call to Moose::Meta::TypeConstraint::Union::_new
14449128µs989.92ms $self->compile_type_constraint()
# spent 7.73ms making 46 calls to Moose::Meta::TypeConstraint::compile_type_constraint, avg 168µs/call # spent 2.13ms making 3 calls to Moose::Meta::TypeConstraint::Parameterized::compile_type_constraint, avg 709µs/call # spent 65µs making 49 calls to Moose::Meta::TypeConstraint::_has_compiled_type_constraint, avg 1µs/call
145 unless $self->_has_compiled_type_constraint;
14649176µs196345µs $self->_default_message($_default_message_generator->($self->name))
# spent 152µs making 49 calls to Moose::Meta::TypeConstraint::__ANON__[Moose/Meta/TypeConstraint.pm:77], avg 3µs/call # spent 79µs making 49 calls to Moose::Meta::TypeConstraint::_default_message, avg 2µs/call # spent 58µs making 49 calls to Moose::Meta::TypeConstraint::name, avg 1µs/call # spent 56µs making 49 calls to Moose::Meta::TypeConstraint::has_message, avg 1µs/call
147 unless $self->has_message;
14849138µ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
178
# spent 57µs (38+19) within Moose::Meta::TypeConstraint::check which was called 4 times, avg 14µs/call: # 4 times (38µs+19µs) by Moose::Meta::Attribute::verify_against_type_constraint at line 1279 of Moose/Meta/Attribute.pm, avg 14µs/call
sub check {
17942µs my ($self, @args) = @_;
18045µs46µs my $constraint_subref = $self->_compiled_type_constraint;
# spent 6µs making 4 calls to Moose::Meta::TypeConstraint::_compiled_type_constraint, avg 2µs/call
181427µs412µs return $constraint_subref->(@args) ? 1 : undef;
# spent 12µs making 4 calls to Eval::Closure::Sandbox_50::__ANON__[(eval 123)[Eval/Closure.pm:135]:3], avg 3µs/call
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 3.62ms (2.41+1.21) within Moose::Meta::TypeConstraint::can_be_inlined which was called 444 times, avg 8µs/call: # 219 times (1.08ms+538µs) by Moose::Meta::TypeConstraint::_inline_check at line 207, avg 7µs/call # 71 times (425µs+221µs) by Moose::Meta::Attribute::_inline_check_constraint at line 711 of Moose/Meta/Attribute.pm, avg 9µs/call # 50 times (306µs+168µs) by Moose::Meta::TypeConstraint::_actually_compile_type_constraint at line 311, avg 9µs/call # 47 times (277µs+140µs) by Moose::Meta::Attribute::_eval_environment at line 789 of Moose/Meta/Attribute.pm, avg 9µs/call # 45 times (263µs+127µs) by Moose::Meta::TypeConstraint::Parameterized::can_be_inlined at line 78 of Moose/Meta/TypeConstraint/Parameterized.pm, avg 9µs/call # 8 times (44µs+23µs) by Moose::Meta::TypeConstraint::Union::can_be_inlined at line 87 of Moose/Meta/TypeConstraint/Union.pm, avg 8µs/call # 2 times (12µs+6µs) by Moose::Meta::Method::Accessor::Native::Collection::_inline_check_member_constraint at line 108 of Moose/Meta/Method/Accessor/Native/Collection.pm, avg 9µs/call # 2 times (9µs+-9µs) by Moose::Meta::TypeConstraint::can_be_inlined at line 197, avg 0s/call
sub can_be_inlined {
19544435µs my $self = shift;
196
197444611µs887791µs if ( $self->has_parent && $self->constraint == $null_constraint ) {
# spent 404µs making 439 calls to Moose::Meta::TypeConstraint::constraint, avg 919ns/call # spent 385µs making 444 calls to Moose::Meta::TypeConstraint::has_parent, avg 867ns/call # spent 2µs making 2 calls to Moose::Meta::TypeConstraint::parent, avg 1µs/call # spent 12µs making 2 calls to Moose::Meta::TypeConstraint::can_be_inlined, avg 6µs/call, recursion: max depth 1, sum of overlapping time 12µs
198 return $self->parent->can_be_inlined;
199 }
200
201442842µs442423µs return $self->_has_inlined_type_constraint;
# spent 423µs making 442 calls to Moose::Meta::TypeConstraint::_has_inlined_type_constraint, avg 956ns/call
202}
203
204
# spent 5.10ms (2.01+3.09) within Moose::Meta::TypeConstraint::_inline_check which was called 219 times, avg 23µs/call: # 71 times (639µs+1.96ms) by Moose::Meta::Attribute::_inline_check_constraint at line 711 of Moose/Meta/Attribute.pm, avg 37µs/call # 50 times (509µs+1.04ms) by Moose::Meta::TypeConstraint::_actually_compile_type_constraint at line 311, avg 31µs/call # 36 times (322µs+-322µs) by Moose::Util::TypeConstraints::Builtins::__ANON__[/Users/dde/perl5/perlbrew/perls/5.18.0t/lib/site_perl/5.18.0/darwin-thread-multi-2level/Moose/Util/TypeConstraints/Builtins.pm:66] at line 64 of Moose/Util/TypeConstraints/Builtins.pm, avg 0s/call # 16 times (139µs+440µs) by Moose::Util::TypeConstraints::Builtins::__ANON__[/Users/dde/perl5/perlbrew/perls/5.18.0t/lib/site_perl/5.18.0/darwin-thread-multi-2level/Moose/Util/TypeConstraints/Builtins.pm:237] at line 229 of Moose/Util/TypeConstraints/Builtins.pm, avg 36µs/call # 13 times (111µs+-111µs) by Moose::Util::TypeConstraints::Builtins::__ANON__[/Users/dde/perl5/perlbrew/perls/5.18.0t/lib/site_perl/5.18.0/darwin-thread-multi-2level/Moose/Util/TypeConstraints/Builtins.pm:112] at line 103 of Moose/Util/TypeConstraints/Builtins.pm, avg 0s/call # 12 times (104µs+-104µs) by Moose::Util::TypeConstraints::Builtins::__ANON__[/Users/dde/perl5/perlbrew/perls/5.18.0t/lib/site_perl/5.18.0/darwin-thread-multi-2level/Moose/Util/TypeConstraints/Builtins.pm:120] at line 118 of Moose/Util/TypeConstraints/Builtins.pm, avg 0s/call # 10 times (88µs+-88µs) by Moose::Util::TypeConstraints::Builtins::__ANON__[/Users/dde/perl5/perlbrew/perls/5.18.0t/lib/site_perl/5.18.0/darwin-thread-multi-2level/Moose/Util/TypeConstraints/Builtins.pm:83] at line 78 of Moose/Util/TypeConstraints/Builtins.pm, avg 0s/call # 6 times (52µs+206µs) by Moose::Meta::TypeConstraint::Union::_inline_check at line 97 of Moose/Meta/TypeConstraint/Union.pm, avg 43µs/call # 2 times (18µs+35µs) by Moose::Meta::Method::Accessor::Native::Collection::_inline_check_member_constraint at line 108 of Moose/Meta/Method/Accessor/Native/Collection.pm, avg 26µs/call # once (9µs+63µs) by Moose::Util::TypeConstraints::Builtins::__ANON__[/Users/dde/perl5/perlbrew/perls/5.18.0t/lib/site_perl/5.18.0/darwin-thread-multi-2level/Moose/Util/TypeConstraints/Builtins.pm:272] at line 264 of Moose/Util/TypeConstraints/Builtins.pm # once (9µs+-9µs) by Moose::Util::TypeConstraints::Builtins::__ANON__[/Users/dde/perl5/perlbrew/perls/5.18.0t/lib/site_perl/5.18.0/darwin-thread-multi-2level/Moose/Util/TypeConstraints/Builtins.pm:176] at line 171 of Moose/Util/TypeConstraints/Builtins.pm # once (9µs+-9µs) by Moose::Meta::TypeConstraint::_inline_check at line 212
sub _inline_check {
20521923µs my $self = shift;
206
207219124µs2191.61ms unless ( $self->can_be_inlined ) {
# spent 1.61ms making 219 calls to Moose::Meta::TypeConstraint::can_be_inlined, avg 7µs/call
208 require Moose;
209 Moose->throw_error( 'Cannot inline a type constraint check for ' . $self->name );
210 }
211
212219290µs438372µs if ( $self->has_parent && $self->constraint == $null_constraint ) {
# spent 188µs making 219 calls to Moose::Meta::TypeConstraint::has_parent, avg 856ns/call # spent 184µs making 217 calls to Moose::Meta::TypeConstraint::constraint, avg 846ns/call # spent 1µs making 1 call to Moose::Meta::TypeConstraint::parent # spent 17µs making 1 call to Moose::Meta::TypeConstraint::_inline_check, recursion: max depth 1, sum of overlapping time 17µs
213 return $self->parent->_inline_check(@_);
214 }
215
216218769µs4363.39ms return '( do { ' . $self->inlined->( $self, @_ ) . ' } )';
# spent 926µs making 36 calls to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:66], avg 26µs/call # spent 623µs making 13 calls to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:112], avg 48µs/call # spent 574µs making 12 calls to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:120], avg 48µs/call # spent 524µs making 10 calls to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:83], avg 52µs/call # spent 211µs making 218 calls to Moose::Meta::TypeConstraint::inlined, avg 969ns/call # spent 191µs making 24 calls to Moose::Meta::TypeConstraint::Class::__ANON__[Moose/Meta/TypeConstraint/Class.pm:30], avg 8µs/call # spent 175µs making 19 calls to Moose::Meta::TypeConstraint::Role::__ANON__[Moose/Meta/TypeConstraint/Role.pm:32], avg 9µs/call # spent 42µs making 37 calls to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:46], avg 1µs/call # spent 38µs making 31 calls to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:223], avg 1µs/call # spent 29µs making 1 call to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:176] # spent 18µs making 13 calls to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:125], avg 1µs/call # spent 15µs making 5 calls to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:58], avg 3µs/call # spent 8µs making 4 calls to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:195], avg 2µs/call # spent 4µs making 2 calls to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:157], 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 2 calls to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:163], avg 1µs/call # spent 2µs making 2 calls to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:28], avg 950ns/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:258] # spent 1µs making 1 call to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:132] # spent 1µs making 1 call to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:39] # spent 1µ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.30ms (885µs+416µs) within Moose::Meta::TypeConstraint::inline_environment which was called 157 times, avg 8µs/call: # 50 times (294µs+142µs) by Moose::Meta::TypeConstraint::_actually_compile_type_constraint at line 311, avg 9µs/call # 47 times (273µs+127µs) by Moose::Meta::Attribute::_eval_environment at line 800 of Moose/Meta/Attribute.pm, avg 9µs/call # 32 times (171µs+82µs) by Moose::Meta::TypeConstraint::Parameterized::inline_environment at line 91 of Moose/Meta/TypeConstraint/Parameterized.pm, avg 8µs/call # 19 times (99µs+48µs) by Moose::Meta::Class::_eval_environment at line 543 of Moose/Meta/Class.pm, avg 8µs/call # 4 times (23µs+11µs) by Class::MOP::Class:::around at line 161 of Moose/Meta/Method/Accessor/Native/Collection.pm, avg 8µs/call # 4 times (21µs+10µs) by Moose::Meta::TypeConstraint::Union::inline_environment at line 108 of Moose/Meta/TypeConstraint/Union.pm, avg 8µs/call # once (5µs+-5µs) by Moose::Meta::TypeConstraint::inline_environment at line 222
sub inline_environment {
22015717µs my $self = shift;
221
222157189µs314258µs if ( $self->has_parent && $self->constraint == $null_constraint ) {
# spent 135µs making 155 calls to Moose::Meta::TypeConstraint::constraint, avg 868ns/call # spent 122µs making 157 calls to Moose::Meta::TypeConstraint::has_parent, avg 778ns/call # spent 1µs making 1 call to Moose::Meta::TypeConstraint::parent # spent 7µs making 1 call to Moose::Meta::TypeConstraint::inline_environment, recursion: max depth 1, sum of overlapping time 7µs
223 return $self->parent->inline_environment;
224 }
225
226156318µs156158µs return $self->_inline_environment;
# spent 158µs making 156 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
250
# spent 630µs (312+318) within Moose::Meta::TypeConstraint::equals which was called 27 times, avg 23µs/call: # 24 times (283µs+283µs) by Moose::Meta::TypeConstraint::is_subtype_of at line 289, avg 24µs/call # 3 times (29µs+35µs) by Moose::Meta::TypeConstraint::is_a_type_of at line 278, avg 21µs/call
sub equals {
251276µs my ( $self, $type_or_name ) = @_;
252
2532741µs54132µs my $other = Moose::Util::TypeConstraints::find_type_constraint($type_or_name) or return;
# spent 116µs making 27 calls to Moose::Util::TypeConstraints::find_type_constraint, avg 4µs/call # spent 17µs making 27 calls to Moose::Meta::TypeConstraint::__ANON__[Moose/Meta/TypeConstraint.pm:16], avg 619ns/call
254
2552759µs54126µs return 1 if $self == $other;
# spent 126µs making 54 calls to Moose::Meta::TypeConstraint::__ANON__[Moose/Meta/TypeConstraint.pm:14], avg 2µs/call
256
2572018µs2022µs if ( $self->has_hand_optimized_type_constraint and $other->has_hand_optimized_type_constraint ) {
# spent 22µs making 20 calls to Moose::Meta::TypeConstraint::has_hand_optimized_type_constraint, avg 1µs/call
258 return 1 if $self->hand_optimized_type_constraint == $other->hand_optimized_type_constraint;
259 }
260
2612052µs4037µs return unless $self->constraint == $other->constraint;
# spent 37µs making 40 calls to Moose::Meta::TypeConstraint::constraint, avg 935ns/call
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
273
# spent 208µs (36+172) within Moose::Meta::TypeConstraint::is_a_type_of which was called 4 times, avg 52µs/call: # 4 times (36µs+172µs) by Moose::Meta::Attribute::Native::Trait::_check_helper_type at line 114 of Moose/Meta/Attribute/Native/Trait.pm, avg 52µs/call
sub is_a_type_of {
27442µs my ($self, $type_or_name) = @_;
275
27647µs862µs my $type = Moose::Util::TypeConstraints::find_type_constraint($type_or_name) or return;
# spent 59µs making 4 calls to Moose::Util::TypeConstraints::find_type_constraint, avg 15µs/call # spent 3µs making 4 calls to Moose::Meta::TypeConstraint::__ANON__[Moose/Meta/TypeConstraint.pm:16], avg 725ns/call
277
278414µs5110µs ($self->equals($type) || $self->is_subtype_of($type));
# spent 64µs making 3 calls to Moose::Meta::TypeConstraint::equals, avg 21µs/call # spent 33µs making 1 call to Moose::Meta::TypeConstraint::is_subtype_of # spent 14µs making 1 call to Moose::Meta::TypeConstraint::Parameterized::equals
279}
280
281
# spent 891µs (185+706) within Moose::Meta::TypeConstraint::is_subtype_of which was called 8 times, avg 111µs/call: # 7 times (175µs+682µs) by Moose::Meta::TypeConstraint::Parameterizable::generate_constraint_for at line 36 of Moose/Meta/TypeConstraint/Parameterizable.pm, avg 122µs/call # once (10µs+23µs) by Moose::Meta::TypeConstraint::is_a_type_of at line 278
sub is_subtype_of {
28282µs my ($self, $type_or_name) = @_;
283
284814µs1698µs my $type = Moose::Util::TypeConstraints::find_type_constraint($type_or_name) or return;
# spent 92µs making 8 calls to Moose::Util::TypeConstraints::find_type_constraint, avg 11µs/call # spent 6µs making 8 calls to Moose::Meta::TypeConstraint::__ANON__[Moose/Meta/TypeConstraint.pm:16], avg 712ns/call
285
28681µs my $current = $self;
287
288845µs5242µs while (my $parent = $current->parent) {
# spent 27µs making 28 calls to Moose::Meta::TypeConstraint::parent, avg 971ns/call # spent 14µs making 24 calls to Moose::Meta::TypeConstraint::__ANON__[Moose/Meta/TypeConstraint.pm:16], avg 600ns/call
2892426µs24566µs return 1 if $parent->equals($type);
# spent 566µs making 24 calls to Moose::Meta::TypeConstraint::equals, avg 24µs/call
290205µs $current = $parent;
291 }
292
29348µs return 0;
294}
295
296## compiling the type constraint
297
298
# spent 13.9ms (4.31+9.64) within Moose::Meta::TypeConstraint::compile_type_constraint which was called 73 times, avg 191µs/call: # 46 times (207µs+7.52ms) by Moose::Meta::TypeConstraint::new at line 144, avg 168µs/call # 19 times (4.06ms+302µs) by Moose::Meta::TypeConstraint::Role::new at line 47 of Moose/Meta/TypeConstraint/Role.pm, avg 230µs/call # 5 times (21µs+809µs) by Moose::Meta::TypeConstraint::Class::new at line 45 of Moose/Meta/TypeConstraint/Class.pm, avg 166µs/call # 3 times (17µs+1.01ms) by Moose::Meta::TypeConstraint::Parameterized::compile_type_constraint at line 63 of Moose/Meta/TypeConstraint/Parameterized.pm, avg 342µs/call
sub compile_type_constraint {
299738µs my $self = shift;
30073217µs1469.64ms $self->_compiled_type_constraint($self->_actually_compile_type_constraint);
# spent 9.34ms making 72 calls to Moose::Meta::TypeConstraint::_actually_compile_type_constraint, avg 130µs/call # spent 289µs making 73 calls to Moose::Meta::TypeConstraint::_compiled_type_constraint, avg 4µs/call # spent 10µs making 1 call to Moose::Meta::TypeConstraint::Union::_actually_compile_type_constraint
301}
302
303## type compilers ...
304
305
# spent 9.34ms (587µs+8.75) within Moose::Meta::TypeConstraint::_actually_compile_type_constraint which was called 72 times, avg 130µs/call: # 72 times (587µs+8.75ms) by Moose::Meta::TypeConstraint::compile_type_constraint at line 300, avg 130µs/call
sub _actually_compile_type_constraint {
306723µs my $self = shift;
307
3087296µs91148µs return $self->_compile_hand_optimized_type_constraint
# spent 74µs making 19 calls to Moose::Meta::TypeConstraint::_compile_hand_optimized_type_constraint, avg 4µs/call # spent 74µs making 72 calls to Moose::Meta::TypeConstraint::has_hand_optimized_type_constraint, avg 1µs/call
309 if $self->has_hand_optimized_type_constraint;
310
31153260µs2128.60ms if ( $self->can_be_inlined ) {
# spent 5.64ms making 53 calls to Eval::Closure::eval_closure, avg 107µs/call # spent 1.54ms making 50 calls to Moose::Meta::TypeConstraint::_inline_check, avg 31µs/call # spent 474µs making 50 calls to Moose::Meta::TypeConstraint::can_be_inlined, avg 9µs/call # spent 436µs making 50 calls to Moose::Meta::TypeConstraint::inline_environment, avg 9µs/call # spent 323µs making 3 calls to Moose::Meta::TypeConstraint::Parameterized::_inline_check, avg 108µs/call # spent 98µs making 3 calls to Moose::Meta::TypeConstraint::Parameterized::inline_environment, avg 33µs/call # spent 84µs making 3 calls to Moose::Meta::TypeConstraint::Parameterized::can_be_inlined, avg 28µ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
332
# spent 74µs (58+16) within Moose::Meta::TypeConstraint::_compile_hand_optimized_type_constraint which was called 19 times, avg 4µs/call: # 19 times (58µs+16µs) by Moose::Meta::TypeConstraint::_actually_compile_type_constraint at line 308, avg 4µs/call
sub _compile_hand_optimized_type_constraint {
333192µs my $self = shift;
334
3351912µs1916µs my $type_constraint = $self->hand_optimized_type_constraint;
# spent 16µs making 19 calls to Moose::Meta::TypeConstraint::hand_optimized_type_constraint, avg 847ns/call
336
337192µs unless ( ref $type_constraint ) {
338 require Moose;
339 Moose->throw_error("Hand optimized type constraint is not a code reference");
340 }
341
3421930µs 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 3.55ms (74µs+3.47) within Moose::Meta::TypeConstraint::create_child_type which was called 16 times, avg 222µs/call: # 16 times (74µs+3.47ms) by Moose::Util::TypeConstraints::_create_type_constraint at line 565 of Moose/Util/TypeConstraints.pm, avg 222µs/call
sub create_child_type {
4211614µs my ($self, %opts) = @_;
422165µs my $class = ref $self;
4231646µs163.47ms return $class->new(%opts, parent => $self);
# spent 3.47ms making 16 calls to Moose::Meta::TypeConstraint::new, avg 217µs/call
424}
425
426113µs1;
427
428# ABSTRACT: The Moose Type Constraint metaclass
429
430__END__