Filename | /Users/dde/perl5/perlbrew/perls/5.18.0t/lib/site_perl/5.18.0/darwin-thread-multi-2level/Moose/Meta/TypeConstraint/Union.pm |
Statements | Executed 86 statements in 1.19ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 345µs | 796µs | BEGIN@14 | Moose::Meta::TypeConstraint::Union::
4 | 2 | 1 | 35µs | 108µs | can_be_inlined | Moose::Meta::TypeConstraint::Union::
3 | 1 | 1 | 34µs | 295µs | _inline_check | Moose::Meta::TypeConstraint::Union::
1 | 1 | 1 | 29µs | 169µs | new | Moose::Meta::TypeConstraint::Union::
2 | 2 | 2 | 19µs | 53µs | inline_environment | Moose::Meta::TypeConstraint::Union::
2 | 1 | 1 | 14µs | 17µs | coercion | Moose::Meta::TypeConstraint::Union::
1 | 1 | 1 | 11µs | 29µs | BEGIN@17 | Moose::Meta::TypeConstraint::Union::
2 | 2 | 2 | 9µs | 25µs | has_coercion | Moose::Meta::TypeConstraint::Union::
1 | 1 | 1 | 8µs | 10µs | _actually_compile_type_constraint | Moose::Meta::TypeConstraint::Union::
1 | 1 | 1 | 8µs | 11µs | BEGIN@11 | Moose::Meta::TypeConstraint::Union::
1 | 1 | 1 | 8µs | 8µs | BEGIN@3 | Moose::Meta::TypeConstraint::Union::
1 | 1 | 1 | 8µs | 17µs | BEGIN@10 | Moose::Meta::TypeConstraint::Union::
1 | 1 | 1 | 6µs | 26µs | BEGIN@16 | Moose::Meta::TypeConstraint::Union::
1 | 1 | 1 | 6µs | 54µs | BEGIN@19 | Moose::Meta::TypeConstraint::Union::
1 | 1 | 1 | 5µs | 336µs | BEGIN@12 | Moose::Meta::TypeConstraint::Union::
1 | 1 | 1 | 600ns | 600ns | CORE:sort (opcode) | Moose::Meta::TypeConstraint::Union::
0 | 0 | 0 | 0s | 0s | __ANON__[:143] | Moose::Meta::TypeConstraint::Union::
0 | 0 | 0 | 0s | 0s | __ANON__[:164] | Moose::Meta::TypeConstraint::Union::
0 | 0 | 0 | 0s | 0s | __ANON__[:170] | Moose::Meta::TypeConstraint::Union::
0 | 0 | 0 | 0s | 0s | __ANON__[:176] | Moose::Meta::TypeConstraint::Union::
0 | 0 | 0 | 0s | 0s | __ANON__[:23] | Moose::Meta::TypeConstraint::Union::
0 | 0 | 0 | 0s | 0s | __ANON__[:78] | Moose::Meta::TypeConstraint::Union::
0 | 0 | 0 | 0s | 0s | create_child_type | Moose::Meta::TypeConstraint::Union::
0 | 0 | 0 | 0s | 0s | equals | Moose::Meta::TypeConstraint::Union::
0 | 0 | 0 | 0s | 0s | find_type_for | Moose::Meta::TypeConstraint::Union::
0 | 0 | 0 | 0s | 0s | is_a_type_of | Moose::Meta::TypeConstraint::Union::
0 | 0 | 0 | 0s | 0s | is_subtype_of | Moose::Meta::TypeConstraint::Union::
0 | 0 | 0 | 0s | 0s | parent | Moose::Meta::TypeConstraint::Union::
0 | 0 | 0 | 0s | 0s | validate | Moose::Meta::TypeConstraint::Union::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | |||||
2 | package Moose::Meta::TypeConstraint::Union; | ||||
3 | # spent 8µs within Moose::Meta::TypeConstraint::Union::BEGIN@3 which was called:
# once (8µs+0s) by Moose::Util::TypeConstraints::BEGIN@33 at line 5 | ||||
4 | 1 | 4µs | $Moose::Meta::TypeConstraint::Union::AUTHORITY = 'cpan:STEVAN'; | ||
5 | 1 | 28µs | 1 | 8µs | } # spent 8µs making 1 call to Moose::Meta::TypeConstraint::Union::BEGIN@3 |
6 | { | ||||
7 | 2 | 900ns | $Moose::Meta::TypeConstraint::Union::VERSION = '2.1005'; | ||
8 | } | ||||
9 | |||||
10 | 2 | 19µs | 2 | 27µs | # spent 17µs (8+10) within Moose::Meta::TypeConstraint::Union::BEGIN@10 which was called:
# once (8µs+10µs) by Moose::Util::TypeConstraints::BEGIN@33 at line 10 # spent 17µs making 1 call to Moose::Meta::TypeConstraint::Union::BEGIN@10
# spent 10µs making 1 call to strict::import |
11 | 2 | 18µs | 2 | 14µs | # spent 11µs (8+3) within Moose::Meta::TypeConstraint::Union::BEGIN@11 which was called:
# once (8µs+3µs) by Moose::Util::TypeConstraints::BEGIN@33 at line 11 # spent 11µs making 1 call to Moose::Meta::TypeConstraint::Union::BEGIN@11
# spent 3µs making 1 call to warnings::import |
12 | 2 | 23µs | 2 | 666µs | # spent 336µs (5+330) within Moose::Meta::TypeConstraint::Union::BEGIN@12 which was called:
# once (5µs+330µs) by Moose::Util::TypeConstraints::BEGIN@33 at line 12 # spent 336µs making 1 call to Moose::Meta::TypeConstraint::Union::BEGIN@12
# spent 330µs making 1 call to metaclass::import |
13 | |||||
14 | 2 | 98µs | 1 | 796µs | # spent 796µs (345+451) within Moose::Meta::TypeConstraint::Union::BEGIN@14 which was called:
# once (345µs+451µs) by Moose::Util::TypeConstraints::BEGIN@33 at line 14 # spent 796µs making 1 call to Moose::Meta::TypeConstraint::Union::BEGIN@14 |
15 | |||||
16 | 2 | 21µs | 2 | 46µs | # spent 26µs (6+20) within Moose::Meta::TypeConstraint::Union::BEGIN@16 which was called:
# once (6µs+20µs) by Moose::Util::TypeConstraints::BEGIN@33 at line 16 # spent 26µs making 1 call to Moose::Meta::TypeConstraint::Union::BEGIN@16
# spent 20µs making 1 call to Exporter::import |
17 | 2 | 22µs | 2 | 46µs | # spent 29µs (11+18) within Moose::Meta::TypeConstraint::Union::BEGIN@17 which was called:
# once (11µs+18µs) by Moose::Util::TypeConstraints::BEGIN@33 at line 17 # spent 29µs making 1 call to Moose::Meta::TypeConstraint::Union::BEGIN@17
# spent 18µs making 1 call to Exporter::import |
18 | |||||
19 | 2 | 833µs | 2 | 102µs | # spent 54µs (6+48) within Moose::Meta::TypeConstraint::Union::BEGIN@19 which was called:
# once (6µs+48µs) by Moose::Util::TypeConstraints::BEGIN@33 at line 19 # spent 54µs making 1 call to Moose::Meta::TypeConstraint::Union::BEGIN@19
# spent 48µs making 1 call to base::import |
20 | |||||
21 | __PACKAGE__->meta->add_attribute('type_constraints' => ( | ||||
22 | accessor => 'type_constraints', | ||||
23 | default => sub { [] }, | ||||
24 | 1 | 5µs | 3 | 309µs | Class::MOP::_definition_context(), # spent 288µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 16µs making 1 call to Moose::Meta::TypeConstraint::Union::meta
# spent 5µs making 1 call to Class::MOP::_definition_context |
25 | )); | ||||
26 | |||||
27 | # spent 169µs (29+140) within Moose::Meta::TypeConstraint::Union::new which was called:
# once (29µs+140µs) by Moose::Util::TypeConstraints::_create_type_constraint_union at line 115 of Moose/Util/TypeConstraints.pm | ||||
28 | 1 | 900ns | my ($class, %options) = @_; | ||
29 | |||||
30 | 2 | 2µs | 2 | 3µs | my $name = join '|' => sort { $a cmp $b } # spent 3µs making 2 calls to Moose::Meta::TypeConstraint::name, avg 1µs/call |
31 | 1 | 7µs | 1 | 600ns | map { $_->name } @{ $options{type_constraints} }; # spent 600ns making 1 call to Moose::Meta::TypeConstraint::Union::CORE:sort |
32 | |||||
33 | 1 | 5µs | 1 | 135µs | my $self = $class->SUPER::new( # spent 135µs making 1 call to Moose::Meta::TypeConstraint::new |
34 | name => $name, | ||||
35 | %options, | ||||
36 | ); | ||||
37 | |||||
38 | 1 | 4µs | 2 | 2µs | $self->_set_constraint( $self->_compiled_type_constraint ); # spent 1µs making 1 call to Moose::Meta::TypeConstraint::_set_constraint
# spent 1µs making 1 call to Moose::Meta::TypeConstraint::_compiled_type_constraint |
39 | |||||
40 | 1 | 3µs | return $self; | ||
41 | } | ||||
42 | |||||
43 | # XXX - this is a rather gross implementation of laziness for the benefit of | ||||
44 | # MX::Types. If we try to call ->has_coercion on the objects during object | ||||
45 | # construction, this does not work when defining a recursive constraint with | ||||
46 | # MX::Types. | ||||
47 | # spent 17µs (14+3) within Moose::Meta::TypeConstraint::Union::coercion which was called 2 times, avg 8µs/call:
# 2 times (14µs+3µs) by Moose::Meta::TypeConstraint::Union::has_coercion at line 64, avg 8µs/call | ||||
48 | 2 | 700ns | my $self = shift; | ||
49 | |||||
50 | 2 | 3µs | return $self->{coercion} if exists $self->{coercion}; | ||
51 | |||||
52 | # Using any instead of grep here causes a weird error with some corner | ||||
53 | # cases when MX::Types is in use. See RT #61001. | ||||
54 | 3 | 4µs | 3 | 3µs | if ( grep { $_->has_coercion } @{ $self->type_constraints } ) { # spent 2µs making 2 calls to Moose::Meta::TypeConstraint::has_coercion, avg 1µs/call
# spent 800ns making 1 call to Moose::Meta::TypeConstraint::Union::type_constraints |
55 | return $self->{coercion} = Moose::Meta::TypeCoercion::Union->new( | ||||
56 | type_constraint => $self ); | ||||
57 | } | ||||
58 | else { | ||||
59 | 1 | 4µs | return $self->{coercion} = undef; | ||
60 | } | ||||
61 | } | ||||
62 | |||||
63 | # spent 25µs (9+17) within Moose::Meta::TypeConstraint::Union::has_coercion which was called 2 times, avg 13µs/call:
# once (5µs+15µs) by Moose::Meta::Attribute::_eval_environment at line 793 of Moose/Meta/Attribute.pm
# once (3µs+2µs) by Moose::Meta::Class::_eval_environment at line 529 of Moose/Meta/Class.pm | ||||
64 | 2 | 7µs | 2 | 17µs | return defined $_[0]->coercion; # spent 17µs making 2 calls to Moose::Meta::TypeConstraint::Union::coercion, avg 8µs/call |
65 | } | ||||
66 | |||||
67 | # spent 10µs (8+2) within Moose::Meta::TypeConstraint::Union::_actually_compile_type_constraint which was called:
# once (8µs+2µs) by Moose::Meta::TypeConstraint::compile_type_constraint at line 300 of Moose/Meta/TypeConstraint.pm | ||||
68 | 1 | 300ns | my $self = shift; | ||
69 | |||||
70 | 1 | 2µs | 1 | 2µs | my @constraints = @{ $self->type_constraints }; # spent 2µs making 1 call to Moose::Meta::TypeConstraint::Union::type_constraints |
71 | |||||
72 | return sub { | ||||
73 | my $value = shift; | ||||
74 | foreach my $type (@constraints) { | ||||
75 | return 1 if $type->check($value); | ||||
76 | } | ||||
77 | return undef; | ||||
78 | 1 | 5µs | }; | ||
79 | } | ||||
80 | |||||
81 | # spent 108µs (35+72) within Moose::Meta::TypeConstraint::Union::can_be_inlined which was called 4 times, avg 27µs/call:
# 3 times (28µs+55µs) by Moose::Meta::Attribute::_inline_check_constraint at line 711 of Moose/Meta/Attribute.pm, avg 28µs/call
# once (7µs+18µs) by Moose::Meta::Attribute::_eval_environment at line 789 of Moose/Meta/Attribute.pm | ||||
82 | 4 | 1µs | my $self = shift; | ||
83 | |||||
84 | # This was originally done with all() from List::MoreUtils, but that | ||||
85 | # caused some sort of bizarro parsing failure under 5.10. | ||||
86 | 4 | 6µs | 4 | 6µs | for my $tc ( @{ $self->type_constraints } ) { # spent 6µs making 4 calls to Moose::Meta::TypeConstraint::Union::type_constraints, avg 1µs/call |
87 | 8 | 9µs | 8 | 66µs | return 0 unless $tc->can_be_inlined; # spent 66µs making 8 calls to Moose::Meta::TypeConstraint::can_be_inlined, avg 8µs/call |
88 | } | ||||
89 | |||||
90 | 4 | 8µs | return 1; | ||
91 | } | ||||
92 | |||||
93 | # spent 295µs (34+261) within Moose::Meta::TypeConstraint::Union::_inline_check which was called 3 times, avg 98µs/call:
# 3 times (34µs+261µs) by Moose::Meta::Attribute::_inline_check_constraint at line 711 of Moose/Meta/Attribute.pm, avg 98µs/call | ||||
94 | 3 | 700ns | my $self = shift; | ||
95 | 3 | 700ns | my $val = shift; | ||
96 | |||||
97 | 6 | 7µs | 6 | 258µs | return '(' # spent 258µs making 6 calls to Moose::Meta::TypeConstraint::_inline_check, avg 43µs/call |
98 | . ( | ||||
99 | join ' || ', map { '(' . $_->_inline_check($val) . ')' } | ||||
100 | 3 | 17µs | 3 | 3µs | @{ $self->type_constraints } # spent 3µs making 3 calls to Moose::Meta::TypeConstraint::Union::type_constraints, avg 867ns/call |
101 | ) | ||||
102 | . ')'; | ||||
103 | } | ||||
104 | |||||
105 | # spent 53µs (19+34) within Moose::Meta::TypeConstraint::Union::inline_environment which was called 2 times, avg 26µs/call:
# once (10µs+18µs) by Moose::Meta::Attribute::_eval_environment at line 800 of Moose/Meta/Attribute.pm
# once (8µs+16µs) by Moose::Meta::Class::_eval_environment at line 543 of Moose/Meta/Class.pm | ||||
106 | 2 | 700ns | my $self = shift; | ||
107 | |||||
108 | 8 | 4µs | 4 | 32µs | return { map { %{ $_->inline_environment } } # spent 32µs making 4 calls to Moose::Meta::TypeConstraint::inline_environment, avg 8µs/call |
109 | 2 | 8µs | 2 | 2µs | @{ $self->type_constraints } }; # spent 2µs making 2 calls to Moose::Meta::TypeConstraint::Union::type_constraints, avg 900ns/call |
110 | } | ||||
111 | |||||
112 | sub equals { | ||||
113 | my ( $self, $type_or_name ) = @_; | ||||
114 | |||||
115 | my $other = Moose::Util::TypeConstraints::find_type_constraint($type_or_name); | ||||
116 | |||||
117 | return unless $other->isa(__PACKAGE__); | ||||
118 | |||||
119 | my @self_constraints = @{ $self->type_constraints }; | ||||
120 | my @other_constraints = @{ $other->type_constraints }; | ||||
121 | |||||
122 | return unless @self_constraints == @other_constraints; | ||||
123 | |||||
124 | # FIXME presort type constraints for efficiency? | ||||
125 | constraint: foreach my $constraint ( @self_constraints ) { | ||||
126 | for ( my $i = 0; $i < @other_constraints; $i++ ) { | ||||
127 | if ( $constraint->equals($other_constraints[$i]) ) { | ||||
128 | splice @other_constraints, $i, 1; | ||||
129 | next constraint; | ||||
130 | } | ||||
131 | } | ||||
132 | } | ||||
133 | |||||
134 | return @other_constraints == 0; | ||||
135 | } | ||||
136 | |||||
137 | sub parent { | ||||
138 | my $self = shift; | ||||
139 | |||||
140 | my ($first, @rest) = @{ $self->type_constraints }; | ||||
141 | |||||
142 | for my $parent ( $first->_collect_all_parents ) { | ||||
143 | return $parent if all { $_->is_a_type_of($parent) } @rest; | ||||
144 | } | ||||
145 | |||||
146 | return; | ||||
147 | } | ||||
148 | |||||
149 | sub validate { | ||||
150 | my ($self, $value) = @_; | ||||
151 | my $message; | ||||
152 | foreach my $type (@{$self->type_constraints}) { | ||||
153 | my $err = $type->validate($value); | ||||
154 | return unless defined $err; | ||||
155 | $message .= ($message ? ' and ' : '') . $err | ||||
156 | if defined $err; | ||||
157 | } | ||||
158 | return ($message . ' in (' . $self->name . ')') ; | ||||
159 | } | ||||
160 | |||||
161 | sub find_type_for { | ||||
162 | my ($self, $value) = @_; | ||||
163 | |||||
164 | return first { $_->check($value) } @{ $self->type_constraints }; | ||||
165 | } | ||||
166 | |||||
167 | sub is_a_type_of { | ||||
168 | my ($self, $type_name) = @_; | ||||
169 | |||||
170 | return all { $_->is_a_type_of($type_name) } @{ $self->type_constraints }; | ||||
171 | } | ||||
172 | |||||
173 | sub is_subtype_of { | ||||
174 | my ($self, $type_name) = @_; | ||||
175 | |||||
176 | return all { $_->is_subtype_of($type_name) } @{ $self->type_constraints }; | ||||
177 | } | ||||
178 | |||||
179 | sub create_child_type { | ||||
180 | my ( $self, %opts ) = @_; | ||||
181 | |||||
182 | my $constraint | ||||
183 | = Moose::Meta::TypeConstraint->new( %opts, parent => $self ); | ||||
184 | |||||
185 | # if we have a type constraint union, and no | ||||
186 | # type check, this means we are just aliasing | ||||
187 | # the union constraint, which means we need to | ||||
188 | # handle this differently. | ||||
189 | # - SL | ||||
190 | if ( not( defined $opts{constraint} ) | ||||
191 | && $self->has_coercion ) { | ||||
192 | $constraint->coercion( | ||||
193 | Moose::Meta::TypeCoercion::Union->new( | ||||
194 | type_constraint => $self, | ||||
195 | ) | ||||
196 | ); | ||||
197 | } | ||||
198 | |||||
199 | return $constraint; | ||||
200 | } | ||||
201 | |||||
202 | 1 | 4µs | 1; | ||
203 | |||||
204 | # ABSTRACT: A union of Moose type constraints | ||||
205 | |||||
206 | __END__ | ||||
# spent 600ns within Moose::Meta::TypeConstraint::Union::CORE:sort which was called:
# once (600ns+0s) by Moose::Meta::TypeConstraint::Union::new at line 31 |