← Index
NYTProf Performance Profile   « block view • line view • sub view »
For -e
  Run on Wed Nov 17 22:00:36 2010
Reported on Wed Nov 17 22:13:22 2010

Filename/home/doy/coding/src/Moose/blib/lib//Moose/Meta/TypeCoercion.pm
StatementsExecuted 22 statements in 2.94ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
11120.2ms396msMoose::Meta::TypeCoercion::::BEGIN@8Moose::Meta::TypeCoercion::BEGIN@8
111105µs131µsMoose::Meta::TypeCoercion::::BEGIN@4Moose::Meta::TypeCoercion::BEGIN@4
11158µs143µsMoose::Meta::TypeCoercion::::BEGIN@5Moose::Meta::TypeCoercion::BEGIN@5
11140µs3.00msMoose::Meta::TypeCoercion::::BEGIN@6Moose::Meta::TypeCoercion::BEGIN@6
11124µs24µsMoose::Meta::TypeCoercion::::BEGIN@9Moose::Meta::TypeCoercion::BEGIN@9
0000s0sMoose::Meta::TypeCoercion::::__ANON__[:17]Moose::Meta::TypeCoercion::__ANON__[:17]
0000s0sMoose::Meta::TypeCoercion::::__ANON__[:67]Moose::Meta::TypeCoercion::__ANON__[:67]
0000s0sMoose::Meta::TypeCoercion::::add_type_coercionsMoose::Meta::TypeCoercion::add_type_coercions
0000s0sMoose::Meta::TypeCoercion::::coerceMoose::Meta::TypeCoercion::coerce
0000s0sMoose::Meta::TypeCoercion::::compile_type_coercionMoose::Meta::TypeCoercion::compile_type_coercion
0000s0sMoose::Meta::TypeCoercion::::has_coercion_for_typeMoose::Meta::TypeCoercion::has_coercion_for_type
0000s0sMoose::Meta::TypeCoercion::::newMoose::Meta::TypeCoercion::new
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::TypeCoercion;
3
43142µs2156µs
# spent 131µs (105+25) within Moose::Meta::TypeCoercion::BEGIN@4 which was called: # once (105µs+25µs) by Moose::BEGIN@21 at line 4
use strict;
# spent 131µs making 1 call to Moose::Meta::TypeCoercion::BEGIN@4 # spent 25µs making 1 call to strict::import
53131µs2227µs
# spent 143µs (58+85) within Moose::Meta::TypeCoercion::BEGIN@5 which was called: # once (58µs+85µs) by Moose::BEGIN@21 at line 5
use warnings;
# spent 143µs making 1 call to Moose::Meta::TypeCoercion::BEGIN@5 # spent 85µs making 1 call to warnings::import
63136µs25.96ms
# spent 3.00ms (40µs+2.96) within Moose::Meta::TypeCoercion::BEGIN@6 which was called: # once (40µs+2.96ms) by Moose::BEGIN@21 at line 6
use metaclass;
# spent 3.00ms making 1 call to Moose::Meta::TypeCoercion::BEGIN@6 # spent 2.96ms making 1 call to metaclass::import
7
83571µs1396ms
# spent 396ms (20.2+376) within Moose::Meta::TypeCoercion::BEGIN@8 which was called: # once (20.2ms+376ms) by Moose::BEGIN@21 at line 8
use Moose::Meta::Attribute;
# spent 396ms making 1 call to Moose::Meta::TypeCoercion::BEGIN@8
931.73ms124µs
# spent 24µs within Moose::Meta::TypeCoercion::BEGIN@9 which was called: # once (24µs+0s) by Moose::BEGIN@21 at line 9
use Moose::Util::TypeConstraints ();
# spent 24µs making 1 call to Moose::Meta::TypeCoercion::BEGIN@9
10
1114µsour $VERSION = '1.19';
12163µs$VERSION = eval $VERSION;
# spent 10µs executing statements in string eval
1314µsour $AUTHORITY = 'cpan:STEVAN';
14
15__PACKAGE__->meta->add_attribute('type_coercion_map' => (
16 reader => 'type_coercion_map',
17 default => sub { [] }
18134µs22.16ms));
# spent 2.03ms making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 132µs making 1 call to Moose::Meta::TypeCoercion::meta
19
20146µs319.3ms__PACKAGE__->meta->add_attribute(
# spent 12.9ms making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 6.26ms making 1 call to Moose::Meta::Attribute::new # spent 86µ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
28125µs22.05ms__PACKAGE__->meta->add_attribute('compiled_type_coercion' => (
# spent 1.97ms making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 79µs making 1 call to Moose::Meta::TypeCoercion::meta
29 accessor => '_compiled_type_coercion'
30));
31
32sub new {
33 my $class = shift;
34 my $self = Class::MOP::class_of($class)->new_object(@_);
35 $self->compile_type_coercion;
36 return $self;
37}
38
39sub compile_type_coercion {
40 my $self = shift;
41 my @coercion_map = @{$self->type_coercion_map};
42 my @coercions;
43 while (@coercion_map) {
44 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 => [
53 $type_constraint->_compiled_type_constraint,
54 $action
55 ];
56 }
57 $self->_compiled_type_coercion(sub {
58 my $thing = shift;
59 foreach my $coercion (@coercions) {
60 my ($constraint, $converter) = @$coercion;
61 if ($constraint->($thing)) {
62 local $_ = $thing;
63 return $converter->($thing);
64 }
65 }
66 return $thing;
67 });
68}
69
70sub 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
76sub 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
97sub coerce { $_[0]->_compiled_type_coercion->($_[1]) }
98
99
100146µs1;
101
102__END__