← Index
NYTProf Performance Profile   « line view »
For fastest.pl
  Run on Fri Jan 31 20:48:16 2014
Reported on Fri Jan 31 20:49:41 2014

Filename/opt/perl-5.18.1/lib/site_perl/5.18.1/Type/Coercion.pm
StatementsExecuted 140 statements in 3.93ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
11171µs850µsType::Coercion::::add_type_coercionsType::Coercion::add_type_coercions
31167µs950µsType::Coercion::::newType::Coercion::new
11126µs26µsType::Coercion::::frozenType::Coercion::frozen
11124µs24µsType::Coercion::::BEGIN@3Type::Coercion::BEGIN@3
185222µs22µsType::Coercion::::nameType::Coercion::name
62222µs29µsType::Coercion::::is_anonType::Coercion::is_anon
31121µs28µsType::Coercion::::qualified_nameType::Coercion::qualified_name
31120µs54µsType::Coercion::::__ANON__[:19]Type::Coercion::__ANON__[:19]
11118µs74µsType::Coercion::::BEGIN@19Type::Coercion::BEGIN@19
31118µs31µsType::Coercion::::display_nameType::Coercion::display_name
62112µs12µsType::Coercion::::CORE:matchType::Coercion::CORE:match (opcode)
31110µs15µsType::Coercion::::is_parameterizableType::Coercion::is_parameterizable
31110µs13µsType::Coercion::::_build_display_nameType::Coercion::_build_display_name
1119µs16µsType::Coercion::::BEGIN@5Type::Coercion::BEGIN@5
1119µs47µsType::Coercion::::BEGIN@13Type::Coercion::BEGIN@13
1119µs27µsType::Coercion::::BEGIN@4Type::Coercion::BEGIN@4
1114µs4µsType::Coercion::::BEGIN@26Type::Coercion::BEGIN@26
3114µs4µsType::Coercion::::has_coercion_generatorType::Coercion::has_coercion_generator
3114µs4µsType::Coercion::::type_coercion_mapType::Coercion::type_coercion_map
1114µs4µsType::Coercion::::BEGIN@7Type::Coercion::BEGIN@7
1114µs4µsType::Coercion::::BEGIN@14Type::Coercion::BEGIN@14
3114µs4µsType::Coercion::::has_libraryType::Coercion::has_library
1114µs4µsType::Coercion::::BEGIN@12Type::Coercion::BEGIN@12
1112µs2µsType::Coercion::::_clear_compiled_coercionType::Coercion::_clear_compiled_coercion
0000s0sType::Coercion::::AUTOLOADType::Coercion::AUTOLOAD
0000s0sType::Coercion::::__ANON__[:20]Type::Coercion::__ANON__[:20]
0000s0sType::Coercion::::__ANON__[:22]Type::Coercion::__ANON__[:22]
0000s0sType::Coercion::::__ANON__[:230]Type::Coercion::__ANON__[:230]
0000s0sType::Coercion::::__ANON__[:28]Type::Coercion::__ANON__[:28]
0000s0sType::Coercion::::__ANON__[:43]Type::Coercion::__ANON__[:43]
0000s0sType::Coercion::::__ANON__[:452]Type::Coercion::__ANON__[:452]
0000s0sType::Coercion::::_build_compiled_coercionType::Coercion::_build_compiled_coercion
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::::_overload_coderefType::Coercion::_overload_coderef
0000s0sType::Coercion::::_source_type_unionType::Coercion::_source_type_union
0000s0sType::Coercion::::addType::Coercion::add
0000s0sType::Coercion::::assert_coerceType::Coercion::assert_coerce
0000s0sType::Coercion::::canType::Coercion::can
0000s0sType::Coercion::::can_be_inlinedType::Coercion::can_be_inlined
0000s0sType::Coercion::::coerceType::Coercion::coerce
0000s0sType::Coercion::::coercion_generatorType::Coercion::coercion_generator
0000s0sType::Coercion::::compiled_coercionType::Coercion::compiled_coercion
0000s0sType::Coercion::::freezeType::Coercion::freeze
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::::has_type_constraintType::Coercion::has_type_constraint
0000s0sType::Coercion::::inline_coercionType::Coercion::inline_coercion
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::::parametersType::Coercion::parameters
0000s0sType::Coercion::::type_constraintType::Coercion::type_constraint
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
3261µs124µs
# spent 24µs within Type::Coercion::BEGIN@3 which was called: # once (24µs+0s) by Type::Library::add_coercion at line 3
use 5.006001;
# spent 24µs making 1 call to Type::Coercion::BEGIN@3
4230µs245µs
# spent 27µs (9+18) within Type::Coercion::BEGIN@4 which was called: # once (9µs+18µs) by Type::Library::add_coercion at line 4
use strict;
# spent 27µs making 1 call to Type::Coercion::BEGIN@4 # spent 18µs making 1 call to strict::import
5255µs222µs
# spent 16µs (9+7) within Type::Coercion::BEGIN@5 which was called: # once (9µs+7µs) by Type::Library::add_coercion at line 5
use warnings;
# spent 16µs making 1 call to Type::Coercion::BEGIN@5 # spent 7µs making 1 call to warnings::import
6
7
# spent 4µs within Type::Coercion::BEGIN@7 which was called: # once (4µs+0s) by Type::Library::add_coercion at line 10
BEGIN {
81500ns $Type::Coercion::AUTHORITY = 'cpan:TOBYINK';
9110µs $Type::Coercion::VERSION = '0.038';
10126µs14µs}
# spent 4µs making 1 call to Type::Coercion::BEGIN@7
11
12229µs14µs
# spent 4µs within Type::Coercion::BEGIN@12 which was called: # once (4µs+0s) by Type::Library::add_coercion at line 12
use Eval::TypeTiny qw<>;
# spent 4µs making 1 call to Type::Coercion::BEGIN@12
13237µs285µs
# spent 47µs (9+38) within Type::Coercion::BEGIN@13 which was called: # once (9µs+38µs) by Type::Library::add_coercion at line 13
use Scalar::Util qw< blessed >;
# spent 47µs making 1 call to Type::Coercion::BEGIN@13 # spent 38µs making 1 call to Exporter::import
142222µs14µs
# spent 4µs within Type::Coercion::BEGIN@14 which was called: # once (4µs+0s) by Type::Library::add_coercion at line 14
use Types::TypeTiny qw<>;
# spent 4µs making 1 call to Type::Coercion::BEGIN@14
15
16sub _croak ($;@) { require Error::TypeTiny; goto \&Error::TypeTiny::croak }
17
18use overload
19321µs634µs
# spent 74µs (18+55) within Type::Coercion::BEGIN@19 which was called: # once (18µs+55µs) by Type::Library::add_coercion at line 24 # spent 54µs (20+34) within Type::Coercion::__ANON__[/opt/perl-5.18.1/lib/site_perl/5.18.1/Type/Coercion.pm:19] which was called 3 times, avg 18µs/call: # 3 times (20µs+34µs) by Type::Library::_mksub at line 100 of Type/Library.pm, avg 18µs/call
q("") => sub { caller =~ m{^(Moo::HandleMoose|Sub::Quote)} ? overload::StrVal($_[0]) : $_[0]->display_name },
# spent 31µs making 3 calls to Type::Coercion::display_name, avg 10µs/call # spent 3µs making 3 calls to Type::Coercion::CORE:match, avg 1µs/call
20 q(bool) => sub { 1 },
21 q(&{}) => "_overload_coderef",
22 q(+) => sub { __PACKAGE__->add(@_) },
231500ns fallback => 1,
24197µs2130µs;
# spent 74µs making 1 call to Type::Coercion::BEGIN@19 # spent 56µs making 1 call to overload::import
25
26
# spent 4µs within Type::Coercion::BEGIN@26 which was called: # once (4µs+0s) by Type::Library::add_coercion at line 30
BEGIN {
271500ns require Type::Tiny;
28 overload->import(q(~~) => sub { $_[0]->has_coercion_for_value($_[1]) })
2916µs if Type::Tiny::SUPPORT_SMARTMATCH();
3013.05ms14µs}
# spent 4µs making 1 call to Type::Coercion::BEGIN@26
31
32sub _overload_coderef
33{
34 my $self = shift;
35
36 if ("Sub::Quote"->can("quote_sub") && $self->can_be_inlined)
37 {
38 $self->{_overload_coderef} = Sub::Quote::quote_sub($self->inline_coercion('$_[0]'))
39 if !$self->{_overload_coderef} || !$self->{_sub_quoted}++;
40 }
41 else
42 {
43 $self->{_overload_coderef} ||= sub { $self->coerce(@_) };
44 }
45
46 $self->{_overload_coderef};
47}
48
49sub new
50
# spent 950µs (67+882) within Type::Coercion::new which was called 3 times, avg 317µs/call: # 3 times (67µs+882µs) by Type::Library::add_coercion at line 271 of Type/Library.pm, avg 317µs/call
{
5131µs my $class = shift;
52310µs my %params = (@_==1) ? %{$_[0]} : @_;
53
5431µs $params{name} = '__ANON__' unless exists($params{name});
5533µs my $C = delete($params{type_coercion_map}) || [];
563600ns my $F = delete($params{frozen});
57
5833µs my $self = bless \%params, $class;
5932µs1850µs $self->add_type_coercions(@$C) if @$C;
# spent 850µs making 1 call to Type::Coercion::add_type_coercions
60313µs34µs Scalar::Util::weaken($self->{type_constraint}); # break ref cycle
# spent 4µs making 3 calls to Scalar::Util::weaken, avg 1µs/call
613300ns $self->{frozen} = $F if $F;
62
6336µs316µs unless ($self->is_anon)
# spent 16µs making 3 calls to Type::Coercion::is_anon, avg 5µs/call
64 {
65 # First try a fast ASCII-only expression, but fall back to Unicode
66321µs612µs $self->name =~ /^_{0,2}[A-Z][A-Za-z0-9_]+$/sm
# spent 9µs making 3 calls to Type::Coercion::CORE:match, avg 3µs/call # spent 3µs making 3 calls to Type::Coercion::name, avg 1µs/call
67 or eval q( use 5.008; $self->name =~ /^_{0,2}\p{Lu}[\p{L}0-9_]+$/sm )
68 or _croak '"%s" is not a valid coercion name', $self->name;
69 }
70
7139µs return $self;
72}
73
741846µs
# spent 22µs within Type::Coercion::name which was called 18 times, avg 1µs/call: # 6 times (8µs+0s) by Type::Coercion::is_anon at line 144, avg 1µs/call # 3 times (4µs+0s) by Type::Library::add_coercion at line 272 of Type/Library.pm, avg 1µs/call # 3 times (4µs+0s) by Type::Coercion::qualified_name at line 138, avg 1µs/call # 3 times (3µs+0s) by Type::Coercion::new at line 66, avg 1µs/call # 3 times (3µs+0s) by Type::Coercion::_build_display_name at line 126, avg 1µs/call
sub name { $_[0]{name} }
75312µs313µs
# spent 31µs (18+13) within Type::Coercion::display_name which was called 3 times, avg 10µs/call: # 3 times (18µs+13µs) by Type::Coercion::__ANON__[/opt/perl-5.18.1/lib/site_perl/5.18.1/Type/Coercion.pm:19] at line 19, avg 10µs/call
sub display_name { $_[0]{display_name} ||= $_[0]->_build_display_name }
# spent 13µs making 3 calls to Type::Coercion::_build_display_name, avg 4µs/call
76sub library { $_[0]{library} }
77sub type_constraint { $_[0]{type_constraint} }
7839µs
# spent 4µs within Type::Coercion::type_coercion_map which was called 3 times, avg 2µs/call: # 3 times (4µs+0s) by Type::Coercion::add_type_coercions at line 218, avg 2µs/call
sub type_coercion_map { $_[0]{type_coercion_map} ||= [] }
79sub moose_coercion { $_[0]{moose_coercion} ||= $_[0]->_build_moose_coercion }
80sub compiled_coercion { $_[0]{compiled_coercion} ||= $_[0]->_build_compiled_coercion }
81129µs
# spent 26µs within Type::Coercion::frozen which was called: # once (26µs+0s) by Type::Coercion::add_type_coercions at line 206
sub frozen { $_[0]{frozen} ||= 0 }
82sub coercion_generator { $_[0]{coercion_generator} }
83sub parameters { $_[0]{parameters} }
84
8539µs
# spent 4µs within Type::Coercion::has_library which was called 3 times, avg 1µs/call: # 3 times (4µs+0s) by Type::Coercion::qualified_name at line 133, avg 1µs/call
sub has_library { exists $_[0]{library} }
86sub has_type_constraint { defined $_[0]{type_constraint} } # sic
8739µs
# spent 4µs within Type::Coercion::has_coercion_generator which was called 3 times, avg 2µs/call: # 3 times (4µs+0s) by Type::Coercion::is_parameterizable at line 401, avg 2µs/call
sub has_coercion_generator { exists $_[0]{coercion_generator} }
88sub has_parameters { exists $_[0]{parameters} }
89
90sub add
91{
92 my $class = shift;
93 my ($x, $y, $swap) = @_;
94
95 Types::TypeTiny::TypeTiny->check($x) and return $x->plus_fallback_coercions($y);
96 Types::TypeTiny::TypeTiny->check($y) and return $y->plus_coercions($x);
97
98 _croak "Attempt to add $class to something that is not a $class"
99 unless blessed($x) && blessed($y) && $x->isa($class) && $y->isa($class);
100
101 ($y, $x) = ($x, $y) if $swap;
102
103 my %opts;
104 if ($x->has_type_constraint and $y->has_type_constraint and $x->type_constraint == $y->type_constraint)
105 {
106 $opts{type_constraint} = $x->type_constraint;
107 }
108 elsif ($x->has_type_constraint and $y->has_type_constraint)
109 {
110# require Type::Tiny::Union;
111# $opts{type_constraint} = "Type::Tiny::Union"->new(
112# type_constraints => [ $x->type_constraint, $y->type_constraint ],
113# );
114 }
115 $opts{display_name} ||= "$x+$y";
116 delete $opts{display_name} if $opts{display_name} eq '__ANON__+__ANON__';
117
118 my $new = $class->new(%opts);
119 $new->add_type_coercions( @{$x->type_coercion_map} );
120 $new->add_type_coercions( @{$y->type_coercion_map} );
121 return $new;
122}
123
124sub _build_display_name
125
# spent 13µs (10+3) within Type::Coercion::_build_display_name which was called 3 times, avg 4µs/call: # 3 times (10µs+3µs) by Type::Coercion::display_name at line 75, avg 4µs/call
{
126313µs33µs shift->name;
# spent 3µs making 3 calls to Type::Coercion::name, avg 1µs/call
127}
128
129sub qualified_name
130
# spent 28µs (21+8) within Type::Coercion::qualified_name which was called 3 times, avg 9µs/call: # 3 times (21µs+8µs) by Type::Library::_mksub at line 100 of Type/Library.pm, avg 9µs/call
{
1313600ns my $self = shift;
132
13334µs34µs if ($self->has_library and not $self->is_anon)
# spent 4µs making 3 calls to Type::Coercion::has_library, avg 1µs/call
134 {
135 return sprintf("%s::%s", $self->library, $self->name);
136 }
137
138310µs34µs return $self->name;
# spent 4µs making 3 calls to Type::Coercion::name, avg 1µs/call
139}
140
141sub is_anon
142
# spent 29µs (22+8) within Type::Coercion::is_anon which was called 6 times, avg 5µs/call: # 3 times (12µs+4µs) by Type::Coercion::new at line 63, avg 5µs/call # 3 times (10µs+3µs) by Type::Library::add_coercion at line 277 of Type/Library.pm, avg 4µs/call
{
14361µs my $self = shift;
144619µs68µs $self->name eq "__ANON__";
# spent 8µs making 6 calls to Type::Coercion::name, avg 1µs/call
145}
146
147
# spent 2µs within Type::Coercion::_clear_compiled_coercion which was called: # once (2µs+0s) by Type::Coercion::add_type_coercions at line 221
sub _clear_compiled_coercion {
1481700ns delete $_[0]{_overload_coderef};
14914µs delete $_[0]{compiled_coercion};
150}
151
152sub freeze { $_[0]{frozen} = 1; $_[0] }
153
154sub coerce
155{
156 my $self = shift;
157 return $self->compiled_coercion->(@_);
158}
159
160sub assert_coerce
161{
162 my $self = shift;
163 my $r = $self->coerce(@_);
164 $self->type_constraint->assert_valid($r)
165 if $self->has_type_constraint;
166 return $r;
167}
168
169sub has_coercion_for_type
170{
171 my $self = shift;
172 my $type = Types::TypeTiny::to_TypeTiny($_[0]);
173
174 return "0 but true"
175 if $self->has_type_constraint && $type->is_a_type_of($self->type_constraint);
176
177 my $c = $self->type_coercion_map;
178 for (my $i = 0; $i <= $#$c; $i += 2)
179 {
180 return !!1 if $type->is_a_type_of($c->[$i]);
181 }
182 return;
183}
184
185sub has_coercion_for_value
186{
187 my $self = shift;
188 local $_ = $_[0];
189
190 return "0 but true"
191 if $self->has_type_constraint && $self->type_constraint->check(@_);
192
193 my $c = $self->type_coercion_map;
194 for (my $i = 0; $i <= $#$c; $i += 2)
195 {
196 return !!1 if $c->[$i]->check(@_);
197 }
198 return;
199}
200
201sub add_type_coercions
202
# spent 850µs (71+780) within Type::Coercion::add_type_coercions which was called: # once (71µs+780µs) by Type::Coercion::new at line 59
{
2031100ns my $self = shift;
20412µs my @args = @_;
205
20611µs126µs _croak "Attempt to add coercion code to a Type::Coercion which has been frozen" if $self->frozen;
# spent 26µs making 1 call to Type::Coercion::frozen
207
2081700ns while (@args)
209 {
21034µs322µs my $type = Types::TypeTiny::to_TypeTiny(shift @args);
# spent 22µs making 3 calls to Types::TypeTiny::to_TypeTiny, avg 7µs/call
21131µs my $coercion = shift @args;
212
21339µs6391µs _croak "Types must be blessed Type::Tiny objects"
# spent 326µs making 3 calls to Type::Tiny::check, avg 109µs/call # spent 65µs making 3 calls to Types::TypeTiny::TypeTiny, avg 22µs/call
214 unless Types::TypeTiny::TypeTiny->check($type);
21538µs6335µs _croak "Coercions must be code references or strings"
# spent 274µs making 3 calls to Type::Tiny::check, avg 91µs/call # spent 61µs making 3 calls to Types::TypeTiny::StringLike, avg 20µs/call
216 unless Types::TypeTiny::StringLike->check($coercion) || Types::TypeTiny::CodeLike->check($coercion);
217
21838µs34µs push @{$self->type_coercion_map}, $type, $coercion;
# spent 4µs making 3 calls to Type::Coercion::type_coercion_map, avg 2µs/call
219 }
220
22111µs12µs $self->_clear_compiled_coercion;
# spent 2µs making 1 call to Type::Coercion::_clear_compiled_coercion
22214µs return $self;
223}
224
225sub _build_compiled_coercion
226{
227 my $self = shift;
228
229 my @mishmash = @{$self->type_coercion_map};
230 return sub { $_[0] } unless @mishmash;
231
232 if ($self->can_be_inlined)
233 {
234 return Eval::TypeTiny::eval_closure(
235 source => sprintf('sub ($) { %s }', $self->inline_coercion('$_[0]')),
236 description => sprintf("compiled coercion '%s'", $self),
237 );
238 }
239
240 # These arrays will be closed over.
241 my (@types, @codes);
242 while (@mishmash)
243 {
244 push @types, shift @mishmash;
245 push @codes, shift @mishmash;
246 }
247 if ($self->has_type_constraint)
248 {
249 unshift @types, $self->type_constraint;
250 unshift @codes, undef;
251 }
252
253 my @sub;
254
255 for my $i (0..$#types)
256 {
257 push @sub,
258 $types[$i]->can_be_inlined ? sprintf('if (%s)', $types[$i]->inline_check('$_[0]')) :
259 sprintf('if ($checks[%d]->(@_))', $i);
260 push @sub,
261 !defined($codes[$i])
262 ? sprintf(' { return $_[0] }') :
263 Types::TypeTiny::StringLike->check($codes[$i])
264 ? sprintf(' { local $_ = $_[0]; return( %s ) }', $codes[$i]) :
265 sprintf(' { local $_ = $_[0]; return $codes[%d]->(@_) }', $i);
266 }
267
268 push @sub, 'return $_[0];';
269
270 return Eval::TypeTiny::eval_closure(
271 source => sprintf('sub ($) { %s }', join qq[\n], @sub),
272 description => sprintf("compiled coercion '%s'", $self),
273 environment => {
274 '@checks' => [ map $_->compiled_check, @types ],
275 '@codes' => \@codes,
276 },
277 );
278}
279
280sub can_be_inlined
281{
282 my $self = shift;
283 return
284 if $self->has_type_constraint
285 && !$self->type_constraint->can_be_inlined;
286
287 my @mishmash = @{$self->type_coercion_map};
288 while (@mishmash)
289 {
290 my ($type, $converter) = splice(@mishmash, 0, 2);
291 return unless $type->can_be_inlined;
292 return unless Types::TypeTiny::StringLike->check($converter);
293 }
294 return !!1;
295}
296
297sub _source_type_union
298{
299 my $self = shift;
300
301 my @r;
302 push @r, $self->type_constraint if $self->has_type_constraint;
303
304 my @mishmash = @{$self->type_coercion_map};
305 while (@mishmash)
306 {
307 my ($type) = splice(@mishmash, 0, 2);
308 push @r, $type;
309 }
310
311 require Type::Tiny::Union;
312 return "Type::Tiny::Union"->new(type_constraints => \@r, tmp => 1);
313}
314
315sub inline_coercion
316{
317 my $self = shift;
318 my $varname = $_[0];
319
320 _croak "This coercion cannot be inlined" unless $self->can_be_inlined;
321
322 my @mishmash = @{$self->type_coercion_map};
323 return "($varname)" unless @mishmash;
324
325 my (@types, @codes);
326 while (@mishmash)
327 {
328 push @types, shift @mishmash;
329 push @codes, shift @mishmash;
330 }
331 if ($self->has_type_constraint)
332 {
333 unshift @types, $self->type_constraint;
334 unshift @codes, undef;
335 }
336
337 my @sub;
338
339 for my $i (0..$#types)
340 {
341 push @sub, sprintf('(%s) ?', $types[$i]->inline_check($varname));
342 push @sub,
343 (defined($codes[$i]) && ($varname eq '$_'))
344 ? sprintf('scalar(%s) :', $codes[$i]) :
345 defined($codes[$i])
346 ? sprintf('do { local $_ = %s; scalar(%s) } :', $varname, $codes[$i]) :
347 sprintf('%s :', $varname);
348 }
349
350 push @sub, "$varname";
351
352 "@sub";
353}
354
355sub _build_moose_coercion
356{
357 my $self = shift;
358
359 my %options = ();
360 $options{type_coercion_map} = [ $self->freeze->_codelike_type_coercion_map('moose_type') ];
361 $options{type_constraint} = $self->type_constraint if $self->has_type_constraint;
362
363 require Moose::Meta::TypeCoercion;
364 my $r = "Moose::Meta::TypeCoercion"->new(%options);
365
366 return $r;
367}
368
369sub _codelike_type_coercion_map
370{
371 my $self = shift;
372 my $modifier = $_[0];
373
374 my @orig = @{ $self->type_coercion_map };
375 my @new;
376
377 while (@orig)
378 {
379 my ($type, $converter) = splice(@orig, 0, 2);
380
381 push @new, $modifier ? $type->$modifier : $type;
382
383 if (Types::TypeTiny::CodeLike->check($converter))
384 {
385 push @new, $converter;
386 }
387 else
388 {
389 Eval::TypeTiny::eval_closure(
390 source => sprintf('sub { local $_ = $_[0]; %s }', $converter),
391 description => sprintf("temporary compiled converter from '%s'", $type),
392 );
393 }
394 }
395
396 return @new;
397}
398
399sub is_parameterizable
400
# spent 15µs (10+5) within Type::Coercion::is_parameterizable which was called 3 times, avg 5µs/call: # 3 times (10µs+5µs) by Type::Library::_mksub at line 82 of Type/Library.pm, avg 5µs/call
{
40139µs34µs shift->has_coercion_generator;
# spent 4µs making 3 calls to Type::Coercion::has_coercion_generator, avg 2µs/call
402}
403
404sub is_parameterized
405{
406 shift->has_parameters;
407}
408
409sub parameterize
410{
411 my $self = shift;
412 return $self unless @_;
413 $self->is_parameterizable
414 or _croak "Constraint '%s' does not accept parameters", "$self";
415
416 @_ = map Types::TypeTiny::to_TypeTiny($_), @_;
417
418 return ref($self)->new(
419 type_constraint => $self->type_constraint,
420 type_coercion_map => [ $self->coercion_generator->($self, $self->type_constraint, @_) ],
421 parameters => \@_,
422 frozen => 1,
423 );
424}
425
426sub isa
427{
428 my $self = shift;
429
430 if ($INC{"Moose.pm"} and blessed($self) and $_[0] eq 'Moose::Meta::TypeCoercion')
431 {
432 return !!1;
433 }
434
435 if ($INC{"Moose.pm"} and blessed($self) and $_[0] =~ /^Moose/ and my $r = $self->moose_coercion->isa(@_))
436 {
437 return $r;
438 }
439
440 $self->SUPER::isa(@_);
441}
442
443sub can
444{
445 my $self = shift;
446
447 my $can = $self->SUPER::can(@_);
448 return $can if $can;
449
450 if ($INC{"Moose.pm"} and blessed($self) and my $method = $self->moose_coercion->can(@_))
451 {
452 return sub { $method->(shift->moose_coercion, @_) };
453 }
454
455 return;
456}
457
458sub AUTOLOAD
459{
460 my $self = shift;
461 my ($m) = (our $AUTOLOAD =~ /::(\w+)$/);
462 return if $m eq 'DESTROY';
463
464 if ($INC{"Moose.pm"} and blessed($self) and my $method = $self->moose_coercion->can($m))
465 {
466 return $method->($self->moose_coercion, @_);
467 }
468
469 _croak q[Can't locate object method "%s" via package "%s"], $m, ref($self)||$self;
470}
471
472# Private Moose method, but Moo uses this...
473sub _compiled_type_coercion
474{
475 my $self = shift;
476 if (@_)
477 {
478 my $thing = $_[0];
479 if (blessed($thing) and $thing->isa("Type::Coercion"))
480 {
481 $self->add_type_coercions(@{$thing->type_coercion_map});
482 }
483 elsif (Types::TypeTiny::CodeLike->check($thing))
484 {
485 require Types::Standard;
486 $self->add_type_coercions(Types::Standard::Any(), $thing);
487 }
488 }
489 $self->compiled_coercion;
490}
491
49212µs*compile_type_coercion = \&compiled_coercion;
493sub meta { _croak("Not really a Moose::Meta::TypeCoercion. Sorry!") }
494
49514µs1;
496
497__END__
 
# spent 12µs within Type::Coercion::CORE:match which was called 6 times, avg 2µs/call: # 3 times (9µs+0s) by Type::Coercion::new at line 66, avg 3µs/call # 3 times (3µs+0s) by Type::Coercion::__ANON__[/opt/perl-5.18.1/lib/site_perl/5.18.1/Type/Coercion.pm:19] at line 19, avg 1µs/call
sub Type::Coercion::CORE:match; # opcode