← Index
NYTProf Performance Profile   « line view »
For ../prof.pl
  Run on Wed Dec 14 16:10:05 2022
Reported on Wed Dec 14 16:12:57 2022

Filename/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Eval/TypeTiny.pm
StatementsExecuted 4320 statements in 20.6ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
1311116.0ms17.2msEval::TypeTiny::::_clean_evalEval::TypeTiny::_clean_eval
131533.14ms21.2msEval::TypeTiny::::eval_closureEval::TypeTiny::eval_closure
19854745µs1.33msEval::TypeTiny::::set_subnameEval::TypeTiny::set_subname
4022559µs6.94msEval::TypeTiny::::type_to_coderefEval::TypeTiny::type_to_coderef
13111257µs257µsEval::TypeTiny::::CORE:substEval::TypeTiny::CORE:subst (opcode)
4011219µs229µsEval::TypeTiny::::_make_lexical_assignmentEval::TypeTiny::_make_lexical_assignment
11161µs61µsEval::TypeTiny::::_pick_alternativeEval::TypeTiny::_pick_alternative
1311147µs47µsEval::TypeTiny::::CORE:sortEval::TypeTiny::CORE:sort (opcode)
11142µs54µsEval::TypeTiny::::BEGIN@3Eval::TypeTiny::BEGIN@3
11117µs289µsEval::TypeTiny::::importEval::TypeTiny::import
401110µs10µsEval::TypeTiny::::CORE:matchEval::TypeTiny::CORE:match (opcode)
1119µs31µsEval::TypeTiny::::BEGIN@13Eval::TypeTiny::BEGIN@13
1114µs4µsEval::TypeTiny::::BEGIN@61Eval::TypeTiny::BEGIN@61
1114µs21µsEval::TypeTiny::::BEGIN@81Eval::TypeTiny::BEGIN@81
1113µs3µsEval::TypeTiny::::BEGIN@15Eval::TypeTiny::BEGIN@15
0000s0sEval::TypeTiny::::ALIAS_IMPLEMENTATIONEval::TypeTiny::ALIAS_IMPLEMENTATION
0000s0sEval::TypeTiny::::__ANON__[:141]Eval::TypeTiny::__ANON__[:141]
0000s0sEval::TypeTiny::::_force_implementationEval::TypeTiny::_force_implementation
0000s0sEval::TypeTiny::::_manufacture_tiesEval::TypeTiny::_manufacture_ties
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package Eval::TypeTiny;
2
3291µs266µs
# spent 54µs (42+12) within Eval::TypeTiny::BEGIN@3 which was called: # once (42µs+12µs) by Type::Library::BEGIN@14 at line 3
use strict;
# spent 54µs making 1 call to Eval::TypeTiny::BEGIN@3 # spent 12µs making 1 call to strict::import
4
5
# spent 17.2ms (16.0+1.20) within Eval::TypeTiny::_clean_eval which was called 131 times, avg 131µs/call: # 131 times (16.0ms+1.20ms) by Eval::TypeTiny::eval_closure at line 235, avg 131µs/call
sub _clean_eval {
613122µs local $@;
7131198µs local $SIG{__DIE__};
813112.5ms my $r = eval $_[0];
# spent 1.45ms executing statements in string eval
# includes 1.16ms spent executing 344 calls to 2 subs defined therein. # spent 1.40ms executing statements in 20 string evals (merged)
# includes 1.01ms spent executing 197 calls to 22 subs defined therein. # spent 523µs executing statements in 20 string evals (merged)
# includes 227µs spent executing 141 calls to 22 subs defined therein. # spent 199µs executing statements in string eval
# includes 16µs spent executing 2 calls to 4 subs defined therein. # spent 152µs executing statements in string eval
# includes 35µs spent executing 2 calls to 4 subs defined therein. # spent 144µs executing statements in string eval
# includes 13µs spent executing 3 calls to 5 subs defined therein. # spent 138µs executing statements in string eval
# includes 12µs spent executing 2 calls to 4 subs defined therein. # spent 130µs executing statements in string eval
# includes 33µs spent executing 2 calls to 4 subs defined therein. # spent 120µs executing statements in string eval
# includes 9µs spent executing 2 calls to 4 subs defined therein. # spent 115µs executing statements in string eval
# includes 11µs spent executing 2 calls to 4 subs defined therein. # spent 105µs executing statements in string eval
# includes 12µs spent executing 2 calls to 4 subs defined therein. # spent 102µs executing statements in string eval
# includes 17µs spent executing 2 calls to 4 subs defined therein. # spent 94µs executing statements in string eval
# includes 25µs spent executing 2 calls to 4 subs defined therein. # spent 87µs executing statements in string eval
# includes 8µs spent executing 2 calls to 4 subs defined therein. # spent 87µs executing statements in string eval
# includes 13µs spent executing 2 calls to 4 subs defined therein. # spent 86µs executing statements in string eval
# includes 11µs spent executing 2 calls to 4 subs defined therein. # spent 83µs executing statements in string eval
# includes 14µs spent executing 2 calls to 4 subs defined therein. # spent 78µs executing statements in string eval
# includes 9µs spent executing 2 calls to 4 subs defined therein. # spent 75µs executing statements in string eval
# includes 14µs spent executing 2 calls to 4 subs defined therein. # spent 70µs executing statements in string eval
# includes 16µs spent executing 2 calls to 4 subs defined therein. # spent 70µs executing statements in string eval
# includes 14µs spent executing 2 calls to 4 subs defined therein. # spent 69µs executing statements in string eval
# includes 45µs spent executing 39 calls to 2 subs defined therein. # spent 68µs executing statements in string eval
# includes 10µs spent executing 2 calls to 4 subs defined therein. # spent 68µs executing statements in string eval
# includes 10µs spent executing 2 calls to 4 subs defined therein. # spent 62µs executing statements in string eval
# includes 13µs spent executing 2 calls to 4 subs defined therein. # spent 61µs executing statements in string eval
# includes 11µs spent executing 2 calls to 4 subs defined therein. # spent 58µs executing statements in string eval
# includes 9µs spent executing 2 calls to 4 subs defined therein. # spent 56µs executing statements in string eval
# includes 10µs spent executing 2 calls to 4 subs defined therein. # spent 54µs executing statements in string eval
# includes 8µs spent executing 2 calls to 4 subs defined therein. # spent 54µs executing statements in string eval
# includes 11µs spent executing 2 calls to 4 subs defined therein. # spent 51µs executing statements in string eval
# includes 10µs spent executing 2 calls to 4 subs defined therein. # spent 50µs executing statements in string eval
# includes 7µs spent executing 2 calls to 4 subs defined therein. # spent 46µs executing statements in string eval
# includes 10µs spent executing 2 calls to 4 subs defined therein. # spent 46µs executing statements in string eval
# includes 8µs spent executing 2 calls to 4 subs defined therein. # spent 46µs executing statements in string eval
# includes 12µs spent executing 2 calls to 4 subs defined therein. # spent 44µs executing statements in string eval
# includes 9µs spent executing 2 calls to 4 subs defined therein. # spent 43µs executing statements in string eval
# includes 7µs spent executing 2 calls to 4 subs defined therein. # spent 42µs executing statements in string eval
# includes 10µs spent executing 2 calls to 4 subs defined therein. # spent 42µs executing statements in string eval
# includes 7µs spent executing 2 calls to 4 subs defined therein. # spent 42µs executing statements in string eval
# includes 42µs spent executing 2 calls to 4 subs defined therein. # spent 42µs executing statements in string eval
# includes 10µs spent executing 2 calls to 4 subs defined therein. # spent 37µs executing statements in string eval
# includes 6µs spent executing 2 calls to 4 subs defined therein. # spent 36µs executing statements in string eval
# includes 32µs spent executing 1 call to 2 subs defined therein. # spent 32µs executing statements in string eval
# includes 0s spent executing 1 call to 3 subs defined therein. # spent 26µs executing statements in string eval
# includes 3µs spent executing 1 call to 3 subs defined therein. # spent 16µs executing statements in string eval
# includes 6µs spent executing 1 call to 2 subs defined therein. # spent 16µs executing statements in string eval
# includes 7µs spent executing 1 call to 2 subs defined therein. # spent 15µs executing statements in 2 string evals (merged)
# includes 4µs spent executing 2 calls to 2 subs defined therein. # spent 14µs executing statements in string eval
# includes 4µs spent executing 1 call to 2 subs defined therein. # spent 13µs executing statements in string eval
# includes 6µs spent executing 1 call to 3 subs defined therein. # spent 12µs executing statements in string eval
# includes 4µs spent executing 1 call to 2 subs defined therein. # spent 11µs executing statements in 2 string evals (merged)
# includes 4µs spent executing 2 calls to 2 subs defined therein. # spent 11µs executing statements in string eval
# includes 6µs spent executing 1 call to 2 subs defined therein. # spent 11µs executing statements in string eval
# includes 3µs spent executing 1 call to 3 subs defined therein. # spent 10µs executing statements in string eval
# includes 4µs spent executing 1 call to 2 subs defined therein. # spent 10µs executing statements in string eval
# includes 1µs spent executing 1 call to 2 subs defined therein. # spent 10µs executing statements in string eval
# includes 3µs spent executing 1 call to 2 subs defined therein. # spent 10µs executing statements in string eval
# includes 3µs spent executing 1 call to 3 subs defined therein. # spent 10µs executing statements in string eval
# includes 3µs spent executing 1 call to 3 subs defined therein. # spent 10µs executing statements in string eval
# includes 5µs spent executing 1 call to 2 subs defined therein. # spent 10µs executing statements in string eval
# includes 2µs spent executing 1 call to 2 subs defined therein. # spent 10µs executing statements in 2 string evals (merged)
# includes 2µs spent executing 2 calls to 4 subs defined therein. # spent 9µs executing statements in string eval
# includes 4µs spent executing 1 call to 2 subs defined therein. # spent 9µs executing statements in string eval
# includes 3µs spent executing 1 call to 2 subs defined therein. # spent 8µs executing statements in string eval
# includes 2µs spent executing 1 call to 2 subs defined therein. # spent 8µs executing statements in string eval
# includes 2µs spent executing 1 call to 2 subs defined therein. # spent 8µs executing statements in string eval
# includes 2µs spent executing 1 call to 3 subs defined therein. # spent 8µs executing statements in string eval
# includes 1µs spent executing 1 call to 3 subs defined therein. # spent 8µs executing statements in string eval
# includes 2µs spent executing 1 call to 3 subs defined therein. # spent 7µs executing statements in string eval
# includes 2µs spent executing 1 call to 3 subs defined therein. # spent 7µs executing statements in string eval
# includes 2µs spent executing 1 call to 2 subs defined therein. # spent 7µs executing statements in string eval
# includes 2µs spent executing 1 call to 3 subs defined therein. # spent 7µs executing statements in string eval
# includes 2µs spent executing 1 call to 3 subs defined therein. # spent 6µs executing statements in string eval
# includes 1µs spent executing 1 call to 3 subs defined therein. # spent 6µs executing statements in string eval
# includes 2µs spent executing 1 call to 2 subs defined therein. # spent 6µs executing statements in string eval
# includes 2µs spent executing 1 call to 2 subs defined therein. # spent 6µs executing statements in string eval
# includes 1µs spent executing 1 call to 2 subs defined therein. # spent 6µs executing statements in string eval
# includes 1µs spent executing 1 call to 2 subs defined therein. # spent 6µs executing statements in string eval
# includes 2µs spent executing 1 call to 2 subs defined therein. # spent 6µs executing statements in string eval
# includes 2µs spent executing 1 call to 2 subs defined therein. # spent 6µs executing statements in string eval
# includes 1µs spent executing 1 call to 3 subs defined therein. # spent 6µs executing statements in string eval
# includes 2µs spent executing 1 call to 3 subs defined therein. # spent 6µs executing statements in string eval
# includes 1µs spent executing 1 call to 3 subs defined therein. # spent 6µs executing statements in string eval
# includes 1µs spent executing 1 call to 3 subs defined therein. # spent 5µs executing statements in string eval
# includes 1µs spent executing 1 call to 3 subs defined therein. # spent 5µs executing statements in string eval
# includes 0s spent executing 1 call to 3 subs defined therein. # spent 5µs executing statements in string eval
# includes 2µs spent executing 1 call to 3 subs defined therein. # spent 5µs executing statements in string eval
# includes 2µs spent executing 1 call to 2 subs defined therein. # spent 4µs executing statements in string eval
# includes 0s spent executing 1 call to 2 subs defined therein. # spent 4µs executing statements in string eval
# includes 0s spent executing 1 call to 3 subs defined therein.
913149µs my $e = $@;
10131622µs return ( $r, $e );
11}
12
132117µs253µs
# spent 31µs (9+22) within Eval::TypeTiny::BEGIN@13 which was called: # once (9µs+22µs) by Type::Library::BEGIN@14 at line 13
use warnings;
# spent 31µs making 1 call to Eval::TypeTiny::BEGIN@13 # spent 22µs making 1 call to warnings::import
14
15
# spent 3µs within Eval::TypeTiny::BEGIN@15 which was called: # once (3µs+0s) by Type::Library::BEGIN@14 at line 18
BEGIN {
1611µs *HAS_LEXICAL_SUBS = ( $] >= 5.018 ) ? sub () { !!1 } : sub () { !!0 };
1712µs *NICE_PROTOTYPES = ( $] >= 5.014 ) ? sub () { !!1 } : sub () { !!0 };
181181µs13µs}
# spent 3µs making 1 call to Eval::TypeTiny::BEGIN@15
19
20
# spent 61µs within Eval::TypeTiny::_pick_alternative which was called: # once (61µs+0s) by Eval::TypeTiny::set_subname at line 96
sub _pick_alternative {
2110s my $ok = 0;
2210s while ( @_ ) {
2312µs my ( $type, $condition, $result ) = splice @_, 0, 3;
2413µs if ( $type eq 'needs' ) {
25126µs ++$ok if eval "require $condition; 1";
# spent 4µs executing statements in string eval
26 }
27 elsif ( $type eq 'if' ) {
28 ++$ok if $condition;
29 }
3010s next unless $ok;
31125µs return ref( $result ) eq 'CODE' ? $result->() : ref( $result ) eq 'SCALAR' ? eval( $$result ) : $result;
# spent 3µs executing statements in string eval
32 }
33 return;
34}
35
36{
37 sub IMPLEMENTATION_DEVEL_LEXALIAS () { 'Devel::LexAlias' }
38 sub IMPLEMENTATION_PADWALKER () { 'PadWalker' }
39 sub IMPLEMENTATION_TIE () { 'tie' }
40 sub IMPLEMENTATION_NATIVE () { 'perl' }
41
4210s my $implementation;
43
44 #<<<
45 # uncoverable subroutine
46 sub ALIAS_IMPLEMENTATION () {
47 $implementation ||= _pick_alternative(
48 if => ( $] ge '5.022' ) => IMPLEMENTATION_NATIVE,
49 needs => 'Devel::LexAlias' => IMPLEMENTATION_DEVEL_LEXALIAS,
50 needs => 'PadWalker' => IMPLEMENTATION_PADWALKER,
51 if => !!1 => IMPLEMENTATION_TIE,
52 );
53 }
54 #>>>
55
56 sub _force_implementation {
57 $implementation = shift;
58 }
59}
60
6110s
# spent 4µs within Eval::TypeTiny::BEGIN@61 which was called: # once (4µs+0s) by Type::Library::BEGIN@14 at line 63
BEGIN {
6213µs *_EXTENDED_TESTING = $ENV{EXTENDED_TESTING} ? sub() { !!1 } : sub() { !!0 };
63184µs14µs}
# spent 4µs making 1 call to Eval::TypeTiny::BEGIN@61
64
6510sour $AUTHORITY = 'cpan:TOBYINK';
6611µsour $VERSION = '2.000001';
6711µsour @EXPORT = qw( eval_closure );
6811µsour @EXPORT_OK = qw(
69 HAS_LEXICAL_SUBS HAS_LEXICAL_VARS ALIAS_IMPLEMENTATION
70 IMPLEMENTATION_DEVEL_LEXALIAS IMPLEMENTATION_PADWALKER
71 IMPLEMENTATION_NATIVE IMPLEMENTATION_TIE
72 set_subname type_to_coderef NICE_PROTOTYPES
73);
74
7511µs$VERSION =~ tr/_//d;
76
77# See Types::TypeTiny for an explanation of this import method.
78#
79# uncoverable subroutine
80
# spent 289µs (17+272) within Eval::TypeTiny::import which was called: # once (17µs+272µs) by Type::Library::BEGIN@14 at line 14 of Type/Library.pm
sub import {
8121.65ms238µs
# spent 21µs (4+17) within Eval::TypeTiny::BEGIN@81 which was called: # once (4µs+17µs) by Type::Library::BEGIN@14 at line 81
no warnings "redefine";
# spent 21µs making 1 call to Eval::TypeTiny::BEGIN@81 # spent 17µs making 1 call to warnings::unimport
8217µs our @ISA = qw( Exporter::Tiny );
8311µs require Exporter::Tiny;
8411µs my $next = \&Exporter::Tiny::import;
8511µs *import = $next;
8610s my $class = shift;
8711µs my $opts = { ref( $_[0] ) ? %{ +shift } : () };
8811µs $opts->{into} ||= scalar( caller );
89112µs1272µs return $class->$next( $opts, @_ );
# spent 272µs making 1 call to Exporter::Tiny::import
90} #/ sub import
91
92{
9310s my $subname;
9410s my %already; # prevent renaming established functions
95
# spent 1.33ms (745µs+582µs) within Eval::TypeTiny::set_subname which was called 198 times, avg 7µs/call: # 148 times (459µs+336µs) by Type::Library::add_type at line 239 of Type/Library.pm, avg 5µs/call # 40 times (234µs+200µs) by Eval::TypeTiny::type_to_coderef at line 177, avg 11µs/call # 7 times (39µs+32µs) by Types::Standard::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Types/Standard.pm:190] at line 186 of Types/Standard.pm, avg 10µs/call # 2 times (6µs+9µs) by Type::Tiny::new at line 364 of Type/Tiny.pm, avg 8µs/call # once (7µs+5µs) by Type::Library::make_immutable at line 322 of Type/Library.pm
sub set_subname ($$) {
9619850µs161µs $subname = _pick_alternative(
# spent 61µs making 1 call to Eval::TypeTiny::_pick_alternative
97 needs => 'Sub::Util' => \ q{ \&Sub::Util::set_subname },
98 needs => 'Sub::Name' => \ q{ \&Sub::Name::subname },
99 if => !!1 => 0,
100 ) unless defined $subname;
1011981.24ms147521µs $subname and !$already{$_[1]}++ and return &$subname;
# spent 521µs making 147 calls to Sub::Util::set_subname, avg 4µs/call
1025169µs $_[1];
103 } #/ sub set_subname ($$)
104}
105
10611µs
# spent 6.94ms (559µs+6.38) within Eval::TypeTiny::type_to_coderef which was called 40 times, avg 173µs/call: # 37 times (517µs+5.71ms) by Type::Tiny::exportables at line 1197 of Type/Tiny.pm, avg 168µs/call # 3 times (42µs+669µs) by Type::Library::add_coercion at line 287 of Type/Library.pm, avg 237µs/call
sub type_to_coderef {
107409µs my ( $type, %args ) = @_;
1084021µs my $post_method = $args{post_method} || q();
109
110407µs my ( $coderef, $qualified_name );
111
1124052µs if ( ! defined $type ) {
113 my $library = $args{type_library};
114 my $name = $args{type_name};
115
116 $qualified_name = "$library\::$name";
117 $coderef = sub (;@) {
118 my $params;
119 $params = shift if ref( $_[0] ) eq "ARRAY";
120
121 $type ||= do {
122 $library->can( 'get_type' )
123 or require Error::TypeTiny
124 && Error::TypeTiny::croak( "Expected $library to be a type library, but it doesn't seem to be" );
125 $library->get_type( $name );
126 };
127
128 my $t;
129 if ( $type ) {
130 $t = $params ? $type->parameterize( @$params ) : $type;
131 $t = $t->$post_method if $post_method;
132 }
133 else {
134 require Error::TypeTiny && Error::TypeTiny::croak( "Cannot parameterize a non-existant type" )
135 if $params;
136 require Type::Tiny::_DeclaredType;
137 $t = Type::Tiny::_DeclaredType->new( library => $library, name => $name );
138 }
139
140 @_ && wantarray ? return ( $t, @_ ) : return $t;
141 };
142
143 require Scalar::Util && &Scalar::Util::set_prototype( $coderef, ';$' )
144 if Eval::TypeTiny::NICE_PROTOTYPES;
145 }
146 else {
147
148 #<<<
1494076µs40145µs my $source = $type->is_parameterizable ?
# spent 134µs making 37 calls to Type::Tiny::is_parameterizable, avg 4µs/call # spent 11µs making 3 calls to Type::Coercion::is_parameterizable, avg 4µs/call
150 sprintf(
151 q{
152 sub (%s) {
153 if (ref($_[0]) eq 'Type::Tiny::_HalfOp') {
154 my $complete_type = shift->complete($type);
155 @_ && wantarray ? return($complete_type, @_) : return $complete_type;
156 }
157 my $params; $params = shift if ref($_[0]) eq q(ARRAY);
158 my $t = $params ? $type->parameterize(@$params) : $type;
159 @_ && wantarray ? return($t%s, @_) : return $t%s;
160 }
161 },
162 NICE_PROTOTYPES ? q(;$) : q(;@),
163 $post_method,
164 $post_method,
165 ) :
166 sprintf( q{ sub () { $type%s if $] } }, $post_method );
167 #>>>
168
1694051µs40170µs $qualified_name = $type->qualified_name;
# spent 146µs making 37 calls to Type::Tiny::qualified_name, avg 4µs/call # spent 24µs making 3 calls to Type::Coercion::qualified_name, avg 8µs/call
170 $coderef = eval_closure(
171 source => $source,
17240123µs405.63ms description => $args{description} || sprintf( "exportable function '%s'", $qualified_name ),
# spent 5.63ms making 40 calls to Eval::TypeTiny::eval_closure, avg 141µs/call
173 environment => { '$type' => \$type },
174 );
175 }
176
17740165µs40434µs $args{anonymous} ? $coderef : set_subname( $qualified_name, $coderef );
# spent 434µs making 40 calls to Eval::TypeTiny::set_subname, avg 11µs/call
178}
179
180
# spent 21.2ms (3.14+18.1) within Eval::TypeTiny::eval_closure which was called 131 times, avg 162µs/call: # 48 times (1.34ms+7.25ms) by Type::Tiny::_build_compiled_check at line 537 of Type/Tiny.pm, avg 179µs/call # 40 times (998µs+4.63ms) by Eval::TypeTiny::type_to_coderef at line 172, avg 141µs/call # 37 times (646µs+5.64ms) by Type::Tiny::_overload_coderef at line 215 of Type/Tiny.pm, avg 170µs/call # 5 times (126µs+371µs) by Type::Tiny::new at line 268 of Type/Tiny.pm, avg 99µs/call # once (28µs+165µs) by Type::Coercion::_build_compiled_coercion at line 265 of Type/Coercion.pm
sub eval_closure {
181131166µs my ( %args ) = @_;
182 my $src =
183 ref $args{source} eq "ARRAY"
184 ? join( "\n", @{ $args{source} } )
18513191µs : $args{source};
186
18713178µs $args{alias} = 0 unless defined $args{alias};
18813162µs $args{line} = 1 unless defined $args{line};
189 $args{description} =~ s/[^\w .:-\[\]\(\)\{\}\']//g
190131543µs131257µs if defined $args{description};
# spent 257µs making 131 calls to Eval::TypeTiny::CORE:subst, avg 2µs/call
191 $src = qq{#line $args{line} "$args{description}"\n$src}
192131123µs if defined $args{description} && !( $^P & 0x10 );
19313182µs $args{environment} ||= {};
194
195 if ( _EXTENDED_TESTING ) {
196 require Scalar::Util;
197 for my $k ( sort keys %{ $args{environment} } ) {
198 next
199 if $k =~ /^\$/
200 && Scalar::Util::reftype( $args{environment}{$k} ) =~ /^(SCALAR|REF)$/;
201 next
202 if $k =~ /^\@/
203 && Scalar::Util::reftype( $args{environment}{$k} ) eq q(ARRAY);
204 next
205 if $k =~ /^\%/
206 && Scalar::Util::reftype( $args{environment}{$k} ) eq q(HASH);
207 next
208 if $k =~ /^\&/
209 && Scalar::Util::reftype( $args{environment}{$k} ) eq q(CODE);
210
211 require Error::TypeTiny;
212 Error::TypeTiny::croak(
213 "Expected a variable name and ref; got %s => %s", $k,
214 $args{environment}{$k}
215 );
216 } #/ for my $k ( sort keys %...)
217 } #/ if ( _EXTENDED_TESTING)
218
21913131µs my $sandpkg = 'Eval::TypeTiny::Sandbox';
220131105µs my $alias = exists( $args{alias} ) ? $args{alias} : 0;
221131413µs13147µs my @keys = sort keys %{ $args{environment} };
# spent 47µs making 131 calls to Eval::TypeTiny::CORE:sort, avg 359ns/call
22213127µs my $i = 0;
223131222µs40229µs my $source = join "\n" => (
# spent 229µs making 40 calls to Eval::TypeTiny::_make_lexical_assignment, avg 6µs/call
224 "package $sandpkg;",
225 "sub {",
226 map( _make_lexical_assignment( $_, $i++, $alias ), @keys ),
227 $src,
228 "}",
229 );
230
23113130µs if ( $alias and ALIAS_IMPLEMENTATION eq IMPLEMENTATION_TIE ) {
232 _manufacture_ties();
233 }
234
235131212µs13117.2ms my ( $compiler, $e ) = _clean_eval( $source );
# spent 17.2ms making 131 calls to Eval::TypeTiny::_clean_eval, avg 131µs/call
23613128µs if ( $e ) {
237 chomp $e;
238 require Error::TypeTiny::Compilation;
239 "Error::TypeTiny::Compilation"->throw(
240 code => (
241 ref $args{source} eq "ARRAY" ? join( "\n", @{ $args{source} } ) : $args{source}
242 ),
243 errstr => $e,
244 environment => $args{environment},
245 );
246 } #/ if ( $e )
247
248131247µs131318µs my $code = $compiler->( @{ $args{environment} }{@keys} );
# spent 54µs making 20 calls to Eval::TypeTiny::Sandbox::__ANON__[(eval 100)[Eval/TypeTiny.pm:8]:5], avg 3µs/call # spent 49µs making 20 calls to Eval::TypeTiny::Sandbox::__ANON__[(eval 103)[Eval/TypeTiny.pm:8]:15], avg 2µs/call # spent 32µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 360)[Eval/TypeTiny.pm:8]:4] # spent 7µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 279)[Eval/TypeTiny.pm:8]:4] # spent 6µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 266)[Eval/TypeTiny.pm:8]:4] # spent 6µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 365)[Eval/TypeTiny.pm:8]:4] # spent 6µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 80)[Eval/TypeTiny.pm:8]:4] # spent 5µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 271)[Eval/TypeTiny.pm:8]:4] # spent 4µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 135)[Eval/TypeTiny.pm:8]:4] # spent 4µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 216)[Eval/TypeTiny.pm:8]:4] # spent 4µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 242)[Eval/TypeTiny.pm:8]:4] # spent 4µs making 2 calls to Eval::TypeTiny::Sandbox::__ANON__[(eval 274)[Eval/TypeTiny.pm:8]:4], avg 2µs/call # spent 4µs making 2 calls to Eval::TypeTiny::Sandbox::__ANON__[(eval 275)[Eval/TypeTiny.pm:8]:4], avg 2µs/call # spent 4µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 282)[Eval/TypeTiny.pm:8]:4] # spent 4µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 339)[Eval/TypeTiny.pm:8]:4] # spent 3µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 113)[Eval/TypeTiny.pm:8]:4] # spent 3µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 116)[Eval/TypeTiny.pm:8]:4] # spent 3µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 151)[Eval/TypeTiny.pm:8]:4] # spent 3µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 278)[Eval/TypeTiny.pm:8]:4] # spent 3µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 324)[Eval/TypeTiny.pm:8]:4] # spent 3µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 53)[Eval/TypeTiny.pm:8]:4] # spent 3µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 55)[Eval/TypeTiny.pm:8]:4] # spent 3µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 57)[Eval/TypeTiny.pm:8]:4] # spent 3µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 64)[Eval/TypeTiny.pm:8]:4] # spent 3µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 78)[Eval/TypeTiny.pm:8]:4] # spent 3µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 86)[Eval/TypeTiny.pm:8]:4] # spent 2µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 102)[Eval/TypeTiny.pm:8]:4] # spent 2µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 105)[Eval/TypeTiny.pm:8]:4] # spent 2µs making 2 calls to Eval::TypeTiny::Sandbox::__ANON__[(eval 107)[Eval/TypeTiny.pm:8]:4], avg 1µs/call # spent 2µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 110)[Eval/TypeTiny.pm:8]:4] # spent 2µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 111)[Eval/TypeTiny.pm:8]:4] # spent 2µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 114)[Eval/TypeTiny.pm:8]:4] # spent 2µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 120)[Eval/TypeTiny.pm:8]:4] # spent 2µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 131)[Eval/TypeTiny.pm:8]:4] # spent 2µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 136)[Eval/TypeTiny.pm:8]:4] # spent 2µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 139)[Eval/TypeTiny.pm:8]:4] # spent 2µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 141)[Eval/TypeTiny.pm:8]:4] # spent 2µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 145)[Eval/TypeTiny.pm:8]:4] # spent 2µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 147)[Eval/TypeTiny.pm:8]:4] # spent 2µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 214)[Eval/TypeTiny.pm:8]:4] # spent 2µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 252)[Eval/TypeTiny.pm:8]:4] # spent 2µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 256)[Eval/TypeTiny.pm:8]:4] # spent 2µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 323)[Eval/TypeTiny.pm:8]:4] # spent 2µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 325)[Eval/TypeTiny.pm:8]:4] # spent 2µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 336)[Eval/TypeTiny.pm:8]:4] # spent 2µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 367)[Eval/TypeTiny.pm:8]:4] # spent 2µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 404)[Eval/TypeTiny.pm:8]:4] # spent 2µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 424)[Eval/TypeTiny.pm:8]:4] # spent 2µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 51)[Eval/TypeTiny.pm:8]:4] # spent 2µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 56)[Eval/TypeTiny.pm:8]:4] # spent 2µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 58)[Eval/TypeTiny.pm:8]:4] # spent 2µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 60)[Eval/TypeTiny.pm:8]:4] # spent 2µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 63)[Eval/TypeTiny.pm:8]:4] # spent 2µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 66)[Eval/TypeTiny.pm:8]:4] # spent 2µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 67)[Eval/TypeTiny.pm:8]:4] # spent 2µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 72)[Eval/TypeTiny.pm:8]:4] # spent 2µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 76)[Eval/TypeTiny.pm:8]:9] # spent 2µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 81)[Eval/TypeTiny.pm:8]:4] # spent 2µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 83)[Eval/TypeTiny.pm:8]:4] # spent 2µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 84)[Eval/TypeTiny.pm:8]:4] # spent 2µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 87)[Eval/TypeTiny.pm:8]:4] # spent 2µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 90)[Eval/TypeTiny.pm:8]:4] # spent 2µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 92)[Eval/TypeTiny.pm:8]:4] # spent 2µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 99)[Eval/TypeTiny.pm:8]:4] # spent 1µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 101)[Eval/TypeTiny.pm:8]:4] # spent 1µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 108)[Eval/TypeTiny.pm:8]:4] # spent 1µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 126)[Eval/TypeTiny.pm:8]:4] # spent 1µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 133)[Eval/TypeTiny.pm:8]:4] # spent 1µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 138)[Eval/TypeTiny.pm:8]:4] # spent 1µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 313)[Eval/TypeTiny.pm:8]:4] # spent 1µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 326)[Eval/TypeTiny.pm:8]:4] # spent 1µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 355)[Eval/TypeTiny.pm:8]:4] # spent 1µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 50)[Eval/TypeTiny.pm:8]:4] # spent 1µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 61)[Eval/TypeTiny.pm:8]:4] # spent 1µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 69)[Eval/TypeTiny.pm:8]:4] # spent 1µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 70)[Eval/TypeTiny.pm:8]:4] # spent 1µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 73)[Eval/TypeTiny.pm:8]:4] # spent 1µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 89)[Eval/TypeTiny.pm:8]:4] # spent 1µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 95)[Eval/TypeTiny.pm:8]:4] # spent 1µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 96)[Eval/TypeTiny.pm:8]:4] # spent 0s making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 104)[Eval/TypeTiny.pm:8]:4] # spent 0s making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 118)[Eval/TypeTiny.pm:8]:4] # spent 0s making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 122)[Eval/TypeTiny.pm:8]:4] # spent 0s making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 124)[Eval/TypeTiny.pm:8]:4] # spent 0s making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 128)[Eval/TypeTiny.pm:8]:4] # spent 0s making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 130)[Eval/TypeTiny.pm:8]:4] # spent 0s making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 143)[Eval/TypeTiny.pm:8]:4] # spent 0s making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 211)[Eval/TypeTiny.pm:8]:4] # spent 0s making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 75)[Eval/TypeTiny.pm:8]:9] # spent 0s making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 93)[Eval/TypeTiny.pm:8]:4]
24913138µs undef( $compiler );
250
25113119µs if ( $alias and ALIAS_IMPLEMENTATION eq IMPLEMENTATION_DEVEL_LEXALIAS ) {
252 require Devel::LexAlias;
253 Devel::LexAlias::lexalias( $code, $_ => $args{environment}{$_} )
254 for grep !/^\&/, @keys;
255 }
256
25713112µs if ( $alias and ALIAS_IMPLEMENTATION eq IMPLEMENTATION_PADWALKER ) {
258 require PadWalker;
259 my %env = map +( $_ => $args{environment}{$_} ), grep !/^\&/, @keys;
260 PadWalker::set_closed_over( $code, \%env );
261 }
262
263131391µs return $code;
264} #/ sub eval_closure
265
26610smy $tmp;
267
268
# spent 229µs (219+10) within Eval::TypeTiny::_make_lexical_assignment which was called 40 times, avg 6µs/call: # 40 times (219µs+10µs) by Eval::TypeTiny::eval_closure at line 223, avg 6µs/call
sub _make_lexical_assignment {
2694015µs my ( $key, $index, $alias ) = @_;
2704034µs my $name = substr( $key, 1 );
271
2724076µs4010µs if ( HAS_LEXICAL_SUBS and $key =~ /^\&/ ) {
# spent 10µs making 40 calls to Eval::TypeTiny::CORE:match, avg 250ns/call
273 $tmp++;
274 my $tmpname = '$__LEXICAL_SUB__' . $tmp;
275 return
276 "no warnings 'experimental::lexical_subs';"
277 . "use feature 'lexical_subs';"
278 . "my $tmpname = \$_[$index];"
279 . "my sub $name { goto $tmpname };";
280 }
281
282407µs if ( !$alias ) {
2834020µs my $sigil = substr( $key, 0, 1 );
28440120µs return "my $key = $sigil\{ \$_[$index] };";
285 }
286 elsif ( ALIAS_IMPLEMENTATION eq IMPLEMENTATION_NATIVE ) {
287 return
288 "no warnings 'experimental::refaliasing';"
289 . "use feature 'refaliasing';"
290 . "my $key; \\$key = \$_[$index];";
291 }
292 elsif ( ALIAS_IMPLEMENTATION eq IMPLEMENTATION_DEVEL_LEXALIAS ) {
293 return "my $key;";
294 }
295 elsif ( ALIAS_IMPLEMENTATION eq IMPLEMENTATION_PADWALKER ) {
296 return "my $key;";
297 }
298 else {
299 my $tieclass = {
300 '@' => 'Eval::TypeTiny::_TieArray',
301 '%' => 'Eval::TypeTiny::_TieHash',
302 '$' => 'Eval::TypeTiny::_TieScalar',
303 }->{ substr( $key, 0, 1 ) };
304
305 return sprintf(
306 'tie(my(%s), "%s", $_[%d]);',
307 $key,
308 $tieclass,
309 $index,
310 );
311 } #/ else [ if ( !$alias ) ]
312} #/ sub _make_lexical_assignment
313
314{
31510s my $tie;
316
317 sub _manufacture_ties {
318 $tie ||= eval <<'FALLBACK'; } }
319no warnings qw(void once uninitialized numeric);
320use Type::Tiny ();
321
322{
323 package #
324 Eval::TypeTiny::_TieArray;
325 require Tie::Array;
326 our @ISA = qw( Tie::StdArray );
327 sub TIEARRAY {
328 my $class = shift;
329 bless $_[0] => $class;
330 }
331 sub AUTOLOAD {
332 my $self = shift;
333 my ($method) = (our $AUTOLOAD =~ /(\w+)$/);
334 defined tied(@$self) and return tied(@$self)->$method(@_);
335 require Carp;
336 Carp::croak(qq[Can't call method "$method" on an undefined value]) unless $method eq 'DESTROY';
337 }
338 sub can {
339 my $self = shift;
340 my $code = $self->SUPER::can(@_)
341 || (defined tied(@$self) and tied(@$self)->can(@_));
342 return $code;
343 }
344 __PACKAGE__->Type::Tiny::_install_overloads(
345 q[bool] => sub { !! tied @{$_[0]} },
346 q[""] => sub { '' . tied @{$_[0]} },
347 q[0+] => sub { 0 + tied @{$_[0]} },
348 );
349}
350{
351 package #
352 Eval::TypeTiny::_TieHash;
353 require Tie::Hash;
354 our @ISA = qw( Tie::StdHash );
355 sub TIEHASH {
356 my $class = shift;
357 bless $_[0] => $class;
358 }
359 sub AUTOLOAD {
360 my $self = shift;
361 my ($method) = (our $AUTOLOAD =~ /(\w+)$/);
362 defined tied(%$self) and return tied(%$self)->$method(@_);
363 require Carp;
364 Carp::croak(qq[Can't call method "$method" on an undefined value]) unless $method eq 'DESTROY';
365 }
366 sub can {
367 my $self = shift;
368 my $code = $self->SUPER::can(@_)
369 || (defined tied(%$self) and tied(%$self)->can(@_));
370 return $code;
371 }
372 __PACKAGE__->Type::Tiny::_install_overloads(
373 q[bool] => sub { !! tied %{$_[0]} },
374 q[""] => sub { '' . tied %{$_[0]} },
375 q[0+] => sub { 0 + tied %{$_[0]} },
376 );
377}
378{
379 package #
380 Eval::TypeTiny::_TieScalar;
381 require Tie::Scalar;
382 our @ISA = qw( Tie::StdScalar );
383 sub TIESCALAR {
384 my $class = shift;
385 bless $_[0] => $class;
386 }
387 sub AUTOLOAD {
388 my $self = shift;
389 my ($method) = (our $AUTOLOAD =~ /(\w+)$/);
390 defined tied($$self) and return tied($$self)->$method(@_);
391 require Carp;
392 Carp::croak(qq[Can't call method "$method" on an undefined value]) unless $method eq 'DESTROY';
393 }
394 sub can {
395 my $self = shift;
396 my $code = $self->SUPER::can(@_)
397 || (defined tied($$self) and tied($$self)->can(@_));
398 return $code;
399 }
400 __PACKAGE__->Type::Tiny::_install_overloads(
401 q[bool] => sub { !! tied ${$_[0]} },
402 q[""] => sub { '' . tied ${$_[0]} },
403 q[0+] => sub { 0 + tied ${$_[0]} },
404 );
405}
406
4071;
408FALLBACK
409
41025µs1;
411
412__END__
 
# spent 10µs within Eval::TypeTiny::CORE:match which was called 40 times, avg 250ns/call: # 40 times (10µs+0s) by Eval::TypeTiny::_make_lexical_assignment at line 272, avg 250ns/call
sub Eval::TypeTiny::CORE:match; # opcode
# spent 47µs within Eval::TypeTiny::CORE:sort which was called 131 times, avg 359ns/call: # 131 times (47µs+0s) by Eval::TypeTiny::eval_closure at line 221, avg 359ns/call
sub Eval::TypeTiny::CORE:sort; # opcode
# spent 257µs within Eval::TypeTiny::CORE:subst which was called 131 times, avg 2µs/call: # 131 times (257µs+0s) by Eval::TypeTiny::eval_closure at line 190, avg 2µs/call
sub Eval::TypeTiny::CORE:subst; # opcode