← Index
NYTProf Performance Profile   « block view • line view • sub view »
For -e
  Run on Wed Nov 17 21:42:38 2010
Reported on Wed Nov 17 22:07:50 2010

Filename/home/doy/coding/src/Moose/blib/lib//Moose/Meta/TypeConstraint/Union.pm
StatementsExecuted 86 statements in 4.99ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
1111.61ms5.16msMoose::Meta::TypeConstraint::Union::::BEGIN@8Moose::Meta::TypeConstraint::Union::BEGIN@8
611930µs3.58msMoose::Meta::TypeConstraint::Union::::newMoose::Meta::TypeConstraint::Union::new
611259µs341µsMoose::Meta::TypeConstraint::Union::::_actually_compile_type_constraintMoose::Meta::TypeConstraint::Union::_actually_compile_type_constraint
111125µs154µsMoose::Meta::TypeConstraint::Union::::BEGIN@4Moose::Meta::TypeConstraint::Union::BEGIN@4
11161µs157µsMoose::Meta::TypeConstraint::Union::::BEGIN@5Moose::Meta::TypeConstraint::Union::BEGIN@5
11150µs228µsMoose::Meta::TypeConstraint::Union::::BEGIN@10Moose::Meta::TypeConstraint::Union::BEGIN@10
11149µs3.95msMoose::Meta::TypeConstraint::Union::::BEGIN@6Moose::Meta::TypeConstraint::Union::BEGIN@6
61142µs42µsMoose::Meta::TypeConstraint::Union::::CORE:sortMoose::Meta::TypeConstraint::Union::CORE:sort (opcode)
11140µs283µsMoose::Meta::TypeConstraint::Union::::BEGIN@16Moose::Meta::TypeConstraint::Union::BEGIN@16
0000s0sMoose::Meta::TypeConstraint::Union::::__ANON__[:123]Moose::Meta::TypeConstraint::Union::__ANON__[:123]
0000s0sMoose::Meta::TypeConstraint::Union::::__ANON__[:20]Moose::Meta::TypeConstraint::Union::__ANON__[:20]
0000s0sMoose::Meta::TypeConstraint::Union::::__ANON__[:34]Moose::Meta::TypeConstraint::Union::__ANON__[:34]
0000s0sMoose::Meta::TypeConstraint::Union::::__ANON__[:74]Moose::Meta::TypeConstraint::Union::__ANON__[:74]
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::::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::::parentsMoose::Meta::TypeConstraint::Union::parents
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
43167µs2182µs
# spent 154µs (125+28) within Moose::Meta::TypeConstraint::Union::BEGIN@4 which was called: # once (125µs+28µs) by Moose::Util::TypeConstraints::BEGIN@30 at line 4
use strict;
# spent 154µs making 1 call to Moose::Meta::TypeConstraint::Union::BEGIN@4 # spent 28µs making 1 call to strict::import
53159µs2254µs
# spent 157µs (61+97) within Moose::Meta::TypeConstraint::Union::BEGIN@5 which was called: # once (61µs+97µs) by Moose::Util::TypeConstraints::BEGIN@30 at line 5
use warnings;
# spent 157µs making 1 call to Moose::Meta::TypeConstraint::Union::BEGIN@5 # spent 96µs making 1 call to warnings::import
63141µs27.84ms
# spent 3.95ms (49µs+3.90) within Moose::Meta::TypeConstraint::Union::BEGIN@6 which was called: # once (49µs+3.90ms) by Moose::Util::TypeConstraints::BEGIN@30 at line 6
use metaclass;
# spent 3.95ms making 1 call to Moose::Meta::TypeConstraint::Union::BEGIN@6 # spent 3.90ms making 1 call to metaclass::import
7
83500µs15.16ms
# spent 5.16ms (1.61+3.55) within Moose::Meta::TypeConstraint::Union::BEGIN@8 which was called: # once (1.61ms+3.55ms) by Moose::Util::TypeConstraints::BEGIN@30 at line 8
use Moose::Meta::TypeCoercion::Union;
# spent 5.16ms making 1 call to Moose::Meta::TypeConstraint::Union::BEGIN@8
9
103230µs2406µs
# spent 228µs (50+178) within Moose::Meta::TypeConstraint::Union::BEGIN@10 which was called: # once (50µs+178µs) by Moose::Util::TypeConstraints::BEGIN@30 at line 10
use List::Util qw(first);
# spent 228µs making 1 call to Moose::Meta::TypeConstraint::Union::BEGIN@10 # spent 178µs making 1 call to Exporter::import
11
1215µsour $VERSION = '1.19';
13160µs$VERSION = eval $VERSION;
# spent 12µs executing statements in string eval
1414µsour $AUTHORITY = 'cpan:STEVAN';
15
1632.53ms2526µs
# spent 283µs (40+243) within Moose::Meta::TypeConstraint::Union::BEGIN@16 which was called: # once (40µs+243µs) by Moose::Util::TypeConstraints::BEGIN@30 at line 16
use base 'Moose::Meta::TypeConstraint';
# spent 283µs making 1 call to Moose::Meta::TypeConstraint::Union::BEGIN@16 # spent 243µs making 1 call to base::import
17
18__PACKAGE__->meta->add_attribute('type_constraints' => (
19 accessor => 'type_constraints',
20 default => sub { [] }
21133µs22.15ms));
# spent 2.01ms making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 147µs making 1 call to Moose::Meta::TypeConstraint::Union::meta
22
23
# spent 3.58ms (930µs+2.65) within Moose::Meta::TypeConstraint::Union::new which was called 6 times, avg 597µs/call: # 6 times (930µs+2.65ms) by Moose::Util::TypeConstraints::create_type_constraint_union at line 95 of Moose/Util/TypeConstraints.pm, avg 597µs/call
sub new {
24647µs my ($class, %options) = @_;
25
2615161µs15195µs my $name = join '|' => sort { $a cmp $b }
# spent 195µs making 15 calls to Moose::Meta::TypeConstraint::name, avg 13µs/call
276196µs642µs map { $_->name } @{ $options{type_constraints} };
# spent 42µs making 6 calls to Moose::Meta::TypeConstraint::Union::CORE:sort, avg 7µs/call
28
296284µs62.35ms my $self = $class->SUPER::new(
# spent 2.35ms making 6 calls to Moose::Meta::TypeConstraint::new, avg 391µs/call
30 name => $name,
31 %options,
32 );
33
346115µs670µs $self->_set_constraint(sub { $self->check($_[0]) });
# spent 70µs making 6 calls to Moose::Meta::TypeConstraint::_set_constraint, avg 12µs/call
35
36680µs return $self;
37}
38
39# XXX - this is a rather gross implementation of laziness for the benefit of
40# MX::Types. If we try to call ->has_coercion on the objects during object
41# construction, this does not work when defining a recursive constraint with
42# MX::Types.
43sub coercion {
44 my $self = shift;
45
46 return $self->{coercion} if exists $self->{coercion};
47
48 # Using any instead of grep here causes a weird error with some corner
49 # cases when MX::Types is in use. See RT #61001.
50 if ( grep { $_->has_coercion } @{ $self->type_constraints } ) {
51 return $self->{coercion} = Moose::Meta::TypeCoercion::Union->new(
52 type_constraint => $self );
53 }
54 else {
55 return $self->{coercion} = undef;
56 }
57}
58
59sub has_coercion {
60 return defined $_[0]->coercion;
61}
62
63
# spent 341µs (259+82) within Moose::Meta::TypeConstraint::Union::_actually_compile_type_constraint which was called 6 times, avg 57µs/call: # 6 times (259µs+82µs) by Moose::Meta::TypeConstraint::compile_type_constraint at line 202 of Moose/Meta/TypeConstraint.pm, avg 57µs/call
sub _actually_compile_type_constraint {
64618µs my $self = shift;
65
66695µs682µs my @constraints = @{ $self->type_constraints };
# spent 82µs making 6 calls to Moose::Meta::TypeConstraint::Union::type_constraints, avg 14µs/call
67
68 return sub {
69 my $value = shift;
70 foreach my $type (@constraints) {
71 return 1 if $type->check($value);
72 }
73 return undef;
746141µs };
75}
76
77
78sub equals {
79 my ( $self, $type_or_name ) = @_;
80
81 my $other = Moose::Util::TypeConstraints::find_type_constraint($type_or_name);
82
83 return unless $other->isa(__PACKAGE__);
84
85 my @self_constraints = @{ $self->type_constraints };
86 my @other_constraints = @{ $other->type_constraints };
87
88 return unless @self_constraints == @other_constraints;
89
90 # FIXME presort type constraints for efficiency?
91 constraint: foreach my $constraint ( @self_constraints ) {
92 for ( my $i = 0; $i < @other_constraints; $i++ ) {
93 if ( $constraint->equals($other_constraints[$i]) ) {
94 splice @other_constraints, $i, 1;
95 next constraint;
96 }
97 }
98 }
99
100 return @other_constraints == 0;
101}
102
103sub parents {
104 my $self = shift;
105 $self->type_constraints;
106}
107
108sub validate {
109 my ($self, $value) = @_;
110 my $message;
111 foreach my $type (@{$self->type_constraints}) {
112 my $err = $type->validate($value);
113 return unless defined $err;
114 $message .= ($message ? ' and ' : '') . $err
115 if defined $err;
116 }
117 return ($message . ' in (' . $self->name . ')') ;
118}
119
120sub find_type_for {
121 my ($self, $value) = @_;
122
123 return first { $_->check($value) } @{ $self->type_constraints };
124}
125
126sub is_a_type_of {
127 my ($self, $type_name) = @_;
128 foreach my $type (@{$self->type_constraints}) {
129 return 1 if $type->is_a_type_of($type_name);
130 }
131 return 0;
132}
133
134sub is_subtype_of {
135 my ($self, $type_name) = @_;
136 foreach my $type (@{$self->type_constraints}) {
137 return 1 if $type->is_subtype_of($type_name);
138 }
139 return 0;
140}
141
142sub create_child_type {
143 my ( $self, %opts ) = @_;
144
145 my $constraint
146 = Moose::Meta::TypeConstraint->new( %opts, parent => $self );
147
148 # if we have a type constraint union, and no
149 # type check, this means we are just aliasing
150 # the union constraint, which means we need to
151 # handle this differently.
152 # - SL
153 if ( not( defined $opts{constraint} )
154 && $self->has_coercion ) {
155 $constraint->coercion(
156 Moose::Meta::TypeCoercion::Union->new(
157 type_constraint => $self,
158 )
159 );
160 }
161
162 return $constraint;
163}
164
165124µs1;
166
167__END__
 
# spent 42µs within Moose::Meta::TypeConstraint::Union::CORE:sort which was called 6 times, avg 7µs/call: # 6 times (42µs+0s) by Moose::Meta::TypeConstraint::Union::new at line 27, avg 7µs/call
sub Moose::Meta::TypeConstraint::Union::CORE:sort; # opcode