Filename | /usr/local/lib/perl/5.14.2/Moose/Meta/TypeCoercion.pm |
Statements | Executed 45 statements in 724µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 5.32ms | 81.5ms | BEGIN@14 | Moose::Meta::TypeCoercion::
2 | 1 | 1 | 38µs | 109µs | compile_type_coercion | Moose::Meta::TypeCoercion::
2 | 1 | 1 | 18µs | 513µs | new | Moose::Meta::TypeCoercion::
1 | 1 | 1 | 8µs | 8µs | BEGIN@3 | Moose::Meta::TypeCoercion::
1 | 1 | 1 | 8µs | 13µs | BEGIN@11 | Moose::Meta::TypeCoercion::
1 | 1 | 1 | 7µs | 11µs | BEGIN@10 | Moose::Meta::TypeCoercion::
1 | 1 | 1 | 6µs | 465µs | BEGIN@12 | Moose::Meta::TypeCoercion::
1 | 1 | 1 | 5µs | 5µs | BEGIN@15 | Moose::Meta::TypeCoercion::
0 | 0 | 0 | 0s | 0s | __ANON__[:19] | Moose::Meta::TypeCoercion::
0 | 0 | 0 | 0s | 0s | __ANON__[:72] | Moose::Meta::TypeCoercion::
0 | 0 | 0 | 0s | 0s | add_type_coercions | Moose::Meta::TypeCoercion::
0 | 0 | 0 | 0s | 0s | coerce | Moose::Meta::TypeCoercion::
0 | 0 | 0 | 0s | 0s | has_coercion_for_type | Moose::Meta::TypeCoercion::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | |||||
2 | package Moose::Meta::TypeCoercion; | ||||
3 | # spent 8µs within Moose::Meta::TypeCoercion::BEGIN@3 which was called:
# once (8µs+0s) by Moose::BEGIN@29 at line 5 | ||||
4 | 1 | 5µs | $Moose::Meta::TypeCoercion::AUTHORITY = 'cpan:STEVAN'; | ||
5 | 1 | 30µs | 1 | 8µs | } # spent 8µs making 1 call to Moose::Meta::TypeCoercion::BEGIN@3 |
6 | { | ||||
7 | 2 | 800ns | $Moose::Meta::TypeCoercion::VERSION = '2.1005'; | ||
8 | } | ||||
9 | |||||
10 | 2 | 30µs | 2 | 14µs | # spent 11µs (7+3) within Moose::Meta::TypeCoercion::BEGIN@10 which was called:
# once (7µs+3µs) by Moose::BEGIN@29 at line 10 # spent 11µs making 1 call to Moose::Meta::TypeCoercion::BEGIN@10
# spent 3µs making 1 call to strict::import |
11 | 2 | 22µs | 2 | 18µs | # spent 13µs (8+5) within Moose::Meta::TypeCoercion::BEGIN@11 which was called:
# once (8µs+5µs) by Moose::BEGIN@29 at line 11 # spent 13µs making 1 call to Moose::Meta::TypeCoercion::BEGIN@11
# spent 5µs making 1 call to warnings::import |
12 | 2 | 29µs | 2 | 925µs | # spent 465µs (6+459) within Moose::Meta::TypeCoercion::BEGIN@12 which was called:
# once (6µs+459µs) by Moose::BEGIN@29 at line 12 # spent 465µs making 1 call to Moose::Meta::TypeCoercion::BEGIN@12
# spent 459µs making 1 call to metaclass::import |
13 | |||||
14 | 2 | 104µs | 1 | 81.5ms | # spent 81.5ms (5.32+76.1) within Moose::Meta::TypeCoercion::BEGIN@14 which was called:
# once (5.32ms+76.1ms) by Moose::BEGIN@29 at line 14 # spent 81.5ms making 1 call to Moose::Meta::TypeCoercion::BEGIN@14 |
15 | 2 | 432µs | 1 | 5µs | # spent 5µs within Moose::Meta::TypeCoercion::BEGIN@15 which was called:
# once (5µs+0s) by Moose::BEGIN@29 at line 15 # spent 5µs making 1 call to Moose::Meta::TypeCoercion::BEGIN@15 |
16 | |||||
17 | __PACKAGE__->meta->add_attribute('type_coercion_map' => ( | ||||
18 | reader => 'type_coercion_map', | ||||
19 | default => sub { [] }, | ||||
20 | 1 | 7µs | 3 | 354µs | Class::MOP::_definition_context(), # spent 328µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 20µs making 1 call to Moose::Meta::TypeCoercion::meta
# spent 6µs making 1 call to Class::MOP::_definition_context |
21 | )); | ||||
22 | |||||
23 | 1 | 6µs | 4 | 3.09ms | __PACKAGE__->meta->add_attribute( # spent 2.23ms making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 849µs making 1 call to Moose::Meta::Attribute::new
# spent 11µs making 1 call to Moose::Meta::TypeCoercion::meta
# spent 6µs making 1 call to Class::MOP::_definition_context |
24 | Moose::Meta::Attribute->new('type_constraint' => ( | ||||
25 | reader => 'type_constraint', | ||||
26 | weak_ref => 1, | ||||
27 | Class::MOP::_definition_context(), | ||||
28 | )) | ||||
29 | ); | ||||
30 | |||||
31 | # private accessor | ||||
32 | 1 | 4µs | 3 | 320µs | __PACKAGE__->meta->add_attribute('compiled_type_coercion' => ( # spent 304µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 10µs making 1 call to Moose::Meta::TypeCoercion::meta
# spent 6µs making 1 call to Class::MOP::_definition_context |
33 | accessor => '_compiled_type_coercion', | ||||
34 | Class::MOP::_definition_context(), | ||||
35 | )); | ||||
36 | |||||
37 | # spent 513µs (18+495) within Moose::Meta::TypeCoercion::new which was called 2 times, avg 256µs/call:
# 2 times (18µs+495µs) by Moose::Util::TypeConstraints::_install_type_coercions at line 594 of Moose/Util/TypeConstraints.pm, avg 256µs/call | ||||
38 | 8 | 14µs | my $class = shift; | ||
39 | 4 | 386µs | my $self = Class::MOP::class_of($class)->new_object(@_); # spent 378µs making 2 calls to Class::MOP::Class::new_object, avg 189µs/call
# spent 8µs making 2 calls to Class::MOP::class_of, avg 4µs/call | ||
40 | 2 | 109µs | $self->compile_type_coercion; # spent 109µs making 2 calls to Moose::Meta::TypeCoercion::compile_type_coercion, avg 54µs/call | ||
41 | return $self; | ||||
42 | } | ||||
43 | |||||
44 | # spent 109µs (38+71) within Moose::Meta::TypeCoercion::compile_type_coercion which was called 2 times, avg 54µs/call:
# 2 times (38µs+71µs) by Moose::Meta::TypeCoercion::new at line 40, avg 54µs/call | ||||
45 | 10 | 18µs | my $self = shift; | ||
46 | 2 | 3µs | 2 | 6µs | my @coercion_map = @{$self->type_coercion_map}; # spent 6µs making 2 calls to Moose::Meta::TypeCoercion::type_coercion_map, avg 3µs/call |
47 | my @coercions; | ||||
48 | while (@coercion_map) { | ||||
49 | 8 | 10µs | my ($constraint_name, $action) = splice(@coercion_map, 0, 2); | ||
50 | 2 | 57µs | my $type_constraint = ref $constraint_name ? $constraint_name : Moose::Util::TypeConstraints::find_or_parse_type_constraint($constraint_name); # spent 57µs making 2 calls to Moose::Util::TypeConstraints::find_or_parse_type_constraint, avg 28µs/call | ||
51 | |||||
52 | unless ( defined $type_constraint ) { | ||||
53 | require Moose; | ||||
54 | Moose->throw_error("Could not find the type constraint ($constraint_name) to coerce from"); | ||||
55 | } | ||||
56 | |||||
57 | 2 | 3µs | push @coercions => [ # spent 3µs making 2 calls to Moose::Meta::TypeConstraint::_compiled_type_constraint, avg 1µs/call | ||
58 | $type_constraint->_compiled_type_constraint, | ||||
59 | $action | ||||
60 | ]; | ||||
61 | } | ||||
62 | $self->_compiled_type_coercion(sub { | ||||
63 | my $thing = shift; | ||||
64 | foreach my $coercion (@coercions) { | ||||
65 | my ($constraint, $converter) = @$coercion; | ||||
66 | if ($constraint->($thing)) { | ||||
67 | local $_ = $thing; | ||||
68 | return $converter->($thing); | ||||
69 | } | ||||
70 | } | ||||
71 | return $thing; | ||||
72 | 2 | 5µs | }); # spent 5µs making 2 calls to Moose::Meta::TypeCoercion::_compiled_type_coercion, avg 3µs/call | ||
73 | } | ||||
74 | |||||
75 | sub has_coercion_for_type { | ||||
76 | my ($self, $type_name) = @_; | ||||
77 | my %coercion_map = @{$self->type_coercion_map}; | ||||
78 | exists $coercion_map{$type_name} ? 1 : 0; | ||||
79 | } | ||||
80 | |||||
81 | sub add_type_coercions { | ||||
82 | my ($self, @new_coercion_map) = @_; | ||||
83 | |||||
84 | my $coercion_map = $self->type_coercion_map; | ||||
85 | my %has_coercion = @$coercion_map; | ||||
86 | |||||
87 | while (@new_coercion_map) { | ||||
88 | my ($constraint_name, $action) = splice(@new_coercion_map, 0, 2); | ||||
89 | |||||
90 | if ( exists $has_coercion{$constraint_name} ) { | ||||
91 | require Moose; | ||||
92 | Moose->throw_error("A coercion action already exists for '$constraint_name'") | ||||
93 | } | ||||
94 | |||||
95 | push @{$coercion_map} => ($constraint_name, $action); | ||||
96 | } | ||||
97 | |||||
98 | # and re-compile ... | ||||
99 | $self->compile_type_coercion; | ||||
100 | } | ||||
101 | |||||
102 | sub coerce { $_[0]->_compiled_type_coercion->($_[1]) } | ||||
103 | |||||
104 | |||||
105 | 1 | 9µs | 1; | ||
106 | |||||
107 | # ABSTRACT: The Moose Type Coercion metaclass | ||||
108 | |||||
109 | __END__ |