| Filename | /usr/local/lib/perl/5.18.2/Moose/Meta/TypeCoercion.pm |
| Statements | Executed 36 statements in 666µs |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1 | 1 | 1 | 4.52ms | 96.6ms | Moose::Meta::TypeCoercion::BEGIN@8 |
| 1 | 1 | 1 | 24µs | 58µs | Moose::Meta::TypeCoercion::compile_type_coercion |
| 1 | 1 | 1 | 12µs | 57µs | Moose::Meta::TypeCoercion::__ANON__[:69] |
| 1 | 1 | 1 | 12µs | 335µs | Moose::Meta::TypeCoercion::new |
| 1 | 1 | 1 | 11µs | 25µs | Moose::Meta::TypeCoercion::BEGIN@4 |
| 1 | 1 | 1 | 10µs | 177µs | Moose::Meta::TypeCoercion::BEGIN@11 |
| 1 | 1 | 1 | 8µs | 13µs | Moose::Meta::TypeCoercion::BEGIN@5 |
| 1 | 1 | 1 | 6µs | 433µs | Moose::Meta::TypeCoercion::BEGIN@6 |
| 1 | 1 | 1 | 5µs | 5µs | Moose::Meta::TypeCoercion::BEGIN@9 |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeCoercion::__ANON__[:15] |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeCoercion::add_type_coercions |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeCoercion::coerce |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::TypeCoercion::has_coercion_for_type |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package Moose::Meta::TypeCoercion; | ||||
| 2 | 1 | 2µs | our $VERSION = '2.1604'; | ||
| 3 | |||||
| 4 | 2 | 22µs | 2 | 38µs | # spent 25µs (11+14) within Moose::Meta::TypeCoercion::BEGIN@4 which was called:
# once (11µs+14µs) by Moose::BEGIN@26 at line 4 # spent 25µs making 1 call to Moose::Meta::TypeCoercion::BEGIN@4
# spent 14µs making 1 call to strict::import |
| 5 | 2 | 20µs | 2 | 19µs | # spent 13µs (8+6) within Moose::Meta::TypeCoercion::BEGIN@5 which was called:
# once (8µs+6µs) by Moose::BEGIN@26 at line 5 # spent 13µs making 1 call to Moose::Meta::TypeCoercion::BEGIN@5
# spent 6µs making 1 call to warnings::import |
| 6 | 2 | 25µs | 2 | 860µs | # spent 433µs (6+427) within Moose::Meta::TypeCoercion::BEGIN@6 which was called:
# once (6µs+427µs) by Moose::BEGIN@26 at line 6 # spent 433µs making 1 call to Moose::Meta::TypeCoercion::BEGIN@6
# spent 427µs making 1 call to metaclass::import |
| 7 | |||||
| 8 | 2 | 98µs | 1 | 96.6ms | # spent 96.6ms (4.52+92.0) within Moose::Meta::TypeCoercion::BEGIN@8 which was called:
# once (4.52ms+92.0ms) by Moose::BEGIN@26 at line 8 # spent 96.6ms making 1 call to Moose::Meta::TypeCoercion::BEGIN@8 |
| 9 | 2 | 24µs | 1 | 5µs | # spent 5µs within Moose::Meta::TypeCoercion::BEGIN@9 which was called:
# once (5µs+0s) by Moose::BEGIN@26 at line 9 # spent 5µs making 1 call to Moose::Meta::TypeCoercion::BEGIN@9 |
| 10 | |||||
| 11 | 2 | 403µs | 2 | 345µs | # spent 177µs (10+167) within Moose::Meta::TypeCoercion::BEGIN@11 which was called:
# once (10µs+167µs) by Moose::BEGIN@26 at line 11 # spent 177µs making 1 call to Moose::Meta::TypeCoercion::BEGIN@11
# spent 167µs making 1 call to Sub::Exporter::__ANON__[Sub/Exporter.pm:337] |
| 12 | |||||
| 13 | __PACKAGE__->meta->add_attribute('type_coercion_map' => ( | ||||
| 14 | reader => 'type_coercion_map', | ||||
| 15 | default => sub { [] }, | ||||
| 16 | 1 | 15µs | 3 | 303µs | Class::MOP::_definition_context(), # spent 274µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 24µs making 1 call to Moose::Meta::TypeCoercion::meta
# spent 5µs making 1 call to Class::MOP::_definition_context |
| 17 | )); | ||||
| 18 | |||||
| 19 | 1 | 6µs | 4 | 6.16ms | __PACKAGE__->meta->add_attribute( # spent 5.43ms making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 715µs making 1 call to Moose::Meta::Attribute::new
# spent 8µs making 1 call to Moose::Meta::TypeCoercion::meta
# spent 4µs making 1 call to Class::MOP::_definition_context |
| 20 | Moose::Meta::Attribute->new('type_constraint' => ( | ||||
| 21 | reader => 'type_constraint', | ||||
| 22 | weak_ref => 1, | ||||
| 23 | Class::MOP::_definition_context(), | ||||
| 24 | )) | ||||
| 25 | ); | ||||
| 26 | |||||
| 27 | # private accessor | ||||
| 28 | 1 | 4µs | 3 | 300µs | __PACKAGE__->meta->add_attribute('compiled_type_coercion' => ( # spent 286µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 9µs making 1 call to Moose::Meta::TypeCoercion::meta
# spent 5µs making 1 call to Class::MOP::_definition_context |
| 29 | accessor => '_compiled_type_coercion', | ||||
| 30 | Class::MOP::_definition_context(), | ||||
| 31 | )); | ||||
| 32 | |||||
| 33 | # spent 335µs (12+323) within Moose::Meta::TypeCoercion::new which was called:
# once (12µs+323µs) by Moose::Util::TypeConstraints::_install_type_coercions at line 601 of Moose/Util/TypeConstraints.pm | ||||
| 34 | 1 | 800ns | my $class = shift; | ||
| 35 | 1 | 4µs | 2 | 266µs | my $self = Class::MOP::class_of($class)->new_object(@_); # spent 260µs making 1 call to Class::MOP::Class::new_object
# spent 6µs making 1 call to Class::MOP::class_of |
| 36 | 1 | 2µs | 1 | 58µs | $self->compile_type_coercion; # spent 58µs making 1 call to Moose::Meta::TypeCoercion::compile_type_coercion |
| 37 | 1 | 4µs | return $self; | ||
| 38 | } | ||||
| 39 | |||||
| 40 | # spent 58µs (24+33) within Moose::Meta::TypeCoercion::compile_type_coercion which was called:
# once (24µs+33µs) by Moose::Meta::TypeCoercion::new at line 36 | ||||
| 41 | 1 | 400ns | my $self = shift; | ||
| 42 | 1 | 3µs | 1 | 2µs | my @coercion_map = @{$self->type_coercion_map}; # spent 2µs making 1 call to Moose::Meta::TypeCoercion::type_coercion_map |
| 43 | 1 | 200ns | my @coercions; | ||
| 44 | 1 | 600ns | while (@coercion_map) { | ||
| 45 | 1 | 1µs | my ($constraint_name, $action) = splice(@coercion_map, 0, 2); | ||
| 46 | 1 | 2µs | 1 | 27µs | my $type_constraint = ref $constraint_name ? $constraint_name : Moose::Util::TypeConstraints::find_or_parse_type_constraint($constraint_name); # spent 27µs making 1 call to Moose::Util::TypeConstraints::find_or_parse_type_constraint |
| 47 | |||||
| 48 | 1 | 300ns | unless ( defined $type_constraint ) { | ||
| 49 | throw_exception( CouldNotFindTypeConstraintToCoerceFrom => constraint_name => $constraint_name, | ||||
| 50 | instance => $self | ||||
| 51 | ); | ||||
| 52 | } | ||||
| 53 | |||||
| 54 | 1 | 3µs | 1 | 1µs | push @coercions => [ # spent 1µs making 1 call to Moose::Meta::TypeConstraint::_compiled_type_constraint |
| 55 | $type_constraint->_compiled_type_constraint, | ||||
| 56 | $action | ||||
| 57 | ]; | ||||
| 58 | } | ||||
| 59 | # spent 57µs (12+44) within Moose::Meta::TypeCoercion::__ANON__[/usr/local/lib/perl/5.18.2/Moose/Meta/TypeCoercion.pm:69] which was called:
# once (12µs+44µs) by PONAPI::Server::ConfigReader::new at line 50 of (eval 45)[Eval/Closure.pm:144] | ||||
| 60 | 1 | 400ns | my $thing = shift; | ||
| 61 | 1 | 700ns | foreach my $coercion (@coercions) { | ||
| 62 | 1 | 700ns | my ($constraint, $converter) = @$coercion; | ||
| 63 | 1 | 2µs | 1 | 4µs | if ($constraint->($thing)) { # spent 4µs making 1 call to Eval::Closure::Sandbox_51::__ANON__[(eval 95)[Eval/Closure.pm:144]:3] |
| 64 | 1 | 500ns | local $_ = $thing; | ||
| 65 | 1 | 6µs | 1 | 41µs | return $converter->($thing); # spent 41µs making 1 call to PONAPI::Server::ConfigReader::__ANON__[lib/PONAPI/Server/ConfigReader.pm:15] |
| 66 | } | ||||
| 67 | } | ||||
| 68 | return $thing; | ||||
| 69 | 1 | 8µs | 1 | 3µs | }); # spent 3µs making 1 call to Moose::Meta::TypeCoercion::_compiled_type_coercion |
| 70 | } | ||||
| 71 | |||||
| 72 | sub has_coercion_for_type { | ||||
| 73 | my ($self, $type_name) = @_; | ||||
| 74 | my %coercion_map = @{$self->type_coercion_map}; | ||||
| 75 | exists $coercion_map{$type_name} ? 1 : 0; | ||||
| 76 | } | ||||
| 77 | |||||
| 78 | sub add_type_coercions { | ||||
| 79 | my ($self, @new_coercion_map) = @_; | ||||
| 80 | |||||
| 81 | my $coercion_map = $self->type_coercion_map; | ||||
| 82 | my %has_coercion = @$coercion_map; | ||||
| 83 | |||||
| 84 | while (@new_coercion_map) { | ||||
| 85 | my ($constraint_name, $action) = splice(@new_coercion_map, 0, 2); | ||||
| 86 | |||||
| 87 | if ( exists $has_coercion{$constraint_name} ) { | ||||
| 88 | throw_exception( CoercionAlreadyExists => constraint_name => $constraint_name, | ||||
| 89 | instance => $self | ||||
| 90 | ); | ||||
| 91 | } | ||||
| 92 | |||||
| 93 | push @{$coercion_map} => ($constraint_name, $action); | ||||
| 94 | } | ||||
| 95 | |||||
| 96 | # and re-compile ... | ||||
| 97 | $self->compile_type_coercion; | ||||
| 98 | } | ||||
| 99 | |||||
| 100 | sub coerce { $_[0]->_compiled_type_coercion->($_[1]) } | ||||
| 101 | |||||
| 102 | |||||
| 103 | 1 | 8µs | 1; | ||
| 104 | |||||
| 105 | # ABSTRACT: The Moose Type Coercion metaclass | ||||
| 106 | |||||
| 107 | __END__ |