← Index
NYTProf Performance Profile   « line view »
For fastest.pl
  Run on Fri Jan 31 20:48:16 2014
Reported on Fri Jan 31 20:49:41 2014

Filename/opt/perl-5.18.1/lib/site_perl/5.18.1/darwin-thread-multi-2level/Moose/Meta/TypeConstraint/Union.pm
StatementsExecuted 19 statements in 1.61ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
111548µs1.22msMoose::Meta::TypeConstraint::Union::::BEGIN@14Moose::Meta::TypeConstraint::Union::BEGIN@14
11115µs54µsMoose::Meta::TypeConstraint::Union::::BEGIN@17Moose::Meta::TypeConstraint::Union::BEGIN@17
11112µs12µsMoose::Meta::TypeConstraint::Union::::BEGIN@3Moose::Meta::TypeConstraint::Union::BEGIN@3
11110µs41µsMoose::Meta::TypeConstraint::Union::::BEGIN@16Moose::Meta::TypeConstraint::Union::BEGIN@16
1119µs14µsMoose::Meta::TypeConstraint::Union::::BEGIN@11Moose::Meta::TypeConstraint::Union::BEGIN@11
1119µs78µsMoose::Meta::TypeConstraint::Union::::BEGIN@19Moose::Meta::TypeConstraint::Union::BEGIN@19
1119µs24µsMoose::Meta::TypeConstraint::Union::::BEGIN@10Moose::Meta::TypeConstraint::Union::BEGIN@10
1118µs512µsMoose::Meta::TypeConstraint::Union::::BEGIN@12Moose::Meta::TypeConstraint::Union::BEGIN@12
0000s0sMoose::Meta::TypeConstraint::Union::::__ANON__[:143]Moose::Meta::TypeConstraint::Union::__ANON__[:143]
0000s0sMoose::Meta::TypeConstraint::Union::::__ANON__[:164]Moose::Meta::TypeConstraint::Union::__ANON__[:164]
0000s0sMoose::Meta::TypeConstraint::Union::::__ANON__[:170]Moose::Meta::TypeConstraint::Union::__ANON__[:170]
0000s0sMoose::Meta::TypeConstraint::Union::::__ANON__[:176]Moose::Meta::TypeConstraint::Union::__ANON__[:176]
0000s0sMoose::Meta::TypeConstraint::Union::::__ANON__[:23]Moose::Meta::TypeConstraint::Union::__ANON__[:23]
0000s0sMoose::Meta::TypeConstraint::Union::::__ANON__[:78]Moose::Meta::TypeConstraint::Union::__ANON__[:78]
0000s0sMoose::Meta::TypeConstraint::Union::::_actually_compile_type_constraintMoose::Meta::TypeConstraint::Union::_actually_compile_type_constraint
0000s0sMoose::Meta::TypeConstraint::Union::::_inline_checkMoose::Meta::TypeConstraint::Union::_inline_check
0000s0sMoose::Meta::TypeConstraint::Union::::can_be_inlinedMoose::Meta::TypeConstraint::Union::can_be_inlined
0000s0sMoose::Meta::TypeConstraint::Union::::coercionMoose::Meta::TypeConstraint::Union::coercion
0000s0sMoose::Meta::TypeConstraint::Union::::create_child_typeMoose::Meta::TypeConstraint::Union::create_child_type
0000s0sMoose::Meta::TypeConstraint::Union::::equalsMoose::Meta::TypeConstraint::Union::equals
0000s0sMoose::Meta::TypeConstraint::Union::::find_type_forMoose::Meta::TypeConstraint::Union::find_type_for
0000s0sMoose::Meta::TypeConstraint::Union::::has_coercionMoose::Meta::TypeConstraint::Union::has_coercion
0000s0sMoose::Meta::TypeConstraint::Union::::inline_environmentMoose::Meta::TypeConstraint::Union::inline_environment
0000s0sMoose::Meta::TypeConstraint::Union::::is_a_type_ofMoose::Meta::TypeConstraint::Union::is_a_type_of
0000s0sMoose::Meta::TypeConstraint::Union::::is_subtype_ofMoose::Meta::TypeConstraint::Union::is_subtype_of
0000s0sMoose::Meta::TypeConstraint::Union::::newMoose::Meta::TypeConstraint::Union::new
0000s0sMoose::Meta::TypeConstraint::Union::::parentMoose::Meta::TypeConstraint::Union::parent
0000s0sMoose::Meta::TypeConstraint::Union::::validateMoose::Meta::TypeConstraint::Union::validate
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1
2package Moose::Meta::TypeConstraint::Union;
3
# spent 12µs within Moose::Meta::TypeConstraint::Union::BEGIN@3 which was called: # once (12µs+0s) by Moose::Util::TypeConstraints::BEGIN@33 at line 5
BEGIN {
417µs $Moose::Meta::TypeConstraint::Union::AUTHORITY = 'cpan:STEVAN';
5141µs112µs}
# spent 12µs making 1 call to Moose::Meta::TypeConstraint::Union::BEGIN@3
6{
721µs $Moose::Meta::TypeConstraint::Union::VERSION = '2.1005';
8}
9
10233µs239µs
# spent 24µs (9+15) within Moose::Meta::TypeConstraint::Union::BEGIN@10 which was called: # once (9µs+15µs) by Moose::Util::TypeConstraints::BEGIN@33 at line 10
use strict;
# spent 24µs making 1 call to Moose::Meta::TypeConstraint::Union::BEGIN@10 # spent 15µs making 1 call to strict::import
11229µs218µs
# spent 14µs (9+4) within Moose::Meta::TypeConstraint::Union::BEGIN@11 which was called: # once (9µs+4µs) by Moose::Util::TypeConstraints::BEGIN@33 at line 11
use warnings;
# spent 14µs making 1 call to Moose::Meta::TypeConstraint::Union::BEGIN@11 # spent 4µs making 1 call to warnings::import
12237µs21.02ms
# spent 512µs (8+504) within Moose::Meta::TypeConstraint::Union::BEGIN@12 which was called: # once (8µs+504µs) by Moose::Util::TypeConstraints::BEGIN@33 at line 12
use metaclass;
# spent 512µs making 1 call to Moose::Meta::TypeConstraint::Union::BEGIN@12 # spent 504µs making 1 call to metaclass::import
13
142145µs11.22ms
# spent 1.22ms (548µs+669µs) within Moose::Meta::TypeConstraint::Union::BEGIN@14 which was called: # once (548µs+669µs) by Moose::Util::TypeConstraints::BEGIN@33 at line 14
use Moose::Meta::TypeCoercion::Union;
# spent 1.22ms making 1 call to Moose::Meta::TypeConstraint::Union::BEGIN@14
15
16235µs272µs
# spent 41µs (10+31) within Moose::Meta::TypeConstraint::Union::BEGIN@16 which was called: # once (10µs+31µs) by Moose::Util::TypeConstraints::BEGIN@33 at line 16
use List::MoreUtils qw(all);
# spent 41µs making 1 call to Moose::Meta::TypeConstraint::Union::BEGIN@16 # spent 31µs making 1 call to Exporter::import
17237µs267µs
# spent 54µs (15+38) within Moose::Meta::TypeConstraint::Union::BEGIN@17 which was called: # once (15µs+38µs) by Moose::Util::TypeConstraints::BEGIN@33 at line 17
use List::Util qw(first);
# spent 54µs making 1 call to Moose::Meta::TypeConstraint::Union::BEGIN@17 # spent 14µs making 1 call to List::Util::import
18
1921.23ms2148µs
# spent 78µs (9+70) within Moose::Meta::TypeConstraint::Union::BEGIN@19 which was called: # once (9µs+70µs) by Moose::Util::TypeConstraints::BEGIN@33 at line 19
use base 'Moose::Meta::TypeConstraint';
# spent 78µs making 1 call to Moose::Meta::TypeConstraint::Union::BEGIN@19 # spent 70µs making 1 call to base::import
20
21__PACKAGE__->meta->add_attribute('type_constraints' => (
22 accessor => 'type_constraints',
23 default => sub { [] },
2417µs3460µs Class::MOP::_definition_context(),
# spent 429µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 23µs making 1 call to Moose::Meta::TypeConstraint::Union::meta # spent 8µs making 1 call to Class::MOP::_definition_context
25));
26
27sub new {
28 my ($class, %options) = @_;
29
30 my $name = join '|' => sort { $a cmp $b }
31 map { $_->name } @{ $options{type_constraints} };
32
33 my $self = $class->SUPER::new(
34 name => $name,
35 %options,
36 );
37
38 $self->_set_constraint( $self->_compiled_type_constraint );
39
40 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.
47sub coercion {
48 my $self = shift;
49
50 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 if ( grep { $_->has_coercion } @{ $self->type_constraints } ) {
55 return $self->{coercion} = Moose::Meta::TypeCoercion::Union->new(
56 type_constraint => $self );
57 }
58 else {
59 return $self->{coercion} = undef;
60 }
61}
62
63sub has_coercion {
64 return defined $_[0]->coercion;
65}
66
67sub _actually_compile_type_constraint {
68 my $self = shift;
69
70 my @constraints = @{ $self->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 };
79}
80
81sub can_be_inlined {
82 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 for my $tc ( @{ $self->type_constraints } ) {
87 return 0 unless $tc->can_be_inlined;
88 }
89
90 return 1;
91}
92
93sub _inline_check {
94 my $self = shift;
95 my $val = shift;
96
97 return '('
98 . (
99 join ' || ', map { '(' . $_->_inline_check($val) . ')' }
100 @{ $self->type_constraints }
101 )
102 . ')';
103}
104
105sub inline_environment {
106 my $self = shift;
107
108 return { map { %{ $_->inline_environment } }
109 @{ $self->type_constraints } };
110}
111
112sub 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
137sub 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
149sub 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
161sub find_type_for {
162 my ($self, $value) = @_;
163
164 return first { $_->check($value) } @{ $self->type_constraints };
165}
166
167sub is_a_type_of {
168 my ($self, $type_name) = @_;
169
170 return all { $_->is_a_type_of($type_name) } @{ $self->type_constraints };
171}
172
173sub is_subtype_of {
174 my ($self, $type_name) = @_;
175
176 return all { $_->is_subtype_of($type_name) } @{ $self->type_constraints };
177}
178
179sub 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
20217µs1;
203
204# ABSTRACT: A union of Moose type constraints
205
206__END__