Profile of /usr/local/lib/perl5/site_perl/5.10.1/darwin-2level/Moose/Meta/TypeCoercion.pm

← Index
NYTProf Performance Profile «block view•line view•sub view»
For 05.Domain_and_Item.t
Run on Tue May 4 17:21:41 2010
Reported on Tue May 4 17:22:26 2010

File | /usr/local/lib/perl5/site_perl/5.10.1/darwin-2level/Moose/Meta/TypeCoercion.pm
Statements Executed | 1119
Statement Execution Time | 2.41ms

Subroutines — ordered by exclusive time
Calls | P | F | Exclusive Time | Inclusive Time | Subroutine
--- | --- | --- | --- | --- | ---
1 | 1 | 1 | 3.08ms | 56.6ms | Moose::Meta::TypeCoercion::::BEGIN@8Moose::Meta::TypeCoercion::BEGIN@8
94 | 1 | 1 | 1.37ms | 44.0ms | Moose::Meta::TypeCoercion::::__ANON__[:67]Moose::Meta::TypeCoercion::__ANON__[:67]
94 | 1 | 1 | 601µs | 44.2ms | Moose::Meta::TypeCoercion::::coerceMoose::Meta::TypeCoercion::coerce
10 | 1 | 1 | 270µs | 815µs | Moose::Meta::TypeCoercion::::compile_type_coercionMoose::Meta::TypeCoercion::compile_type_coercion
11 | 2 | 2 | 99µs | 3.08ms | Moose::Meta::TypeCoercion::::newMoose::Meta::TypeCoercion::new
1 | 1 | 1 | 14µs | 17µs | Moose::Meta::TypeCoercion::::BEGIN@4Moose::Meta::TypeCoercion::BEGIN@4
1 | 1 | 1 | 7µs | 15µs | Moose::Meta::TypeCoercion::::BEGIN@5Moose::Meta::TypeCoercion::BEGIN@5
1 | 1 | 1 | 6µs | 116µs | Moose::Meta::TypeCoercion::::BEGIN@6Moose::Meta::TypeCoercion::BEGIN@6
1 | 1 | 1 | 5µs | 5µs | Moose::Meta::TypeCoercion::::BEGIN@9Moose::Meta::TypeCoercion::BEGIN@9
1 | 1 | 1 | 3µs | 3µs | Moose::Meta::TypeCoercion::::__ANON__[:17]Moose::Meta::TypeCoercion::__ANON__[:17]
0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeCoercion::::add_type_coercionsMoose::Meta::TypeCoercion::add_type_coercions
0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeCoercion::::has_coercion_for_typeMoose::Meta::TypeCoercion::has_coercion_for_type

Call graph for these subroutines as a Graphviz dot language file.

