← Index
NYTProf Performance Profile   « line view »
For ../prof.pl
  Run on Wed Dec 14 15:57:08 2022
Reported on Wed Dec 14 16:00:33 2022

Filename/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Type/Coercion.pm
StatementsExecuted 1368 statements in 4.79ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
5833842µs9.41msType::Coercion::::newType::Coercion::new
5811403µs7.90msType::Coercion::::_preserve_type_constraintType::Coercion::_preserve_type_constraint
6122220µs286µsType::Coercion::::is_anonType::Coercion::is_anon
5643124µs124µsType::Coercion::::freezeType::Coercion::freeze
22296µs781µsType::Coercion::::add_type_coercionsType::Coercion::add_type_coercions
565285µs85µsType::Coercion::::type_coercion_mapType::Coercion::type_coercion_map
704272µs72µsType::Coercion::::nameType::Coercion::name
11152µs185µsType::Coercion::::inline_coercionType::Coercion::inline_coercion
22140µs155µsType::Coercion::::can_be_inlinedType::Coercion::can_be_inlined
11132µs32µsType::Coercion::::BEGIN@3Type::Coercion::BEGIN@3
522131µs31µsType::Coercion::::__ANON__[:28]Type::Coercion::__ANON__[:28]
11124µs537µsType::Coercion::::_build_compiled_coercionType::Coercion::_build_compiled_coercion
53120µs20µsType::Coercion::::CORE:matchType::Coercion::CORE:match (opcode)
31118µs22µsType::Coercion::::qualified_nameType::Coercion::qualified_name
63115µs21µsType::Coercion::::type_constraintType::Coercion::type_constraint
11113µs16µsType::Coercion::::__ANON__[:27]Type::Coercion::__ANON__[:27]
31111µs14µsType::Coercion::::is_parameterizableType::Coercion::is_parameterizable
3219µs22µsType::Coercion::::has_type_constraintType::Coercion::has_type_constraint
6438µs8µsType::Coercion::::frozenType::Coercion::frozen
1116µs8µsType::Coercion::::BEGIN@4Type::Coercion::BEGIN@4
1115µs30µsType::Coercion::::BEGIN@15Type::Coercion::BEGIN@15
1115µs35µsType::Coercion::::BEGIN@5Type::Coercion::BEGIN@5
1115µs542µsType::Coercion::::compiled_coercionType::Coercion::compiled_coercion
1113µs9µsType::Coercion::::AUTOLOADType::Coercion::AUTOLOAD
1113µs3µsType::Coercion::::BEGIN@14Type::Coercion::BEGIN@14
1113µs3µsType::Coercion::::BEGIN@7Type::Coercion::BEGIN@7
3113µs3µsType::Coercion::::has_coercion_generatorType::Coercion::has_coercion_generator
1112µs2µsType::Coercion::::BEGIN@16Type::Coercion::BEGIN@16
2112µs2µsType::Coercion::::_clear_compiled_coercionType::Coercion::_clear_compiled_coercion
1112µs2µsType::Coercion::::display_nameType::Coercion::display_name
3112µs2µsType::Coercion::::has_libraryType::Coercion::has_library
0000s0sType::Coercion::::__ANON__[:262]Type::Coercion::__ANON__[:262]
0000s0sType::Coercion::::__ANON__[:33]Type::Coercion::__ANON__[:33]
0000s0sType::Coercion::::__ANON__[:46]Type::Coercion::__ANON__[:46]
0000s0sType::Coercion::::__ANON__[:500]Type::Coercion::__ANON__[:500]
0000s0sType::Coercion::::_build_display_nameType::Coercion::_build_display_name
0000s0sType::Coercion::::_build_moose_coercionType::Coercion::_build_moose_coercion
0000s0sType::Coercion::::_codelike_type_coercion_mapType::Coercion::_codelike_type_coercion_map
0000s0sType::Coercion::::_compiled_type_coercionType::Coercion::_compiled_type_coercion
0000s0sType::Coercion::::_croakType::Coercion::_croak
0000s0sType::Coercion::::_maybe_restore_type_constraintType::Coercion::_maybe_restore_type_constraint
0000s0sType::Coercion::::_overload_coderefType::Coercion::_overload_coderef
0000s0sType::Coercion::::_reparameterizeType::Coercion::_reparameterize
0000s0sType::Coercion::::_source_type_unionType::Coercion::_source_type_union
0000s0sType::Coercion::::_stringify_no_magicType::Coercion::_stringify_no_magic
0000s0sType::Coercion::::addType::Coercion::add
0000s0sType::Coercion::::assert_coerceType::Coercion::assert_coerce
0000s0sType::Coercion::::canType::Coercion::can
0000s0sType::Coercion::::coerceType::Coercion::coerce
0000s0sType::Coercion::::coercion_generatorType::Coercion::coercion_generator
0000s0sType::Coercion::::has_coercion_for_typeType::Coercion::has_coercion_for_type
0000s0sType::Coercion::::has_coercion_for_valueType::Coercion::has_coercion_for_value
0000s0sType::Coercion::::has_parametersType::Coercion::has_parameters
0000s0sType::Coercion::::i_really_want_to_unfreezeType::Coercion::i_really_want_to_unfreeze
0000s0sType::Coercion::::is_parameterizedType::Coercion::is_parameterized
0000s0sType::Coercion::::isaType::Coercion::isa
0000s0sType::Coercion::::libraryType::Coercion::library
0000s0sType::Coercion::::metaType::Coercion::meta
0000s0sType::Coercion::::moose_coercionType::Coercion::moose_coercion
0000s0sType::Coercion::::parameterizeType::Coercion::parameterize
0000s0sType::Coercion::::parameterized_fromType::Coercion::parameterized_from
0000s0sType::Coercion::::parametersType::Coercion::parameters
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package Type::Coercion;
2
3245µs132µs
# spent 32µs within Type::Coercion::BEGIN@3 which was called: # once (32µs+0s) by Type::Tiny::_build_coercion at line 3
use 5.008001;
# spent 32µs making 1 call to Type::Coercion::BEGIN@3
4218µs210µs
# spent 8µs (6+2) within Type::Coercion::BEGIN@4 which was called: # once (6µs+2µs) by Type::Tiny::_build_coercion at line 4
use strict;
# spent 8µs making 1 call to Type::Coercion::BEGIN@4 # spent 2µs making 1 call to strict::import
5228µs265µs
# spent 35µs (5+30) within Type::Coercion::BEGIN@5 which was called: # once (5µs+30µs) by Type::Tiny::_build_coercion at line 5
use warnings;
# spent 35µs making 1 call to Type::Coercion::BEGIN@5 # spent 30µs making 1 call to warnings::import
6
7
# spent 3µs within Type::Coercion::BEGIN@7 which was called: # once (3µs+0s) by Type::Tiny::_build_coercion at line 10
BEGIN {
810s $Type::Coercion::AUTHORITY = 'cpan:TOBYINK';
913µs $Type::Coercion::VERSION = '2.000001';
10123µs13µs}
# spent 3µs making 1 call to Type::Coercion::BEGIN@7
11
1211µs$Type::Coercion::VERSION =~ tr/_//d;
13
14213µs13µs
# spent 3µs within Type::Coercion::BEGIN@14 which was called: # once (3µs+0s) by Type::Tiny::_build_coercion at line 14
use Eval::TypeTiny qw<>;
# spent 3µs making 1 call to Type::Coercion::BEGIN@14
15217µs255µs
# spent 30µs (5+25) within Type::Coercion::BEGIN@15 which was called: # once (5µs+25µs) by Type::Tiny::_build_coercion at line 15
use Scalar::Util qw< blessed >;
# spent 30µs making 1 call to Type::Coercion::BEGIN@15 # spent 25µs making 1 call to Exporter::import
1622.20ms12µs
# spent 2µs within Type::Coercion::BEGIN@16 which was called: # once (2µs+0s) by Type::Tiny::_build_coercion at line 16
use Types::TypeTiny qw<>;
# spent 2µs making 1 call to Type::Coercion::BEGIN@16
17
18sub _croak ($;@) { require Error::TypeTiny; goto \&Error::TypeTiny::croak }
19
2011µsrequire Type::Tiny;
21
22__PACKAGE__->Type::Tiny::_install_overloads(
23
# spent 16µs (13+3) within Type::Coercion::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Type/Coercion.pm:27] which was called: # once (13µs+3µs) by Type::Coercion::_build_compiled_coercion at line 265
q("") => sub {
24114µs23µs caller =~ m{^(Moo::HandleMoose|Sub::Quote)}
# spent 2µs making 1 call to Type::Coercion::display_name # spent 1µs making 1 call to Type::Coercion::CORE:match
25 ? $_[0]->_stringify_no_magic
26 : $_[0]->display_name;
27 },
2852140µs
# spent 31µs within Type::Coercion::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Type/Coercion.pm:28] which was called 52 times, avg 596ns/call: # 48 times (29µs+0s) by Type::Tiny::has_coercion at line 472 of Type/Tiny.pm, avg 604ns/call # 4 times (2µs+0s) by Type::Tiny::coercion at line 439 of Type/Tiny.pm, avg 500ns/call
q(bool) => sub { 1 },
2916µs122µs q(&{}) => "_overload_coderef",
# spent 22µs making 1 call to Type::Tiny::_install_overloads
30);
31
32__PACKAGE__->Type::Tiny::_install_overloads(
33 q(~~) => sub { $_[0]->has_coercion_for_value( $_[1] ) },
3412µs17µs) if Type::Tiny::SUPPORT_SMARTMATCH();
# spent 7µs making 1 call to Type::Tiny::_install_overloads
35
36sub _overload_coderef {
37 my $self = shift;
38
39 if ( "Sub::Quote"->can( "quote_sub" ) && $self->can_be_inlined ) {
40 $self->{_overload_coderef} =
41 Sub::Quote::quote_sub( $self->inline_coercion( '$_[0]' ) )
42 if !$self->{_overload_coderef} || !$self->{_sub_quoted}++;
43 }
44 else {
45 Scalar::Util::weaken( my $weak = $self );
46 $self->{_overload_coderef} ||= sub { $weak->coerce( @_ ) };
47 }
48
49 $self->{_overload_coderef};
50} #/ sub _overload_coderef
51
52
# spent 9.41ms (842µs+8.57) within Type::Coercion::new which was called 58 times, avg 162µs/call: # 54 times (741µs+8.26ms) by Type::Tiny::_build_coercion at line 503 of Type/Tiny.pm, avg 167µs/call # 3 times (88µs+294µs) by Type::Library::add_coercion at line 274 of Type/Library.pm, avg 127µs/call # once (13µs+15µs) by Types::Standard::Dict::__coercion_generator at line 251 of Types/Standard/Dict.pm
sub new {
535814µs my $class = shift;
545892µs my %params = ( @_ == 1 ) ? %{ $_[0] } : @_;
55
565855µs $params{name} = '__ANON__' unless exists( $params{name} );
575832µs my $C = delete( $params{type_coercion_map} ) || [];
585820µs my $F = delete( $params{frozen} );
59
605831µs my $self = bless \%params, $class;
615818µs1204µs $self->add_type_coercions( @$C ) if @$C;
# spent 204µs making 1 call to Type::Coercion::add_type_coercions
625876µs587.90ms $self->_preserve_type_constraint;
# spent 7.90ms making 58 calls to Type::Coercion::_preserve_type_constraint, avg 136µs/call
6358285µs58172µs Scalar::Util::weaken( $self->{type_constraint} ); # break ref cycle
# spent 172µs making 58 calls to Scalar::Util::weaken, avg 3µs/call
645813µs $self->{frozen} = $F if $F;
65
665871µs58279µs unless ( $self->is_anon ) {
# spent 279µs making 58 calls to Type::Coercion::is_anon, avg 5µs/call
67
68 # First try a fast ASCII-only expression, but fall back to Unicode
69324µs615µs $self->name =~ /^_{0,2}[A-Z][A-Za-z0-9_]+$/sm
# spent 13µs making 3 calls to Type::Coercion::CORE:match, avg 4µs/call # spent 2µs making 3 calls to Type::Coercion::name, avg 667ns/call
70 or eval q( use 5.008; $self->name =~ /^_{0,2}\p{Lu}[\p{L}0-9_]+$/sm )
71 or _croak '"%s" is not a valid coercion name', $self->name;
72 }
73
7458127µs return $self;
75} #/ sub new
76
77sub _stringify_no_magic {
78 sprintf(
79 '%s=%s(0x%08x)', blessed( $_[0] ), Scalar::Util::reftype( $_[0] ),
80 Scalar::Util::refaddr( $_[0] )
81 );
82}
83
8470133µs
# spent 72µs within Type::Coercion::name which was called 70 times, avg 1µs/call: # 61 times (66µs+0s) by Type::Coercion::is_anon at line 176, avg 1µs/call # 3 times (2µs+0s) by Type::Library::add_coercion at line 275 of Type/Library.pm, avg 667ns/call # 3 times (2µs+0s) by Type::Coercion::qualified_name at line 171, avg 667ns/call # 3 times (2µs+0s) by Type::Coercion::new at line 69, avg 667ns/call
sub name { $_[0]{name} }
8513µs
# spent 2µs within Type::Coercion::display_name which was called: # once (2µs+0s) by Type::Coercion::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Type/Coercion.pm:27] at line 24
sub display_name { $_[0]{display_name} ||= $_[0]->_build_display_name }
86sub library { $_[0]{library} }
87
88
# spent 21µs (15+6) within Type::Coercion::type_constraint which was called 6 times, avg 4µs/call: # 3 times (9µs+4µs) by Type::Coercion::has_type_constraint at line 103, avg 4µs/call # 2 times (4µs+1µs) by Type::Coercion::can_be_inlined at line 318, avg 2µs/call # once (2µs+1µs) by Type::Coercion::inline_coercion at line 361
sub type_constraint {
89617µs66µs $_[0]{type_constraint} ||= $_[0]->_maybe_restore_type_constraint;
# spent 6µs making 6 calls to Type::Tiny::__ANON__[Type/Tiny.pm:101], avg 1µs/call
90}
9156142µs
# spent 85µs within Type::Coercion::type_coercion_map which was called 56 times, avg 2µs/call: # 48 times (77µs+0s) by Type::Tiny::has_coercion at line 472 of Type/Tiny.pm, avg 2µs/call # 4 times (5µs+0s) by Type::Coercion::add_type_coercions at line 250, avg 1µs/call # 2 times (1µs+0s) by Type::Coercion::can_be_inlined at line 321, avg 500ns/call # once (1µs+0s) by Type::Coercion::inline_coercion at line 352 # once (1µs+0s) by Type::Coercion::_build_compiled_coercion at line 261
sub type_coercion_map { $_[0]{type_coercion_map} ||= [] }
92sub moose_coercion { $_[0]{moose_coercion} ||= $_[0]->_build_moose_coercion }
93
94
# spent 542µs (5+537) within Type::Coercion::compiled_coercion which was called: # once (5µs+537µs) by Type::Tiny::exportables at line 1220 of Type/Tiny.pm
sub compiled_coercion {
9516µs1537µs $_[0]{compiled_coercion} ||= $_[0]->_build_compiled_coercion;
# spent 537µs making 1 call to Type::Coercion::_build_compiled_coercion
96}
97621µs
# spent 8µs within Type::Coercion::frozen which was called 6 times, avg 1µs/call: # 2 times (5µs+0s) by Type::Coercion::add_type_coercions at line 234, avg 2µs/call # 2 times (1µs+0s) by Type::Coercion::can_be_inlined at line 315, avg 500ns/call # once (2µs+0s) by Type::Library::make_immutable at line 319 of Type/Library.pm # once (0s+0s) by Type::Tiny::exportables at line 1220 of Type/Tiny.pm
sub frozen { $_[0]{frozen} ||= 0 }
98sub coercion_generator { $_[0]{coercion_generator} }
99sub parameters { $_[0]{parameters} }
100sub parameterized_from { $_[0]{parameterized_from} }
101
10236µs
# spent 2µs within Type::Coercion::has_library which was called 3 times, avg 667ns/call: # 3 times (2µs+0s) by Type::Coercion::qualified_name at line 167, avg 667ns/call
sub has_library { exists $_[0]{library} }
10339µs313µs
# spent 22µs (9+13) within Type::Coercion::has_type_constraint which was called 3 times, avg 7µs/call: # 2 times (6µs+9µs) by Type::Coercion::can_be_inlined at line 318, avg 8µs/call # once (3µs+4µs) by Type::Coercion::inline_coercion at line 360
sub has_type_constraint { defined $_[0]->type_constraint } # sic
# spent 13µs making 3 calls to Type::Coercion::type_constraint, avg 4µs/call
10437µs
# spent 3µs within Type::Coercion::has_coercion_generator which was called 3 times, avg 1µs/call: # 3 times (3µs+0s) by Type::Coercion::is_parameterizable at line 426, avg 1µs/call
sub has_coercion_generator { exists $_[0]{coercion_generator} }
105sub has_parameters { exists $_[0]{parameters} }
106
107
# spent 7.90ms (403µs+7.50) within Type::Coercion::_preserve_type_constraint which was called 58 times, avg 136µs/call: # 58 times (403µs+7.50ms) by Type::Coercion::new at line 62, avg 136µs/call
sub _preserve_type_constraint {
108588µs my $self = shift;
109 $self->{_compiled_type_constraint_check} =
110 $self->{type_constraint}->compiled_check
11158366µs1167.50ms if $self->{type_constraint};
# spent 7.41ms making 58 calls to Type::Tiny::compiled_check, avg 128µs/call # spent 89µs making 58 calls to Type::Tiny::__ANON__[Type/Tiny.pm:101], avg 2µs/call
112}
113
114sub _maybe_restore_type_constraint {
115 my $self = shift;
116 if ( my $check = $self->{_compiled_type_constraint_check} ) {
117 return Type::Tiny->new( constraint => $check );
118 }
119 return; # uncoverable statement
120}
121
122sub add {
123 my $class = shift;
124 my ( $x, $y, $swap ) = @_;
125
126 Types::TypeTiny::is_TypeTiny( $x ) and return $x->plus_fallback_coercions( $y );
127 Types::TypeTiny::is_TypeTiny( $y ) and return $y->plus_coercions( $x );
128
129 _croak "Attempt to add $class to something that is not a $class"
130 unless blessed( $x )
131 && blessed( $y )
132 && $x->isa( $class )
133 && $y->isa( $class );
134
135 ( $y, $x ) = ( $x, $y ) if $swap;
136
137 my %opts;
138 if ( $x->has_type_constraint
139 and $y->has_type_constraint
140 and $x->type_constraint == $y->type_constraint )
141 {
142 $opts{type_constraint} = $x->type_constraint;
143 }
144 elsif ( $x->has_type_constraint and $y->has_type_constraint ) {
145
146 # require Type::Tiny::Union;
147 # $opts{type_constraint} = "Type::Tiny::Union"->new(
148 # type_constraints => [ $x->type_constraint, $y->type_constraint ],
149 # );
150 }
151 $opts{display_name} ||= "$x+$y";
152 delete $opts{display_name} if $opts{display_name} eq '__ANON__+__ANON__';
153
154 my $new = $class->new( %opts );
155 $new->add_type_coercions( @{ $x->type_coercion_map } );
156 $new->add_type_coercions( @{ $y->type_coercion_map } );
157 return $new;
158} #/ sub add
159
160sub _build_display_name {
161 shift->name;
162}
163
164
# spent 22µs (18+4) within Type::Coercion::qualified_name which was called 3 times, avg 7µs/call: # 3 times (18µs+4µs) by Eval::TypeTiny::type_to_coderef at line 169 of Eval/TypeTiny.pm, avg 7µs/call
sub qualified_name {
16531µs my $self = shift;
166
16735µs32µs if ( $self->has_library and not $self->is_anon ) {
# spent 2µs making 3 calls to Type::Coercion::has_library, avg 667ns/call
168 return sprintf( "%s::%s", $self->library, $self->name );
169 }
170
17137µs32µs return $self->name;
# spent 2µs making 3 calls to Type::Coercion::name, avg 667ns/call
172}
173
174
# spent 286µs (220+66) within Type::Coercion::is_anon which was called 61 times, avg 5µs/call: # 58 times (214µs+65µs) by Type::Coercion::new at line 66, avg 5µs/call # 3 times (6µs+1000ns) by Type::Library::add_coercion at line 279 of Type/Library.pm, avg 2µs/call
sub is_anon {
1756135µs my $self = shift;
17661282µs6166µs $self->name eq "__ANON__";
# spent 66µs making 61 calls to Type::Coercion::name, avg 1µs/call
177}
178
179
# spent 2µs within Type::Coercion::_clear_compiled_coercion which was called 2 times, avg 1µs/call: # 2 times (2µs+0s) by Type::Coercion::add_type_coercions at line 254, avg 1µs/call
sub _clear_compiled_coercion {
18020s delete $_[0]{_overload_coderef};
18125µs delete $_[0]{compiled_coercion};
182}
183
184112177µs
# spent 124µs within Type::Coercion::freeze which was called 56 times, avg 2µs/call: # 37 times (94µs+0s) by Type::Library::make_immutable at line 318 of Type/Library.pm, avg 3µs/call # 14 times (24µs+0s) by Type::Tiny::parameterize at line 1082 of Type/Tiny.pm, avg 2µs/call # 3 times (5µs+0s) by Type::Tiny::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Type/Tiny.pm:1073] at line 1072 of Type/Tiny.pm, avg 2µs/call # 2 times (1µs+0s) by Types::Standard::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Types/Standard.pm:732] at line 731 of Types/Standard.pm, avg 500ns/call
sub freeze { $_[0]{frozen} = 1; $_[0] }
185sub i_really_want_to_unfreeze { $_[0]{frozen} = 0; $_[0] }
186
187sub coerce {
188 my $self = shift;
189 return $self->compiled_coercion->( @_ );
190}
191
192sub assert_coerce {
193 my $self = shift;
194 my $r = $self->coerce( @_ );
195 $self->type_constraint->assert_valid( $r )
196 if $self->has_type_constraint;
197 return $r;
198}
199
200sub has_coercion_for_type {
201 my $self = shift;
202 my $type = Types::TypeTiny::to_TypeTiny( $_[0] );
203
204 return "0 but true"
205 if $self->has_type_constraint
206 && $type->is_a_type_of( $self->type_constraint );
207
208 my $c = $self->type_coercion_map;
209 for ( my $i = 0 ; $i <= $#$c ; $i += 2 ) {
210 return !!1 if $type->is_a_type_of( $c->[$i] );
211 }
212 return;
213} #/ sub has_coercion_for_type
214
215sub has_coercion_for_value {
216 my $self = shift;
217 local $_ = $_[0];
218
219 return "0 but true"
220 if $self->has_type_constraint
221 && $self->type_constraint->check( @_ );
222
223 my $c = $self->type_coercion_map;
224 for ( my $i = 0 ; $i <= $#$c ; $i += 2 ) {
225 return !!1 if $c->[$i]->check( @_ );
226 }
227 return;
228} #/ sub has_coercion_for_value
229
230
# spent 781µs (96+685) within Type::Coercion::add_type_coercions which was called 2 times, avg 390µs/call: # once (29µs+548µs) by JSON::Schema::Modern::BEGIN@31 at line 234 of Types/Standard.pm # once (67µs+137µs) by Type::Coercion::new at line 61
sub add_type_coercions {
23120s my $self = shift;
23222µs my @args = @_;
233
23424µs25µs _croak "Attempt to add coercion code to a Type::Coercion which has been frozen"
# spent 5µs making 2 calls to Type::Coercion::frozen, avg 2µs/call
235 if $self->frozen;
236
23722µs while ( @args ) {
23848µs433µs my $type = Types::TypeTiny::to_TypeTiny( shift @args );
# spent 33µs making 4 calls to Types::TypeTiny::to_TypeTiny, avg 8µs/call
239
240438µs853µs if ( blessed $type and my $method = $type->can( 'type_coercion_map' ) ) {
# spent 46µs making 4 calls to Type::Tiny::can, avg 12µs/call # spent 7µs making 4 calls to Scalar::Util::blessed, avg 2µs/call
241 push @{ $self->type_coercion_map }, @{ $method->( $type ) };
242 }
243 else {
24442µs my $coercion = shift @args;
24547µs4349µs _croak "Types must be blessed Type::Tiny objects"
# spent 349µs making 4 calls to Types::TypeTiny::is_TypeTiny, avg 87µs/call
246 unless Types::TypeTiny::is_TypeTiny( $type );
24743µs4238µs _croak "Coercions must be code references or strings"
# spent 238µs making 4 calls to Types::TypeTiny::is_StringLike, avg 60µs/call
248 unless Types::TypeTiny::is_StringLike( $coercion )
249 || Types::TypeTiny::is_CodeLike( $coercion );
25049µs45µs push @{ $self->type_coercion_map }, $type, $coercion;
# spent 5µs making 4 calls to Type::Coercion::type_coercion_map, avg 1µs/call
251 }
252 } #/ while ( @args )
253
25423µs22µs $self->_clear_compiled_coercion;
# spent 2µs making 2 calls to Type::Coercion::_clear_compiled_coercion, avg 1µs/call
25526µs return $self;
256} #/ sub add_type_coercions
257
258
# spent 537µs (24+513) within Type::Coercion::_build_compiled_coercion which was called: # once (24µs+513µs) by Type::Coercion::compiled_coercion at line 95
sub _build_compiled_coercion {
25911µs my $self = shift;
260
26112µs11µs my @mishmash = @{ $self->type_coercion_map };
# spent 1µs making 1 call to Type::Coercion::type_coercion_map
262 return sub { $_[0] }
26311µs unless @mishmash;
264
265115µs4512µs if ( $self->can_be_inlined ) {
# spent 210µs making 1 call to Eval::TypeTiny::eval_closure # spent 185µs making 1 call to Type::Coercion::inline_coercion # spent 101µs making 1 call to Type::Coercion::can_be_inlined # spent 16µs making 1 call to Type::Coercion::__ANON__[Type/Coercion.pm:27]
266 return Eval::TypeTiny::eval_closure(
267 source => sprintf( 'sub ($) { %s }', $self->inline_coercion( '$_[0]' ) ),
268 description => sprintf( "compiled coercion '%s'", $self ),
269 );
270 }
271
272 # These arrays will be closed over.
273 my ( @types, @codes );
274 while ( @mishmash ) {
275 push @types, shift @mishmash;
276 push @codes, shift @mishmash;
277 }
278 if ( $self->has_type_constraint ) {
279 unshift @types, $self->type_constraint;
280 unshift @codes, undef;
281 }
282
283 my @sub;
284
285 for my $i ( 0 .. $#types ) {
286 push @sub,
287 $types[$i]->can_be_inlined
288 ? sprintf( 'if (%s)', $types[$i]->inline_check( '$_[0]' ) )
289 : sprintf( 'if ($checks[%d]->(@_))', $i );
290 push @sub,
291 !defined( $codes[$i] )
292 ? sprintf( ' { return $_[0] }' )
293 : Types::TypeTiny::is_StringLike( $codes[$i] ) ? sprintf(
294 ' { local $_ = $_[0]; return scalar(%s); }',
295 $codes[$i]
296 )
297 : sprintf( ' { local $_ = $_[0]; return scalar($codes[%d]->(@_)) }', $i );
298 } #/ for my $i ( 0 .. $#types)
299
300 push @sub, 'return $_[0];';
301
302 return Eval::TypeTiny::eval_closure(
303 source => sprintf( 'sub ($) { %s }', join qq[\n], @sub ),
304 description => sprintf( "compiled coercion '%s'", $self ),
305 environment => {
306 '@checks' => [ map $_->compiled_check, @types ],
307 '@codes' => \@codes,
308 },
309 );
310} #/ sub _build_compiled_coercion
311
312
# spent 155µs (40+115) within Type::Coercion::can_be_inlined which was called 2 times, avg 78µs/call: # once (23µs+78µs) by Type::Coercion::_build_compiled_coercion at line 265 # once (17µs+37µs) by Type::Coercion::inline_coercion at line 350
sub can_be_inlined {
31321µs my $self = shift;
314
31522µs21µs return unless $self->frozen;
# spent 1µs making 2 calls to Type::Coercion::frozen, avg 500ns/call
316
317 return
31827µs654µs if $self->has_type_constraint
# spent 34µs making 2 calls to Type::Tiny::can_be_inlined, avg 17µs/call # spent 15µs making 2 calls to Type::Coercion::has_type_constraint, avg 8µs/call # spent 5µs making 2 calls to Type::Coercion::type_constraint, avg 2µs/call
319 && !$self->type_constraint->can_be_inlined;
320
32122µs21µs my @mishmash = @{ $self->type_coercion_map };
# spent 1µs making 2 calls to Type::Coercion::type_coercion_map, avg 500ns/call
32222µs while ( @mishmash ) {
32323µs my ( $type, $converter ) = splice( @mishmash, 0, 2 );
32421µs216µs return unless $type->can_be_inlined;
# spent 16µs making 2 calls to Type::Tiny::can_be_inlined, avg 8µs/call
32522µs243µs return unless Types::TypeTiny::is_StringLike( $converter );
# spent 43µs making 2 calls to Types::TypeTiny::is_StringLike, avg 22µs/call
326 }
32726µs return !!1;
328} #/ sub can_be_inlined
329
330sub _source_type_union {
331 my $self = shift;
332
333 my @r;
334 push @r, $self->type_constraint if $self->has_type_constraint;
335
336 my @mishmash = @{ $self->type_coercion_map };
337 while ( @mishmash ) {
338 my ( $type ) = splice( @mishmash, 0, 2 );
339 push @r, $type;
340 }
341
342 require Type::Tiny::Union;
343 return "Type::Tiny::Union"->new( type_constraints => \@r, tmp => 1 );
344} #/ sub _source_type_union
345
346
# spent 185µs (52+133) within Type::Coercion::inline_coercion which was called: # once (52µs+133µs) by Type::Coercion::_build_compiled_coercion at line 265
sub inline_coercion {
34711µs my $self = shift;
34811µs my $varname = $_[0];
349
35012µs154µs _croak "This coercion cannot be inlined" unless $self->can_be_inlined;
# spent 54µs making 1 call to Type::Coercion::can_be_inlined
351
35212µs11µs my @mishmash = @{ $self->type_coercion_map };
# spent 1µs making 1 call to Type::Coercion::type_coercion_map
35310s return "($varname)" unless @mishmash;
354
35511µs my ( @types, @codes );
35611µs while ( @mishmash ) {
35711µs push @types, shift @mishmash;
35810s push @codes, shift @mishmash;
359 }
36013µs17µs if ( $self->has_type_constraint ) {
# spent 7µs making 1 call to Type::Coercion::has_type_constraint
36112µs13µs unshift @types, $self->type_constraint;
# spent 3µs making 1 call to Type::Coercion::type_constraint
36211µs unshift @codes, undef;
363 }
364
36510s my @sub;
366
36712µs for my $i ( 0 .. $#types ) {
36828µs268µs push @sub, sprintf( '(%s) ?', $types[$i]->inline_check( $varname ) );
# spent 68µs making 2 calls to Type::Tiny::inline_check, avg 34µs/call
36924µs push @sub,
370 ( defined( $codes[$i] ) && ( $varname eq '$_' ) )
371 ? sprintf( 'scalar(do { %s }) :', $codes[$i] )
372 : defined( $codes[$i] ) ? sprintf(
373 'scalar(do { local $_ = %s; %s }) :', $varname,
374 $codes[$i]
375 )
376 : sprintf( '%s :', $varname );
377 } #/ for my $i ( 0 .. $#types)
378
37911µs push @sub, "$varname";
380
38116µs "@sub";
382} #/ sub inline_coercion
383
384sub _build_moose_coercion {
385 my $self = shift;
386
387 my %options = ();
388 $options{type_coercion_map} =
389 [ $self->freeze->_codelike_type_coercion_map( 'moose_type' ) ];
390 $options{type_constraint} = $self->type_constraint
391 if $self->has_type_constraint;
392
393 require Moose::Meta::TypeCoercion;
394 my $r = "Moose::Meta::TypeCoercion"->new( %options );
395
396 return $r;
397} #/ sub _build_moose_coercion
398
399sub _codelike_type_coercion_map {
400 my $self = shift;
401 my $modifier = $_[0];
402
403 my @orig = @{ $self->type_coercion_map };
404 my @new;
405
406 while ( @orig ) {
407 my ( $type, $converter ) = splice( @orig, 0, 2 );
408
409 push @new, $modifier ? $type->$modifier : $type;
410
411 if ( Types::TypeTiny::is_CodeLike( $converter ) ) {
412 push @new, $converter;
413 }
414 else {
415 push @new, Eval::TypeTiny::eval_closure(
416 source => sprintf( 'sub { local $_ = $_[0]; %s }', $converter ),
417 description => sprintf( "temporary compiled converter from '%s'", $type ),
418 );
419 }
420 } #/ while ( @orig )
421
422 return @new;
423} #/ sub _codelike_type_coercion_map
424
425
# spent 14µs (11+3) within Type::Coercion::is_parameterizable which was called 3 times, avg 5µs/call: # 3 times (11µs+3µs) by Eval::TypeTiny::type_to_coderef at line 149 of Eval/TypeTiny.pm, avg 5µs/call
sub is_parameterizable {
42639µs33µs shift->has_coercion_generator;
# spent 3µs making 3 calls to Type::Coercion::has_coercion_generator, avg 1µs/call
427}
428
429sub is_parameterized {
430 shift->has_parameters;
431}
432
433sub parameterize {
434 my $self = shift;
435 return $self unless @_;
436 $self->is_parameterizable
437 or _croak "Constraint '%s' does not accept parameters", "$self";
438
439 @_ = map Types::TypeTiny::to_TypeTiny( $_ ), @_;
440
441 return ref( $self )->new(
442 type_constraint => $self->type_constraint,
443 type_coercion_map =>
444 [ $self->coercion_generator->( $self, $self->type_constraint, @_ ) ],
445 parameters => \@_,
446 frozen => 1,
447 parameterized_from => $self,
448 );
449} #/ sub parameterize
450
451sub _reparameterize {
452 my $self = shift;
453 my ( $target_type ) = @_;
454
455 $self->is_parameterized or return $self;
456 my $parent = $self->parameterized_from;
457
458 return ref( $self )->new(
459 type_constraint => $target_type,
460 type_coercion_map => [
461 $parent->coercion_generator->( $parent, $target_type, @{ $self->parameters } )
462 ],
463 parameters => \@_,
464 frozen => 1,
465 parameterized_from => $parent,
466 );
467} #/ sub _reparameterize
468
469sub isa {
470 my $self = shift;
471
472 if ( $INC{"Moose.pm"}
473 and blessed( $self )
474 and $_[0] eq 'Moose::Meta::TypeCoercion' )
475 {
476 return !!1;
477 }
478
479 if ( $INC{"Moose.pm"}
480 and blessed( $self )
481 and $_[0] =~ /^(Class::MOP|MooseX?)::/ )
482 {
483 my $r = $self->moose_coercion->isa( @_ );
484 return $r if $r;
485 }
486
487 $self->SUPER::isa( @_ );
488} #/ sub isa
489
490sub can {
491 my $self = shift;
492
493 my $can = $self->SUPER::can( @_ );
494 return $can if $can;
495
496 if ( $INC{"Moose.pm"}
497 and blessed( $self )
498 and my $method = $self->moose_coercion->can( @_ ) )
499 {
500 return sub { $method->( shift->moose_coercion, @_ ) };
501 }
502
503 return;
504} #/ sub can
505
506
# spent 9µs (3+6) within Type::Coercion::AUTOLOAD which was called: # once (3µs+6µs) by Types::Standard::Dict::__coercion_generator at line 267 of Types/Standard/Dict.pm
sub AUTOLOAD {
50710s my $self = shift;
50818µs16µs my ( $m ) = ( our $AUTOLOAD =~ /::(\w+)$/ );
# spent 6µs making 1 call to Type::Coercion::CORE:match
50913µs return if $m eq 'DESTROY';
510
511 if ( $INC{"Moose.pm"}
512 and blessed( $self )
513 and my $method = $self->moose_coercion->can( $m ) )
514 {
515 return $method->( $self->moose_coercion, @_ );
516 }
517
518 _croak q[Can't locate object method "%s" via package "%s"], $m,
519 ref( $self ) || $self;
520} #/ sub AUTOLOAD
521
522# Private Moose method, but Moo uses this...
523sub _compiled_type_coercion {
524 my $self = shift;
525 if ( @_ ) {
526 my $thing = $_[0];
527 if ( blessed( $thing ) and $thing->isa( "Type::Coercion" ) ) {
528 $self->add_type_coercions( @{ $thing->type_coercion_map } );
529 }
530 elsif ( Types::TypeTiny::is_CodeLike( $thing ) ) {
531 require Types::Standard;
532 $self->add_type_coercions( Types::Standard::Any(), $thing );
533 }
534 } #/ if ( @_ )
535 $self->compiled_coercion;
536} #/ sub _compiled_type_coercion
537
53811µs*compile_type_coercion = \&compiled_coercion;
539sub meta { _croak( "Not really a Moose::Meta::TypeCoercion. Sorry!" ) }
540
54117µs1;
542
543__END__
 
# spent 20µs within Type::Coercion::CORE:match which was called 5 times, avg 4µs/call: # 3 times (13µs+0s) by Type::Coercion::new at line 69, avg 4µs/call # once (6µs+0s) by Type::Coercion::AUTOLOAD at line 508 # once (1µs+0s) by Type::Coercion::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Type/Coercion.pm:27] at line 24
sub Type::Coercion::CORE:match; # opcode