| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Evo::Internal::Util; | 
| 2 | 67 |  |  | 67 |  | 492 | use strict; | 
|  | 67 |  |  |  |  | 157 |  | 
|  | 67 |  |  |  |  | 1854 |  | 
| 3 | 67 |  |  | 67 |  | 366 | use warnings; | 
|  | 67 |  |  |  |  | 512 |  | 
|  | 67 |  |  |  |  | 2463 |  | 
| 4 | 67 |  |  | 67 |  | 31705 | use experimental 'signatures'; | 
|  | 67 |  |  |  |  | 227410 |  | 
|  | 67 |  |  |  |  | 423 |  | 
| 5 | 67 |  |  | 67 |  | 10558 | no warnings 'experimental::signatures'; | 
|  | 67 |  |  |  |  | 172 |  | 
|  | 67 |  |  |  |  | 2211 |  | 
| 6 | 67 |  |  | 67 |  | 433 | use Carp qw(carp croak); | 
|  | 67 |  |  |  |  | 158 |  | 
|  | 67 |  |  |  |  | 3754 |  | 
| 7 | 67 |  |  | 67 |  | 509 | use B qw(svref_2object); | 
|  | 67 |  |  |  |  | 183 |  | 
|  | 67 |  |  |  |  | 9256 |  | 
| 8 |  |  |  |  |  |  |  | 
| 9 |  |  |  |  |  |  | our $RX_PKG_NOT_FIRST = qr/[0-9A-Z_a-z]+(?:::[0-9A-Z_a-z]+)*/; | 
| 10 |  |  |  |  |  |  | our $RX_PKG           = qr/^[A-Z_a-z]$RX_PKG_NOT_FIRST*$/; | 
| 11 |  |  |  |  |  |  |  | 
| 12 |  |  |  |  |  |  |  | 
| 13 | 67 |  |  | 67 |  | 503 | use constant SUBRE => qr/^[a-zA-Z_]\w*$/; | 
|  | 67 |  |  |  |  | 161 |  | 
|  | 67 |  |  |  |  | 16080 |  | 
| 14 | 728 |  |  | 728 | 0 | 4945 | sub check_subname { $_[0] =~ SUBRE } | 
| 15 |  |  |  |  |  |  |  | 
| 16 |  |  |  |  |  |  | # usefull? | 
| 17 | 0 | 0 |  | 0 | 0 | 0 | sub find_caller_except ($skip_ns, $i, $caller) { | 
|  | 0 | 0 |  |  |  | 0 |  | 
|  | 0 |  |  |  |  | 0 |  | 
|  | 0 |  |  |  |  | 0 |  | 
|  | 0 |  |  |  |  | 0 |  | 
|  | 0 |  |  |  |  | 0 |  | 
| 18 | 0 |  |  |  |  | 0 | while ($caller = (caller($i++))[0]) { | 
| 19 | 0 | 0 |  |  |  | 0 | return $caller if $caller ne $skip_ns; | 
| 20 |  |  |  |  |  |  | } | 
| 21 |  |  |  |  |  |  | } | 
| 22 |  |  |  |  |  |  |  | 
| 23 | 2168 | 50 |  | 2168 | 0 | 6283 | sub monkey_patch ($pkg, %hash) { | 
|  | 2168 | 50 |  |  |  | 5587 |  | 
|  | 2168 |  |  |  |  | 3805 |  | 
|  | 2168 |  |  |  |  | 8833 |  | 
|  | 2168 |  |  |  |  | 4100 |  | 
| 24 | 67 |  |  | 67 |  | 527 | no strict 'refs';    ## no critic | 
|  | 67 |  |  |  |  | 174 |  | 
|  | 67 |  |  |  |  | 8569 |  | 
| 25 | 2168 |  |  |  |  | 9314 | *{"${pkg}::$_"} = $hash{$_} for keys %hash; | 
|  | 5754 |  |  |  |  | 91049 |  | 
| 26 |  |  |  |  |  |  | } | 
| 27 |  |  |  |  |  |  |  | 
| 28 |  |  |  |  |  |  | #todo: decide what to do with empty subroutins | 
| 29 | 9 | 50 |  | 9 | 0 | 2618 | sub monkey_patch_silent ($pkg, %hash) { | 
|  | 9 | 50 |  |  |  | 28 |  | 
|  | 9 |  |  |  |  | 18 |  | 
|  | 9 |  |  |  |  | 28 |  | 
|  | 9 |  |  |  |  | 16 |  | 
| 30 | 67 |  |  | 67 |  | 481 | no strict 'refs';    ## no critic | 
|  | 67 |  |  |  |  | 164 |  | 
|  | 67 |  |  |  |  | 2040 |  | 
| 31 | 67 |  |  | 67 |  | 390 | no warnings 'redefine'; | 
|  | 67 |  |  |  |  | 184 |  | 
|  | 67 |  |  |  |  | 17326 |  | 
| 32 | 9 |  |  |  |  | 15 | my %restore; | 
| 33 | 9 |  |  |  |  | 23 | foreach my $name (keys %hash) { | 
| 34 | 10 |  |  |  |  | 22 | $restore{$name} = *{"${pkg}::$name"}{CODE}; | 
|  | 10 |  |  |  |  | 41 |  | 
| 35 | 10 | 50 | 0 |  |  | 31 | warn "Can't delete empty ${pkg}::$name" and next unless $hash{$name}; | 
| 36 | 10 |  |  |  |  | 16 | *{"${pkg}::$name"} = $hash{$name}; | 
|  | 10 |  |  |  |  | 37 |  | 
| 37 |  |  |  |  |  |  | } | 
| 38 | 9 |  |  |  |  | 49 | \%restore; | 
| 39 |  |  |  |  |  |  | } | 
| 40 |  |  |  |  |  |  |  | 
| 41 |  |  |  |  |  |  | # returns a package where code was declared and a name | 
| 42 |  |  |  |  |  |  | # ->CONST not documented, but exists in B::CV and defined in /CORE/cv.h as | 
| 43 |  |  |  |  |  |  | # define CvCONST(cv)		(CvFLAGS(cv) & CVf_CONST) | 
| 44 |  |  |  |  |  |  | # this flag is used by Evo::Class to determine that constants should be inherited | 
| 45 | 2807 | 50 |  | 2807 | 0 | 10092 | sub code2names($r) { | 
|  | 2807 | 50 |  |  |  | 10585 |  | 
|  | 2807 |  |  |  |  | 5273 |  | 
|  | 2807 |  |  |  |  | 4452 |  | 
| 46 | 2807 |  |  |  |  | 8510 | my $sv    = svref_2object($r); | 
| 47 | 2807 |  |  |  |  | 8824 | my $gv    = $sv->GV; | 
| 48 | 2807 |  |  |  |  | 7673 | my $stash = $gv->STASH; | 
| 49 | 2807 |  |  |  |  | 16246 | ($stash->NAME, $gv->NAME, $sv->CONST); | 
| 50 |  |  |  |  |  |  | } | 
| 51 |  |  |  |  |  |  |  | 
| 52 | 3903 | 50 |  | 3903 | 0 | 12561 | sub names2code ($pkg, $name) { | 
|  | 3903 | 50 |  |  |  | 8037 |  | 
|  | 3903 |  |  |  |  | 5951 |  | 
|  | 3903 |  |  |  |  | 5613 |  | 
|  | 3903 |  |  |  |  | 5464 |  | 
| 53 | 67 |  |  | 67 |  | 545 | no strict 'refs';    ## no critic | 
|  | 67 |  |  |  |  | 161 |  | 
|  | 67 |  |  |  |  | 6487 |  | 
| 54 | 3903 |  |  |  |  | 5376 | *{"${pkg}::$name"}{CODE}; | 
|  | 3903 |  |  |  |  | 19390 |  | 
| 55 |  |  |  |  |  |  | } | 
| 56 |  |  |  |  |  |  |  | 
| 57 |  |  |  |  |  |  |  | 
| 58 | 62 | 50 |  | 62 | 0 | 1111 | sub list_symbols($pkg) { | 
|  | 62 | 50 |  |  |  | 177 |  | 
|  | 62 |  |  |  |  | 115 |  | 
|  | 62 |  |  |  |  | 99 |  | 
| 59 | 67 |  |  | 67 |  | 462 | no strict 'refs';    ##no critic | 
|  | 67 |  |  |  |  | 169 |  | 
|  | 67 |  |  |  |  | 33096 |  | 
| 60 | 62 |  |  |  |  | 110 | grep { $_ =~ /^[a-zA-Z_]\w*$/ } keys %{"${pkg}::"}; | 
|  | 1658 |  |  |  |  | 4390 |  | 
|  | 62 |  |  |  |  | 490 |  | 
| 61 |  |  |  |  |  |  | } | 
| 62 |  |  |  |  |  |  |  | 
| 63 |  |  |  |  |  |  | #sub undef_symbols($ns) { | 
| 64 |  |  |  |  |  |  | #  no strict 'refs';    ## no critic | 
| 65 |  |  |  |  |  |  | #  undef *{"${ns}::$_"} for list_symbols($ns); | 
| 66 |  |  |  |  |  |  | #} | 
| 67 |  |  |  |  |  |  |  | 
| 68 |  |  |  |  |  |  |  | 
| 69 |  |  |  |  |  |  | #sub uniq { | 
| 70 |  |  |  |  |  |  | #  my %seen; | 
| 71 |  |  |  |  |  |  | #  return grep { !$seen{$_}++ } @_; | 
| 72 |  |  |  |  |  |  | #} | 
| 73 |  |  |  |  |  |  |  | 
| 74 |  |  |  |  |  |  | # returns a subroutine than can pretend a code in the other package/file/line | 
| 75 | 1979 | 50 |  | 1979 | 0 | 5994 | sub inject(%opts) { | 
|  | 1979 |  |  |  |  | 8509 |  | 
|  | 1979 |  |  |  |  | 3413 |  | 
| 76 | 1979 |  |  |  |  | 5935 | my ($package, $filename, $line, $code) = @opts{qw(package filename line code)}; | 
| 77 |  |  |  |  |  |  |  | 
| 78 |  |  |  |  |  |  | ## no critic | 
| 79 |  |  |  |  |  |  | ( | 
| 80 | 1979 |  |  |  |  | 130797 | eval qq{package $package; | 
| 81 |  |  |  |  |  |  | #line $line "$filename" | 
| 82 |  |  |  |  |  |  | sub { \$code->(\@_) } | 
| 83 |  |  |  |  |  |  | } | 
| 84 |  |  |  |  |  |  | ); | 
| 85 |  |  |  |  |  |  | } | 
| 86 |  |  |  |  |  |  |  | 
| 87 |  |  |  |  |  |  | #sub find_subnames ($pkg, $code) { | 
| 88 |  |  |  |  |  |  | #  no strict 'refs';    ## no critic | 
| 89 |  |  |  |  |  |  | #  my %symbols = %{$pkg . "::"}; | 
| 90 |  |  |  |  |  |  | # | 
| 91 |  |  |  |  |  |  | #  # because use constant adds refs to package symbols hash | 
| 92 |  |  |  |  |  |  | #  grep { !ref($symbols{$_}) && (*{$symbols{$_}}{CODE} // 0) == $code } keys %symbols; | 
| 93 |  |  |  |  |  |  | #} | 
| 94 |  |  |  |  |  |  |  | 
| 95 |  |  |  |  |  |  |  | 
| 96 | 140 | 50 |  | 140 |  | 570 | sub _parent ($caller) { | 
|  | 140 | 50 |  |  |  | 533 |  | 
|  | 140 |  |  |  |  | 310 |  | 
|  | 140 |  |  |  |  | 328 |  | 
| 97 | 140 |  |  |  |  | 642 | my @arr = split /::/, $caller; | 
| 98 | 140 |  |  |  |  | 335 | pop @arr; | 
| 99 | 140 |  |  |  |  | 829 | join '::', @arr; | 
| 100 |  |  |  |  |  |  | } | 
| 101 |  |  |  |  |  |  |  | 
| 102 | 2698 | 50 |  | 2698 | 0 | 7726 | sub resolve_package ($caller, $pkg) { | 
|  | 2698 | 50 |  |  |  | 6533 |  | 
|  | 2698 |  |  |  |  | 5132 |  | 
|  | 2698 |  |  |  |  | 5721 |  | 
|  | 2698 |  |  |  |  | 4347 |  | 
| 103 |  |  |  |  |  |  |  | 
| 104 | 2698 | 100 |  |  |  | 19243 | return $pkg if $pkg =~ $RX_PKG; | 
| 105 |  |  |  |  |  |  |  | 
| 106 | 1780 | 100 |  |  |  | 17332 | return "Evo::$1" if $pkg =~ /^\-($RX_PKG_NOT_FIRST)$/; | 
| 107 |  |  |  |  |  |  |  | 
| 108 |  |  |  |  |  |  | # parent. TODO: many // | 
| 109 | 251 | 100 |  |  |  | 1204 | if ($pkg =~ /^\/(.*)$/) { | 
| 110 | 140 |  |  |  |  | 428 | my $rest   = $1; | 
| 111 | 140 | 100 |  |  |  | 624 | my $parent = _parent($caller) | 
| 112 |  |  |  |  |  |  | or croak "Can't resolve $pkg: can't find parent of caller $caller"; | 
| 113 |  |  |  |  |  |  |  | 
| 114 | 139 | 50 |  |  |  | 3433 | return "$parent$rest" if "$parent$rest" =~ /^$RX_PKG$/; | 
| 115 |  |  |  |  |  |  | } | 
| 116 |  |  |  |  |  |  |  | 
| 117 | 111 | 100 |  |  |  | 2904 | return "${caller}::$1" if $pkg =~ /^::($RX_PKG_NOT_FIRST)$/; | 
| 118 |  |  |  |  |  |  |  | 
| 119 | 4 |  |  |  |  | 357 | croak "Can't resolve $pkg for caller $caller"; | 
| 120 |  |  |  |  |  |  | } | 
| 121 |  |  |  |  |  |  |  | 
| 122 |  |  |  |  |  |  |  | 
| 123 | 3 | 50 |  | 3 | 0 | 2769 | sub suppress_carp ($me, $caller) { | 
|  | 3 | 50 |  |  |  | 8 |  | 
|  | 3 |  |  |  |  | 5 |  | 
|  | 3 |  |  |  |  | 5 |  | 
|  | 3 |  |  |  |  | 5 |  | 
| 124 | 67 |  |  | 67 |  | 524 | no strict 'refs';    ## no critic | 
|  | 67 |  |  |  |  | 174 |  | 
|  | 67 |  |  |  |  | 6560 |  | 
| 125 | 3 | 100 |  |  |  | 5 | push @{"${caller}::CARP_NOT"}, $me if !grep { $_ eq $me } @{"${caller}::CARP_NOT"}; | 
|  | 2 |  |  |  |  | 7 |  | 
|  | 3 |  |  |  |  | 10 |  | 
|  | 3 |  |  |  |  | 14 |  | 
| 126 |  |  |  |  |  |  | } | 
| 127 |  |  |  |  |  |  |  | 
| 128 |  |  |  |  |  |  | 1; | 
| 129 |  |  |  |  |  |  |  | 
| 130 |  |  |  |  |  |  | __END__ |