← Index
NYTProf Performance Profile   « line view »
For /home/ss5/perl5/perlbrew/perls/perl-5.22.0/bin/benchmarkanything-storage
  Run on Mon Jan 29 16:55:34 2018
Reported on Mon Jan 29 16:57:06 2018

Filename/home/ss5/perl5/perlbrew/perls/perl-5.22.0/lib/site_perl/5.22.0/x86_64-linux/Moose/Meta/TypeCoercion.pm
StatementsExecuted 17 statements in 454µs
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
1113.15ms79.6msMoose::Meta::TypeCoercion::::BEGIN@8Moose::Meta::TypeCoercion::BEGIN@8
11115µs408µsMoose::Meta::TypeCoercion::::BEGIN@6Moose::Meta::TypeCoercion::BEGIN@6
1119µs11µsMoose::Meta::TypeCoercion::::BEGIN@4Moose::Meta::TypeCoercion::BEGIN@4
1115µs144µsMoose::Meta::TypeCoercion::::BEGIN@11Moose::Meta::TypeCoercion::BEGIN@11
1115µs9µsMoose::Meta::TypeCoercion::::BEGIN@5Moose::Meta::TypeCoercion::BEGIN@5
1113µs3µsMoose::Meta::TypeCoercion::::BEGIN@9Moose::Meta::TypeCoercion::BEGIN@9
0000s0sMoose::Meta::TypeCoercion::::__ANON__[:15]Moose::Meta::TypeCoercion::__ANON__[:15]
0000s0sMoose::Meta::TypeCoercion::::__ANON__[:69]Moose::Meta::TypeCoercion::__ANON__[:69]
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
1package Moose::Meta::TypeCoercion;
21500nsour $VERSION = '2.1605';
3
4225µs213µs
# spent 11µs (9+2) within Moose::Meta::TypeCoercion::BEGIN@4 which was called: # once (9µs+2µs) by Moose::BEGIN@26 at line 4
use strict;
# spent 11µs making 1 call to Moose::Meta::TypeCoercion::BEGIN@4 # spent 2µs making 1 call to strict::import
5212µs213µs
# spent 9µs (5+4) within Moose::Meta::TypeCoercion::BEGIN@5 which was called: # once (5µs+4µs) by Moose::BEGIN@26 at line 5
use warnings;
# spent 9µs making 1 call to Moose::Meta::TypeCoercion::BEGIN@5 # spent 4µs making 1 call to warnings::import
6235µs2800µs
# spent 408µs (15+392) within Moose::Meta::TypeCoercion::BEGIN@6 which was called: # once (15µs+392µs) by Moose::BEGIN@26 at line 6
use metaclass;
# spent 408µs making 1 call to Moose::Meta::TypeCoercion::BEGIN@6 # spent 392µs making 1 call to metaclass::import
7
8271µs179.6ms
# spent 79.6ms (3.15+76.4) within Moose::Meta::TypeCoercion::BEGIN@8 which was called: # once (3.15ms+76.4ms) by Moose::BEGIN@26 at line 8
use Moose::Meta::Attribute;
# spent 79.6ms making 1 call to Moose::Meta::TypeCoercion::BEGIN@8
9215µs13µs
# spent 3µs within Moose::Meta::TypeCoercion::BEGIN@9 which was called: # once (3µs+0s) by Moose::BEGIN@26 at line 9
use Moose::Util::TypeConstraints ();
# spent 3µs making 1 call to Moose::Meta::TypeCoercion::BEGIN@9
10
112280µs2284µs
# spent 144µs (5+139) within Moose::Meta::TypeCoercion::BEGIN@11 which was called: # once (5µs+139µs) by Moose::BEGIN@26 at line 11
use Moose::Util 'throw_exception';
# spent 144µs making 1 call to Moose::Meta::TypeCoercion::BEGIN@11 # spent 139µ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 { [] },
1614µs3220µs Class::MOP::_definition_context(),
# spent 203µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 13µs making 1 call to Moose::Meta::TypeCoercion::meta # spent 4µs making 1 call to Class::MOP::_definition_context
17));
18
1914µs41.80ms__PACKAGE__->meta->add_attribute(
# spent 1.26ms making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 529µs making 1 call to Moose::Meta::Attribute::new # spent 6µs making 1 call to Moose::Meta::TypeCoercion::meta # spent 3µ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
2812µs3197µs__PACKAGE__->meta->add_attribute('compiled_type_coercion' => (
# spent 189µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 5µs making 1 call to Moose::Meta::TypeCoercion::meta # spent 4µs making 1 call to Class::MOP::_definition_context
29 accessor => '_compiled_type_coercion',
30 Class::MOP::_definition_context(),
31));
32
33sub new {
34 my $class = shift;
35 my $self = Class::MOP::class_of($class)->new_object(@_);
36 $self->compile_type_coercion;
37 return $self;
38}
39
40sub compile_type_coercion {
41 my $self = shift;
42 my @coercion_map = @{$self->type_coercion_map};
43 my @coercions;
44 while (@coercion_map) {
45 my ($constraint_name, $action) = splice(@coercion_map, 0, 2);
46 my $type_constraint = ref $constraint_name ? $constraint_name : Moose::Util::TypeConstraints::find_or_parse_type_constraint($constraint_name);
47
48 unless ( defined $type_constraint ) {
49 throw_exception( CouldNotFindTypeConstraintToCoerceFrom => constraint_name => $constraint_name,
50 instance => $self
51 );
52 }
53
54 push @coercions => [
55 $type_constraint->_compiled_type_constraint,
56 $action
57 ];
58 }
59 $self->_compiled_type_coercion(sub {
60 my $thing = shift;
61 foreach my $coercion (@coercions) {
62 my ($constraint, $converter) = @$coercion;
63 if ($constraint->($thing)) {
64 local $_ = $thing;
65 return $converter->($thing);
66 }
67 }
68 return $thing;
69 });
70}
71
72sub 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
78sub 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
100sub coerce { $_[0]->_compiled_type_coercion->($_[1]) }
101
102
10315µs1;
104
105# ABSTRACT: The Moose Type Coercion metaclass
106
107__END__