← Index
NYTProf Performance Profile   « line view »
For script/ponapi
  Run on Wed Feb 10 15:51:26 2016
Reported on Thu Feb 11 09:43:10 2016

Filename/usr/local/lib/perl/5.18.2/Moose/Meta/TypeConstraint/Union.pm
StatementsExecuted 265 statements in 1.35ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
111322µs840µsMoose::Meta::TypeConstraint::Union::::BEGIN@8Moose::Meta::TypeConstraint::Union::BEGIN@8
2222155µs525µsMoose::Meta::TypeConstraint::Union::::can_be_inlinedMoose::Meta::TypeConstraint::Union::can_be_inlined
122294µs271µsMoose::Meta::TypeConstraint::Union::::inline_environmentMoose::Meta::TypeConstraint::Union::inline_environment
83291µs510µsMoose::Meta::TypeConstraint::Union::::_inline_checkMoose::Meta::TypeConstraint::Union::_inline_check
21152µs335µsMoose::Meta::TypeConstraint::Union::::newMoose::Meta::TypeConstraint::Union::new
21118µs22µsMoose::Meta::TypeConstraint::Union::::_actually_compile_type_constraintMoose::Meta::TypeConstraint::Union::_actually_compile_type_constraint
11114µs56µsMoose::Meta::TypeConstraint::Union::::BEGIN@10Moose::Meta::TypeConstraint::Union::BEGIN@10
11111µs14µsMoose::Meta::TypeConstraint::Union::::coercionMoose::Meta::TypeConstraint::Union::coercion
1119µs18µsMoose::Meta::TypeConstraint::Union::::BEGIN@4Moose::Meta::TypeConstraint::Union::BEGIN@4
1117µs481µsMoose::Meta::TypeConstraint::Union::::BEGIN@6Moose::Meta::TypeConstraint::Union::BEGIN@6
1116µs26µsMoose::Meta::TypeConstraint::Union::::BEGIN@12Moose::Meta::TypeConstraint::Union::BEGIN@12
1116µs9µsMoose::Meta::TypeConstraint::Union::::BEGIN@5Moose::Meta::TypeConstraint::Union::BEGIN@5
1114µs18µsMoose::Meta::TypeConstraint::Union::::has_coercionMoose::Meta::TypeConstraint::Union::has_coercion
2112µs2µsMoose::Meta::TypeConstraint::Union::::CORE:sortMoose::Meta::TypeConstraint::Union::CORE:sort (opcode)
0000s0sMoose::Meta::TypeConstraint::Union::::__ANON__[:136]Moose::Meta::TypeConstraint::Union::__ANON__[:136]
0000s0sMoose::Meta::TypeConstraint::Union::::__ANON__[:157]Moose::Meta::TypeConstraint::Union::__ANON__[:157]
0000s0sMoose::Meta::TypeConstraint::Union::::__ANON__[:163]Moose::Meta::TypeConstraint::Union::__ANON__[:163]
0000s0sMoose::Meta::TypeConstraint::Union::::__ANON__[:169]Moose::Meta::TypeConstraint::Union::__ANON__[:169]
0000s0sMoose::Meta::TypeConstraint::Union::::__ANON__[:16]Moose::Meta::TypeConstraint::Union::__ANON__[:16]
0000s0sMoose::Meta::TypeConstraint::Union::::__ANON__[:71]Moose::Meta::TypeConstraint::Union::__ANON__[:71]
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::::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::::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
1package Moose::Meta::TypeConstraint::Union;
21500nsour $VERSION = '2.1604';
3
4219µs227µs
# spent 18µs (9+9) within Moose::Meta::TypeConstraint::Union::BEGIN@4 which was called: # once (9µs+9µs) by Moose::Util::TypeConstraints::BEGIN@25 at line 4
use strict;
# spent 18µs making 1 call to Moose::Meta::TypeConstraint::Union::BEGIN@4 # spent 9µs making 1 call to strict::import
5218µs212µs
# spent 9µs (6+3) within Moose::Meta::TypeConstraint::Union::BEGIN@5 which was called: # once (6µs+3µs) by Moose::Util::TypeConstraints::BEGIN@25 at line 5
use warnings;
# spent 9µs making 1 call to Moose::Meta::TypeConstraint::Union::BEGIN@5 # spent 3µs making 1 call to warnings::import
6224µs2955µs
# spent 481µs (7+474) within Moose::Meta::TypeConstraint::Union::BEGIN@6 which was called: # once (7µs+474µs) by Moose::Util::TypeConstraints::BEGIN@25 at line 6
use metaclass;
# spent 481µs making 1 call to Moose::Meta::TypeConstraint::Union::BEGIN@6 # spent 474µs making 1 call to metaclass::import
7
82104µs1840µs
# spent 840µs (322+518) within Moose::Meta::TypeConstraint::Union::BEGIN@8 which was called: # once (322µs+518µs) by Moose::Util::TypeConstraints::BEGIN@25 at line 8
use Moose::Meta::TypeCoercion::Union;
# spent 840µs making 1 call to Moose::Meta::TypeConstraint::Union::BEGIN@8
9
10339µs375µs
# spent 56µs (14+42) within Moose::Meta::TypeConstraint::Union::BEGIN@10 which was called: # once (14µs+42µs) by Moose::Util::TypeConstraints::BEGIN@25 at line 10
use List::Util 1.33 qw(first all);
# spent 56µs making 1 call to Moose::Meta::TypeConstraint::Union::BEGIN@10 # spent 10µs making 1 call to UNIVERSAL::VERSION # spent 8µs making 1 call to List::Util::import
11
122786µs245µs
# spent 26µs (6+20) within Moose::Meta::TypeConstraint::Union::BEGIN@12 which was called: # once (6µs+20µs) by Moose::Util::TypeConstraints::BEGIN@25 at line 12
use parent 'Moose::Meta::TypeConstraint';
# spent 26µs making 1 call to Moose::Meta::TypeConstraint::Union::BEGIN@12 # spent 20µs making 1 call to parent::import
13
14__PACKAGE__->meta->add_attribute('type_constraints' => (
15 accessor => 'type_constraints',
16 default => sub { [] },
1717µs3404µs Class::MOP::_definition_context(),
# spent 381µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 15µs making 1 call to Moose::Meta::TypeConstraint::Union::meta # spent 7µs making 1 call to Class::MOP::_definition_context
18));
19
20
# spent 335µs (52+282) within Moose::Meta::TypeConstraint::Union::new which was called 2 times, avg 167µs/call: # 2 times (52µs+282µs) by Moose::Util::TypeConstraints::_create_type_constraint_union at line 107 of Moose/Util/TypeConstraints.pm, avg 167µs/call
sub new {
2122µs my ($class, %options) = @_;
22
2345µs49µs my $name = join '|' => sort { $a cmp $b }
# spent 9µs making 4 calls to Moose::Meta::TypeConstraint::name, avg 2µs/call
24217µs22µs map { $_->name } @{ $options{type_constraints} };
# spent 2µs making 2 calls to Moose::Meta::TypeConstraint::Union::CORE:sort, avg 1µs/call
25
26210µs2265µs my $self = $class->SUPER::new(
# spent 265µs making 2 calls to Moose::Meta::TypeConstraint::new, avg 132µs/call
27 name => $name,
28 %options,
29 );
30
3127µs46µs $self->_set_constraint( $self->_compiled_type_constraint );
# spent 4µs making 2 calls to Moose::Meta::TypeConstraint::_set_constraint, avg 2µs/call # spent 2µs making 2 calls to Moose::Meta::TypeConstraint::_compiled_type_constraint, avg 900ns/call
32
3325µs return $self;
34}
35
36# XXX - this is a rather gross implementation of laziness for the benefit of
37# MX::Types. If we try to call ->has_coercion on the objects during object
38# construction, this does not work when defining a recursive constraint with
39# MX::Types.
40
# spent 14µs (11+3) within Moose::Meta::TypeConstraint::Union::coercion which was called: # once (11µs+3µs) by Moose::Meta::TypeConstraint::Union::has_coercion at line 57
sub coercion {
411300ns my $self = shift;
42
431500ns return $self->{coercion} if exists $self->{coercion};
44
45 # Using any instead of grep here causes a weird error with some corner
46 # cases when MX::Types is in use. See RT #61001.
4734µs33µs if ( grep { $_->has_coercion } @{ $self->type_constraints } ) {
# spent 2µs making 2 calls to Moose::Meta::TypeConstraint::has_coercion, avg 950ns/call # spent 700ns making 1 call to Moose::Meta::TypeConstraint::Union::type_constraints
48 return $self->{coercion} = Moose::Meta::TypeCoercion::Union->new(
49 type_constraint => $self );
50 }
51 else {
5213µs return $self->{coercion} = undef;
53 }
54}
55
56
# spent 18µs (4+14) within Moose::Meta::TypeConstraint::Union::has_coercion which was called: # once (4µs+14µs) by Class::MOP::Class:::around at line 149 of Moose/Meta/Method/Accessor/Native/Collection.pm
sub has_coercion {
5715µs114µs return defined $_[0]->coercion;
# spent 14µs making 1 call to Moose::Meta::TypeConstraint::Union::coercion
58}
59
60
# spent 22µs (18+4) within Moose::Meta::TypeConstraint::Union::_actually_compile_type_constraint which was called 2 times, avg 11µs/call: # 2 times (18µs+4µs) by Moose::Meta::TypeConstraint::compile_type_constraint at line 280 of Moose/Meta/TypeConstraint.pm, avg 11µs/call
sub _actually_compile_type_constraint {
612400ns my $self = shift;
62
6325µs24µs my @constraints = @{ $self->type_constraints };
# spent 4µs making 2 calls to Moose::Meta::TypeConstraint::Union::type_constraints, avg 2µs/call
64
65 return sub {
66 my $value = shift;
67 foreach my $type (@constraints) {
68 return 1 if $type->check($value);
69 }
70 return undef;
71212µs };
72}
73
74
# spent 525µs (155+370) within Moose::Meta::TypeConstraint::Union::can_be_inlined which was called 22 times, avg 24µs/call: # 21 times (149µs+355µs) by Moose::Meta::TypeConstraint::Parameterized::can_be_inlined at line 72 of Moose/Meta/TypeConstraint/Parameterized.pm, avg 24µs/call # once (6µs+15µs) by Moose::Meta::Method::Accessor::Native::Collection::_inline_check_member_constraint at line 103 of Moose/Meta/Method/Accessor/Native/Collection.pm
sub can_be_inlined {
75224µs my $self = shift;
76
77 # This was originally done with all() from List::MoreUtils, but that
78 # caused some sort of bizarro parsing failure under 5.10.
792226µs2217µs for my $tc ( @{ $self->type_constraints } ) {
# spent 17µs making 22 calls to Moose::Meta::TypeConstraint::Union::type_constraints, avg 791ns/call
804452µs44352µs return 0 unless $tc->can_be_inlined;
# spent 352µs making 44 calls to Moose::Meta::TypeConstraint::can_be_inlined, avg 8µs/call
81 }
82
832238µs return 1;
84}
85
86
# spent 510µs (91+419) within Moose::Meta::TypeConstraint::Union::_inline_check which was called 8 times, avg 64µs/call: # 5 times (62µs+282µ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 69µs/call # 2 times (19µs+88µs) by Moose::Util::TypeConstraints::Builtins::__ANON__[/usr/local/lib/perl/5.18.2/Moose/Util/TypeConstraints/Builtins.pm:292] at line 290 of Moose/Util/TypeConstraints/Builtins.pm, avg 54µs/call # once (10µs+49µs) by Moose::Meta::Method::Accessor::Native::Collection::_inline_check_member_constraint at line 103 of Moose/Meta/Method/Accessor/Native/Collection.pm
sub _inline_check {
8782µs my $self = shift;
8882µs my $val = shift;
89
901631µs16414µs return '('
# spent 414µs making 16 calls to Moose::Meta::TypeConstraint::_inline_check, avg 26µs/call
91 . (
92 join ' || ', map { '(' . $_->_inline_check($val) . ')' }
93847µs85µs @{ $self->type_constraints }
# spent 5µs making 8 calls to Moose::Meta::TypeConstraint::Union::type_constraints, avg 675ns/call
94 )
95 . ')';
96}
97
98
# spent 271µs (94+177) within Moose::Meta::TypeConstraint::Union::inline_environment which was called 12 times, avg 23µs/call: # 11 times (88µs+163µs) by Moose::Meta::TypeConstraint::Parameterized::inline_environment at line 85 of Moose/Meta/TypeConstraint/Parameterized.pm, avg 23µs/call # once (6µs+14µs) by Class::MOP::Class:::around at line 158 of Moose/Meta/Method/Accessor/Native/Collection.pm
sub inline_environment {
99124µs my $self = shift;
100
1014826µs24166µs return { map { %{ $_->inline_environment } }
# spent 166µs making 24 calls to Moose::Meta::TypeConstraint::inline_environment, avg 7µs/call
1021244µs1211µs @{ $self->type_constraints } };
# spent 11µs making 12 calls to Moose::Meta::TypeConstraint::Union::type_constraints, avg 900ns/call
103}
104
105sub equals {
106 my ( $self, $type_or_name ) = @_;
107
108 my $other = Moose::Util::TypeConstraints::find_type_constraint($type_or_name);
109
110 return unless $other->isa(__PACKAGE__);
111
112 my @self_constraints = @{ $self->type_constraints };
113 my @other_constraints = @{ $other->type_constraints };
114
115 return unless @self_constraints == @other_constraints;
116
117 # FIXME presort type constraints for efficiency?
118 constraint: foreach my $constraint ( @self_constraints ) {
119 for ( my $i = 0; $i < @other_constraints; $i++ ) {
120 if ( $constraint->equals($other_constraints[$i]) ) {
121 splice @other_constraints, $i, 1;
122 next constraint;
123 }
124 }
125 }
126
127 return @other_constraints == 0;
128}
129
130sub parent {
131 my $self = shift;
132
133 my ($first, @rest) = @{ $self->type_constraints };
134
135 for my $parent ( $first->_collect_all_parents ) {
136 return $parent if all { $_->is_a_type_of($parent) } @rest;
137 }
138
139 return;
140}
141
142sub validate {
143 my ($self, $value) = @_;
144 my $message;
145 foreach my $type (@{$self->type_constraints}) {
146 my $err = $type->validate($value);
147 return unless defined $err;
148 $message .= ($message ? ' and ' : '') . $err
149 if defined $err;
150 }
151 return ($message . ' in (' . $self->name . ')') ;
152}
153
154sub find_type_for {
155 my ($self, $value) = @_;
156
157 return first { $_->check($value) } @{ $self->type_constraints };
158}
159
160sub is_a_type_of {
161 my ($self, $type_name) = @_;
162
163 return all { $_->is_a_type_of($type_name) } @{ $self->type_constraints };
164}
165
166sub is_subtype_of {
167 my ($self, $type_name) = @_;
168
169 return all { $_->is_subtype_of($type_name) } @{ $self->type_constraints };
170}
171
172sub create_child_type {
173 my ( $self, %opts ) = @_;
174
175 my $constraint
176 = Moose::Meta::TypeConstraint->new( %opts, parent => $self );
177
178 # if we have a type constraint union, and no
179 # type check, this means we are just aliasing
180 # the union constraint, which means we need to
181 # handle this differently.
182 # - SL
183 if ( not( defined $opts{constraint} )
184 && $self->has_coercion ) {
185 $constraint->coercion(
186 Moose::Meta::TypeCoercion::Union->new(
187 type_constraint => $self,
188 )
189 );
190 }
191
192 return $constraint;
193}
194
19514µs1;
196
197# ABSTRACT: A union of Moose type constraints
198
199__END__
 
# spent 2µs within Moose::Meta::TypeConstraint::Union::CORE:sort which was called 2 times, avg 1µs/call: # 2 times (2µs+0s) by Moose::Meta::TypeConstraint::Union::new at line 24, avg 1µs/call
sub Moose::Meta::TypeConstraint::Union::CORE:sort; # opcode