← Index
NYTProf Performance Profile   « line view »
For examples/Atom-timer.pl
  Run on Mon Aug 12 14:45:28 2013
Reported on Mon Aug 12 14:46:14 2013

Filename/Users/dde/perl5/perlbrew/perls/5.18.0t/lib/site_perl/5.18.0/darwin-thread-multi-2level/Moose/Meta/TypeCoercion.pm
StatementsExecuted 17 statements in 628µs
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
1115.11ms82.0msMoose::Meta::TypeCoercion::::BEGIN@14Moose::Meta::TypeCoercion::BEGIN@14
1118µs8µsMoose::Meta::TypeCoercion::::BEGIN@3Moose::Meta::TypeCoercion::BEGIN@3
1116µs16µsMoose::Meta::TypeCoercion::::BEGIN@10Moose::Meta::TypeCoercion::BEGIN@10
1116µs9µsMoose::Meta::TypeCoercion::::BEGIN@11Moose::Meta::TypeCoercion::BEGIN@11
1115µs331µsMoose::Meta::TypeCoercion::::BEGIN@12Moose::Meta::TypeCoercion::BEGIN@12
1113µs3µsMoose::Meta::TypeCoercion::::BEGIN@15Moose::Meta::TypeCoercion::BEGIN@15
0000s0sMoose::Meta::TypeCoercion::::__ANON__[:19]Moose::Meta::TypeCoercion::__ANON__[:19]
0000s0sMoose::Meta::TypeCoercion::::__ANON__[:72]Moose::Meta::TypeCoercion::__ANON__[:72]
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
# spent 8µs within Moose::Meta::TypeCoercion::BEGIN@3 which was called: # once (8µs+0s) by Moose::BEGIN@29 at line 5
BEGIN {
416µs $Moose::Meta::TypeCoercion::AUTHORITY = 'cpan:STEVAN';
5128µs18µs}
# spent 8µs making 1 call to Moose::Meta::TypeCoercion::BEGIN@3
6{
72800ns $Moose::Meta::TypeCoercion::VERSION = '2.1005';
8}
9
10220µs226µs
# spent 16µs (6+10) within Moose::Meta::TypeCoercion::BEGIN@10 which was called: # once (6µs+10µs) by Moose::BEGIN@29 at line 10
use strict;
# spent 16µs making 1 call to Moose::Meta::TypeCoercion::BEGIN@10 # spent 10µs making 1 call to strict::import
11218µs212µs
# spent 9µs (6+3) within Moose::Meta::TypeCoercion::BEGIN@11 which was called: # once (6µs+3µs) by Moose::BEGIN@29 at line 11
use warnings;
# spent 9µs making 1 call to Moose::Meta::TypeCoercion::BEGIN@11 # spent 3µs making 1 call to warnings::import
12223µs2656µs
# spent 331µs (5+326) within Moose::Meta::TypeCoercion::BEGIN@12 which was called: # once (5µs+326µs) by Moose::BEGIN@29 at line 12
use metaclass;
# spent 331µs making 1 call to Moose::Meta::TypeCoercion::BEGIN@12 # spent 326µs making 1 call to metaclass::import
13
142103µs182.0ms
# spent 82.0ms (5.11+76.9) within Moose::Meta::TypeCoercion::BEGIN@14 which was called: # once (5.11ms+76.9ms) by Moose::BEGIN@29 at line 14
use Moose::Meta::Attribute;
# spent 82.0ms making 1 call to Moose::Meta::TypeCoercion::BEGIN@14
152409µs13µs
# spent 3µs within Moose::Meta::TypeCoercion::BEGIN@15 which was called: # once (3µs+0s) by Moose::BEGIN@29 at line 15
use Moose::Util::TypeConstraints ();
# spent 3µ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 { [] },
2016µs3295µs Class::MOP::_definition_context(),
# spent 276µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 14µs making 1 call to Moose::Meta::TypeCoercion::meta # spent 5µs making 1 call to Class::MOP::_definition_context
21));
22
2315µs42.59ms__PACKAGE__->meta->add_attribute(
# spent 1.88ms making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 698µs making 1 call to Moose::Meta::Attribute::new # spent 8µs making 1 call to Moose::Meta::TypeCoercion::meta # spent 5µ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
3213µs33.39ms__PACKAGE__->meta->add_attribute('compiled_type_coercion' => (
# spent 3.37ms making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute # spent 8µs making 1 call to Moose::Meta::TypeCoercion::meta # spent 5µs making 1 call to Class::MOP::_definition_context
33 accessor => '_compiled_type_coercion',
34 Class::MOP::_definition_context(),
35));
36
37sub new {
38 my $class = shift;
39 my $self = Class::MOP::class_of($class)->new_object(@_);
40 $self->compile_type_coercion;
41 return $self;
42}
43
44sub compile_type_coercion {
45 my $self = shift;
46 my @coercion_map = @{$self->type_coercion_map};
47 my @coercions;
48 while (@coercion_map) {
49 my ($constraint_name, $action) = splice(@coercion_map, 0, 2);
50 my $type_constraint = ref $constraint_name ? $constraint_name : Moose::Util::TypeConstraints::find_or_parse_type_constraint($constraint_name);
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 push @coercions => [
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 });
73}
74
75sub 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
81sub 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
102sub coerce { $_[0]->_compiled_type_coercion->($_[1]) }
103
104
10517µs1;
106
107# ABSTRACT: The Moose Type Coercion metaclass
108
109__END__