Filename | /usr/local/lib/perl/5.18.2/Moose/Meta/TypeConstraint.pm |
Statements | Executed 11727 statements in 35.4ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1321 | 9 | 5 | 7.57ms | 11.5ms | can_be_inlined (recurses: max depth 1, inclusive time 12µs) | Moose::Meta::TypeConstraint::
96 | 10 | 7 | 6.94ms | 41.5ms | new | Moose::Meta::TypeConstraint::
611 | 13 | 5 | 5.91ms | 19.1ms | _inline_check (recurses: max depth 2, inclusive time 4.64ms) | Moose::Meta::TypeConstraint::
88 | 2 | 1 | 4.96ms | 5.89ms | equals | Moose::Meta::TypeConstraint::
607 | 7 | 6 | 3.71ms | 5.40ms | inline_environment (recurses: max depth 1, inclusive time 17µs) | Moose::Meta::TypeConstraint::
160 | 1 | 1 | 1.37ms | 32.3ms | _actually_compile_type_constraint | Moose::Meta::TypeConstraint::
162 | 4 | 4 | 850µs | 33.9ms | compile_type_constraint | Moose::Meta::TypeConstraint::
674 | 16 | 6 | 506µs | 506µs | __ANON__[:10] | Moose::Meta::TypeConstraint::
23 | 2 | 2 | 463µs | 1.99ms | is_subtype_of | Moose::Meta::TypeConstraint::
96 | 1 | 1 | 436µs | 436µs | __ANON__[:72] | Moose::Meta::TypeConstraint::
176 | 1 | 1 | 352µs | 421µs | __ANON__[:8] | Moose::Meta::TypeConstraint::
1 | 1 | 1 | 290µs | 825µs | BEGIN@6 | Moose::Meta::TypeConstraint::
32 | 1 | 1 | 260µs | 5.60ms | is_a_type_of | Moose::Meta::TypeConstraint::
96 | 2 | 1 | 160µs | 160µs | __ANON__[:89] | Moose::Meta::TypeConstraint::
16 | 1 | 1 | 68µs | 3.27ms | create_child_type | Moose::Meta::TypeConstraint::
10 | 1 | 1 | 16µs | 16µs | __ANON__[:36] | Moose::Meta::TypeConstraint::
1 | 1 | 1 | 13µs | 47µs | BEGIN@8 | Moose::Meta::TypeConstraint::
1 | 1 | 1 | 10µs | 23µs | BEGIN@4 | Moose::Meta::TypeConstraint::
1 | 1 | 1 | 9µs | 42µs | BEGIN@13 | Moose::Meta::TypeConstraint::
1 | 1 | 1 | 8µs | 167µs | BEGIN@20 | Moose::Meta::TypeConstraint::
1 | 1 | 1 | 8µs | 14µs | BEGIN@5 | Moose::Meta::TypeConstraint::
1 | 1 | 1 | 7µs | 31µs | BEGIN@16 | Moose::Meta::TypeConstraint::
1 | 1 | 1 | 7µs | 26µs | BEGIN@14 | Moose::Meta::TypeConstraint::
1 | 1 | 1 | 7µs | 23µs | BEGIN@15 | Moose::Meta::TypeConstraint::
1 | 1 | 1 | 7µs | 72µs | BEGIN@18 | Moose::Meta::TypeConstraint::
0 | 0 | 0 | 0s | 0s | __ANON__[:32] | Moose::Meta::TypeConstraint::
0 | 0 | 0 | 0s | 0s | __ANON__[:330] | Moose::Meta::TypeConstraint::
0 | 0 | 0 | 0s | 0s | __ANON__[:343] | Moose::Meta::TypeConstraint::
0 | 0 | 0 | 0s | 0s | __ANON__[:63] | Moose::Meta::TypeConstraint::
0 | 0 | 0 | 0s | 0s | __ANON__[:71] | Moose::Meta::TypeConstraint::
0 | 0 | 0 | 0s | 0s | __ANON__[:9] | Moose::Meta::TypeConstraint::
0 | 0 | 0 | 0s | 0s | _collect_all_parents | Moose::Meta::TypeConstraint::
0 | 0 | 0 | 0s | 0s | _compile_subtype | Moose::Meta::TypeConstraint::
0 | 0 | 0 | 0s | 0s | _compile_type | Moose::Meta::TypeConstraint::
0 | 0 | 0 | 0s | 0s | assert_coerce | Moose::Meta::TypeConstraint::
0 | 0 | 0 | 0s | 0s | assert_valid | Moose::Meta::TypeConstraint::
0 | 0 | 0 | 0s | 0s | check | Moose::Meta::TypeConstraint::
0 | 0 | 0 | 0s | 0s | coerce | Moose::Meta::TypeConstraint::
0 | 0 | 0 | 0s | 0s | get_message | Moose::Meta::TypeConstraint::
0 | 0 | 0 | 0s | 0s | parents | Moose::Meta::TypeConstraint::
0 | 0 | 0 | 0s | 0s | validate | Moose::Meta::TypeConstraint::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package Moose::Meta::TypeConstraint; | ||||
2 | 1 | 1µs | our $VERSION = '2.1604'; | ||
3 | |||||
4 | 2 | 22µs | 2 | 37µs | # spent 23µs (10+13) within Moose::Meta::TypeConstraint::BEGIN@4 which was called:
# once (10µs+13µs) by Moose::BEGIN@25 at line 4 # spent 23µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@4
# spent 13µs making 1 call to strict::import |
5 | 2 | 19µs | 2 | 20µs | # spent 14µs (8+6) within Moose::Meta::TypeConstraint::BEGIN@5 which was called:
# once (8µs+6µs) by Moose::BEGIN@25 at line 5 # spent 14µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@5
# spent 6µs making 1 call to warnings::import |
6 | 2 | 131µs | 2 | 1.31ms | # spent 825µs (290+535) within Moose::Meta::TypeConstraint::BEGIN@6 which was called:
# once (290µs+535µs) by Moose::BEGIN@25 at line 6 # spent 825µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@6
# spent 482µs making 1 call to metaclass::import |
7 | |||||
8 | 176 | 4.62ms | 176 | 69µs | # spent 421µs (352+69) within Moose::Meta::TypeConstraint::__ANON__[/usr/local/lib/perl/5.18.2/Moose/Meta/TypeConstraint.pm:8] which was called 176 times, avg 2µs/call:
# 176 times (352µs+69µs) by Moose::Meta::TypeConstraint::equals at line 237, avg 2µs/call
# spent 47µs (13+34) within Moose::Meta::TypeConstraint::BEGIN@8 which was called:
# once (13µs+34µs) by Moose::BEGIN@25 at line 11 # spent 69µs making 176 calls to Scalar::Util::refaddr, avg 390ns/call |
9 | '""' => sub { shift->name }, # stringify to tc name | ||||
10 | 674 | 1.14ms | # spent 506µs within Moose::Meta::TypeConstraint::__ANON__[/usr/local/lib/perl/5.18.2/Moose/Meta/TypeConstraint.pm:10] which was called 674 times, avg 751ns/call:
# 156 times (176µs+0s) by Moose::Util::TypeConstraints::find_or_parse_type_constraint at line 260 of Moose/Util/TypeConstraints.pm, avg 1µs/call
# 120 times (54µs+0s) by Moose::Util::TypeConstraints::find_or_create_isa_type_constraint at line 246 of Moose/Util/TypeConstraints.pm, avg 450ns/call
# 96 times (120µs+0s) by Moose::Meta::TypeConstraint::Registry::add_type_constraint at line 47 of Moose/Meta/TypeConstraint/Registry.pm, avg 1µs/call
# 88 times (43µs+0s) by Moose::Meta::TypeConstraint::equals at line 235, avg 485ns/call
# 61 times (26µs+0s) by Moose::Meta::TypeConstraint::is_subtype_of at line 268, avg 431ns/call
# 32 times (17µs+0s) by Moose::Meta::TypeConstraint::is_a_type_of at line 255, avg 528ns/call
# 32 times (15µs+0s) by Moose::Util::TypeConstraints::find_or_create_type_constraint at line 218 of Moose/Util/TypeConstraints.pm, avg 466ns/call
# 23 times (12µs+0s) by Moose::Meta::TypeConstraint::is_subtype_of at line 264, avg 526ns/call
# 17 times (20µs+0s) by Moose::Meta::Method::Accessor::Native::Collection::_tc_member_type at line 36 of Moose/Meta/Method/Accessor/Native/Collection.pm, avg 1µs/call
# 16 times (7µs+0s) by Moose::Util::TypeConstraints::_create_type_constraint at line 572 of Moose/Util/TypeConstraints.pm, avg 419ns/call
# 8 times (4µs+0s) by Moose::Meta::Method::Accessor::Native::Collection::_tc_member_type at line 39 of Moose/Meta/Method/Accessor/Native/Collection.pm, avg 450ns/call
# 8 times (4µs+0s) by Moose::Util::TypeConstraints::find_or_create_does_type_constraint at line 252 of Moose/Util/TypeConstraints.pm, avg 450ns/call
# 7 times (4µs+0s) by Moose::Meta::TypeConstraint::Parameterizable::parameterize at line 78 of Moose/Meta/TypeConstraint/Parameterizable.pm, avg 514ns/call
# 5 times (3µs+0s) by Class::MOP::Class:::around at line 146 of Moose/Meta/Method/Accessor/Native/Collection.pm, avg 620ns/call
# 4 times (2µs+0s) by Moose::Util::TypeConstraints::_create_type_constraint_union at line 97 of Moose/Util/TypeConstraints.pm, avg 450ns/call
# once (2µs+0s) by Moose::Role::init_meta at line 126 of Moose/Role.pm | ||
11 | 2 | 27µs | 2 | 81µs | fallback => 1; # spent 47µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@8
# spent 34µs making 1 call to overload::import |
12 | |||||
13 | 2 | 28µs | 2 | 75µs | # spent 42µs (9+33) within Moose::Meta::TypeConstraint::BEGIN@13 which was called:
# once (9µs+33µs) by Moose::BEGIN@25 at line 13 # spent 42µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@13
# spent 33µs making 1 call to Exporter::import |
14 | 2 | 22µs | 2 | 46µs | # spent 26µs (7+20) within Moose::Meta::TypeConstraint::BEGIN@14 which was called:
# once (7µs+20µs) by Moose::BEGIN@25 at line 14 # spent 26µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@14
# spent 20µs making 1 call to Exporter::import |
15 | 2 | 20µs | 2 | 39µs | # spent 23µs (7+16) within Moose::Meta::TypeConstraint::BEGIN@15 which was called:
# once (7µs+16µs) by Moose::BEGIN@25 at line 15 # spent 23µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@15
# spent 16µs making 1 call to Exporter::import |
16 | 2 | 21µs | 2 | 54µs | # spent 31µs (7+24) within Moose::Meta::TypeConstraint::BEGIN@16 which was called:
# once (7µs+24µs) by Moose::BEGIN@25 at line 16 # spent 31µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@16
# spent 24µs making 1 call to Exporter::import |
17 | |||||
18 | 2 | 27µs | 2 | 138µs | # spent 72µs (7+65) within Moose::Meta::TypeConstraint::BEGIN@18 which was called:
# once (7µs+65µs) by Moose::BEGIN@25 at line 18 # spent 72µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@18
# spent 65µs making 1 call to base::import |
19 | |||||
20 | 2 | 1.30ms | 2 | 326µs | # spent 167µs (8+159) within Moose::Meta::TypeConstraint::BEGIN@20 which was called:
# once (8µs+159µs) by Moose::BEGIN@25 at line 20 # spent 167µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@20
# spent 159µs making 1 call to Sub::Exporter::__ANON__[Sub/Exporter.pm:337] |
21 | |||||
22 | 1 | 4µs | 3 | 384µs | __PACKAGE__->meta->add_attribute('name' => ( # spent 362µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 17µs making 1 call to Moose::Meta::TypeConstraint::meta
# spent 6µs making 1 call to Class::MOP::_definition_context |
23 | reader => 'name', | ||||
24 | Class::MOP::_definition_context(), | ||||
25 | )); | ||||
26 | 1 | 3µs | 3 | 412µs | __PACKAGE__->meta->add_attribute('parent' => ( # spent 400µ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 |
27 | reader => 'parent', | ||||
28 | predicate => 'has_parent', | ||||
29 | Class::MOP::_definition_context(), | ||||
30 | )); | ||||
31 | |||||
32 | 1 | 2µs | my $null_constraint = sub { 1 }; | ||
33 | __PACKAGE__->meta->add_attribute('constraint' => ( | ||||
34 | reader => 'constraint', | ||||
35 | writer => '_set_constraint', | ||||
36 | 10 | 24µs | # spent 16µs within Moose::Meta::TypeConstraint::__ANON__[/usr/local/lib/perl/5.18.2/Moose/Meta/TypeConstraint.pm:36] which was called 10 times, avg 2µs/call:
# 10 times (16µs+0s) by Moose::Meta::TypeConstraint::Parameterized::_new or Moose::Meta::TypeConstraint::Union::_new or Moose::Meta::TypeConstraint::_new at line 24 of (eval 45)[Eval/Closure.pm:144], avg 2µs/call | ||
37 | 1 | 4µs | 3 | 405µs | Class::MOP::_definition_context(), # spent 393µ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 |
38 | )); | ||||
39 | |||||
40 | 1 | 2µs | 3 | 386µs | __PACKAGE__->meta->add_attribute('message' => ( # spent 375µ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 |
41 | accessor => 'message', | ||||
42 | predicate => 'has_message', | ||||
43 | Class::MOP::_definition_context(), | ||||
44 | )); | ||||
45 | |||||
46 | 1 | 2µs | 3 | 262µs | __PACKAGE__->meta->add_attribute('_default_message' => ( # spent 251µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 7µs making 1 call to Moose::Meta::TypeConstraint::meta
# spent 4µs making 1 call to Class::MOP::_definition_context |
47 | accessor => '_default_message', | ||||
48 | Class::MOP::_definition_context(), | ||||
49 | )); | ||||
50 | |||||
51 | # can't make this a default because it has to close over the type name, and | ||||
52 | # cmop attributes don't have lazy | ||||
53 | # spent 436µs within Moose::Meta::TypeConstraint::__ANON__[/usr/local/lib/perl/5.18.2/Moose/Meta/TypeConstraint.pm:72] which was called 96 times, avg 5µs/call:
# 96 times (436µs+0s) by Moose::Meta::TypeConstraint::new at line 127, avg 5µs/call | ||||
54 | 96 | 49µs | my $name = shift; | ||
55 | sub { | ||||
56 | my $value = shift; | ||||
57 | # have to load it late like this, since it uses Moose itself | ||||
58 | my $can_partialdump = try { | ||||
59 | # versions prior to 0.14 had a potential infinite loop bug | ||||
60 | require Devel::PartialDump; | ||||
61 | Devel::PartialDump->VERSION(0.14); | ||||
62 | 1; | ||||
63 | }; | ||||
64 | if ($can_partialdump) { | ||||
65 | $value = Devel::PartialDump->new->dump($value); | ||||
66 | } | ||||
67 | else { | ||||
68 | $value = (defined $value ? overload::StrVal($value) : 'undef'); | ||||
69 | } | ||||
70 | return "Validation failed for '" . $name . "' with value $value"; | ||||
71 | } | ||||
72 | 97 | 432µs | }; | ||
73 | 1 | 3µs | 3 | 372µs | __PACKAGE__->meta->add_attribute('coercion' => ( # spent 360µ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 |
74 | accessor => 'coercion', | ||||
75 | predicate => 'has_coercion', | ||||
76 | Class::MOP::_definition_context(), | ||||
77 | )); | ||||
78 | |||||
79 | 1 | 3µs | 3 | 4.35ms | __PACKAGE__->meta->add_attribute('inlined' => ( # spent 4.34ms 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 |
80 | init_arg => 'inlined', | ||||
81 | accessor => 'inlined', | ||||
82 | predicate => '_has_inlined_type_constraint', | ||||
83 | Class::MOP::_definition_context(), | ||||
84 | )); | ||||
85 | |||||
86 | __PACKAGE__->meta->add_attribute('inline_environment' => ( | ||||
87 | init_arg => 'inline_environment', | ||||
88 | accessor => '_inline_environment', | ||||
89 | 96 | 5.35ms | # spent 160µs within Moose::Meta::TypeConstraint::__ANON__[/usr/local/lib/perl/5.18.2/Moose/Meta/TypeConstraint.pm:89] which was called 96 times, avg 2µs/call:
# 61 times (99µ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 30 of (eval 45)[Eval/Closure.pm:144], avg 2µs/call
# 35 times (60µs+0s) by Moose::Meta::TypeConstraint::Class::_new or Moose::Meta::TypeConstraint::Parameterizable::_new at line 33 of (eval 45)[Eval/Closure.pm:144], avg 2µs/call | ||
90 | 1 | 5µs | 3 | 261µs | Class::MOP::_definition_context(), # spent 248µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 9µs making 1 call to Moose::Meta::TypeConstraint::meta
# spent 4µs making 1 call to Class::MOP::_definition_context |
91 | )); | ||||
92 | |||||
93 | sub parents { | ||||
94 | my $self = shift; | ||||
95 | $self->parent; | ||||
96 | } | ||||
97 | |||||
98 | # private accessors | ||||
99 | |||||
100 | 1 | 3µs | 3 | 378µs | __PACKAGE__->meta->add_attribute('compiled_type_constraint' => ( # spent 366µ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 |
101 | accessor => '_compiled_type_constraint', | ||||
102 | predicate => '_has_compiled_type_constraint', | ||||
103 | Class::MOP::_definition_context(), | ||||
104 | )); | ||||
105 | |||||
106 | 1 | 3µs | 3 | 236µs | __PACKAGE__->meta->add_attribute('package_defined_in' => ( # spent 225µ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 |
107 | accessor => '_package_defined_in', | ||||
108 | Class::MOP::_definition_context(), | ||||
109 | )); | ||||
110 | |||||
111 | # spent 41.5ms (6.94+34.6) within Moose::Meta::TypeConstraint::new which was called 96 times, avg 433µs/call:
# 35 times (895µs+14.0ms) by Moose::Meta::TypeConstraint::Role::new at line 39 of Moose/Meta/TypeConstraint/Role.pm, avg 424µs/call
# 31 times (5.43ms+11.1ms) by Moose::Meta::TypeConstraint::Class::new at line 38 of Moose/Meta/TypeConstraint/Class.pm, avg 534µs/call
# 16 times (256µs+2.95ms) by Moose::Meta::TypeConstraint::create_child_type at line 362, avg 200µs/call
# 7 times (187µs+5.32ms) by Moose::Meta::TypeConstraint::Parameterizable::parameterize at line 90 of Moose/Meta/TypeConstraint/Parameterizable.pm, avg 786µs/call
# 2 times (60µs+205µs) by Moose::Meta::TypeConstraint::Union::new at line 26 of Moose/Meta/TypeConstraint/Union.pm, avg 132µs/call
# once (31µs+280µs) by Moose::Util::TypeConstraints::_create_type_constraint at line 582 of Moose/Util/TypeConstraints.pm
# once (30µs+279µs) by Moose::Util::TypeConstraints::Builtins::define_builtins at line 198 of Moose/Util/TypeConstraints/Builtins.pm
# once (20µs+180µs) by Moose::Util::TypeConstraints::Builtins::define_builtins at line 233 of Moose/Util/TypeConstraints/Builtins.pm
# once (18µs+150µs) by Moose::Util::TypeConstraints::Builtins::define_builtins at line 268 of Moose/Util/TypeConstraints/Builtins.pm
# once (18µs+147µs) by Moose::Util::TypeConstraints::Builtins::define_builtins at line 294 of Moose/Util/TypeConstraints/Builtins.pm | ||||
112 | 96 | 31µs | my $class = shift; | ||
113 | 96 | 73µs | my ($first, @rest) = @_; | ||
114 | 96 | 235µs | my %args = ref $first ? %$first : $first ? ($first, @rest) : (); | ||
115 | 96 | 128µs | $args{name} = $args{name} ? "$args{name}" : "__ANON__"; | ||
116 | |||||
117 | 96 | 43µs | if ( exists $args{message} | ||
118 | && (!ref($args{message}) || ref($args{message}) ne 'CODE') ) { | ||||
119 | throw_exception( MessageParameterMustBeCodeRef => params => \%args, | ||||
120 | class => $class | ||||
121 | ); | ||||
122 | } | ||||
123 | |||||
124 | 96 | 262µs | 96 | 7.72ms | my $self = $class->_new(%args); # spent 6.06ms making 35 calls to Moose::Meta::TypeConstraint::Role::_new, avg 173µs/call
# spent 828µs making 31 calls to Moose::Meta::TypeConstraint::Class::_new, avg 27µs/call
# spent 286µs making 17 calls to Moose::Meta::TypeConstraint::_new, avg 17µs/call
# spent 274µs making 7 calls to Moose::Meta::TypeConstraint::Parameterized::_new, avg 39µs/call
# spent 139µs making 4 calls to Moose::Meta::TypeConstraint::Parameterizable::_new, avg 35µs/call
# spent 134µs making 2 calls to Moose::Meta::TypeConstraint::Union::_new, avg 67µs/call |
125 | 96 | 332µs | 192 | 25.8ms | $self->compile_type_constraint() # spent 20.7ms making 89 calls to Moose::Meta::TypeConstraint::compile_type_constraint, avg 232µs/call
# spent 4.96ms making 7 calls to Moose::Meta::TypeConstraint::Parameterized::compile_type_constraint, avg 708µs/call
# spent 194µs making 96 calls to Moose::Meta::TypeConstraint::_has_compiled_type_constraint, avg 2µs/call |
126 | unless $self->_has_compiled_type_constraint; | ||||
127 | 96 | 582µs | 384 | 1.04ms | $self->_default_message($_default_message_generator->($self->name)) # spent 436µs making 96 calls to Moose::Meta::TypeConstraint::__ANON__[Moose/Meta/TypeConstraint.pm:72], avg 5µs/call
# spent 242µs making 96 calls to Moose::Meta::TypeConstraint::_default_message, avg 3µs/call
# spent 181µs making 96 calls to Moose::Meta::TypeConstraint::name, avg 2µs/call
# spent 178µs making 96 calls to Moose::Meta::TypeConstraint::has_message, avg 2µs/call |
128 | unless $self->has_message; | ||||
129 | 96 | 302µs | return $self; | ||
130 | } | ||||
131 | |||||
- - | |||||
134 | sub coerce { | ||||
135 | my $self = shift; | ||||
136 | |||||
137 | my $coercion = $self->coercion; | ||||
138 | |||||
139 | unless ($coercion) { | ||||
140 | throw_exception( CoercingWithoutCoercions => type_name => $self->name ); | ||||
141 | } | ||||
142 | |||||
143 | return $_[0] if $self->check($_[0]); | ||||
144 | |||||
145 | return $coercion->coerce(@_); | ||||
146 | } | ||||
147 | |||||
148 | sub assert_coerce { | ||||
149 | my $self = shift; | ||||
150 | |||||
151 | my $result = $self->coerce(@_); | ||||
152 | |||||
153 | $self->assert_valid($result); | ||||
154 | |||||
155 | return $result; | ||||
156 | } | ||||
157 | |||||
158 | sub check { | ||||
159 | my ($self, @args) = @_; | ||||
160 | my $constraint_subref = $self->_compiled_type_constraint; | ||||
161 | return $constraint_subref->(@args) ? 1 : undef; | ||||
162 | } | ||||
163 | |||||
164 | sub validate { | ||||
165 | my ($self, $value) = @_; | ||||
166 | if ($self->_compiled_type_constraint->($value)) { | ||||
167 | return undef; | ||||
168 | } | ||||
169 | else { | ||||
170 | $self->get_message($value); | ||||
171 | } | ||||
172 | } | ||||
173 | |||||
174 | # spent 11.5ms (7.57+3.94) within Moose::Meta::TypeConstraint::can_be_inlined which was called 1321 times, avg 9µs/call:
# 611 times (2.91ms+1.38ms) by Moose::Meta::TypeConstraint::_inline_check at line 187, avg 7µs/call
# 253 times (1.49ms+776µs) by Moose::Meta::Attribute::_inline_check_constraint at line 686 of Moose/Meta/Attribute.pm, avg 9µs/call
# 165 times (1.19ms+694µs) by Moose::Meta::Attribute::_eval_environment at line 766 of Moose/Meta/Attribute.pm, avg 11µs/call
# 153 times (1.03ms+585µs) by Moose::Meta::TypeConstraint::_actually_compile_type_constraint at line 288, avg 11µs/call
# 88 times (660µs+381µs) by Moose::Meta::TypeConstraint::Parameterized::can_be_inlined at line 72 of Moose/Meta/TypeConstraint/Parameterized.pm, avg 12µs/call
# 44 times (236µs+116µs) by Moose::Meta::TypeConstraint::Union::can_be_inlined at line 80 of Moose/Meta/TypeConstraint/Union.pm, avg 8µs/call
# 4 times (32µs+16µs) by Moose::Meta::Method::Accessor::Native::Collection::_inline_check_member_constraint at line 103 of Moose/Meta/Method/Accessor/Native/Collection.pm, avg 12µs/call
# 2 times (9µs+-9µs) by Moose::Meta::TypeConstraint::can_be_inlined at line 177, avg 0s/call
# once (6µs+2µs) by Moose::Meta::Attribute::_inline_check_coercion at line 662 of Moose/Meta/Attribute.pm | ||||
175 | 1321 | 190µs | my $self = shift; | ||
176 | |||||
177 | 1321 | 2.28ms | 2641 | 2.64ms | if ( $self->has_parent && $self->constraint == $null_constraint ) { # spent 1.39ms making 1321 calls to Moose::Meta::TypeConstraint::has_parent, avg 1µs/call
# spent 1.25ms making 1316 calls to Moose::Meta::TypeConstraint::constraint, avg 949ns/call
# spent 3µ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 |
178 | return $self->parent->can_be_inlined; | ||||
179 | } | ||||
180 | |||||
181 | 1319 | 3.04ms | 1319 | 1.30ms | return $self->_has_inlined_type_constraint; # spent 1.30ms making 1319 calls to Moose::Meta::TypeConstraint::_has_inlined_type_constraint, avg 986ns/call |
182 | } | ||||
183 | |||||
184 | # spent 19.1ms (5.91+13.2) within Moose::Meta::TypeConstraint::_inline_check which was called 611 times, avg 31µs/call:
# 253 times (2.32ms+6.78ms) by Moose::Meta::Attribute::_inline_check_constraint at line 686 of Moose/Meta/Attribute.pm, avg 36µs/call
# 153 times (1.60ms+6.52ms) by Moose::Meta::TypeConstraint::_actually_compile_type_constraint at line 288, avg 53µs/call
# 75 times (640µs+-640µs) by Moose::Util::TypeConstraints::Builtins::__ANON__[/usr/local/lib/perl/5.18.2/Moose/Util/TypeConstraints/Builtins.pm:60] at line 58 of Moose/Util/TypeConstraints/Builtins.pm, avg 0s/call
# 60 times (515µs+-515µs) by Moose::Util::TypeConstraints::Builtins::__ANON__[/usr/local/lib/perl/5.18.2/Moose/Util/TypeConstraints/Builtins.pm:77] at line 72 of Moose/Util/TypeConstraints/Builtins.pm, avg 0s/call
# 18 times (228µs+471µs) by Moose::Util::TypeConstraints::Builtins::__ANON__[/usr/local/lib/perl/5.18.2/Moose/Util/TypeConstraints/Builtins.pm:266] at line 258 of Moose/Util/TypeConstraints/Builtins.pm, avg 39µs/call
# 16 times (154µs+259µs) by Moose::Meta::TypeConstraint::Union::_inline_check at line 90 of Moose/Meta/TypeConstraint/Union.pm, avg 26µs/call
# 15 times (271µs+347µs) by Moose::Util::TypeConstraints::Builtins::__ANON__[/usr/local/lib/perl/5.18.2/Moose/Util/TypeConstraints/Builtins.pm:231] at line 223 of Moose/Util/TypeConstraints/Builtins.pm, avg 41µs/call
# 11 times (86µs+-86µs) by Moose::Util::TypeConstraints::Builtins::__ANON__[/usr/local/lib/perl/5.18.2/Moose/Util/TypeConstraints/Builtins.pm:114] at line 112 of Moose/Util/TypeConstraints/Builtins.pm, avg 0s/call
# 4 times (46µs+90µs) by Moose::Meta::Method::Accessor::Native::Collection::_inline_check_member_constraint at line 103 of Moose/Meta/Method/Accessor/Native/Collection.pm, avg 34µs/call
# 3 times (25µs+-25µs) by Moose::Util::TypeConstraints::Builtins::__ANON__[/usr/local/lib/perl/5.18.2/Moose/Util/TypeConstraints/Builtins.pm:106] at line 97 of Moose/Util/TypeConstraints/Builtins.pm, avg 0s/call
# once (9µs+20µs) by Moose::Meta::Attribute::_inline_check_coercion at line 662 of Moose/Meta/Attribute.pm
# once (8µs+-8µs) by Moose::Util::TypeConstraints::Builtins::__ANON__[/usr/local/lib/perl/5.18.2/Moose/Util/TypeConstraints/Builtins.pm:170] at line 165 of Moose/Util/TypeConstraints/Builtins.pm
# once (10µs+-10µs) by Moose::Meta::TypeConstraint::_inline_check at line 191 | ||||
185 | 611 | 114µs | my $self = shift; | ||
186 | |||||
187 | 611 | 364µs | 611 | 4.29ms | unless ( $self->can_be_inlined ) { # spent 4.29ms making 611 calls to Moose::Meta::TypeConstraint::can_be_inlined, avg 7µs/call |
188 | throw_exception( CannotInlineTypeConstraintCheck => type_name => $self->name ); | ||||
189 | } | ||||
190 | |||||
191 | 611 | 936µs | 1222 | 886µs | if ( $self->has_parent && $self->constraint == $null_constraint ) { # spent 466µs making 611 calls to Moose::Meta::TypeConstraint::has_parent, avg 764ns/call
# spent 419µs making 609 calls to Moose::Meta::TypeConstraint::constraint, avg 687ns/call
# spent 800ns making 1 call to Moose::Meta::TypeConstraint::parent
# spent 28µs making 1 call to Moose::Meta::TypeConstraint::_inline_check, recursion: max depth 1, sum of overlapping time 28µs |
192 | return $self->parent->_inline_check(@_); | ||||
193 | } | ||||
194 | |||||
195 | 610 | 2.42ms | 1220 | 12.6ms | return '( do { ' . $self->inlined->( $self, @_ ) . ' } )'; # spent 5.02ms making 149 calls to Moose::Meta::TypeConstraint::Class::__ANON__[Moose/Meta/TypeConstraint/Class.pm:25], avg 34µs/call
# spent 3.09ms making 60 calls to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:77], avg 52µs/call
# spent 1.89ms making 75 calls to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:60], avg 25µs/call
# spent 942µs making 89 calls to Moose::Meta::TypeConstraint::Role::__ANON__[Moose/Meta/TypeConstraint/Role.pm:27], avg 11µs/call
# spent 693µs making 610 calls to Moose::Meta::TypeConstraint::inlined, avg 1µs/call
# spent 468µs making 11 calls to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:114], avg 43µs/call
# spent 144µs making 3 calls to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:106], avg 48µs/call
# spent 124µs making 58 calls to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:52], avg 2µs/call
# spent 104µs making 76 calls to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:40], avg 1µs/call
# spent 81µs making 53 calls to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:252], avg 2µs/call
# spent 33µs making 22 calls to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:217], avg 2µs/call
# spent 27µs making 1 call to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:170]
# spent 3µs making 1 call to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:189]
# spent 3µs making 1 call to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:146]
# spent 2µs making 2 calls to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:157], avg 1µs/call
# spent 2µs making 1 call to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:126]
# spent 2µs making 2 calls to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:22], avg 800ns/call
# spent 1µs making 1 call to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:119]
# spent 1µs making 1 call to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:33]
# spent 1µs making 1 call to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:151]
# spent 1µs making 1 call to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:285]
# spent 1µs making 1 call to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:66]
# spent 1µs making 1 call to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:131] |
196 | } | ||||
197 | |||||
198 | # spent 5.40ms (3.71+1.69) within Moose::Meta::TypeConstraint::inline_environment which was called 607 times, avg 9µs/call:
# 173 times (921µs+411µs) by Moose::Meta::Class::_eval_environment at line 535 of Moose/Meta/Class.pm, avg 8µs/call
# 165 times (1.10ms+494µs) by Moose::Meta::Attribute::_eval_environment at line 777 of Moose/Meta/Attribute.pm, avg 10µs/call
# 153 times (954µs+452µs) by Moose::Meta::TypeConstraint::_actually_compile_type_constraint at line 288, avg 9µs/call
# 87 times (588µs+271µs) by Moose::Meta::TypeConstraint::Parameterized::inline_environment at line 85 of Moose/Meta/TypeConstraint/Parameterized.pm, avg 10µs/call
# 24 times (116µs+51µs) by Moose::Meta::TypeConstraint::Union::inline_environment at line 101 of Moose/Meta/TypeConstraint/Union.pm, avg 7µs/call
# 4 times (25µs+13µs) by Class::MOP::Class:::around at line 158 of Moose/Meta/Method/Accessor/Native/Collection.pm, avg 9µs/call
# once (6µs+-6µs) by Moose::Meta::TypeConstraint::inline_environment at line 201 | ||||
199 | 607 | 138µs | my $self = shift; | ||
200 | |||||
201 | 607 | 920µs | 1214 | 924µs | if ( $self->has_parent && $self->constraint == $null_constraint ) { # spent 464µs making 605 calls to Moose::Meta::TypeConstraint::constraint, avg 767ns/call
# spent 460µs making 607 calls to Moose::Meta::TypeConstraint::has_parent, avg 757ns/call
# spent 800ns making 1 call to Moose::Meta::TypeConstraint::parent
# spent 17µs making 1 call to Moose::Meta::TypeConstraint::inline_environment, recursion: max depth 1, sum of overlapping time 17µs |
202 | return $self->parent->inline_environment; | ||||
203 | } | ||||
204 | |||||
205 | 606 | 6.97ms | 606 | 761µs | return $self->_inline_environment; # spent 761µs making 606 calls to Moose::Meta::TypeConstraint::_inline_environment, avg 1µs/call |
206 | } | ||||
207 | |||||
208 | sub assert_valid { | ||||
209 | my ( $self, $value ) = @_; | ||||
210 | |||||
211 | return 1 if $self->check($value); | ||||
212 | |||||
213 | throw_exception( | ||||
214 | 'ValidationFailedForTypeConstraint', | ||||
215 | type => $self, | ||||
216 | value => $value | ||||
217 | ); | ||||
218 | } | ||||
219 | |||||
220 | sub get_message { | ||||
221 | my ($self, $value) = @_; | ||||
222 | my $msg = $self->has_message | ||||
223 | ? $self->message | ||||
224 | : $self->_default_message; | ||||
225 | local $_ = $value; | ||||
226 | return $msg->($value); | ||||
227 | } | ||||
228 | |||||
229 | ## type predicates ... | ||||
230 | |||||
231 | # spent 5.89ms (4.96+938µs) within Moose::Meta::TypeConstraint::equals which was called 88 times, avg 67µs/call:
# 61 times (593µs+598µs) by Moose::Meta::TypeConstraint::is_subtype_of at line 269, avg 20µs/call
# 27 times (4.36ms+340µs) by Moose::Meta::TypeConstraint::is_a_type_of at line 257, avg 174µs/call | ||||
232 | 88 | 24µs | my ( $self, $type_or_name ) = @_; | ||
233 | |||||
234 | 88 | 58µs | 88 | 392µs | my $other = Moose::Util::TypeConstraints::find_type_constraint($type_or_name); # spent 392µs making 88 calls to Moose::Util::TypeConstraints::find_type_constraint, avg 4µs/call |
235 | 88 | 82µs | 88 | 43µs | return if not $other; # spent 43µs making 88 calls to Moose::Meta::TypeConstraint::__ANON__[Moose/Meta/TypeConstraint.pm:10], avg 485ns/call |
236 | |||||
237 | 88 | 270µs | 176 | 421µs | return 1 if $self == $other; # spent 421µs making 176 calls to Moose::Meta::TypeConstraint::__ANON__[Moose/Meta/TypeConstraint.pm:8], avg 2µs/call |
238 | |||||
239 | 49 | 134µs | 98 | 83µs | return unless $self->constraint == $other->constraint; # spent 83µs making 98 calls to Moose::Meta::TypeConstraint::constraint, avg 849ns/call |
240 | |||||
241 | if ( $self->has_parent ) { | ||||
242 | return unless $other->has_parent; | ||||
243 | return unless $self->parent->equals( $other->parent ); | ||||
244 | } else { | ||||
245 | return if $other->has_parent; | ||||
246 | } | ||||
247 | |||||
248 | return; | ||||
249 | } | ||||
250 | |||||
251 | # spent 5.60ms (260µs+5.34) within Moose::Meta::TypeConstraint::is_a_type_of which was called 32 times, avg 175µs/call:
# 32 times (260µs+5.34ms) by Moose::Meta::Attribute::Native::Trait::_check_helper_type at line 41 of Moose/Meta/Attribute/Native/Trait.pm, avg 175µs/call | ||||
252 | 32 | 12µs | my ($self, $type_or_name) = @_; | ||
253 | |||||
254 | 32 | 26µs | 32 | 352µs | my $type = Moose::Util::TypeConstraints::find_type_constraint($type_or_name); # spent 352µs making 32 calls to Moose::Util::TypeConstraints::find_type_constraint, avg 11µs/call |
255 | 32 | 33µs | 32 | 17µs | return if not $type; # spent 17µs making 32 calls to Moose::Meta::TypeConstraint::__ANON__[Moose/Meta/TypeConstraint.pm:10], avg 528ns/call |
256 | |||||
257 | 32 | 100µs | 37 | 4.97ms | ($self->equals($type) || $self->is_subtype_of($type)); # spent 4.70ms making 27 calls to Moose::Meta::TypeConstraint::equals, avg 174µs/call
# spent 161µs making 5 calls to Moose::Meta::TypeConstraint::is_subtype_of, avg 32µs/call
# spent 102µs making 5 calls to Moose::Meta::TypeConstraint::Parameterized::equals, avg 20µs/call |
258 | } | ||||
259 | |||||
260 | # spent 1.99ms (463µs+1.53) within Moose::Meta::TypeConstraint::is_subtype_of which was called 23 times, avg 87µs/call:
# 18 times (416µs+1.41ms) by Moose::Meta::TypeConstraint::Parameterizable::generate_constraint_for at line 33 of Moose/Meta/TypeConstraint/Parameterizable.pm, avg 102µs/call
# 5 times (47µs+114µs) by Moose::Meta::TypeConstraint::is_a_type_of at line 257, avg 32µs/call | ||||
261 | 23 | 9µs | my ($self, $type_or_name) = @_; | ||
262 | |||||
263 | 23 | 15µs | 23 | 233µs | my $type = Moose::Util::TypeConstraints::find_type_constraint($type_or_name); # spent 233µs making 23 calls to Moose::Util::TypeConstraints::find_type_constraint, avg 10µs/call |
264 | 23 | 24µs | 23 | 12µs | return if not $type; # spent 12µs making 23 calls to Moose::Meta::TypeConstraint::__ANON__[Moose/Meta/TypeConstraint.pm:10], avg 526ns/call |
265 | |||||
266 | 23 | 4µs | my $current = $self; | ||
267 | |||||
268 | 23 | 119µs | 133 | 91µs | while (my $parent = $current->parent) { # spent 64µs making 72 calls to Moose::Meta::TypeConstraint::parent, avg 894ns/call
# spent 26µs making 61 calls to Moose::Meta::TypeConstraint::__ANON__[Moose/Meta/TypeConstraint.pm:10], avg 431ns/call |
269 | 61 | 69µs | 61 | 1.19ms | return 1 if $parent->equals($type); # spent 1.19ms making 61 calls to Moose::Meta::TypeConstraint::equals, avg 20µs/call |
270 | 49 | 12µs | $current = $parent; | ||
271 | } | ||||
272 | |||||
273 | 11 | 20µs | return 0; | ||
274 | } | ||||
275 | |||||
276 | ## compiling the type constraint | ||||
277 | |||||
278 | # spent 33.9ms (850µs+33.0) within Moose::Meta::TypeConstraint::compile_type_constraint which was called 162 times, avg 209µs/call:
# 89 times (530µs+20.1ms) by Moose::Meta::TypeConstraint::new at line 125, avg 232µs/call
# 35 times (146µs+5.42ms) by Moose::Meta::TypeConstraint::Role::new at line 41 of Moose/Meta/TypeConstraint/Role.pm, avg 159µs/call
# 31 times (128µs+4.98ms) by Moose::Meta::TypeConstraint::Class::new at line 40 of Moose/Meta/TypeConstraint/Class.pm, avg 165µs/call
# 7 times (46µs+2.48ms) by Moose::Meta::TypeConstraint::Parameterized::compile_type_constraint at line 57 of Moose/Meta/TypeConstraint/Parameterized.pm, avg 361µs/call | ||||
279 | 162 | 38µs | my $self = shift; | ||
280 | 162 | 666µs | 324 | 33.0ms | $self->_compiled_type_constraint($self->_actually_compile_type_constraint); # spent 32.3ms making 160 calls to Moose::Meta::TypeConstraint::_actually_compile_type_constraint, avg 202µs/call
# spent 739µs making 162 calls to Moose::Meta::TypeConstraint::_compiled_type_constraint, avg 5µs/call
# spent 22µs making 2 calls to Moose::Meta::TypeConstraint::Union::_actually_compile_type_constraint, avg 11µs/call |
281 | } | ||||
282 | |||||
283 | ## type compilers ... | ||||
284 | |||||
285 | # spent 32.3ms (1.37+30.9) within Moose::Meta::TypeConstraint::_actually_compile_type_constraint which was called 160 times, avg 202µs/call:
# 160 times (1.37ms+30.9ms) by Moose::Meta::TypeConstraint::compile_type_constraint at line 280, avg 202µs/call | ||||
286 | 160 | 20µs | my $self = shift; | ||
287 | |||||
288 | 160 | 958µs | 640 | 30.9ms | if ( $self->can_be_inlined ) { # spent 18.6ms making 160 calls to Eval::Closure::eval_closure, avg 116µs/call
# spent 8.12ms making 153 calls to Moose::Meta::TypeConstraint::_inline_check, avg 53µs/call
# spent 1.62ms making 153 calls to Moose::Meta::TypeConstraint::can_be_inlined, avg 11µs/call
# spent 1.41ms making 153 calls to Moose::Meta::TypeConstraint::inline_environment, avg 9µs/call
# spent 661µs making 7 calls to Moose::Meta::TypeConstraint::Parameterized::_inline_check, avg 94µs/call
# spent 273µs making 7 calls to Moose::Meta::TypeConstraint::Parameterized::inline_environment, avg 39µs/call
# spent 259µs making 7 calls to Moose::Meta::TypeConstraint::Parameterized::can_be_inlined, avg 37µs/call |
289 | return eval_closure( | ||||
290 | source => 'sub { ' . $self->_inline_check('$_[0]') . ' }', | ||||
291 | environment => $self->inline_environment, | ||||
292 | ); | ||||
293 | } | ||||
294 | |||||
295 | my $check = $self->constraint; | ||||
296 | unless ( defined $check ) { | ||||
297 | throw_exception( NoConstraintCheckForTypeConstraint => type_name => $self->name ); | ||||
298 | } | ||||
299 | |||||
300 | return $self->_compile_subtype($check) | ||||
301 | if $self->has_parent; | ||||
302 | |||||
303 | return $self->_compile_type($check); | ||||
304 | } | ||||
305 | |||||
306 | sub _compile_subtype { | ||||
307 | my ($self, $check) = @_; | ||||
308 | |||||
309 | # gather all the parent constraints in order | ||||
310 | my @parents; | ||||
311 | foreach my $parent ($self->_collect_all_parents) { | ||||
312 | push @parents => $parent->constraint; | ||||
313 | } | ||||
314 | |||||
315 | @parents = grep { $_ != $null_constraint } reverse @parents; | ||||
316 | |||||
317 | unless ( @parents ) { | ||||
318 | return $self->_compile_type($check); | ||||
319 | } else { | ||||
320 | # general case, check all the constraints, from the first parent to ourselves | ||||
321 | my @checks = @parents; | ||||
322 | push @checks, $check if $check != $null_constraint; | ||||
323 | return subname($self->name => sub { | ||||
324 | my (@args) = @_; | ||||
325 | local $_ = $args[0]; | ||||
326 | foreach my $check (@checks) { | ||||
327 | return undef unless $check->(@args); | ||||
328 | } | ||||
329 | return 1; | ||||
330 | }); | ||||
331 | } | ||||
332 | } | ||||
333 | |||||
334 | sub _compile_type { | ||||
335 | my ($self, $check) = @_; | ||||
336 | |||||
337 | return $check if $check == $null_constraint; # Item, Any | ||||
338 | |||||
339 | return subname($self->name => sub { | ||||
340 | my (@args) = @_; | ||||
341 | local $_ = $args[0]; | ||||
342 | $check->(@args); | ||||
343 | }); | ||||
344 | } | ||||
345 | |||||
346 | ## other utils ... | ||||
347 | |||||
348 | sub _collect_all_parents { | ||||
349 | my $self = shift; | ||||
350 | my @parents; | ||||
351 | my $current = $self->parent; | ||||
352 | while (defined $current) { | ||||
353 | push @parents => $current; | ||||
354 | $current = $current->parent; | ||||
355 | } | ||||
356 | return @parents; | ||||
357 | } | ||||
358 | |||||
359 | # spent 3.27ms (68µs+3.21) within Moose::Meta::TypeConstraint::create_child_type which was called 16 times, avg 205µs/call:
# 16 times (68µs+3.21ms) by Moose::Util::TypeConstraints::_create_type_constraint at line 572 of Moose/Util/TypeConstraints.pm, avg 205µs/call | ||||
360 | 16 | 16µs | my ($self, %opts) = @_; | ||
361 | 16 | 5µs | my $class = ref $self; | ||
362 | 16 | 45µs | 16 | 3.21ms | return $class->new(%opts, parent => $self); # spent 3.21ms making 16 calls to Moose::Meta::TypeConstraint::new, avg 200µs/call |
363 | } | ||||
364 | |||||
365 | 1 | 35µs | 1; | ||
366 | |||||
367 | # ABSTRACT: The Moose Type Constraint metaclass | ||||
368 | |||||
369 | __END__ |