Line | State ments | Time on line | Calls | Time in subs | Code
--- | --- | --- | --- | --- | ---
1 |  |  |  |  |
2 |  |  |  |  | package Moose::Meta::TypeCoercion;
3 |  |  |  |  |
4 | 3 | 20µs | 2 | 20µs | # spent 17µs (14+3) within Moose::Meta::TypeCoercion::BEGIN@4 which was called # once (14µs+3µs) by Moose::BEGIN@20 at line 4 use strict; # spent 17µs making 1 call to Moose::Meta::TypeCoercion::BEGIN@4 # spent 3µs making 1 call to strict::import
5 | 3 | 18µs | 2 | 24µs | # spent 15µs (7+9) within Moose::Meta::TypeCoercion::BEGIN@5 which was called # once (7µs+9µs) by Moose::BEGIN@20 at line 5 use warnings; # spent 15µs making 1 call to Moose::Meta::TypeCoercion::BEGIN@5 # spent 9µs making 1 call to warnings::import
6 | 3 | 26µs | 2 | 226µs | # spent 116µs (6+110) within Moose::Meta::TypeCoercion::BEGIN@6 which was called # once (6µs+110µs) by Moose::BEGIN@20 at line 6 use metaclass; # spent 116µs making 1 call to Moose::Meta::TypeCoercion::BEGIN@6 # spent 110µs making 1 call to metaclass::import
7 |  |  |  |  |
8 | 3 | 144µs | 1 | 56.6ms | # spent 56.6ms (3.08+53.5) within Moose::Meta::TypeCoercion::BEGIN@8 which was called # once (3.08ms+53.5ms) by Moose::BEGIN@20 at line 8 use Moose::Meta::Attribute; # spent 56.6ms making 1 call to Moose::Meta::TypeCoercion::BEGIN@8
9 | 3 | 393µs | 1 | 5µs | # spent 5µs within Moose::Meta::TypeCoercion::BEGIN@9 which was called # once (5µs+0s) by Moose::BEGIN@20 at line 9 use Moose::Util::TypeConstraints (); # spent 5µs making 1 call to Moose::Meta::TypeCoercion::BEGIN@9
10 |  |  |  |  |
11 | 1 | 500ns |  |  | our $VERSION = '0.98';
12 | 1 | 20µs |  |  | $VERSION = eval $VERSION;
13 | 1 | 400ns |  |  | our $AUTHORITY = 'cpan:STEVAN';
14 |  |  |  |  |
15 |  |  |  |  | __PACKAGE__->meta->add_attribute('type_coercion_map' => (
16 |  |  |  |  | reader => 'type_coercion_map',
17 | 1 | 5µs |  |  | # spent 3µs within Moose::Meta::TypeCoercion::__ANON__[/usr/local/lib/perl5/site_perl/5.10.1/darwin-2level/Moose/Meta/TypeCoercion.pm:17] which was called # once (3µs+0s) by Class::MOP::Mixin::AttributeCore::default at line 53 of Class/MOP/Mixin/AttributeCore.pm default => sub { [] }
18 | 1 | 6µs | 2 | 293µs | )); # spent 272µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 21µs making 1 call to Moose::Meta::TypeCoercion::meta
19 |  |  |  |  |
20 | 1 | 6µs | 3 | 2.50ms | __PACKAGE__->meta->add_attribute( # spent 1.55ms making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 940µs making 1 call to Moose::Meta::Attribute::new # spent 11µs making 1 call to Moose::Meta::TypeCoercion::meta
21 |  |  |  |  | Moose::Meta::Attribute->new('type_constraint' => (
22 |  |  |  |  | reader => 'type_constraint',
23 |  |  |  |  | weak_ref => 1
24 |  |  |  |  | ))
25 |  |  |  |  | );
26 |  |  |  |  |
27 |  |  |  |  | # private accessor
28 | 1 | 3µs | 2 | 285µs | __PACKAGE__->meta->add_attribute('compiled_type_coercion' => ( # spent 275µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 11µs making 1 call to Moose::Meta::TypeCoercion::meta
29 |  |  |  |  | accessor => '_compiled_type_coercion'
30 |  |  |  |  | ));
31 |  |  |  |  |
32 |  |  |  |  | # spent 3.08ms (99µs+2.98) within Moose::Meta::TypeCoercion::new which was called 11 times, avg 280µs/call: # 10 times (84µs+2.58ms) by Moose::Util::TypeConstraints::_install_type_coercions at line 552 of Moose/Util/TypeConstraints.pm, avg 267µs/call # once (15µs+399µs) by Moose::Meta::TypeConstraint::Union::new at line 33 of Moose/Meta/TypeConstraint/Union.pm sub new {
33 | 44 | 77µs |  |  | my $class = shift;
34 |  |  |  |  | my $self = Class::MOP::class_of($class)->new_object(@_); # spent 2.07ms making 11 calls to Class::MOP::Class::new_object, avg 188µs/call # spent 50µs making 11 calls to Class::MOP::class_of, avg 5µs/call
35 |  |  |  |  | $self->compile_type_coercion; # spent 815µs making 10 calls to Moose::Meta::TypeCoercion::compile_type_coercion, avg 81µs/call # spent 47µs making 1 call to Moose::Meta::TypeCoercion::Union::compile_type_coercion
36 |  |  |  |  | return $self;
37 |  |  |  |  | }
38 |  |  |  |  |
39 |  |  |  |  | # spent 815µs (270+545) within Moose::Meta::TypeCoercion::compile_type_coercion which was called 10 times, avg 81µs/call: # 10 times (270µs+545µs) by Moose::Meta::TypeCoercion::new at line 35, avg 81µs/call sub compile_type_coercion {
40 | 50 | 88µs |  |  | my $self = shift;
41 |  |  |  |  | my @coercion_map = @{$self->type_coercion_map}; # spent 16µs making 10 calls to Moose::Meta::TypeCoercion::type_coercion_map, avg 2µs/call
42 |  |  |  |  | my @coercions;
43 |  |  |  |  | while (@coercion_map) {
44 | 116 | 128µs |  |  | my ($constraint_name, $action) = splice(@coercion_map, 0, 2);
45 |  |  |  |  | my $type_constraint = ref $constraint_name ? $constraint_name : Moose::Util::TypeConstraints::find_or_parse_type_constraint($constraint_name);
46 |  |  |  |  |
47 |  |  |  |  | unless ( defined $type_constraint ) {
48 |  |  |  |  | require Moose;
49 |  |  |  |  | Moose->throw_error("Could not find the type constraint ($constraint_name) to coerce from");
50 |  |  |  |  | }
51 |  |  |  |  |
52 |  |  |  |  | push @coercions => [ # spent 503µs making 29 calls to MooseX::Types::TypeDecorator::AUTOLOAD, avg 17µs/call
53 |  |  |  |  | $type_constraint->_compiled_type_constraint,
54 |  |  |  |  | $action
55 |  |  |  |  | ];
56 |  |  |  |  | }
57 |  |  |  |  | # spent 44.0ms (1.37+42.6) within Moose::Meta::TypeCoercion::__ANON__[/usr/local/lib/perl5/site_perl/5.10.1/darwin-2level/Moose/Meta/TypeCoercion.pm:67] which was called 94 times, avg 468µs/call: # 94 times (1.37ms+42.6ms) by Moose::Meta::TypeCoercion::coerce at line 97, avg 468µs/call $self->_compiled_type_coercion(sub {
58 | 188 | 107µs |  |  | my $thing = shift;
59 |  |  |  |  | foreach my $coercion (@coercions) {
60 | 416 | 393µs |  |  | my ($constraint, $converter) = @$coercion;
61 | 188 | 459µs | 208 | 2.62ms | if ($constraint->($thing)) { # spent 1.10ms making 42 calls to SimpleDB::Class::Types::SdbArrayRefOfStr, avg 26µs/call # spent 422µs making 36 calls to SimpleDB::Class::Types::SdbArrayRefOfDateTime, avg 12µs/call # spent 320µs making 39 calls to SimpleDB::Class::Types::SdbStr, avg 8µs/call # spent 288µs making 14 calls to SimpleDB::Class::Types::SdbInt, avg 21µs/call # spent 222µs making 36 calls to SimpleDB::Class::Types::SdbMediumStr, avg 6µs/call # spent 154µs making 28 calls to Moose::Meta::TypeConstraint::Class::__ANON__[Moose/Meta/TypeConstraint/Class.pm:38], avg 5µs/call # spent 96µs making 5 calls to Moose::Meta::TypeConstraint::Undef, avg 19µs/call # spent 11µs making 8 calls to Moose::Util::TypeConstraints::OptimizedConstraints::HashRef, avg 1µs/call
62 |  |  |  |  | local $_ = $thing;
63 |  |  |  |  | return $converter->($thing); # spent 28.8ms making 5 calls to SimpleDB::Class::Types::__ANON__[../lib/SimpleDB/Class/Types.pm:186], avg 5.75ms/call # spent 28.2ms making 5 calls to SimpleDB::Class::Types::__ANON__[../lib/SimpleDB/Class/Types.pm:185], avg 5.63ms/call # spent 6.95ms making 9 calls to SimpleDB::Class::Types::__ANON__[../lib/SimpleDB/Class/Types.pm:205], avg 772µs/call # spent 1.68ms making 8 calls to SimpleDB::Class::Types::__ANON__[../lib/SimpleDB/Class/Types.pm:152], avg 210µs/call # spent 1.25ms making 5 calls to SimpleDB::Class::Types::__ANON__[../lib/SimpleDB/Class/Types.pm:221], avg 250µs/call # spent 648µs making 5 calls to SimpleDB::Class::Types::__ANON__[../lib/SimpleDB/Class/Types.pm:206], avg 130µs/call # spent 544µs making 8 calls to SimpleDB::Class::Types::__ANON__[../lib/SimpleDB/Class/Types.pm:165], avg 68µs/call # spent 184µs making 7 calls to SimpleDB::Class::Types::__ANON__[../lib/SimpleDB/Class/Types.pm:170], avg 26µs/call # spent 86µs making 8 calls to SimpleDB::Class::Types::__ANON__[../lib/SimpleDB/Class/Types.pm:163], avg 11µs/call # spent 76µs making 14 calls to SimpleDB::Class::Types::__ANON__[../lib/SimpleDB/Class/Types.pm:159], avg 5µs/call # spent 33µs making 20 calls to SimpleDB::Class::Types::__ANON__[../lib/SimpleDB/Class/Types.pm:155], avg 2µs/call
64 |  |  |  |  | }
65 |  |  |  |  | }
66 |  |  |  |  | return $thing;
67 |  |  |  |  | }); # spent 26µs making 10 calls to Moose::Meta::TypeCoercion::_compiled_type_coercion, avg 3µs/call
68 |  |  |  |  | }
69 |  |  |  |  |
70 |  |  |  |  | sub has_coercion_for_type {
71 |  |  |  |  | my ($self, $type_name) = @_;
72 |  |  |  |  | my %coercion_map = @{$self->type_coercion_map};
73 |  |  |  |  | exists $coercion_map{$type_name} ? 1 : 0;
74 |  |  |  |  | }
75 |  |  |  |  |
76 |  |  |  |  | sub add_type_coercions {
77 |  |  |  |  | my ($self, @new_coercion_map) = @_;
78 |  |  |  |  |
79 |  |  |  |  | my $coercion_map = $self->type_coercion_map;
80 |  |  |  |  | my %has_coercion = @$coercion_map;
81 |  |  |  |  |
82 |  |  |  |  | while (@new_coercion_map) {
83 |  |  |  |  | my ($constraint_name, $action) = splice(@new_coercion_map, 0, 2);
84 |  |  |  |  |
85 |  |  |  |  | if ( exists $has_coercion{$constraint_name} ) {
86 |  |  |  |  | require Moose;
87 |  |  |  |  | Moose->throw_error("A coercion action already exists for '$constraint_name'")
88 |  |  |  |  | }
89 |  |  |  |  |
90 |  |  |  |  | push @{$coercion_map} => ($constraint_name, $action);
91 |  |  |  |  | }
92 |  |  |  |  |
93 |  |  |  |  | # and re-compile ...
94 |  |  |  |  | $self->compile_type_coercion;
95 |  |  |  |  | }
96 |  |  |  |  |
97 | 94 | 503µs | 188 | 44.2ms | # spent 44.2ms (601µs+43.6) within Moose::Meta::TypeCoercion::coerce which was called 94 times, avg 471µs/call: # 94 times (601µs+43.6ms) by Moose::Meta::TypeConstraint::coerce at line 88 of Moose/Meta/TypeConstraint.pm, avg 471µs/call sub coerce { $_[0]->_compiled_type_coercion->($_[1]) } # spent 72.4ms making 94 calls to Moose::Meta::TypeCoercion::__ANON__[Moose/Meta/TypeCoercion.pm:67], avg 770µs/call, recursion: max depth 1, time 28.4ms # spent 204µs making 94 calls to Moose::Meta::TypeCoercion::_compiled_type_coercion, avg 2µs/call
98 |  |  |  |  |
99 |  |  |  |  |
100 | 1 | 13µs |  |  | 1;
101 |  |  |  |  |
102 |  |  |  |  | __END__
103 |  |  |  |  |
104 |  |  |  |  | =pod
105 |  |  |  |  |
106 |  |  |  |  | =head1 NAME
107 |  |  |  |  |
108 |  |  |  |  | Moose::Meta::TypeCoercion - The Moose Type Coercion metaclass
109 |  |  |  |  |
110 |  |  |  |  | =head1 DESCRIPTION
111 |  |  |  |  |
112 |  |  |  |  | A type coercion object is basically a mapping of one or more type
113 |  |  |  |  | constraints and the associated coercions subroutines.
114 |  |  |  |  |
115 |  |  |  |  | It's unlikely that you will need to instantiate an object of this
116 |  |  |  |  | class directly, as it's part of the deep internals of Moose.
117 |  |  |  |  |
118 |  |  |  |  | =head1 METHODS
119 |  |  |  |  |
120 |  |  |  |  | =over 4
121 |  |  |  |  |
122 |  |  |  |  | =item B<< Moose::Meta::TypeCoercion->new(%options) >>
123 |  |  |  |  |
124 |  |  |  |  | Creates a new type coercion object, based on the options provided.
125 |  |  |  |  |
126 |  |  |  |  | =over 8
127 |  |  |  |  |
128 |  |  |  |  | =item * type_constraint
129 |  |  |  |  |
130 |  |  |  |  | This is the L<Moose::Meta::TypeConstraint> object for the type that is
131 |  |  |  |  | being coerced I<to>.
132 |  |  |  |  |
133 |  |  |  |  | =back
134 |  |  |  |  |
135 |  |  |  |  | =item B<< $coercion->type_coercion_map >>
136 |  |  |  |  |
137 |  |  |  |  | This returns the map of type constraints to coercions as an array
138 |  |  |  |  | reference. The values of the array alternate between type names and
139 |  |  |  |  | subroutine references which implement the coercion.
140 |  |  |  |  |
141 |  |  |  |  | The value is an array reference because coercions are tried in the
142 |  |  |  |  | order they are added.
143 |  |  |  |  |
144 |  |  |  |  | =item B<< $coercion->type_constraint >>
145 |  |  |  |  |
146 |  |  |  |  | This returns the L<Moose::Meta::TypeConstraint> that was passed to the
147 |  |  |  |  | constructor.
148 |  |  |  |  |
149 |  |  |  |  | =item B<< $coercion->has_coercion_for_type($type_name) >>
150 |  |  |  |  |
151 |  |  |  |  | Returns true if the coercion can coerce the named type.
152 |  |  |  |  |
153 |  |  |  |  | =item B<< $coercion->add_type_coercions( $type_name => $sub, ... ) >>
154 |  |  |  |  |
155 |  |  |  |  | This method takes a list of type names and subroutine references. If
156 |  |  |  |  | the coercion already has a mapping for a given type, it throws an
157 |  |  |  |  | exception.
158 |  |  |  |  |
159 |  |  |  |  | Coercions are actually
160 |  |  |  |  |
161 |  |  |  |  | =item B<< $coercion->coerce($value) >>
162 |  |  |  |  |
163 |  |  |  |  | This method takes a value and applies the first valid coercion it
164 |  |  |  |  | finds.
165 |  |  |  |  |
166 |  |  |  |  | This means that if the value could belong to more than type in the
167 |  |  |  |  | coercion object, the first coercion added is used.
168 |  |  |  |  |
169 |  |  |  |  | =item B<< Moose::Meta::TypeCoercion->meta >>
170 |  |  |  |  |
171 |  |  |  |  | This will return a L<Class::MOP::Class> instance for this class.
172 |  |  |  |  |
173 |  |  |  |  | =back
174 |  |  |  |  |
175 |  |  |  |  | =head1 BUGS
176 |  |  |  |  |
177 |  |  |  |  | See L<Moose/BUGS> for details on reporting bugs.
178 |  |  |  |  |
179 |  |  |  |  | =head1 AUTHOR
180 |  |  |  |  |
181 |  |  |  |  | Stevan Little E<lt>stevan@iinteractive.comE<gt>
182 |  |  |  |  |
183 |  |  |  |  | =head1 COPYRIGHT AND LICENSE
184 |  |  |  |  |
185 |  |  |  |  | Copyright 2006-2010 by Infinity Interactive, Inc.
186 |  |  |  |  |
187 |  |  |  |  | L<http://www.iinteractive.com>
188 |  |  |  |  |
189 |  |  |  |  | This library is free software; you can redistribute it and/or modify
190 |  |  |  |  | it under the same terms as Perl itself.
191 |  |  |  |  |
192 |  |  |  |  | =cut