| Filename | /Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Eval/TypeTiny.pm |
| Statements | Executed 4320 statements in 23.0ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 131 | 1 | 1 | 17.6ms | 19.0ms | Eval::TypeTiny::_clean_eval |
| 131 | 5 | 3 | 3.60ms | 23.6ms | Eval::TypeTiny::eval_closure |
| 198 | 5 | 4 | 785µs | 1.46ms | Eval::TypeTiny::set_subname |
| 40 | 2 | 2 | 719µs | 8.52ms | Eval::TypeTiny::type_to_coderef |
| 131 | 1 | 1 | 291µs | 291µs | Eval::TypeTiny::CORE:subst (opcode) |
| 40 | 1 | 1 | 273µs | 292µs | Eval::TypeTiny::_make_lexical_assignment |
| 131 | 1 | 1 | 75µs | 75µs | Eval::TypeTiny::CORE:sort (opcode) |
| 1 | 1 | 1 | 62µs | 62µs | Eval::TypeTiny::_pick_alternative |
| 1 | 1 | 1 | 25µs | 335µs | Eval::TypeTiny::import |
| 1 | 1 | 1 | 20µs | 23µs | Eval::TypeTiny::BEGIN@3 |
| 40 | 1 | 1 | 19µs | 19µs | Eval::TypeTiny::CORE:match (opcode) |
| 1 | 1 | 1 | 7µs | 39µs | Eval::TypeTiny::BEGIN@13 |
| 1 | 1 | 1 | 5µs | 5µs | Eval::TypeTiny::BEGIN@61 |
| 1 | 1 | 1 | 5µs | 19µs | Eval::TypeTiny::BEGIN@81 |
| 1 | 1 | 1 | 4µs | 4µs | Eval::TypeTiny::BEGIN@15 |
| 0 | 0 | 0 | 0s | 0s | Eval::TypeTiny::ALIAS_IMPLEMENTATION |
| 0 | 0 | 0 | 0s | 0s | Eval::TypeTiny::__ANON__[:141] |
| 0 | 0 | 0 | 0s | 0s | Eval::TypeTiny::_force_implementation |
| 0 | 0 | 0 | 0s | 0s | Eval::TypeTiny::_manufacture_ties |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package Eval::TypeTiny; | ||||
| 2 | |||||
| 3 | 2 | 66µs | 2 | 26µs | # spent 23µs (20+3) within Eval::TypeTiny::BEGIN@3 which was called:
# once (20µs+3µs) by Type::Library::BEGIN@14 at line 3 # spent 23µs making 1 call to Eval::TypeTiny::BEGIN@3
# spent 3µs making 1 call to strict::import |
| 4 | |||||
| 5 | # spent 19.0ms (17.6+1.46) within Eval::TypeTiny::_clean_eval which was called 131 times, avg 145µs/call:
# 131 times (17.6ms+1.46ms) by Eval::TypeTiny::eval_closure at line 235, avg 145µs/call | ||||
| 6 | 131 | 27µs | local $@; | ||
| 7 | 131 | 292µs | local $SIG{__DIE__}; | ||
| 8 | 131 | 13.7ms | my $r = eval $_[0]; # spent 1.63ms executing statements in string eval # includes 1.29ms spent executing 344 calls to 2 subs defined therein. # spent 1.21ms executing statements in 20 string evals (merged) # includes 1.01ms spent executing 197 calls to 22 subs defined therein. # spent 458µs executing statements in 20 string evals (merged) # includes 271µs spent executing 141 calls to 22 subs defined therein. # spent 187µs executing statements in string eval # includes 25µs spent executing 2 calls to 4 subs defined therein. # spent 153µs executing statements in string eval # includes 23µs spent executing 3 calls to 5 subs defined therein. # spent 136µs executing statements in string eval # includes 13µs spent executing 2 calls to 4 subs defined therein. # spent 131µs executing statements in string eval # includes 11µs spent executing 2 calls to 4 subs defined therein. # spent 131µs executing statements in string eval # includes 16µs spent executing 2 calls to 4 subs defined therein. # spent 128µs executing statements in string eval # includes 12µs spent executing 2 calls to 4 subs defined therein. # spent 124µs executing statements in string eval # includes 16µs spent executing 2 calls to 4 subs defined therein. # spent 120µs executing statements in string eval # includes 14µs spent executing 2 calls to 4 subs defined therein. # spent 119µs executing statements in string eval # includes 21µs spent executing 2 calls to 4 subs defined therein. # spent 113µs executing statements in string eval # includes 14µs spent executing 2 calls to 4 subs defined therein. # spent 106µs executing statements in string eval # includes 61µs spent executing 2 calls to 4 subs defined therein. # spent 102µs executing statements in string eval # includes 19µs spent executing 2 calls to 4 subs defined therein. # spent 100µs executing statements in string eval # includes 31µs spent executing 2 calls to 4 subs defined therein. # spent 99µs executing statements in string eval # includes 15µs spent executing 2 calls to 4 subs defined therein. # spent 93µs executing statements in string eval # includes 14µs spent executing 2 calls to 4 subs defined therein. # spent 89µs executing statements in string eval # includes 41µs spent executing 2 calls to 4 subs defined therein. # spent 86µs executing statements in string eval # includes 23µs spent executing 2 calls to 4 subs defined therein. # spent 77µs executing statements in string eval # includes 13µs spent executing 2 calls to 4 subs defined therein. # spent 77µs executing statements in string eval # includes 13µs spent executing 2 calls to 4 subs defined therein. # spent 75µs executing statements in string eval # includes 11µs spent executing 2 calls to 4 subs defined therein. # spent 74µs executing statements in string eval # includes 66µs spent executing 2 calls to 4 subs defined therein. # spent 74µs executing statements in string eval # includes 12µs spent executing 2 calls to 4 subs defined therein. # spent 73µs executing statements in string eval # includes 15µs spent executing 2 calls to 4 subs defined therein. # spent 69µs executing statements in string eval # includes 18µs spent executing 2 calls to 4 subs defined therein. # spent 67µs executing statements in string eval # includes 14µs spent executing 2 calls to 4 subs defined therein. # spent 67µs executing statements in string eval # includes 8µs spent executing 2 calls to 4 subs defined therein. # spent 66µs executing statements in string eval # includes 15µs spent executing 2 calls to 4 subs defined therein. # spent 65µs executing statements in string eval # includes 40µs spent executing 39 calls to 2 subs defined therein. # spent 63µs executing statements in string eval # includes 8µs spent executing 2 calls to 4 subs defined therein. # spent 60µs executing statements in string eval # includes 10µs spent executing 2 calls to 4 subs defined therein. # spent 58µs executing statements in string eval # includes 7µs spent executing 2 calls to 4 subs defined therein. # spent 56µs executing statements in string eval # includes 8µs spent executing 2 calls to 4 subs defined therein. # spent 55µ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 13µs spent executing 2 calls to 4 subs defined therein. # spent 53µs executing statements in string eval # includes 13µ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 48µs executing statements in string eval # includes 8µs spent executing 2 calls to 4 subs defined therein. # spent 47µs executing statements in string eval # includes 10µs spent executing 2 calls to 4 subs defined therein. # spent 47µs executing statements in string eval # includes 35µs spent executing 1 call to 2 subs defined therein. # spent 42µs executing statements in string eval # includes 6µs spent executing 2 calls to 4 subs defined therein. # spent 36µs executing statements in 2 string evals (merged) # includes 6µs spent executing 2 calls to 2 subs defined therein. # spent 22µs executing statements in string eval # includes 7µs spent executing 1 call to 2 subs defined therein. # spent 17µ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 12µs executing statements in string eval # includes 3µs spent executing 1 call to 2 subs defined therein. # spent 12µs executing statements in string eval # includes 2µs spent executing 1 call to 3 subs defined therein. # spent 11µs executing statements in 2 string evals (merged) # includes 3µs spent executing 2 calls to 4 subs defined therein. # spent 11µs executing statements in string eval # includes 5µ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 2 subs defined therein. # spent 11µs executing statements in string eval # includes 4µ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 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 string eval # includes 4µs spent executing 1 call to 3 subs defined therein. # spent 10µs executing statements in string eval # includes 2µ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 2 subs defined therein. # spent 10µs executing statements in string eval # includes 2µs spent executing 1 call to 3 subs defined therein. # spent 10µs executing statements in string eval # includes 2µs spent executing 1 call to 3 subs defined therein. # spent 9µs executing statements in string eval # includes 2µs spent executing 1 call to 3 subs defined therein. # spent 9µs executing statements in string eval # includes 1µ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 9µ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 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 7µs executing statements in string eval # includes 1µ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 2 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 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 0s 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 3 subs defined therein. # spent 6µs executing statements in string eval # includes 3µ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 2µ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 0s spent executing 1 call to 2 subs defined therein. # spent 5µs executing statements in string eval # includes 1µs spent executing 1 call to 3 subs defined therein. # spent 4µs executing statements in string eval # includes 2µs spent executing 1 call to 3 subs defined therein. # spent 4µs executing statements in string eval # includes 0s spent executing 1 call to 3 subs defined therein. # spent 4µs executing statements in string eval # includes 2µs spent executing 1 call to 3 subs defined therein. # spent 4µs executing statements in string eval # includes 1µs spent executing 1 call to 3 subs defined therein. # spent 4µs executing statements in string eval # includes 1µs spent executing 1 call to 3 subs defined therein. | ||
| 9 | 131 | 64µs | my $e = $@; | ||
| 10 | 131 | 664µs | return ( $r, $e ); | ||
| 11 | } | ||||
| 12 | |||||
| 13 | 2 | 63µs | 2 | 71µs | # spent 39µs (7+32) within Eval::TypeTiny::BEGIN@13 which was called:
# once (7µs+32µs) by Type::Library::BEGIN@14 at line 13 # spent 39µs making 1 call to Eval::TypeTiny::BEGIN@13
# spent 32µs making 1 call to warnings::import |
| 14 | |||||
| 15 | # spent 4µs within Eval::TypeTiny::BEGIN@15 which was called:
# once (4µs+0s) by Type::Library::BEGIN@14 at line 18 | ||||
| 16 | 1 | 1µs | *HAS_LEXICAL_SUBS = ( $] >= 5.018 ) ? sub () { !!1 } : sub () { !!0 }; | ||
| 17 | 1 | 3µs | *NICE_PROTOTYPES = ( $] >= 5.014 ) ? sub () { !!1 } : sub () { !!0 }; | ||
| 18 | 1 | 174µs | 1 | 4µs | } # spent 4µs making 1 call to Eval::TypeTiny::BEGIN@15 |
| 19 | |||||
| 20 | # spent 62µs within Eval::TypeTiny::_pick_alternative which was called:
# once (62µs+0s) by Eval::TypeTiny::set_subname at line 96 | ||||
| 21 | 1 | 1µs | my $ok = 0; | ||
| 22 | 1 | 0s | while ( @_ ) { | ||
| 23 | 1 | 1µs | my ( $type, $condition, $result ) = splice @_, 0, 3; | ||
| 24 | 1 | 2µs | if ( $type eq 'needs' ) { | ||
| 25 | 1 | 26µs | ++$ok if eval "require $condition; 1"; # spent 2µs executing statements in string eval | ||
| 26 | } | ||||
| 27 | elsif ( $type eq 'if' ) { | ||||
| 28 | ++$ok if $condition; | ||||
| 29 | } | ||||
| 30 | 1 | 0s | next unless $ok; | ||
| 31 | 1 | 24µs | return ref( $result ) eq 'CODE' ? $result->() : ref( $result ) eq 'SCALAR' ? eval( $$result ) : $result; # spent 7µ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 | |||||
| 42 | 1 | 1µs | 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 | |||||
| 61 | 1 | 0s | # spent 5µs within Eval::TypeTiny::BEGIN@61 which was called:
# once (5µs+0s) by Type::Library::BEGIN@14 at line 63 | ||
| 62 | 1 | 4µs | *_EXTENDED_TESTING = $ENV{EXTENDED_TESTING} ? sub() { !!1 } : sub() { !!0 }; | ||
| 63 | 1 | 60µs | 1 | 5µs | } # spent 5µs making 1 call to Eval::TypeTiny::BEGIN@61 |
| 64 | |||||
| 65 | 1 | 1µs | our $AUTHORITY = 'cpan:TOBYINK'; | ||
| 66 | 1 | 0s | our $VERSION = '2.000001'; | ||
| 67 | 1 | 1µs | our @EXPORT = qw( eval_closure ); | ||
| 68 | 1 | 0s | our @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 | |||||
| 75 | 1 | 2µs | $VERSION =~ tr/_//d; | ||
| 76 | |||||
| 77 | # See Types::TypeTiny for an explanation of this import method. | ||||
| 78 | # | ||||
| 79 | # uncoverable subroutine | ||||
| 80 | # spent 335µs (25+310) within Eval::TypeTiny::import which was called:
# once (25µs+310µs) by Type::Library::BEGIN@14 at line 14 of Type/Library.pm | ||||
| 81 | 2 | 1.74ms | 2 | 33µs | # spent 19µs (5+14) within Eval::TypeTiny::BEGIN@81 which was called:
# once (5µs+14µs) by Type::Library::BEGIN@14 at line 81 # spent 19µs making 1 call to Eval::TypeTiny::BEGIN@81
# spent 14µs making 1 call to warnings::unimport |
| 82 | 1 | 8µs | our @ISA = qw( Exporter::Tiny ); | ||
| 83 | 1 | 1µs | require Exporter::Tiny; | ||
| 84 | 1 | 2µs | my $next = \&Exporter::Tiny::import; | ||
| 85 | 1 | 1µs | *import = $next; | ||
| 86 | 1 | 1µs | my $class = shift; | ||
| 87 | 1 | 1µs | my $opts = { ref( $_[0] ) ? %{ +shift } : () }; | ||
| 88 | 1 | 2µs | $opts->{into} ||= scalar( caller ); | ||
| 89 | 1 | 14µs | 1 | 310µs | return $class->$next( $opts, @_ ); # spent 310µs making 1 call to Exporter::Tiny::import |
| 90 | } #/ sub import | ||||
| 91 | |||||
| 92 | { | ||||
| 93 | 1 | 0s | my $subname; | ||
| 94 | 1 | 1µs | my %already; # prevent renaming established functions | ||
| 95 | # spent 1.46ms (785µs+678µs) within Eval::TypeTiny::set_subname which was called 198 times, avg 7µs/call:
# 148 times (514µs+391µs) by Type::Library::add_type at line 239 of Type/Library.pm, avg 6µs/call
# 40 times (212µs+227µs) by Eval::TypeTiny::type_to_coderef at line 177, avg 11µs/call
# 7 times (45µs+37µ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 12µs/call
# 2 times (8µs+17µs) by Type::Tiny::new at line 364 of Type/Tiny.pm, avg 12µs/call
# once (6µs+6µs) by Type::Library::make_immutable at line 322 of Type/Library.pm | ||||
| 96 | 198 | 40µs | 1 | 62µs | $subname = _pick_alternative( # spent 62µ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; | ||||
| 101 | 198 | 1.36ms | 147 | 616µs | $subname and !$already{$_[1]}++ and return &$subname; # spent 616µs making 147 calls to Sub::Util::set_subname, avg 4µs/call |
| 102 | 51 | 103µs | $_[1]; | ||
| 103 | } #/ sub set_subname ($$) | ||||
| 104 | } | ||||
| 105 | |||||
| 106 | 1 | 0s | # spent 8.52ms (719µs+7.80) within Eval::TypeTiny::type_to_coderef which was called 40 times, avg 213µs/call:
# 37 times (660µs+7.13ms) by Type::Tiny::exportables at line 1197 of Type/Tiny.pm, avg 211µs/call
# 3 times (59µs+664µs) by Type::Library::add_coercion at line 287 of Type/Library.pm, avg 241µs/call | ||
| 107 | 40 | 12µs | my ( $type, %args ) = @_; | ||
| 108 | 40 | 19µs | my $post_method = $args{post_method} || q(); | ||
| 109 | |||||
| 110 | 40 | 8µs | my ( $coderef, $qualified_name ); | ||
| 111 | |||||
| 112 | 40 | 70µ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 | #<<< | ||||
| 149 | 40 | 149µs | 40 | 279µs | my $source = $type->is_parameterizable ? # spent 265µs making 37 calls to Type::Tiny::is_parameterizable, avg 7µs/call
# spent 14µs making 3 calls to Type::Coercion::is_parameterizable, avg 5µ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 | |||||
| 169 | 40 | 81µs | 40 | 253µs | $qualified_name = $type->qualified_name; # spent 231µs making 37 calls to Type::Tiny::qualified_name, avg 6µs/call
# spent 22µs making 3 calls to Type::Coercion::qualified_name, avg 7µs/call |
| 170 | $coderef = eval_closure( | ||||
| 171 | source => $source, | ||||
| 172 | 40 | 135µs | 40 | 6.83ms | description => $args{description} || sprintf( "exportable function '%s'", $qualified_name ), # spent 6.83ms making 40 calls to Eval::TypeTiny::eval_closure, avg 171µs/call |
| 173 | environment => { '$type' => \$type }, | ||||
| 174 | ); | ||||
| 175 | } | ||||
| 176 | |||||
| 177 | 40 | 219µs | 40 | 439µs | $args{anonymous} ? $coderef : set_subname( $qualified_name, $coderef ); # spent 439µs making 40 calls to Eval::TypeTiny::set_subname, avg 11µs/call |
| 178 | } | ||||
| 179 | |||||
| 180 | # spent 23.6ms (3.60+20.0) within Eval::TypeTiny::eval_closure which was called 131 times, avg 181µs/call:
# 48 times (1.29ms+7.28ms) by Type::Tiny::_build_compiled_check at line 537 of Type/Tiny.pm, avg 179µs/call
# 40 times (1.23ms+5.60ms) by Eval::TypeTiny::type_to_coderef at line 172, avg 171µs/call
# 37 times (841µs+6.50ms) by Type::Tiny::_overload_coderef at line 215 of Type/Tiny.pm, avg 198µs/call
# 5 times (199µs+491µs) by Type::Tiny::new at line 268 of Type/Tiny.pm, avg 138µs/call
# once (35µs+175µs) by Type::Coercion::_build_compiled_coercion at line 265 of Type/Coercion.pm | ||||
| 181 | 131 | 165µs | my ( %args ) = @_; | ||
| 182 | my $src = | ||||
| 183 | ref $args{source} eq "ARRAY" | ||||
| 184 | ? join( "\n", @{ $args{source} } ) | ||||
| 185 | 131 | 111µs | : $args{source}; | ||
| 186 | |||||
| 187 | 131 | 88µs | $args{alias} = 0 unless defined $args{alias}; | ||
| 188 | 131 | 56µs | $args{line} = 1 unless defined $args{line}; | ||
| 189 | $args{description} =~ s/[^\w .:-\[\]\(\)\{\}\']//g | ||||
| 190 | 131 | 600µs | 131 | 291µs | if defined $args{description}; # spent 291µs making 131 calls to Eval::TypeTiny::CORE:subst, avg 2µs/call |
| 191 | $src = qq{#line $args{line} "$args{description}"\n$src} | ||||
| 192 | 131 | 151µs | if defined $args{description} && !( $^P & 0x10 ); | ||
| 193 | 131 | 96µ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 | |||||
| 219 | 131 | 52µs | my $sandpkg = 'Eval::TypeTiny::Sandbox'; | ||
| 220 | 131 | 52µs | my $alias = exists( $args{alias} ) ? $args{alias} : 0; | ||
| 221 | 131 | 614µs | 131 | 75µs | my @keys = sort keys %{ $args{environment} }; # spent 75µs making 131 calls to Eval::TypeTiny::CORE:sort, avg 573ns/call |
| 222 | 131 | 19µs | my $i = 0; | ||
| 223 | 131 | 288µs | 40 | 292µs | my $source = join "\n" => ( # spent 292µs making 40 calls to Eval::TypeTiny::_make_lexical_assignment, avg 7µs/call |
| 224 | "package $sandpkg;", | ||||
| 225 | "sub {", | ||||
| 226 | map( _make_lexical_assignment( $_, $i++, $alias ), @keys ), | ||||
| 227 | $src, | ||||
| 228 | "}", | ||||
| 229 | ); | ||||
| 230 | |||||
| 231 | 131 | 22µs | if ( $alias and ALIAS_IMPLEMENTATION eq IMPLEMENTATION_TIE ) { | ||
| 232 | _manufacture_ties(); | ||||
| 233 | } | ||||
| 234 | |||||
| 235 | 131 | 277µs | 131 | 19.0ms | my ( $compiler, $e ) = _clean_eval( $source ); # spent 19.0ms making 131 calls to Eval::TypeTiny::_clean_eval, avg 145µs/call |
| 236 | 131 | 30µ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 | |||||
| 248 | 131 | 343µs | 131 | 361µs | my $code = $compiler->( @{ $args{environment} }{@keys} ); # spent 73µs making 20 calls to Eval::TypeTiny::Sandbox::__ANON__[(eval 103)[Eval/TypeTiny.pm:8]:15], avg 4µs/call
# spent 47µs making 20 calls to Eval::TypeTiny::Sandbox::__ANON__[(eval 100)[Eval/TypeTiny.pm:8]:5], avg 2µs/call
# spent 35µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 361)[Eval/TypeTiny.pm:8]:4]
# spent 29µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 124)[Eval/TypeTiny.pm:8]:4]
# spent 7µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 420)[Eval/TypeTiny.pm:8]:4]
# spent 7µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 53)[Eval/TypeTiny.pm:8]:4]
# spent 6µs making 2 calls to Eval::TypeTiny::Sandbox::__ANON__[(eval 271)[Eval/TypeTiny.pm:8]:4], avg 3µs/call
# spent 5µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 274)[Eval/TypeTiny.pm:8]:4]
# spent 5µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 64)[Eval/TypeTiny.pm:8]:4]
# spent 4µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 101)[Eval/TypeTiny.pm:8]:4]
# spent 4µs making 2 calls to Eval::TypeTiny::Sandbox::__ANON__[(eval 270)[Eval/TypeTiny.pm:8]:4], avg 2µs/call
# spent 4µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 320)[Eval/TypeTiny.pm:8]:4]
# spent 4µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 322)[Eval/TypeTiny.pm:8]:4]
# spent 4µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 57)[Eval/TypeTiny.pm:8]:4]
# spent 3µs making 2 calls to Eval::TypeTiny::Sandbox::__ANON__[(eval 107)[Eval/TypeTiny.pm:8]:4], avg 2µs/call
# spent 3µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 135)[Eval/TypeTiny.pm:8]:4]
# spent 3µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 136)[Eval/TypeTiny.pm:8]:4]
# spent 3µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 143)[Eval/TypeTiny.pm:8]:4]
# spent 3µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 147)[Eval/TypeTiny.pm:8]:4]
# spent 3µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 275)[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 309)[Eval/TypeTiny.pm:8]:4]
# spent 3µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 356)[Eval/TypeTiny.pm:8]:4]
# spent 3µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 363)[Eval/TypeTiny.pm:8]:4]
# spent 3µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 80)[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 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 116)[Eval/TypeTiny.pm:8]:4]
# spent 2µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 118)[Eval/TypeTiny.pm:8]:4]
# spent 2µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 122)[Eval/TypeTiny.pm:8]:4]
# spent 2µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 126)[Eval/TypeTiny.pm:8]:4]
# spent 2µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 128)[Eval/TypeTiny.pm:8]:4]
# spent 2µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 130)[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 133)[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 151)[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 216)[Eval/TypeTiny.pm:8]:4]
# spent 2µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 238)[Eval/TypeTiny.pm:8]:4]
# spent 2µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 248)[Eval/TypeTiny.pm:8]:4]
# spent 2µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 262)[Eval/TypeTiny.pm:8]:4]
# spent 2µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 319)[Eval/TypeTiny.pm:8]:4]
# spent 2µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 321)[Eval/TypeTiny.pm:8]:4]
# spent 2µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 332)[Eval/TypeTiny.pm:8]:4]
# spent 2µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 335)[Eval/TypeTiny.pm:8]:4]
# spent 2µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 351)[Eval/TypeTiny.pm:8]:4]
# spent 2µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 400)[Eval/TypeTiny.pm:8]:4]
# spent 2µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 50)[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 55)[Eval/TypeTiny.pm:8]:4]
# spent 2µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 61)[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 69)[Eval/TypeTiny.pm:8]:4]
# spent 2µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 75)[Eval/TypeTiny.pm:8]:9]
# 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 84)[Eval/TypeTiny.pm:8]:4]
# spent 2µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 89)[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 93)[Eval/TypeTiny.pm:8]:4]
# spent 2µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 95)[Eval/TypeTiny.pm:8]:4]
# spent 2µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 96)[Eval/TypeTiny.pm:8]:4]
# spent 1µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 104)[Eval/TypeTiny.pm:8]:4]
# spent 1µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 120)[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 145)[Eval/TypeTiny.pm:8]:4]
# spent 1µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 267)[Eval/TypeTiny.pm:8]:4]
# spent 1µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 56)[Eval/TypeTiny.pm:8]:4]
# spent 1µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 58)[Eval/TypeTiny.pm:8]:4]
# spent 1µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 72)[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 83)[Eval/TypeTiny.pm:8]:4]
# spent 1µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 86)[Eval/TypeTiny.pm:8]:4]
# spent 1µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 99)[Eval/TypeTiny.pm:8]:4]
# spent 0s making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 105)[Eval/TypeTiny.pm:8]:4]
# spent 0s making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 108)[Eval/TypeTiny.pm:8]:4]
# spent 0s making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 113)[Eval/TypeTiny.pm:8]:4]
# spent 0s making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 141)[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 252)[Eval/TypeTiny.pm:8]:4]
# spent 0s making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 60)[Eval/TypeTiny.pm:8]:4]
# spent 0s making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 67)[Eval/TypeTiny.pm:8]:4]
# spent 0s making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 70)[Eval/TypeTiny.pm:8]:4]
# spent 0s making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 78)[Eval/TypeTiny.pm:8]:4]
# spent 0s making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 81)[Eval/TypeTiny.pm:8]:4]
# spent 0s making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 87)[Eval/TypeTiny.pm:8]:4] |
| 249 | 131 | 41µs | undef( $compiler ); | ||
| 250 | |||||
| 251 | 131 | 24µ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 | |||||
| 257 | 131 | 25µ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 | |||||
| 263 | 131 | 539µs | return $code; | ||
| 264 | } #/ sub eval_closure | ||||
| 265 | |||||
| 266 | 1 | 0s | my $tmp; | ||
| 267 | |||||
| 268 | # spent 292µs (273+19) within Eval::TypeTiny::_make_lexical_assignment which was called 40 times, avg 7µs/call:
# 40 times (273µs+19µs) by Eval::TypeTiny::eval_closure at line 223, avg 7µs/call | ||||
| 269 | 40 | 15µs | my ( $key, $index, $alias ) = @_; | ||
| 270 | 40 | 56µs | my $name = substr( $key, 1 ); | ||
| 271 | |||||
| 272 | 40 | 91µs | 40 | 19µs | if ( HAS_LEXICAL_SUBS and $key =~ /^\&/ ) { # spent 19µs making 40 calls to Eval::TypeTiny::CORE:match, avg 475ns/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 | |||||
| 282 | 40 | 12µs | if ( !$alias ) { | ||
| 283 | 40 | 24µs | my $sigil = substr( $key, 0, 1 ); | ||
| 284 | 40 | 108µ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 | { | ||||
| 315 | 1 | 0s | my $tie; | ||
| 316 | |||||
| 317 | sub _manufacture_ties { | ||||
| 318 | $tie ||= eval <<'FALLBACK'; } } | ||||
| 319 | no warnings qw(void once uninitialized numeric); | ||||
| 320 | use 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 | |||||
| 407 | 1; | ||||
| 408 | FALLBACK | ||||
| 409 | |||||
| 410 | 2 | 6µs | 1; | ||
| 411 | |||||
| 412 | __END__ | ||||
# spent 19µs within Eval::TypeTiny::CORE:match which was called 40 times, avg 475ns/call:
# 40 times (19µs+0s) by Eval::TypeTiny::_make_lexical_assignment at line 272, avg 475ns/call | |||||
# spent 75µs within Eval::TypeTiny::CORE:sort which was called 131 times, avg 573ns/call:
# 131 times (75µs+0s) by Eval::TypeTiny::eval_closure at line 221, avg 573ns/call | |||||
# spent 291µs within Eval::TypeTiny::CORE:subst which was called 131 times, avg 2µs/call:
# 131 times (291µs+0s) by Eval::TypeTiny::eval_closure at line 190, avg 2µs/call |