Filename | /opt/perl-5.18.1/lib/site_perl/5.18.1/darwin-thread-multi-2level/Moose/Meta/TypeConstraint.pm |
Statements | Executed 1135 statements in 10.8ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
25 | 7 | 4 | 6.00ms | 13.5ms | new | Moose::Meta::TypeConstraint::
78 | 5 | 2 | 629µs | 936µs | can_be_inlined (recurses: max depth 1, inclusive time 17µs) | Moose::Meta::TypeConstraint::
44 | 8 | 3 | 627µs | 1.54ms | _inline_check (recurses: max depth 2, inclusive time 563µs) | Moose::Meta::TypeConstraint::
1 | 1 | 1 | 567µs | 1.40ms | BEGIN@12 | Moose::Meta::TypeConstraint::
29 | 1 | 1 | 410µs | 7.04ms | _actually_compile_type_constraint | Moose::Meta::TypeConstraint::
32 | 4 | 3 | 285µs | 415µs | inline_environment (recurses: max depth 1, inclusive time 10µs) | Moose::Meta::TypeConstraint::
29 | 2 | 2 | 195µs | 7.36ms | compile_type_constraint | Moose::Meta::TypeConstraint::
16 | 1 | 1 | 111µs | 5.18ms | create_child_type | Moose::Meta::TypeConstraint::
25 | 1 | 1 | 110µs | 110µs | __ANON__[:77] | Moose::Meta::TypeConstraint::
75 | 4 | 2 | 87µs | 87µs | __ANON__[:16] | Moose::Meta::TypeConstraint::
25 | 3 | 3 | 37µs | 37µs | __ANON__[:101] | Moose::Meta::TypeConstraint::
1 | 1 | 1 | 17µs | 17µs | BEGIN@3 | Moose::Meta::TypeConstraint::
1 | 1 | 1 | 15µs | 66µs | BEGIN@14 | Moose::Meta::TypeConstraint::
1 | 1 | 1 | 10µs | 37µs | BEGIN@21 | Moose::Meta::TypeConstraint::
1 | 1 | 1 | 10µs | 16µs | BEGIN@11 | Moose::Meta::TypeConstraint::
1 | 1 | 1 | 10µs | 47µs | BEGIN@19 | Moose::Meta::TypeConstraint::
1 | 1 | 1 | 10µs | 46µs | BEGIN@22 | Moose::Meta::TypeConstraint::
1 | 1 | 1 | 10µs | 44µs | BEGIN@24 | Moose::Meta::TypeConstraint::
1 | 1 | 1 | 9µs | 35µs | BEGIN@23 | Moose::Meta::TypeConstraint::
1 | 1 | 1 | 9µs | 37µs | BEGIN@20 | Moose::Meta::TypeConstraint::
1 | 1 | 1 | 9µs | 83µs | BEGIN@26 | Moose::Meta::TypeConstraint::
1 | 1 | 1 | 8µs | 25µs | BEGIN@10 | Moose::Meta::TypeConstraint::
1 | 1 | 1 | 2µs | 2µs | __ANON__[:42] | Moose::Meta::TypeConstraint::
0 | 0 | 0 | 0s | 0s | __ANON__[:14] | Moose::Meta::TypeConstraint::
0 | 0 | 0 | 0s | 0s | __ANON__[:15] | Moose::Meta::TypeConstraint::
0 | 0 | 0 | 0s | 0s | __ANON__[:378] | Moose::Meta::TypeConstraint::
0 | 0 | 0 | 0s | 0s | __ANON__[:38] | Moose::Meta::TypeConstraint::
0 | 0 | 0 | 0s | 0s | __ANON__[:391] | Moose::Meta::TypeConstraint::
0 | 0 | 0 | 0s | 0s | __ANON__[:404] | Moose::Meta::TypeConstraint::
0 | 0 | 0 | 0s | 0s | __ANON__[:68] | Moose::Meta::TypeConstraint::
0 | 0 | 0 | 0s | 0s | __ANON__[:76] | Moose::Meta::TypeConstraint::
0 | 0 | 0 | 0s | 0s | _collect_all_parents | Moose::Meta::TypeConstraint::
0 | 0 | 0 | 0s | 0s | _compile_hand_optimized_type_constraint | 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 | equals | Moose::Meta::TypeConstraint::
0 | 0 | 0 | 0s | 0s | get_message | Moose::Meta::TypeConstraint::
0 | 0 | 0 | 0s | 0s | is_a_type_of | Moose::Meta::TypeConstraint::
0 | 0 | 0 | 0s | 0s | is_subtype_of | 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 | |||||
2 | package Moose::Meta::TypeConstraint; | ||||
3 | # spent 17µs within Moose::Meta::TypeConstraint::BEGIN@3 which was called:
# once (17µs+0s) by Moose::BEGIN@28 at line 5 | ||||
4 | 1 | 7µs | $Moose::Meta::TypeConstraint::AUTHORITY = 'cpan:STEVAN'; | ||
5 | 1 | 42µs | 1 | 17µs | } # spent 17µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@3 |
6 | { | ||||
7 | 2 | 1µs | $Moose::Meta::TypeConstraint::VERSION = '2.1005'; | ||
8 | } | ||||
9 | |||||
10 | 2 | 30µs | 2 | 42µs | # spent 25µs (8+17) within Moose::Meta::TypeConstraint::BEGIN@10 which was called:
# once (8µs+17µs) by Moose::BEGIN@28 at line 10 # spent 25µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@10
# spent 17µs making 1 call to strict::import |
11 | 2 | 29µs | 2 | 21µs | # spent 16µs (10+6) within Moose::Meta::TypeConstraint::BEGIN@11 which was called:
# once (10µs+6µs) by Moose::BEGIN@28 at line 11 # spent 16µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@11
# spent 6µs making 1 call to warnings::import |
12 | 2 | 216µs | 2 | 2.02ms | # spent 1.40ms (567µs+834µs) within Moose::Meta::TypeConstraint::BEGIN@12 which was called:
# once (567µs+834µs) by Moose::BEGIN@28 at line 12 # spent 1.40ms making 1 call to Moose::Meta::TypeConstraint::BEGIN@12
# spent 615µs making 1 call to metaclass::import |
13 | |||||
14 | # spent 66µs (15+51) within Moose::Meta::TypeConstraint::BEGIN@14 which was called:
# once (15µs+51µs) by Moose::BEGIN@28 at line 17 | ||||
15 | '""' => sub { shift->name }, # stringify to tc name | ||||
16 | 75 | 170µs | # spent 87µs within Moose::Meta::TypeConstraint::__ANON__[/opt/perl-5.18.1/lib/site_perl/5.18.1/darwin-thread-multi-2level/Moose/Meta/TypeConstraint.pm:16] which was called 75 times, avg 1µs/call:
# 25 times (26µs+0s) by Moose::Meta::TypeConstraint::Registry::add_type_constraint at line 51 of Moose/Meta/TypeConstraint/Registry.pm, avg 1µs/call
# 17 times (34µs+0s) by Moose::Util::TypeConstraints::find_or_parse_type_constraint at line 274 of Moose/Util/TypeConstraints.pm, avg 2µs/call
# 17 times (14µs+0s) by Moose::Util::TypeConstraints::find_or_create_isa_type_constraint at line 260 of Moose/Util/TypeConstraints.pm, avg 841ns/call
# 16 times (13µs+0s) by Moose::Util::TypeConstraints::_create_type_constraint at line 565 of Moose/Util/TypeConstraints.pm, avg 806ns/call | ||
17 | 2 | 41µs | 2 | 117µs | fallback => 1; # spent 66µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@14
# spent 51µs making 1 call to overload::import |
18 | |||||
19 | 2 | 37µs | 2 | 83µs | # spent 47µs (10+37) within Moose::Meta::TypeConstraint::BEGIN@19 which was called:
# once (10µs+37µs) by Moose::BEGIN@28 at line 19 # spent 47µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@19
# spent 37µs making 1 call to Exporter::import |
20 | 2 | 33µs | 2 | 65µs | # spent 37µs (9+28) within Moose::Meta::TypeConstraint::BEGIN@20 which was called:
# once (9µs+28µs) by Moose::BEGIN@28 at line 20 # spent 37µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@20
# spent 28µs making 1 call to Exporter::import |
21 | 2 | 35µs | 2 | 64µs | # spent 37µs (10+27) within Moose::Meta::TypeConstraint::BEGIN@21 which was called:
# once (10µs+27µs) by Moose::BEGIN@28 at line 21 # spent 37µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@21
# spent 27µs making 1 call to Exporter::import |
22 | 2 | 35µs | 2 | 82µs | # spent 46µs (10+36) within Moose::Meta::TypeConstraint::BEGIN@22 which was called:
# once (10µs+36µs) by Moose::BEGIN@28 at line 22 # spent 46µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@22
# spent 36µs making 1 call to Exporter::import |
23 | 2 | 32µs | 2 | 61µs | # spent 35µs (9+26) within Moose::Meta::TypeConstraint::BEGIN@23 which was called:
# once (9µs+26µs) by Moose::BEGIN@28 at line 23 # spent 35µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@23
# spent 26µs making 1 call to Exporter::import |
24 | 2 | 40µs | 2 | 78µs | # spent 44µs (10+34) within Moose::Meta::TypeConstraint::BEGIN@24 which was called:
# once (10µs+34µs) by Moose::BEGIN@28 at line 24 # spent 44µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@24
# spent 34µs making 1 call to Exporter::import |
25 | |||||
26 | 2 | 2.45ms | 2 | 157µs | # spent 83µs (9+74) within Moose::Meta::TypeConstraint::BEGIN@26 which was called:
# once (9µs+74µs) by Moose::BEGIN@28 at line 26 # spent 83µs making 1 call to Moose::Meta::TypeConstraint::BEGIN@26
# spent 74µs making 1 call to base::import |
27 | |||||
28 | 1 | 5µs | 3 | 426µs | __PACKAGE__->meta->add_attribute('name' => ( # spent 396µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 22µs making 1 call to Moose::Meta::TypeConstraint::meta
# spent 7µs making 1 call to Class::MOP::_definition_context |
29 | reader => 'name', | ||||
30 | Class::MOP::_definition_context(), | ||||
31 | )); | ||||
32 | 1 | 4µs | 3 | 612µs | __PACKAGE__->meta->add_attribute('parent' => ( # spent 592µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 13µs making 1 call to Moose::Meta::TypeConstraint::meta
# spent 7µs making 1 call to Class::MOP::_definition_context |
33 | reader => 'parent', | ||||
34 | predicate => 'has_parent', | ||||
35 | Class::MOP::_definition_context(), | ||||
36 | )); | ||||
37 | |||||
38 | 1 | 2µs | my $null_constraint = sub { 1 }; | ||
39 | __PACKAGE__->meta->add_attribute('constraint' => ( | ||||
40 | reader => 'constraint', | ||||
41 | writer => '_set_constraint', | ||||
42 | 1 | 4µs | # spent 2µs within Moose::Meta::TypeConstraint::__ANON__[/opt/perl-5.18.1/lib/site_perl/5.18.1/darwin-thread-multi-2level/Moose/Meta/TypeConstraint.pm:42] which was called:
# once (2µs+0s) by Moose::Meta::TypeConstraint::_new at line 24 of (eval 88)[Eval/Closure.pm:144] | ||
43 | 1 | 6µs | 3 | 629µs | Class::MOP::_definition_context(), # spent 609µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 13µs making 1 call to Moose::Meta::TypeConstraint::meta
# spent 7µs making 1 call to Class::MOP::_definition_context |
44 | )); | ||||
45 | |||||
46 | 1 | 4µs | 3 | 616µs | __PACKAGE__->meta->add_attribute('message' => ( # spent 597µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 13µs making 1 call to Moose::Meta::TypeConstraint::meta
# spent 7µs making 1 call to Class::MOP::_definition_context |
47 | accessor => 'message', | ||||
48 | predicate => 'has_message', | ||||
49 | Class::MOP::_definition_context(), | ||||
50 | )); | ||||
51 | |||||
52 | 1 | 4µs | 3 | 390µs | __PACKAGE__->meta->add_attribute('_default_message' => ( # spent 370µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 13µs making 1 call to Moose::Meta::TypeConstraint::meta
# spent 7µs making 1 call to Class::MOP::_definition_context |
53 | accessor => '_default_message', | ||||
54 | Class::MOP::_definition_context(), | ||||
55 | )); | ||||
56 | |||||
57 | # can't make this a default because it has to close over the type name, and | ||||
58 | # cmop attributes don't have lazy | ||||
59 | # spent 110µs within Moose::Meta::TypeConstraint::__ANON__[/opt/perl-5.18.1/lib/site_perl/5.18.1/darwin-thread-multi-2level/Moose/Meta/TypeConstraint.pm:77] which was called 25 times, avg 4µs/call:
# 25 times (110µs+0s) by Moose::Meta::TypeConstraint::new at line 146, avg 4µs/call | ||||
60 | 25 | 11µ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 | } | ||||
77 | 26 | 5.37ms | }; | ||
78 | 1 | 5µs | 3 | 634µs | __PACKAGE__->meta->add_attribute('coercion' => ( # spent 610µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 13µs making 1 call to Moose::Meta::TypeConstraint::meta
# spent 11µs making 1 call to Class::MOP::_definition_context |
79 | accessor => 'coercion', | ||||
80 | predicate => 'has_coercion', | ||||
81 | Class::MOP::_definition_context(), | ||||
82 | )); | ||||
83 | |||||
84 | 1 | 5µs | 3 | 617µs | __PACKAGE__->meta->add_attribute('hand_optimized_type_constraint' => ( # spent 597µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 13µs making 1 call to Moose::Meta::TypeConstraint::meta
# spent 7µs making 1 call to Class::MOP::_definition_context |
85 | init_arg => 'optimized', | ||||
86 | accessor => 'hand_optimized_type_constraint', | ||||
87 | predicate => 'has_hand_optimized_type_constraint', | ||||
88 | Class::MOP::_definition_context(), | ||||
89 | )); | ||||
90 | |||||
91 | 1 | 4µs | 3 | 613µs | __PACKAGE__->meta->add_attribute('inlined' => ( # spent 593µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 13µs making 1 call to Moose::Meta::TypeConstraint::meta
# spent 7µs making 1 call to Class::MOP::_definition_context |
92 | init_arg => 'inlined', | ||||
93 | accessor => 'inlined', | ||||
94 | predicate => '_has_inlined_type_constraint', | ||||
95 | Class::MOP::_definition_context(), | ||||
96 | )); | ||||
97 | |||||
98 | __PACKAGE__->meta->add_attribute('inline_environment' => ( | ||||
99 | init_arg => 'inline_environment', | ||||
100 | accessor => '_inline_environment', | ||||
101 | 25 | 75µs | # spent 37µs within Moose::Meta::TypeConstraint::__ANON__[/opt/perl-5.18.1/lib/site_perl/5.18.1/darwin-thread-multi-2level/Moose/Meta/TypeConstraint.pm:101] which was called 25 times, avg 1µs/call:
# 17 times (22µs+0s) by Moose::Meta::TypeConstraint::_new at line 33 of (eval 88)[Eval/Closure.pm:144], avg 1µs/call
# 4 times (9µs+0s) by Moose::Meta::TypeConstraint::Class::_new at line 36 of (eval 102)[Eval/Closure.pm:144], avg 2µs/call
# 4 times (6µs+0s) by Moose::Meta::TypeConstraint::Parameterizable::_new at line 36 of (eval 100)[Eval/Closure.pm:144], avg 2µs/call | ||
102 | 1 | 6µs | 3 | 5.32ms | Class::MOP::_definition_context(), # spent 5.30ms making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 12µs making 1 call to Moose::Meta::TypeConstraint::meta
# spent 7µs making 1 call to Class::MOP::_definition_context |
103 | )); | ||||
104 | |||||
105 | sub parents { | ||||
106 | my $self = shift; | ||||
107 | $self->parent; | ||||
108 | } | ||||
109 | |||||
110 | # private accessors | ||||
111 | |||||
112 | 1 | 4µs | 3 | 606µs | __PACKAGE__->meta->add_attribute('compiled_type_constraint' => ( # spent 586µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 13µs making 1 call to Moose::Meta::TypeConstraint::meta
# spent 7µs making 1 call to Class::MOP::_definition_context |
113 | accessor => '_compiled_type_constraint', | ||||
114 | predicate => '_has_compiled_type_constraint', | ||||
115 | Class::MOP::_definition_context(), | ||||
116 | )); | ||||
117 | |||||
118 | 1 | 4µs | 3 | 392µs | __PACKAGE__->meta->add_attribute('package_defined_in' => ( # spent 372µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 13µs making 1 call to Moose::Meta::TypeConstraint::meta
# spent 7µs making 1 call to Class::MOP::_definition_context |
119 | accessor => '_package_defined_in', | ||||
120 | Class::MOP::_definition_context(), | ||||
121 | )); | ||||
122 | |||||
123 | # spent 13.5ms (6.00+7.52) within Moose::Meta::TypeConstraint::new which was called 25 times, avg 541µs/call:
# 16 times (428µs+4.64ms) by Moose::Meta::TypeConstraint::create_child_type at line 423, avg 317µs/call
# 4 times (160µs+1.45ms) by Moose::Meta::TypeConstraint::Class::new at line 43 of Moose/Meta/TypeConstraint/Class.pm, avg 402µs/call
# once (5.28ms+315µs) by Moose::Util::TypeConstraints::_create_type_constraint at line 575 of Moose/Util/TypeConstraints.pm
# once (42µs+383µs) by Moose::Util::TypeConstraints::Builtins::define_builtins at line 204 of Moose/Util/TypeConstraints/Builtins.pm
# once (29µs+263µs) by Moose::Util::TypeConstraints::Builtins::define_builtins at line 274 of Moose/Util/TypeConstraints/Builtins.pm
# once (34µs+242µs) by Moose::Util::TypeConstraints::Builtins::define_builtins at line 239 of Moose/Util/TypeConstraints/Builtins.pm
# once (29µs+233µs) by Moose::Util::TypeConstraints::Builtins::define_builtins at line 300 of Moose/Util/TypeConstraints/Builtins.pm | ||||
124 | 25 | 7µs | my $class = shift; | ||
125 | 25 | 42µs | my ($first, @rest) = @_; | ||
126 | 25 | 66µs | my %args = ref $first ? %$first : $first ? ($first, @rest) : (); | ||
127 | 25 | 22µs | $args{name} = $args{name} ? "$args{name}" : "__ANON__"; | ||
128 | |||||
129 | 25 | 6µ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 | |||||
138 | 25 | 7µ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 | |||||
143 | 25 | 62µs | 25 | 841µs | my $self = $class->_new(%args); # spent 422µs making 17 calls to Moose::Meta::TypeConstraint::_new, avg 25µs/call
# spent 232µs making 4 calls to Moose::Meta::TypeConstraint::Class::_new, avg 58µs/call
# spent 186µs making 4 calls to Moose::Meta::TypeConstraint::Parameterizable::_new, avg 47µs/call |
144 | 25 | 101µs | 50 | 6.40ms | $self->compile_type_constraint() # spent 6.35ms making 25 calls to Moose::Meta::TypeConstraint::compile_type_constraint, avg 254µs/call
# spent 51µs making 25 calls to Moose::Meta::TypeConstraint::_has_compiled_type_constraint, avg 2µs/call |
145 | unless $self->_has_compiled_type_constraint; | ||||
146 | 25 | 142µs | 100 | 273µs | $self->_default_message($_default_message_generator->($self->name)) # spent 110µs making 25 calls to Moose::Meta::TypeConstraint::__ANON__[Moose/Meta/TypeConstraint.pm:77], avg 4µs/call
# spent 73µs making 25 calls to Moose::Meta::TypeConstraint::_default_message, avg 3µs/call
# spent 45µs making 25 calls to Moose::Meta::TypeConstraint::name, avg 2µs/call
# spent 44µs making 25 calls to Moose::Meta::TypeConstraint::has_message, avg 2µs/call |
147 | unless $self->has_message; | ||||
148 | 25 | 119µs | return $self; | ||
149 | } | ||||
150 | |||||
- - | |||||
153 | sub 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 | |||||
168 | sub 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 | sub check { | ||||
179 | my ($self, @args) = @_; | ||||
180 | my $constraint_subref = $self->_compiled_type_constraint; | ||||
181 | return $constraint_subref->(@args) ? 1 : undef; | ||||
182 | } | ||||
183 | |||||
184 | sub validate { | ||||
185 | my ($self, $value) = @_; | ||||
186 | if ($self->_compiled_type_constraint->($value)) { | ||||
187 | return undef; | ||||
188 | } | ||||
189 | else { | ||||
190 | $self->get_message($value); | ||||
191 | } | ||||
192 | } | ||||
193 | |||||
194 | # spent 936µs (629+307) within Moose::Meta::TypeConstraint::can_be_inlined which was called 78 times, avg 12µs/call:
# 44 times (316µs+162µs) by Moose::Meta::TypeConstraint::_inline_check at line 207, avg 11µs/call
# 29 times (271µs+140µs) by Moose::Meta::TypeConstraint::_actually_compile_type_constraint at line 311, avg 14µs/call
# 2 times (21µs+12µs) by Moose::Meta::Attribute::_inline_check_constraint at line 711 of Moose/Meta/Attribute.pm, avg 16µs/call
# 2 times (12µs+-12µs) by Moose::Meta::TypeConstraint::can_be_inlined at line 197, avg 0s/call
# once (9µs+5µs) by Moose::Meta::Attribute::_eval_environment at line 789 of Moose/Meta/Attribute.pm | ||||
195 | 78 | 12µs | my $self = shift; | ||
196 | |||||
197 | 78 | 179µs | 155 | 201µs | if ( $self->has_parent && $self->constraint == $null_constraint ) { # spent 99µs making 73 calls to Moose::Meta::TypeConstraint::constraint, avg 1µs/call
# spent 98µs making 78 calls to Moose::Meta::TypeConstraint::has_parent, avg 1µs/call
# spent 3µs making 2 calls to Moose::Meta::TypeConstraint::parent, avg 2µs/call
# spent 17µs making 2 calls to Moose::Meta::TypeConstraint::can_be_inlined, avg 8µs/call, recursion: max depth 1, sum of overlapping time 17µs |
198 | return $self->parent->can_be_inlined; | ||||
199 | } | ||||
200 | |||||
201 | 76 | 230µs | 76 | 106µs | return $self->_has_inlined_type_constraint; # spent 106µs making 76 calls to Moose::Meta::TypeConstraint::_has_inlined_type_constraint, avg 1µs/call |
202 | } | ||||
203 | |||||
204 | # spent 1.54ms (627µs+908µs) within Moose::Meta::TypeConstraint::_inline_check which was called 44 times, avg 35µs/call:
# 29 times (429µs+895µs) by Moose::Meta::TypeConstraint::_actually_compile_type_constraint at line 311, avg 46µs/call
# 6 times (80µs+-80µs) by Moose::Util::TypeConstraints::Builtins::__ANON__[/opt/perl-5.18.1/lib/site_perl/5.18.1/darwin-thread-multi-2level/Moose/Util/TypeConstraints/Builtins.pm:66] at line 64 of Moose/Util/TypeConstraints/Builtins.pm, avg 0s/call
# 3 times (39µs+-39µs) by Moose::Util::TypeConstraints::Builtins::__ANON__[/opt/perl-5.18.1/lib/site_perl/5.18.1/darwin-thread-multi-2level/Moose/Util/TypeConstraints/Builtins.pm:120] at line 118 of Moose/Util/TypeConstraints/Builtins.pm, avg 0s/call
# 2 times (28µs+183µs) by Moose::Meta::Attribute::_inline_check_constraint at line 711 of Moose/Meta/Attribute.pm, avg 106µs/call
# once (13µs+-13µs) by Moose::Meta::TypeConstraint::_inline_check at line 212
# once (12µs+-12µs) by Moose::Util::TypeConstraints::Builtins::__ANON__[/opt/perl-5.18.1/lib/site_perl/5.18.1/darwin-thread-multi-2level/Moose/Util/TypeConstraints/Builtins.pm:176] at line 171 of Moose/Util/TypeConstraints/Builtins.pm
# once (14µs+-14µs) by Moose::Util::TypeConstraints::Builtins::__ANON__[/opt/perl-5.18.1/lib/site_perl/5.18.1/darwin-thread-multi-2level/Moose/Util/TypeConstraints/Builtins.pm:83] at line 78 of Moose/Util/TypeConstraints/Builtins.pm
# once (12µs+-12µs) by Moose::Util::TypeConstraints::Builtins::__ANON__[/opt/perl-5.18.1/lib/site_perl/5.18.1/darwin-thread-multi-2level/Moose/Util/TypeConstraints/Builtins.pm:112] at line 103 of Moose/Util/TypeConstraints/Builtins.pm | ||||
205 | 44 | 9µs | my $self = shift; | ||
206 | |||||
207 | 44 | 42µs | 44 | 477µs | unless ( $self->can_be_inlined ) { # spent 477µs making 44 calls to Moose::Meta::TypeConstraint::can_be_inlined, avg 11µs/call |
208 | require Moose; | ||||
209 | Moose->throw_error( 'Cannot inline a type constraint check for ' . $self->name ); | ||||
210 | } | ||||
211 | |||||
212 | 44 | 86µs | 88 | 93µs | if ( $self->has_parent && $self->constraint == $null_constraint ) { # spent 48µs making 44 calls to Moose::Meta::TypeConstraint::has_parent, avg 1µs/call
# spent 44µs making 42 calls to Moose::Meta::TypeConstraint::constraint, avg 1µs/call
# spent 1µs making 1 call to Moose::Meta::TypeConstraint::parent
# spent 24µs making 1 call to Moose::Meta::TypeConstraint::_inline_check, recursion: max depth 1, sum of overlapping time 24µs |
213 | return $self->parent->_inline_check(@_); | ||||
214 | } | ||||
215 | |||||
216 | 43 | 245µs | 86 | 877µs | return '( do { ' . $self->inlined->( $self, @_ ) . ' } )'; # spent 243µs making 6 calls to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:66], avg 40µs/call
# spent 224µs making 3 calls to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:120], avg 75µs/call
# spent 106µs making 8 calls to Moose::Meta::TypeConstraint::Class::__ANON__[Moose/Meta/TypeConstraint/Class.pm:30], avg 13µs/call
# spent 83µs making 1 call to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:83]
# spent 68µs making 1 call to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:112]
# spent 62µs making 43 calls to Moose::Meta::TypeConstraint::inlined, avg 1µs/call
# spent 40µs making 1 call to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:176]
# spent 13µs making 7 calls to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:46], avg 2µs/call
# spent 4µs making 2 calls to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:163], avg 2µs/call
# spent 4µs making 1 call to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:152]
# spent 4µs making 1 call to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:58]
# spent 3µs making 1 call to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:195]
# spent 3µs making 1 call to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:125]
# spent 2µs making 1 call to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:137]
# spent 2µs making 2 calls to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:28], avg 1µs/call
# spent 2µs making 1 call to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:223]
# spent 2µs making 1 call to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:258]
# spent 2µs making 1 call to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:39]
# spent 2µs making 1 call to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:72]
# spent 2µs making 1 call to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:132]
# spent 2µs making 1 call to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:157]
# spent 1µs making 1 call to Moose::Util::TypeConstraints::Builtins::__ANON__[Moose/Util/TypeConstraints/Builtins.pm:291] |
217 | } | ||||
218 | |||||
219 | # spent 415µs (285+130) within Moose::Meta::TypeConstraint::inline_environment which was called 32 times, avg 13µs/call:
# 29 times (258µs+128µs) by Moose::Meta::TypeConstraint::_actually_compile_type_constraint at line 311, avg 13µs/call
# once (10µs+5µs) by Moose::Meta::Attribute::_eval_environment at line 800 of Moose/Meta/Attribute.pm
# once (10µs+5µs) by Moose::Meta::Class::_eval_environment at line 543 of Moose/Meta/Class.pm
# once (8µs+-8µs) by Moose::Meta::TypeConstraint::inline_environment at line 222 | ||||
220 | 32 | 7µs | my $self = shift; | ||
221 | |||||
222 | 32 | 65µs | 64 | 80µs | if ( $self->has_parent && $self->constraint == $null_constraint ) { # spent 38µs making 32 calls to Moose::Meta::TypeConstraint::has_parent, avg 1µs/call
# spent 35µs making 30 calls to Moose::Meta::TypeConstraint::constraint, avg 1µs/call
# spent 7µs making 1 call to Moose::Meta::TypeConstraint::parent
# spent 10µs making 1 call to Moose::Meta::TypeConstraint::inline_environment, recursion: max depth 1, sum of overlapping time 10µs |
223 | return $self->parent->inline_environment; | ||||
224 | } | ||||
225 | |||||
226 | 31 | 110µs | 31 | 50µs | return $self->_inline_environment; # spent 50µs making 31 calls to Moose::Meta::TypeConstraint::_inline_environment, avg 2µs/call |
227 | } | ||||
228 | |||||
229 | sub 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 | |||||
239 | sub 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 | sub 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 | |||||
273 | sub 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 | |||||
281 | sub is_subtype_of { | ||||
282 | my ($self, $type_or_name) = @_; | ||||
283 | |||||
284 | my $type = Moose::Util::TypeConstraints::find_type_constraint($type_or_name) or return; | ||||
285 | |||||
286 | my $current = $self; | ||||
287 | |||||
288 | while (my $parent = $current->parent) { | ||||
289 | return 1 if $parent->equals($type); | ||||
290 | $current = $parent; | ||||
291 | } | ||||
292 | |||||
293 | return 0; | ||||
294 | } | ||||
295 | |||||
296 | ## compiling the type constraint | ||||
297 | |||||
298 | # spent 7.36ms (195µs+7.17) within Moose::Meta::TypeConstraint::compile_type_constraint which was called 29 times, avg 254µs/call:
# 25 times (170µs+6.18ms) by Moose::Meta::TypeConstraint::new at line 144, avg 254µs/call
# 4 times (25µs+986µs) by Moose::Meta::TypeConstraint::Class::new at line 45 of Moose/Meta/TypeConstraint/Class.pm, avg 253µs/call | ||||
299 | 29 | 7µs | my $self = shift; | ||
300 | 29 | 141µs | 58 | 7.17ms | $self->_compiled_type_constraint($self->_actually_compile_type_constraint); # spent 7.04ms making 29 calls to Moose::Meta::TypeConstraint::_actually_compile_type_constraint, avg 243µs/call
# spent 133µs making 29 calls to Moose::Meta::TypeConstraint::_compiled_type_constraint, avg 5µs/call |
301 | } | ||||
302 | |||||
303 | ## type compilers ... | ||||
304 | |||||
305 | # spent 7.04ms (410µs+6.63) within Moose::Meta::TypeConstraint::_actually_compile_type_constraint which was called 29 times, avg 243µs/call:
# 29 times (410µs+6.63ms) by Moose::Meta::TypeConstraint::compile_type_constraint at line 300, avg 243µs/call | ||||
306 | 29 | 4µs | my $self = shift; | ||
307 | |||||
308 | 29 | 41µs | 29 | 44µs | return $self->_compile_hand_optimized_type_constraint # spent 44µs making 29 calls to Moose::Meta::TypeConstraint::has_hand_optimized_type_constraint, avg 2µs/call |
309 | if $self->has_hand_optimized_type_constraint; | ||||
310 | |||||
311 | 29 | 217µs | 116 | 6.58ms | if ( $self->can_be_inlined ) { # spent 4.46ms making 29 calls to Eval::Closure::eval_closure, avg 154µs/call
# spent 1.32ms making 29 calls to Moose::Meta::TypeConstraint::_inline_check, avg 46µs/call
# spent 412µs making 29 calls to Moose::Meta::TypeConstraint::can_be_inlined, avg 14µs/call
# spent 386µs making 29 calls to Moose::Meta::TypeConstraint::inline_environment, avg 13µs/call |
312 | return eval_closure( | ||||
313 | source => 'sub { ' . $self->_inline_check('$_[0]') . ' }', | ||||
314 | environment => $self->inline_environment, | ||||
315 | ); | ||||
316 | } | ||||
317 | |||||
318 | my $check = $self->constraint; | ||||
319 | unless ( defined $check ) { | ||||
320 | require Moose; | ||||
321 | Moose->throw_error( "Could not compile type constraint '" | ||||
322 | . $self->name | ||||
323 | . "' because no constraint check" ); | ||||
324 | } | ||||
325 | |||||
326 | return $self->_compile_subtype($check) | ||||
327 | if $self->has_parent; | ||||
328 | |||||
329 | return $self->_compile_type($check); | ||||
330 | } | ||||
331 | |||||
332 | sub _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 | sub _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 | |||||
395 | sub _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 | sub _collect_all_parents { | ||||
410 | my $self = shift; | ||||
411 | my @parents; | ||||
412 | my $current = $self->parent; | ||||
413 | while (defined $current) { | ||||
414 | push @parents => $current; | ||||
415 | $current = $current->parent; | ||||
416 | } | ||||
417 | return @parents; | ||||
418 | } | ||||
419 | |||||
420 | # spent 5.18ms (111µs+5.06) within Moose::Meta::TypeConstraint::create_child_type which was called 16 times, avg 323µs/call:
# 16 times (111µs+5.06ms) by Moose::Util::TypeConstraints::_create_type_constraint at line 565 of Moose/Util/TypeConstraints.pm, avg 323µs/call | ||||
421 | 16 | 21µs | my ($self, %opts) = @_; | ||
422 | 16 | 9µs | my $class = ref $self; | ||
423 | 16 | 72µs | 16 | 5.06ms | return $class->new(%opts, parent => $self); # spent 5.06ms making 16 calls to Moose::Meta::TypeConstraint::new, avg 317µs/call |
424 | } | ||||
425 | |||||
426 | 1 | 25µs | 1; | ||
427 | |||||
428 | # ABSTRACT: The Moose Type Constraint metaclass | ||||
429 | |||||
430 | __END__ |