| Filename | /Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Eval/TypeTiny.pm |
| Statements | Executed 4320 statements in 14.2ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 131 | 1 | 1 | 10.9ms | 11.5ms | Eval::TypeTiny::_clean_eval |
| 131 | 5 | 3 | 2.18ms | 14.3ms | Eval::TypeTiny::eval_closure |
| 198 | 5 | 4 | 456µs | 884µs | Eval::TypeTiny::set_subname |
| 40 | 2 | 2 | 367µs | 4.72ms | Eval::TypeTiny::type_to_coderef |
| 131 | 1 | 1 | 185µs | 185µs | Eval::TypeTiny::CORE:subst (opcode) |
| 40 | 1 | 1 | 139µs | 147µs | Eval::TypeTiny::_make_lexical_assignment |
| 1 | 1 | 1 | 39µs | 39µs | Eval::TypeTiny::_pick_alternative |
| 131 | 1 | 1 | 27µs | 27µs | Eval::TypeTiny::CORE:sort (opcode) |
| 1 | 1 | 1 | 15µs | 286µs | Eval::TypeTiny::import |
| 1 | 1 | 1 | 14µs | 16µs | Eval::TypeTiny::BEGIN@3 |
| 40 | 1 | 1 | 8µs | 8µs | Eval::TypeTiny::CORE:match (opcode) |
| 1 | 1 | 1 | 7µs | 24µs | Eval::TypeTiny::BEGIN@13 |
| 1 | 1 | 1 | 4µs | 4µs | Eval::TypeTiny::BEGIN@15 |
| 1 | 1 | 1 | 4µs | 20µs | Eval::TypeTiny::BEGIN@81 |
| 1 | 1 | 1 | 2µs | 2µs | Eval::TypeTiny::BEGIN@61 |
| 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 | 55µs | 2 | 18µs | # spent 16µs (14+2) within Eval::TypeTiny::BEGIN@3 which was called:
# once (14µs+2µs) by Type::Library::BEGIN@14 at line 3 # spent 16µs making 1 call to Eval::TypeTiny::BEGIN@3
# spent 2µs making 1 call to strict::import |
| 4 | |||||
| 5 | # spent 11.5ms (10.9+682µs) within Eval::TypeTiny::_clean_eval which was called 131 times, avg 88µs/call:
# 131 times (10.9ms+682µs) by Eval::TypeTiny::eval_closure at line 235, avg 88µs/call | ||||
| 6 | 131 | 18µs | local $@; | ||
| 7 | 131 | 158µs | local $SIG{__DIE__}; | ||
| 8 | 131 | 8.43ms | my $r = eval $_[0]; # spent 1.06ms executing statements in string eval # includes 807µs spent executing 344 calls to 2 subs defined therein. # spent 830µs executing statements in 20 string evals (merged) # includes 685µs spent executing 197 calls to 22 subs defined therein. # spent 337µs executing statements in 20 string evals (merged) # includes 154µs spent executing 141 calls to 22 subs defined therein. # spent 132µs executing statements in string eval # includes 14µs spent executing 3 calls to 5 subs defined therein. # spent 121µs executing statements in string eval # includes 28µs spent executing 39 calls to 2 subs defined therein. # spent 106µs executing statements in string eval # includes 8µs spent executing 2 calls to 4 subs defined therein. # spent 92µs executing statements in string eval # includes 7µs spent executing 2 calls to 4 subs defined therein. # spent 87µs executing statements in string eval # includes 6µs spent executing 2 calls to 4 subs defined therein. # spent 84µs executing statements in string eval # includes 7µs spent executing 2 calls to 4 subs defined therein. # spent 77µs executing statements in string eval # includes 7µs spent executing 2 calls to 4 subs defined therein. # spent 74µs executing statements in string eval # includes 10µs spent executing 2 calls to 4 subs defined therein. # spent 70µs executing statements in string eval # includes 5µs spent executing 2 calls to 4 subs defined therein. # spent 64µs executing statements in string eval # includes 12µs spent executing 2 calls to 4 subs defined therein. # spent 57µs executing statements in string eval # includes 10µs spent executing 2 calls to 4 subs defined therein. # spent 57µs executing statements in string eval # includes 6µs spent executing 2 calls to 4 subs defined therein. # spent 56µs executing statements in string eval # includes 5µs spent executing 2 calls to 4 subs defined therein. # spent 55µs executing statements in string eval # includes 7µs spent executing 2 calls to 4 subs defined therein. # spent 50µs executing statements in string eval # includes 9µs spent executing 2 calls to 4 subs defined therein. # spent 47µs executing statements in string eval # includes 9µs spent executing 2 calls to 4 subs defined therein. # spent 46µs executing statements in string eval # includes 5µs spent executing 2 calls to 4 subs defined therein. # spent 45µs executing statements in string eval # includes 8µs spent executing 2 calls to 4 subs defined therein. # spent 45µs executing statements in string eval # includes 7µs spent executing 2 calls to 4 subs defined therein. # spent 44µs executing statements in string eval # includes 8µs spent executing 2 calls to 4 subs defined therein. # spent 43µ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 10µs spent executing 2 calls to 4 subs defined therein. # spent 42µs executing statements in string eval # includes 8µ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 41µs executing statements in string eval # includes 10µs spent executing 2 calls to 4 subs defined therein. # spent 41µs executing statements in string eval # includes 7µs spent executing 2 calls to 4 subs defined therein. # spent 41µs executing statements in string eval # includes 7µs spent executing 2 calls to 4 subs defined therein. # spent 40µs executing statements in string eval # includes 8µs spent executing 2 calls to 4 subs defined therein. # spent 40µs executing statements in string eval # includes 6µs spent executing 2 calls to 4 subs defined therein. # spent 39µs executing statements in string eval # includes 6µs spent executing 2 calls to 4 subs defined therein. # spent 39µs executing statements in string eval # includes 7µs spent executing 2 calls to 4 subs defined therein. # spent 39µs executing statements in string eval # includes 6µs spent executing 2 calls to 4 subs defined therein. # spent 39µs executing statements in string eval # includes 8µs spent executing 2 calls to 4 subs defined therein. # spent 38µs executing statements in string eval # includes 29µs spent executing 2 calls to 4 subs defined therein. # spent 38µs executing statements in string eval # includes 9µs spent executing 2 calls to 4 subs defined therein. # spent 37µs executing statements in string eval # includes 7µ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 6µs spent executing 2 calls to 4 subs defined therein. # spent 33µs executing statements in string eval # includes 2µs spent executing 1 call to 2 subs defined therein. # spent 31µs executing statements in string eval # includes 12µs spent executing 2 calls to 4 subs defined therein. # spent 15µs executing statements in string eval # includes 3µs spent executing 1 call to 2 subs defined therein. # spent 13µs executing statements in string eval # includes 9µs spent executing 1 call to 2 subs defined therein. # spent 11µ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 2 string evals (merged) # includes 1µs spent executing 2 calls to 2 subs defined therein. # spent 9µs executing statements in 2 string evals (merged) # includes 2µs spent executing 2 calls 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 2µs spent executing 1 call to 2 subs defined therein. # spent 8µs executing statements in string eval # includes 3µ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 8µs executing statements in string eval # includes 4µ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 3µs spent executing 1 call to 2 subs defined therein. # spent 8µs executing statements in string eval # includes 7µs spent executing 1 call to 2 subs defined therein. # spent 7µs executing statements in string eval # includes 3µ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 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 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 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 0s 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 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 2 subs defined therein. # spent 5µs executing statements in string eval # includes 2µs spent executing 1 call to 2 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 0s spent executing 1 call to 2 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 2µs 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 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 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 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. # 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 0s spent executing 1 call to 2 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 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 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. # spent 4µs executing statements in string eval # includes 1µs spent executing 1 call to 3 subs defined therein. | ||
| 9 | 131 | 25µs | my $e = $@; | ||
| 10 | 131 | 378µs | return ( $r, $e ); | ||
| 11 | } | ||||
| 12 | |||||
| 13 | 2 | 59µs | 2 | 41µs | # spent 24µs (7+17) within Eval::TypeTiny::BEGIN@13 which was called:
# once (7µs+17µs) by Type::Library::BEGIN@14 at line 13 # spent 24µs making 1 call to Eval::TypeTiny::BEGIN@13
# spent 17µ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 | 2µs | *HAS_LEXICAL_SUBS = ( $] >= 5.018 ) ? sub () { !!1 } : sub () { !!0 }; | ||
| 17 | 1 | 2µs | *NICE_PROTOTYPES = ( $] >= 5.014 ) ? sub () { !!1 } : sub () { !!0 }; | ||
| 18 | 1 | 171µs | 1 | 4µs | } # spent 4µs making 1 call to Eval::TypeTiny::BEGIN@15 |
| 19 | |||||
| 20 | # spent 39µs within Eval::TypeTiny::_pick_alternative which was called:
# once (39µs+0s) by Eval::TypeTiny::set_subname at line 96 | ||||
| 21 | 1 | 0s | my $ok = 0; | ||
| 22 | 1 | 1µs | while ( @_ ) { | ||
| 23 | 1 | 1µs | my ( $type, $condition, $result ) = splice @_, 0, 3; | ||
| 24 | 1 | 2µs | if ( $type eq 'needs' ) { | ||
| 25 | 1 | 15µs | ++$ok if eval "require $condition; 1"; # spent 1µ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 | 17µs | return ref( $result ) eq 'CODE' ? $result->() : ref( $result ) eq 'SCALAR' ? eval( $$result ) : $result; # spent 2µ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 | 0s | 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 | 1µs | # spent 2µs within Eval::TypeTiny::BEGIN@61 which was called:
# once (2µs+0s) by Type::Library::BEGIN@14 at line 63 | ||
| 62 | 1 | 3µs | *_EXTENDED_TESTING = $ENV{EXTENDED_TESTING} ? sub() { !!1 } : sub() { !!0 }; | ||
| 63 | 1 | 55µs | 1 | 2µs | } # spent 2µ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 | 1µs | 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 | 1µs | $VERSION =~ tr/_//d; | ||
| 76 | |||||
| 77 | # See Types::TypeTiny for an explanation of this import method. | ||||
| 78 | # | ||||
| 79 | # uncoverable subroutine | ||||
| 80 | # spent 286µs (15+271) within Eval::TypeTiny::import which was called:
# once (15µs+271µs) by Type::Library::BEGIN@14 at line 14 of Type/Library.pm | ||||
| 81 | 2 | 1.33ms | 2 | 36µs | # spent 20µs (4+16) within Eval::TypeTiny::BEGIN@81 which was called:
# once (4µs+16µs) by Type::Library::BEGIN@14 at line 81 # spent 20µs making 1 call to Eval::TypeTiny::BEGIN@81
# spent 16µs making 1 call to warnings::unimport |
| 82 | 1 | 6µs | our @ISA = qw( Exporter::Tiny ); | ||
| 83 | 1 | 2µs | require Exporter::Tiny; | ||
| 84 | 1 | 0s | my $next = \&Exporter::Tiny::import; | ||
| 85 | 1 | 0s | *import = $next; | ||
| 86 | 1 | 0s | my $class = shift; | ||
| 87 | 1 | 1µs | my $opts = { ref( $_[0] ) ? %{ +shift } : () }; | ||
| 88 | 1 | 1µs | $opts->{into} ||= scalar( caller ); | ||
| 89 | 1 | 13µs | 1 | 271µs | return $class->$next( $opts, @_ ); # spent 271µs making 1 call to Exporter::Tiny::import |
| 90 | } #/ sub import | ||||
| 91 | |||||
| 92 | { | ||||
| 93 | 1 | 0s | my $subname; | ||
| 94 | 1 | 0s | my %already; # prevent renaming established functions | ||
| 95 | # spent 884µs (456+428) within Eval::TypeTiny::set_subname which was called 198 times, avg 4µs/call:
# 148 times (297µs+263µs) by Type::Library::add_type at line 239 of Type/Library.pm, avg 4µs/call
# 40 times (127µs+131µs) by Eval::TypeTiny::type_to_coderef at line 177, avg 6µs/call
# 7 times (26µs+22µ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 7µs/call
# 2 times (2µs+8µs) by Type::Tiny::new at line 364 of Type/Tiny.pm, avg 5µs/call
# once (4µs+4µs) by Type::Library::make_immutable at line 322 of Type/Library.pm | ||||
| 96 | 198 | 25µs | 1 | 39µs | $subname = _pick_alternative( # spent 39µ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 | 850µs | 147 | 389µs | $subname and !$already{$_[1]}++ and return &$subname; # spent 389µs making 147 calls to Sub::Util::set_subname, avg 3µs/call |
| 102 | 51 | 51µs | $_[1]; | ||
| 103 | } #/ sub set_subname ($$) | ||||
| 104 | } | ||||
| 105 | |||||
| 106 | 1 | 1µs | # spent 4.72ms (367µs+4.36) within Eval::TypeTiny::type_to_coderef which was called 40 times, avg 118µs/call:
# 37 times (342µs+4.06ms) by Type::Tiny::exportables at line 1197 of Type/Tiny.pm, avg 119µs/call
# 3 times (25µs+297µs) by Type::Library::add_coercion at line 287 of Type/Library.pm, avg 107µs/call | ||
| 107 | 40 | 9µs | my ( $type, %args ) = @_; | ||
| 108 | 40 | 16µs | my $post_method = $args{post_method} || q(); | ||
| 109 | |||||
| 110 | 40 | 5µs | my ( $coderef, $qualified_name ); | ||
| 111 | |||||
| 112 | 40 | 37µ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 | 48µs | 40 | 92µs | my $source = $type->is_parameterizable ? # spent 84µs making 37 calls to Type::Tiny::is_parameterizable, avg 2µs/call
# spent 8µs making 3 calls to Type::Coercion::is_parameterizable, avg 3µ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 | 48µs | 40 | 123µs | $qualified_name = $type->qualified_name; # spent 111µs making 37 calls to Type::Tiny::qualified_name, avg 3µs/call
# spent 12µs making 3 calls to Type::Coercion::qualified_name, avg 4µs/call |
| 170 | $coderef = eval_closure( | ||||
| 171 | source => $source, | ||||
| 172 | 40 | 66µs | 40 | 3.88ms | description => $args{description} || sprintf( "exportable function '%s'", $qualified_name ), # spent 3.88ms making 40 calls to Eval::TypeTiny::eval_closure, avg 97µs/call |
| 173 | environment => { '$type' => \$type }, | ||||
| 174 | ); | ||||
| 175 | } | ||||
| 176 | |||||
| 177 | 40 | 82µs | 40 | 258µs | $args{anonymous} ? $coderef : set_subname( $qualified_name, $coderef ); # spent 258µs making 40 calls to Eval::TypeTiny::set_subname, avg 6µs/call |
| 178 | } | ||||
| 179 | |||||
| 180 | # spent 14.3ms (2.18+12.1) within Eval::TypeTiny::eval_closure which was called 131 times, avg 109µs/call:
# 48 times (852µs+4.64ms) by Type::Tiny::_build_compiled_check at line 537 of Type/Tiny.pm, avg 114µs/call
# 40 times (695µs+3.19ms) by Eval::TypeTiny::type_to_coderef at line 172, avg 97µs/call
# 37 times (476µs+3.72ms) by Type::Tiny::_overload_coderef at line 215 of Type/Tiny.pm, avg 113µs/call
# 5 times (139µs+365µs) by Type::Tiny::new at line 268 of Type/Tiny.pm, avg 101µs/call
# once (20µs+179µs) by Type::Coercion::_build_compiled_coercion at line 265 of Type/Coercion.pm | ||||
| 181 | 131 | 100µs | my ( %args ) = @_; | ||
| 182 | my $src = | ||||
| 183 | ref $args{source} eq "ARRAY" | ||||
| 184 | ? join( "\n", @{ $args{source} } ) | ||||
| 185 | 131 | 70µs | : $args{source}; | ||
| 186 | |||||
| 187 | 131 | 56µs | $args{alias} = 0 unless defined $args{alias}; | ||
| 188 | 131 | 30µs | $args{line} = 1 unless defined $args{line}; | ||
| 189 | $args{description} =~ s/[^\w .:-\[\]\(\)\{\}\']//g | ||||
| 190 | 131 | 370µs | 131 | 185µs | if defined $args{description}; # spent 185µs making 131 calls to Eval::TypeTiny::CORE:subst, avg 1µs/call |
| 191 | $src = qq{#line $args{line} "$args{description}"\n$src} | ||||
| 192 | 131 | 80µs | if defined $args{description} && !( $^P & 0x10 ); | ||
| 193 | 131 | 64µ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 | 57µs | my $sandpkg = 'Eval::TypeTiny::Sandbox'; | ||
| 220 | 131 | 30µs | my $alias = exists( $args{alias} ) ? $args{alias} : 0; | ||
| 221 | 131 | 331µs | 131 | 27µs | my @keys = sort keys %{ $args{environment} }; # spent 27µs making 131 calls to Eval::TypeTiny::CORE:sort, avg 206ns/call |
| 222 | 131 | 17µs | my $i = 0; | ||
| 223 | 131 | 165µs | 40 | 147µs | my $source = join "\n" => ( # spent 147µs making 40 calls to Eval::TypeTiny::_make_lexical_assignment, avg 4µs/call |
| 224 | "package $sandpkg;", | ||||
| 225 | "sub {", | ||||
| 226 | map( _make_lexical_assignment( $_, $i++, $alias ), @keys ), | ||||
| 227 | $src, | ||||
| 228 | "}", | ||||
| 229 | ); | ||||
| 230 | |||||
| 231 | 131 | 12µs | if ( $alias and ALIAS_IMPLEMENTATION eq IMPLEMENTATION_TIE ) { | ||
| 232 | _manufacture_ties(); | ||||
| 233 | } | ||||
| 234 | |||||
| 235 | 131 | 147µs | 131 | 11.5ms | my ( $compiler, $e ) = _clean_eval( $source ); # spent 11.5ms making 131 calls to Eval::TypeTiny::_clean_eval, avg 88µs/call |
| 236 | 131 | 11µ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 | 179µs | 131 | 195µs | my $code = $compiler->( @{ $args{environment} }{@keys} ); # spent 35µs making 20 calls to Eval::TypeTiny::Sandbox::__ANON__[(eval 103)[Eval/TypeTiny.pm:8]:15], avg 2µs/call
# spent 34µs making 20 calls to Eval::TypeTiny::Sandbox::__ANON__[(eval 100)[Eval/TypeTiny.pm:8]:5], avg 2µs/call
# spent 9µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 365)[Eval/TypeTiny.pm:8]:4]
# spent 7µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 355)[Eval/TypeTiny.pm:8]:4]
# spent 4µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 214)[Eval/TypeTiny.pm:8]:4]
# spent 4µ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 266)[Eval/TypeTiny.pm:8]:4]
# spent 3µ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 424)[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 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 126)[Eval/TypeTiny.pm:8]:4]
# spent 2µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 135)[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 138)[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 151)[Eval/TypeTiny.pm:8]:4]
# spent 2µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 211)[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 252)[Eval/TypeTiny.pm:8]:4]
# spent 2µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 271)[Eval/TypeTiny.pm:8]:4]
# spent 2µs making 2 calls to Eval::TypeTiny::Sandbox::__ANON__[(eval 275)[Eval/TypeTiny.pm:8]:4], avg 1µs/call
# spent 2µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 278)[Eval/TypeTiny.pm:8]:4]
# spent 2µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 282)[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 326)[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 360)[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 53)[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 60)[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 67)[Eval/TypeTiny.pm:8]:4]
# spent 2µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 70)[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 73)[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 87)[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 110)[Eval/TypeTiny.pm:8]:4]
# spent 1µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 111)[Eval/TypeTiny.pm:8]:4]
# spent 1µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 113)[Eval/TypeTiny.pm:8]:4]
# spent 1µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 114)[Eval/TypeTiny.pm:8]:4]
# spent 1µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 116)[Eval/TypeTiny.pm:8]:4]
# spent 1µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 118)[Eval/TypeTiny.pm:8]:4]
# spent 1µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 124)[Eval/TypeTiny.pm:8]:4]
# spent 1µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 128)[Eval/TypeTiny.pm:8]:4]
# spent 1µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 130)[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 147)[Eval/TypeTiny.pm:8]:4]
# spent 1µs making 2 calls to Eval::TypeTiny::Sandbox::__ANON__[(eval 274)[Eval/TypeTiny.pm:8]:4], avg 500ns/call
# 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 56)[Eval/TypeTiny.pm:8]:4]
# spent 1µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 57)[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 69)[Eval/TypeTiny.pm:8]:4]
# spent 1µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 76)[Eval/TypeTiny.pm:8]:9]
# 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 84)[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 89)[Eval/TypeTiny.pm:8]:4]
# spent 1µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 92)[Eval/TypeTiny.pm:8]:4]
# spent 1µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 93)[Eval/TypeTiny.pm:8]:4]
# spent 1µs making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 95)[Eval/TypeTiny.pm:8]:4]
# spent 0s making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 101)[Eval/TypeTiny.pm:8]:4]
# spent 0s making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 102)[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 120)[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 131)[Eval/TypeTiny.pm:8]:4]
# spent 0s making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 133)[Eval/TypeTiny.pm:8]:4]
# spent 0s making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 139)[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 242)[Eval/TypeTiny.pm:8]:4]
# spent 0s making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 256)[Eval/TypeTiny.pm:8]:4]
# spent 0s making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 279)[Eval/TypeTiny.pm:8]:4]
# spent 0s making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 313)[Eval/TypeTiny.pm:8]:4]
# spent 0s making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 324)[Eval/TypeTiny.pm:8]:4]
# spent 0s making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 404)[Eval/TypeTiny.pm:8]:4]
# spent 0s making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 51)[Eval/TypeTiny.pm:8]:4]
# spent 0s making 1 call to Eval::TypeTiny::Sandbox::__ANON__[(eval 66)[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 90)[Eval/TypeTiny.pm:8]:4]
# spent 0s 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 99)[Eval/TypeTiny.pm:8]:4] |
| 249 | 131 | 28µs | undef( $compiler ); | ||
| 250 | |||||
| 251 | 131 | 13µ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 | 15µ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 | 274µs | return $code; | ||
| 264 | } #/ sub eval_closure | ||||
| 265 | |||||
| 266 | 1 | 0s | my $tmp; | ||
| 267 | |||||
| 268 | # spent 147µs (139+8) within Eval::TypeTiny::_make_lexical_assignment which was called 40 times, avg 4µs/call:
# 40 times (139µs+8µs) by Eval::TypeTiny::eval_closure at line 223, avg 4µs/call | ||||
| 269 | 40 | 12µs | my ( $key, $index, $alias ) = @_; | ||
| 270 | 40 | 20µs | my $name = substr( $key, 1 ); | ||
| 271 | |||||
| 272 | 40 | 46µs | 40 | 8µs | if ( HAS_LEXICAL_SUBS and $key =~ /^\&/ ) { # spent 8µs making 40 calls to Eval::TypeTiny::CORE:match, avg 200ns/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 | 8µs | if ( !$alias ) { | ||
| 283 | 40 | 9µs | my $sigil = substr( $key, 0, 1 ); | ||
| 284 | 40 | 66µ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 | 5µs | 1; | ||
| 411 | |||||
| 412 | __END__ | ||||
# spent 8µs within Eval::TypeTiny::CORE:match which was called 40 times, avg 200ns/call:
# 40 times (8µs+0s) by Eval::TypeTiny::_make_lexical_assignment at line 272, avg 200ns/call | |||||
# spent 27µs within Eval::TypeTiny::CORE:sort which was called 131 times, avg 206ns/call:
# 131 times (27µs+0s) by Eval::TypeTiny::eval_closure at line 221, avg 206ns/call | |||||
# spent 185µs within Eval::TypeTiny::CORE:subst which was called 131 times, avg 1µs/call:
# 131 times (185µs+0s) by Eval::TypeTiny::eval_closure at line 190, avg 1µs/call |