← Index
NYTProf Performance Profile   « block view • line view • sub view »
For bin/pan_genome_post_analysis
  Run on Fri Mar 27 11:43:32 2015
Reported on Fri Mar 27 11:45:26 2015

Filename/Users/ap13/perl5/lib/perl5/darwin-2level/Moose/Meta/TypeConstraint/Union.pm
StatementsExecuted 16 statements in 1.20ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
111365µs1.04msMoose::Meta::TypeConstraint::Union::::BEGIN@8Moose::Meta::TypeConstraint::Union::BEGIN@8
11118µs66µsMoose::Meta::TypeConstraint::Union::::BEGIN@10Moose::Meta::TypeConstraint::Union::BEGIN@10
11113µs26µsMoose::Meta::TypeConstraint::Union::::BEGIN@4Moose::Meta::TypeConstraint::Union::BEGIN@4
11111µs15µsMoose::Meta::TypeConstraint::Union::::BEGIN@5Moose::Meta::TypeConstraint::Union::BEGIN@5
1118µs32µsMoose::Meta::TypeConstraint::Union::::BEGIN@12Moose::Meta::TypeConstraint::Union::BEGIN@12
1118µs588µsMoose::Meta::TypeConstraint::Union::::BEGIN@6Moose::Meta::TypeConstraint::Union::BEGIN@6
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::::_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
1package Moose::Meta::TypeConstraint::Union;
21700nsour $VERSION = '2.1403';
3
4223µs239µs
# spent 26µs (13+13) within Moose::Meta::TypeConstraint::Union::BEGIN@4 which was called: # once (13µs+13µs) by Moose::Util::TypeConstraints::BEGIN@25 at line 4
use strict;
# spent 26µs making 1 call to Moose::Meta::TypeConstraint::Union::BEGIN@4 # spent 13µs making 1 call to strict::import
5222µs219µs
# spent 15µs (11+4) within Moose::Meta::TypeConstraint::Union::BEGIN@5 which was called: # once (11µs+4µs) by Moose::Util::TypeConstraints::BEGIN@25 at line 5
use warnings;
# spent 15µs making 1 call to Moose::Meta::TypeConstraint::Union::BEGIN@5 # spent 4µs making 1 call to warnings::import
6227µs21.17ms
# spent 588µs (8+579) within Moose::Meta::TypeConstraint::Union::BEGIN@6 which was called: # once (8µs+579µs) by Moose::Util::TypeConstraints::BEGIN@25 at line 6
use metaclass;
# spent 588µs making 1 call to Moose::Meta::TypeConstraint::Union::BEGIN@6 # spent 579µs making 1 call to metaclass::import
7
82124µs11.04ms
# spent 1.04ms (365µs+678µs) within Moose::Meta::TypeConstraint::Union::BEGIN@8 which was called: # once (365µs+678µs) by Moose::Util::TypeConstraints::BEGIN@25 at line 8
use Moose::Meta::TypeCoercion::Union;
# spent 1.04ms making 1 call to Moose::Meta::TypeConstraint::Union::BEGIN@8
9
10345µs390µs
# spent 66µs (18+49) within Moose::Meta::TypeConstraint::Union::BEGIN@10 which was called: # once (18µs+49µs) by Moose::Util::TypeConstraints::BEGIN@25 at line 10
use List::Util 1.33 qw(first all);
# spent 66µs making 1 call to Moose::Meta::TypeConstraint::Union::BEGIN@10 # spent 12µs making 1 call to UNIVERSAL::VERSION # spent 11µs making 1 call to List::Util::import
11
122941µs255µs
# spent 32µs (8+24) within Moose::Meta::TypeConstraint::Union::BEGIN@12 which was called: # once (8µs+24µs) by Moose::Util::TypeConstraints::BEGIN@25 at line 12
use parent 'Moose::Meta::TypeConstraint';
# spent 32µs making 1 call to Moose::Meta::TypeConstraint::Union::BEGIN@12 # spent 24µs making 1 call to parent::import
13
14__PACKAGE__->meta->add_attribute('type_constraints' => (
15 accessor => 'type_constraints',
16 default => sub { [] },
17110µs3515µs Class::MOP::_definition_context(),
# spent 485µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 22µs making 1 call to Moose::Meta::TypeConstraint::Union::meta # spent 8µs making 1 call to Class::MOP::_definition_context
18));
19
20sub new {
21 my ($class, %options) = @_;
22
23 my $name = join '|' => sort { $a cmp $b }
24 map { $_->name } @{ $options{type_constraints} };
25
26 my $self = $class->SUPER::new(
27 name => $name,
28 %options,
29 );
30
31 $self->_set_constraint( $self->_compiled_type_constraint );
32
33 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.
40sub coercion {
41 my $self = shift;
42
43 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.
47 if ( grep { $_->has_coercion } @{ $self->type_constraints } ) {
48 return $self->{coercion} = Moose::Meta::TypeCoercion::Union->new(
49 type_constraint => $self );
50 }
51 else {
52 return $self->{coercion} = undef;
53 }
54}
55
56sub has_coercion {
57 return defined $_[0]->coercion;
58}
59
60sub _actually_compile_type_constraint {
61 my $self = shift;
62
63 my @constraints = @{ $self->type_constraints };
64
65 return sub {
66 my $value = shift;
67 foreach my $type (@constraints) {
68 return 1 if $type->check($value);
69 }
70 return undef;
71 };
72}
73
74sub can_be_inlined {
75 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.
79 for my $tc ( @{ $self->type_constraints } ) {
80 return 0 unless $tc->can_be_inlined;
81 }
82
83 return 1;
84}
85
86sub _inline_check {
87 my $self = shift;
88 my $val = shift;
89
90 return '('
91 . (
92 join ' || ', map { '(' . $_->_inline_check($val) . ')' }
93 @{ $self->type_constraints }
94 )
95 . ')';
96}
97
98sub inline_environment {
99 my $self = shift;
100
101 return { map { %{ $_->inline_environment } }
102 @{ $self->type_constraints } };
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
19518µs1;
196
197# ABSTRACT: A union of Moose type constraints
198
199__END__