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

Filename/home/doy/perl5/perlbrew/perls/perl-5.10.1/lib/site_perl/5.10.1/x86_64-linux/Moose/Meta/TypeCoercion.pm
StatementsExecuted 22 statements in 2.78ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
11115.7ms353msMoose::Meta::TypeCoercion::::BEGIN@8Moose::Meta::TypeCoercion::BEGIN@8
11175µs93µsMoose::Meta::TypeCoercion::::BEGIN@4Moose::Meta::TypeCoercion::BEGIN@4
11144µs124µsMoose::Meta::TypeCoercion::::BEGIN@5Moose::Meta::TypeCoercion::BEGIN@5
11139µs3.39msMoose::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
43101µs2111µs
# spent 93µs (75+18) within Moose::Meta::TypeCoercion::BEGIN@4 which was called: # once (75µs+18µs) by Moose::BEGIN@21 at line 4
use strict;
# spent 93µs making 1 call to Moose::Meta::TypeCoercion::BEGIN@4 # spent 18µs making 1 call to strict::import
53107µs2205µs
# spent 124µs (44+81) within Moose::Meta::TypeCoercion::BEGIN@5 which was called: # once (44µs+81µs) by Moose::BEGIN@21 at line 5
use warnings;
# spent 124µs making 1 call to Moose::Meta::TypeCoercion::BEGIN@5 # spent 80µs making 1 call to warnings::import
63169µs26.75ms
# spent 3.39ms (39µs+3.36) within Moose::Meta::TypeCoercion::BEGIN@6 which was called: # once (39µs+3.36ms) by Moose::BEGIN@21 at line 6
use metaclass;
# spent 3.39ms making 1 call to Moose::Meta::TypeCoercion::BEGIN@6 # spent 3.36ms making 1 call to metaclass::import
7
83509µs1353ms
# spent 353ms (15.7+338) within Moose::Meta::TypeCoercion::BEGIN@8 which was called: # once (15.7ms+338ms) by Moose::BEGIN@21 at line 8
use Moose::Meta::Attribute;
# spent 353ms making 1 call to Moose::Meta::TypeCoercion::BEGIN@8
931.64ms124µ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';
12185µs$VERSION = eval $VERSION;
# spent 13µs executing statements in string eval
1315µsour $AUTHORITY = 'cpan:STEVAN';
14
15__PACKAGE__->meta->add_attribute('type_coercion_map' => (
16 reader => 'type_coercion_map',
17 default => sub { [] }
18141µs22.28ms));
# spent 2.14ms making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 137µs making 1 call to Moose::Meta::TypeCoercion::meta
19
20145µs319.6ms__PACKAGE__->meta->add_attribute(
# spent 13.0ms making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 6.51ms making 1 call to Moose::Meta::Attribute::new # spent 84µ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.17ms__PACKAGE__->meta->add_attribute('compiled_type_coercion' => (
# spent 2.09ms making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 81µ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__