| 1 | package App::SlimPacker::Minify; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 35 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 35 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 35 | ▶ | use PPI; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 35 | ▶ | use Scalar::Util 'refaddr'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 35 | ▶ | use Exporter 'import'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 35 | our $VERSION = '0.08'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 35 | our @EXPORT_OK = qw( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | process process_deps minify_file name_gen needs_space | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | module_deps collect_bundle_globals | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | rename_module_name rename_module_path | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 3000 | ▶ | sub needs_space { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
needs_space: called CC=25 SCAR=32.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 3000 | my ($l, $r) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 3000 | my $lc = $l->content; my $rc = $r->content; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 3000 | my $lr = ref($l); my $rr = ref($r); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 3000 | ▶ | return 1 if $lc =~ /\w$/ && $rc =~ /^\w/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$lc =~ /\w$/ and $rc =~ /^\w/
MC/DC100%2/2
$lc =~ /\w$/ and $rc =~ /^\w/
$lc =~ /\w$/
$rc =~ /^\w/
Truth table100%3/3
A and B
A= $lc =~ /\w$/B= $rc =~ /^\w/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 2523 | ▶ | return 1 if $lc =~ /[\$\@\%]$/ && $rc =~ /^\w/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$lc =~ /[\$\@\%]$/ and $rc =~ /^\w/
MC/DC100%2/2
$lc =~ /[\$\@\%]$/ and $rc =~ /^\w/
$lc =~ /[\$\@\%]$/
$rc =~ /^\w/
Truth table100%3/3
A and B
A= $lc =~ /[\$\@\%]$/B= $rc =~ /^\w/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 2520 | ▶ | return 1 if $lc =~ /\w$/ && $rr =~ /Quote/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$lc =~ /\w$/ and $rr =~ /Quote/
MC/DC100%2/2
$lc =~ /\w$/ and $rr =~ /Quote/
$lc =~ /\w$/
$rr =~ /Quote/
Truth table100%3/3
A and B
A= $lc =~ /\w$/B= $rr =~ /Quote/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 2411 | ▶ | return 1 if $lr =~ /Quote/ && $rc =~ /^\w/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$lr =~ /Quote/ and $rc =~ /^\w/
MC/DC100%2/2
$lr =~ /Quote/ and $rc =~ /^\w/
$lr =~ /Quote/
$rc =~ /^\w/
Truth table100%3/3
A and B
A= $lr =~ /Quote/B= $rc =~ /^\w/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 2397 | ▶ | return 1 if $lr =~ /Symbol/ && $rr =~ /Symbol/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$lr =~ /Symbol/ and $rr =~ /Symbol/
MC/DC100%2/2
$lr =~ /Symbol/ and $rr =~ /Symbol/
$lr =~ /Symbol/
$rr =~ /Symbol/
Truth table100%3/3
A and B
A= $lr =~ /Symbol/B= $rr =~ /Symbol/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | # A bare Cast sigil (`$`, `@`, `%`) must not be glued to the token before | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | # it: `print $fh $$source` -> `print$fh$$source` (or `$fh@$source`) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | # silently changes meaning / breaks parsing. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 2396 | ▶ | return 1 if $rr =~ /Cast/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 2383 | ▶ | return 1 if $lc =~ /\w$/ && $rc =~ /^['"\/]/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$lc =~ /\w$/ and $rc =~ m[^['"/]]
MC/DC100%2/2
$lc =~ /\w$/ and $rc =~ m[^['"/]]
$lc =~ /\w$/
$rc =~ m[^['"/]]
Truth table100%3/3
A and B
A= $lc =~ /\w$/B= $rc =~ m[^['"/]]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 2380 | ▶ | return 1 if $lr =~ /Regexp/ && $rc =~ /^\w/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$lr =~ /Regexp/ and $rc =~ /^\w/
MC/DC100%2/2
$lr =~ /Regexp/ and $rc =~ /^\w/
$lr =~ /Regexp/
$rc =~ /^\w/
Truth table100%3/3
A and B
A= $lr =~ /Regexp/B= $rc =~ /^\w/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | # `use Foo VERSION (LIST)` needs the space before the paren; dropping it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | # (e.g. `use Foo 5.57(qw/x/)`) is a Perl syntax error. The paren arrives as | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | # a Structure whose content starts with '('. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 2379 | ▶ | return 1 if $lr =~ /Number/ && $rc =~ /^\(/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$lr =~ /Number/ and $rc =~ /^\(/
MC/DC100%2/2
$lr =~ /Number/ and $rc =~ /^\(/
$lr =~ /Number/
$rc =~ /^\(/
Truth table100%3/3
A and B
A= $lr =~ /Number/B= $rc =~ /^\(/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | # Perl <= 5.18 mis-tokenizes `&&WORD` (also `&`, `||`, `//`) when a method | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | # call follows (`$x&&Foo::Bar->baz`): "Operator or semicolon missing | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | # before &Foo::Bar". Keep the space after the operator. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 2376 | ▶ | return 1 if ($lc eq '&&' || $lc eq '||' || $lc eq '//' || $lc eq '&') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%10/12
$lc eq "&&" || $lc eq "||" || $lc eq "//" || $lc eq "&" and $rc =~ /^[A-Za-z_]/
$lc eq "&&" or $lc eq "||" or $lc eq "//" or $lc eq "&"
$lc eq "&&" or $lc eq "||" or $lc eq "//"
$lc eq "&&" or $lc eq "||"
MC/DC60%3/5
$lc eq "&&" || $lc eq "||" || $lc eq "//" || $lc eq "&" and $rc =~ /^[A-Za-z_]/
$lc eq "&&"
$lc eq "||"
$lc eq "//"
$lc eq "&"
$rc =~ /^[A-Za-z_]/
Truth table44%4/9
A or B or C or D and E
A= $lc eq "&&"B= $lc eq "||"C= $lc eq "//"D= $lc eq "&"E= $rc =~ /^[A-Za-z_]/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | && $rc =~ /^[A-Za-z_]/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | # `-WORD` is a filetest (`-e $x`) or, on perl <= 5.20, an ambiguous | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | # bareword negation ("Ambiguous use of -WORD resolved as -&WORD()"). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | # Keep the space after a minus that preceded a word. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 2373 | ▶ | return 1 if $lc eq '-' && $rc =~ /^[A-Za-z_]/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$lc eq "-" and $rc =~ /^[A-Za-z_]/
MC/DC100%2/2
$lc eq "-" and $rc =~ /^[A-Za-z_]/
$lc eq "-"
$rc =~ /^[A-Za-z_]/
Truth table100%3/3
A and B
A= $lc eq "-"B= $rc =~ /^[A-Za-z_]/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 2371 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 35 | my @_chars = ('a'..'z'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 641 | ▶ | sub name_gen { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
name_gen: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 641 | my ($n) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 641 | my $out = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 641 | $n++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 641 | ▶ | while ($n > 0) { $out = $_chars[($n-1)%26] . $out; $n = int(($n-1)/26) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 641 | return $out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | # Previous/next sibling skipping whitespace. Builtins never appear as direct | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | # siblings of a Word token (Whitespace is its own sibling), so the rename | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | # contexts below must see through it. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 190 | ▶ | sub _prev_sig_sib { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_prev_sig_sib: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 190 | my ($t) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 190 | my $p = $t->previous_sibling; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 190 | ▶ | $p = $p->previous_sibling while $p && ref($p) eq 'PPI::Token::Whitespace'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$p and ref $p eq "PPI::Token::Whitespace"
MC/DC100%2/2
$p and ref $p eq "PPI::Token::Whitespace"
$p
ref $p eq "PPI::Token::Whitespace"
Truth table100%3/3
A and B
A= $pB= ref $p eq "PPI::Token::Whitespace"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 190 | return $p; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 176 | ▶ | sub _next_sig_sib { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_next_sig_sib: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 176 | my ($t) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 176 | my $n = $t->next_sibling; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 176 | ▶ | $n = $n->next_sibling while $n && ref($n) eq 'PPI::Token::Whitespace'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$n and ref $n eq "PPI::Token::Whitespace"
MC/DC100%2/2
$n and ref $n eq "PPI::Token::Whitespace"
$n
ref $n eq "PPI::Token::Whitespace"
Truth table100%3/3
A and B
A= $nB= ref $n eq "PPI::Token::Whitespace"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 176 | return $n; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | # --------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | # Per-name eligibility: what may be renamed, and to what. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | # --------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | # Pragma/pseudo modules whose `use` argument list is NOT a list of exported | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | # sub names to rename: names there are pragma settings, class names or data | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | # (`use lib 'cache'`, `use parent qw(App::Base)`, `use constant FOO => 'bar'`). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | # When a sub name collides with one of these the rename is refused rather than | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | # risk turning data into a renamed identifier. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 35 | my %USE_LITERAL_ARGS = map { $_ => 1 } qw( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | strict warnings feature lib parent base constant vars subs if integer bytes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | utf8 overload re sigtrap open sort | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | # Is this token part of a sub-name "protocol site": a `use` import list, an | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | # @EXPORT/@EXPORT_OK/%EXPORT_TAGS assignment, or a can()/DOES()/import() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | # argument? With rename_exports on, words at these sites are RENAMED in step | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | # with the sub they refer to (two sides of the same name surface), so they must | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | # neither freeze the name for eligibility nor be left behind when the sub is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | # shortened. Everything that looks like a site but is really data is excluded | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | # (pragma import args, the module-name word of the `use`, non-single-word | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | # strings). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 138 | ▶ | sub _protocol_site { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_protocol_site: called CC=20 SCAR=31.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 138 | my ($tok) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 138 | ▶ | my $stmt = $tok->statement or return 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 138 | ▶ | if ($stmt->isa('PPI::Statement::Include')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 27 | my $type = $stmt->type; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 27 | ▶ | return 0 unless defined $type && $type eq 'use'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $type and $type eq "use"
MC/DC50%1/2
defined $type and $type eq "use"
defined $type
$type eq "use"
Truth table66%2/3
A and B
A= defined $typeB= $type eq "use"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 25 | my $mod = $stmt->module; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 25 | ▶ | return 0 unless defined $mod && length $mod; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $mod and length $mod
MC/DC0%0/2
defined $mod and length $mod
defined $mod
length $mod
Truth table33%1/3
A and B
A= defined $modB= length $mod
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 25 | ▶ | return 0 if $mod eq $tok->content; # the module-name word | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 25 | (my $leaf = $mod) =~ s/^.*:://; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 25 | ▶ | return 0 if $USE_LITERAL_ARGS{$leaf}; # pragma args are data | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 4 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 111 | my $syms = $stmt->find('PPI::Token::Symbol'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 111 | ▶ | if ($syms) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 63 | for my $s (@$syms) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 77 | ▶ | next if $s == $tok; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 77 | ▶ | return 1 if $s->content =~ /^[\$\@\%](?:EXPORT|EXPORT_OK|EXPORT_TAGS)$/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 105 | my $par = $tok->parent; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | # PPI wraps a bare method-call argument in a Statement::Expression inside | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | # the argument List, so climb through those wrappers to find the List. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 105 | ▶ | while ($par && $par->isa('PPI::Statement::Expression')) { $par = $par->parent } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$par and $par->isa("PPI::Statement::Expression")
MC/DC50%1/2
$par and $par->isa("PPI::Statement::Expression")
$par
$par->isa("PPI::Statement::Expression")
Truth table66%2/3
A and B
A= $parB= $par->isa("PPI::Statement::Expression")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 105 | ▶ | if ($par && $par->isa('PPI::Structure::List')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$par and $par->isa("PPI::Structure::List")
MC/DC50%1/2
$par and $par->isa("PPI::Structure::List")
$par
$par->isa("PPI::Structure::List")
Truth table66%2/3
A and B
A= $parB= $par->isa("PPI::Structure::List")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 14 | my $prev = _prev_sig_sib($par); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 14 | ▶ | return 1 if $prev && $prev->isa('PPI::Token::Word') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
$prev and $prev->isa("PPI::Token::Word") and $prev->content =~ /^(?:can|DOES|import)$/
$prev and $prev->isa("PPI::Token::Word")
MC/DC33%1/3
$prev and $prev->isa("PPI::Token::Word") and $prev->content =~ /^(?:can|DOES|import)$/
$prev
$prev->isa("PPI::Token::Word")
$prev->content =~ /^(?:can|DOES|import)$/
Truth table50%2/4
A and B and C
A= $prevB= $prev->isa("PPI::Token::Word")C= $prev->content =~ /^(?:can|DOES|import)$/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | && $prev->content =~ /^(?:can|DOES|import)$/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 103 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | # Namespace components of bundled packages are renamed to short names, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | # INCLUDING each package's leaf (final) component: the bundle is closed, so a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | # `use Pkg::Leaf` compiles to a `require 'Pkg/Leaf.pm'` that the loader's | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | # %INC key matches, and both are rewritten from the same component map. Module | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | # names that are only ever built at runtime (from user config, directory | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | # globbing, string-eval) are not rewritten — slimpack documents that any such | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | # name must be whitelisted by the app author. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | # rename_module_name(NAME, $mods) rewrites a "Foo::Bar" style name; $mods is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | # the module struct from collect_bundle_globals() (a fourth return value): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | # { map => { component => short }, pkgs => [longest-first package names] } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | # A name is rewritten when it equals a declared bundled package, starts with | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | # one ("Pkg::Leaf::sub" — the package part only), or is a strict namespace | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | # ancestor of one (search-path strings like "App::Saisons::Adapter", where | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | # every component is renamed). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 72 | ▶ | sub rename_module_name { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
rename_module_name: called CC=14 SCAR=27.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 72 | my ($name, $m) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 72 | ▶ | return $name unless $m && $m->{pkgs} && @{ $m->{pkgs} } && $name =~ /::/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition44%4/9
$m and $m->{"pkgs"} and @{$m->{"pkgs"};} and $name =~ /::/
$m and $m->{"pkgs"} and @{$m->{"pkgs"};}
$m and $m->{"pkgs"}
MC/DC25%1/4
$m and $m->{"pkgs"} and @{$m->{"pkgs"};} and $name =~ /::/
$m
$m->{"pkgs"}
@{$m->{"pkgs"};}
$name =~ /::/
Truth table40%2/5
A and B and C and D
A= $mB= $m->{"pkgs"}C= @{$m->{"pkgs"};}D= $name =~ /::/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 61 | my @caps = split /::/, $name; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 61 | for my $p (@{ $m->{pkgs} }) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 82 | my @pc = split /::/, $p; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 82 | ▶ | if ($name eq $p && @pc >= 2) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$name eq $p and @pc >= 2
MC/DC50%1/2
$name eq $p and @pc >= 2
$name eq $p
@pc >= 2
Truth table66%2/3
A and B
A= $name eq $pB= @pc >= 2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 46 | ▶ | return join('::', map { $m->{map}{$_} // $_ } @pc); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$m->{"map"}{$_} // $_
MC/DC0%0/2
$m->{"map"}{$_} // $_
$m->{"map"}{$_}
$_
Truth table66%2/3
A // B
A= $m->{"map"}{$_}B= $_
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 36 | ▶ | if (@pc >= 2 && substr($name, 0, length($p) + 2) eq $p . '::') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@pc >= 2 and substr($name, 0, length($p) + 2) eq $p . '::'
MC/DC50%1/2
@pc >= 2 and substr($name, 0, length($p) + 2) eq $p . '::'
@pc >= 2
substr($name, 0, length($p) + 2) eq $p . '::'
Truth table66%2/3
A and B
A= @pc >= 2B= substr($name, 0, length($p) + 2) eq $p . '::'
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | # `name` lives under the declared package $p. $p may itself be an | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | # ancestor-namespace (a deeper declared package renames $p's last | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | # component too — App::Saisons -> a::b when App::Saisons::UI is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | # declared), so resolve the renamed prefix via a recursive call | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | # rather than mapping only $p's ancestors and appending its leaf | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | # verbatim. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 4 | my $ren = rename_module_name($p, $m); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 4 | return $ren . substr($name, length $p); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 32 | ▶ | if (@caps >= 2 && substr($p, 0, length($name) + 2) eq $name . '::') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@caps >= 2 and substr($p, 0, length($name) + 2) eq $name . '::'
MC/DC50%1/2
@caps >= 2 and substr($p, 0, length($name) + 2) eq $name . '::'
@caps >= 2
substr($p, 0, length($name) + 2) eq $name . '::'
Truth table66%2/3
A and B
A= @caps >= 2B= substr($p, 0, length($name) + 2) eq $name . '::'
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 4 | ▶ | return join('::', map { $m->{map}{$_} // $_ } @caps); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$m->{"map"}{$_} // $_
MC/DC0%0/2
$m->{"map"}{$_} // $_
$m->{"map"}{$_}
$_
Truth table33%1/3
A // B
A= $m->{"map"}{$_}B= $_
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 7 | return $name; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | # rename_module_path('App/Saisons/UI.pm', $mods) rewrites the %INC/loader key | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | # form of a module name, so a renamed `require 'a/Saisons/UI.pm'` resolves in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | # the loader. The leaf is renamed too when the component map contains it (the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | # bundler includes every component of a declared package), which is what keeps | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | # the loader's %INC table keys in step with the rewritten package names. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 4 | ▶ | sub rename_module_path { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
rename_module_path: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 4 | my ($path, $m) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 4 | ▶ | return $path unless $path =~ /\.pm\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 4 | (my $name = $path) =~ s{\.pm\z}{}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 4 | $name =~ s{/}{::}g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 4 | my $ren = rename_module_name($name, $m); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 4 | $ren =~ s{::}{/}g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 4 | return $ren . '.pm'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | # Is a Word whose content is in the sub rename map really a reference to that | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | # sub (so renaming is safe and consistent), as opposed to a hash key, a label, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | # or the target of a dereference? $qualified selects the rules for a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | # Pkg::name token (PPI emits the whole qualified name as one Word): those are | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | # only ever renamed when the token is unambiguously a sub reference — a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | # definition, an &name, or an actual call with parentheses. Bare qualified | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | # words (constants, typeglob elements) and foreign-method chains are left | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | # alone. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | # Renamed contexts (plain names): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | # sub foo {...} definition (also sub Pkg::foo) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | # $o->foo(...) method call (never $h->{foo} / {foo=>}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | # &foo, \&foo direct / coderef call | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | # Foo::bar(...) qualified call (qualified defs handled too) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | # foo(...) plain bareword call | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | # Anything else — a bare `foo` word, `foo =>`, `$o->{foo}`, `Pkg::foo` without | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | # parens, `foo:`, `\foo` — is left alone. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 176 | ▶ | sub _sub_word_context { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_sub_word_context: called CC=38 SCAR=45.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 176 | my ($tok, $qualified) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 176 | my $parent = $tok->parent; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 176 | ▶ | return 0 if $parent && ($parent->isa('PPI::Structure::Brace') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$parent and $parent->isa("PPI::Structure::Brace") || $parent->isa("PPI::Structure::Constructor")
$parent->isa("PPI::Structure::Brace") or $parent->isa("PPI::Structure::Constructor")
MC/DC0%0/3
$parent and $parent->isa("PPI::Structure::Brace") || $parent->isa("PPI::Structure::Constructor")
$parent
$parent->isa("PPI::Structure::Brace")
$parent->isa("PPI::Structure::Constructor")
Truth table25%1/4
A and B or C
A= $parentB= $parent->isa("PPI::Structure::Brace")C= $parent->isa("PPI::Structure::Constructor")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | || $parent->isa('PPI::Structure::Constructor')); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 176 | my $prev = _prev_sig_sib($tok); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 176 | my $next = _next_sig_sib($tok); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 176 | ▶ | if ($qualified) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 14 | ▶ | return 1 if $prev && $prev->content eq 'sub'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$prev and $prev->content eq "sub"
MC/DC50%1/2
$prev and $prev->content eq "sub"
$prev
$prev->content eq "sub"
Truth table66%2/3
A and B
A= $prevB= $prev->content eq "sub"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 13 | ▶ | return 1 if $prev && $prev->content eq '&'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$prev and $prev->content eq "&"
MC/DC0%0/2
$prev and $prev->content eq "&"
$prev
$prev->content eq "&"
Truth table33%1/3
A and B
A= $prevB= $prev->content eq "&"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 13 | ▶ | return 1 if $next && $next->isa('PPI::Structure::List'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$next and $next->isa("PPI::Structure::List")
MC/DC0%0/2
$next and $next->isa("PPI::Structure::List")
$next
$next->isa("PPI::Structure::List")
Truth table33%1/3
A and B
A= $nextB= $next->isa("PPI::Structure::List")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 162 | ▶ | return 1 if $prev && $prev->content eq 'sub'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$prev and $prev->content eq "sub"
MC/DC100%2/2
$prev and $prev->content eq "sub"
$prev
$prev->content eq "sub"
Truth table100%3/3
A and B
A= $prevB= $prev->content eq "sub"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 40 | ▶ | return 1 if $prev && $prev->content eq '->'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$prev and $prev->content eq "->"
MC/DC100%2/2
$prev and $prev->content eq "->"
$prev
$prev->content eq "->"
Truth table100%3/3
A and B
A= $prevB= $prev->content eq "->"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 36 | ▶ | return 1 if $prev && $prev->content eq '&'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$prev and $prev->content eq "&"
MC/DC0%0/2
$prev and $prev->content eq "&"
$prev
$prev->content eq "&"
Truth table66%2/3
A and B
A= $prevB= $prev->content eq "&"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 36 | ▶ | if ($prev && $prev->content eq '::') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$prev and $prev->content eq "::"
MC/DC0%0/2
$prev and $prev->content eq "::"
$prev
$prev->content eq "::"
Truth table66%2/3
A and B
A= $prevB= $prev->content eq "::"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 0 | my $p = _prev_sig_sib($prev); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 0 | ▶ | return 1 if $p && $p->content eq 'sub'; # sub Pkg::foo {...} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$p and $p->content eq "sub"
MC/DC0%0/2
$p and $p->content eq "sub"
$p
$p->content eq "sub"
Truth table0%0/3
A and B
A= $pB= $p->content eq "sub"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 0 | ▶ | return 1 if $next && $next->isa('PPI::Structure::List'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$next and $next->isa("PPI::Structure::List")
MC/DC0%0/2
$next and $next->isa("PPI::Structure::List")
$next
$next->isa("PPI::Structure::List")
Truth table0%0/3
A and B
A= $nextB= $next->isa("PPI::Structure::List")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 0 | return 0; # Pkg::foo bare (const/sym) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | # Bareword call. Every name in the sub map is a defined sub, so any | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | # remaining bareword occurrence of it is a call to it (`foo . $x`, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | # `foo if $x`, `&`-less `foo(...)`, `foo;`, `foo, bar`) — except where | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | # the word is really a hash key, a label, or a constant being declared. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 36 | ▶ | if ($next) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 28 | ▶ | return 0 if $next->isa('PPI::Structure::Brace') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$next->isa("PPI::Structure::Brace") or $next->isa("PPI::Structure::Constructor")
MC/DC0%0/2
$next->isa("PPI::Structure::Brace") or $next->isa("PPI::Structure::Constructor")
$next->isa("PPI::Structure::Brace")
$next->isa("PPI::Structure::Constructor")
Truth table33%1/3
A or B
A= $next->isa("PPI::Structure::Brace")B= $next->isa("PPI::Structure::Constructor")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | || $next->isa('PPI::Structure::Constructor'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 28 | my $c = $next->content; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 28 | ▶ | return 0 if $c eq '=>'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 26 | ▶ | return 0 if $c eq ':' && $tok->statement | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
$c eq ":" and $tok->statement and $tok->statement->first_token == $tok
$c eq ":" and $tok->statement
MC/DC0%0/3
$c eq ":" and $tok->statement and $tok->statement->first_token == $tok
$c eq ":"
$tok->statement
$tok->statement->first_token == $tok
Truth table50%2/4
A and B and C
A= $c eq ":"B= $tok->statementC= $tok->statement->first_token == $tok
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | && $tok->statement->first_token == $tok; # foo: label | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 26 | ▶ | return 0 if $prev && $prev->content =~ /^(?:goto|next|last|redo)$/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$prev and $prev->content =~ /^(?:goto|next|last|redo)$/
MC/DC0%0/2
$prev and $prev->content =~ /^(?:goto|next|last|redo)$/
$prev
$prev->content =~ /^(?:goto|next|last|redo)$/
Truth table66%2/3
A and B
A= $prevB= $prev->content =~ /^(?:goto|next|last|redo)$/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 26 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | # Last word of its expression (`(... && !foo)`, `[foo]`, a block ending | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | # in `foo`) is still a call - unless it is a hash key ($h{foo}). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 8 | ▶ | return 0 if $prev && $prev->content =~ /^(?:goto|next|last|redo)$/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$prev and $prev->content =~ /^(?:goto|next|last|redo)$/
MC/DC100%2/2
$prev and $prev->content =~ /^(?:goto|next|last|redo)$/
$prev
$prev->content =~ /^(?:goto|next|last|redo)$/
Truth table100%3/3
A and B
A= $prevB= $prev->content =~ /^(?:goto|next|last|redo)$/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 7 | my $holder = $parent; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 7 | ▶ | $holder = $holder->parent if $holder && $holder->isa('PPI::Statement::Expression'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$holder and $holder->isa("PPI::Statement::Expression")
MC/DC50%1/2
$holder and $holder->isa("PPI::Statement::Expression")
$holder
$holder->isa("PPI::Statement::Expression")
Truth table66%2/3
A and B
A= $holderB= $holder->isa("PPI::Statement::Expression")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 7 | ▶ | return 0 if $holder && $holder->isa('PPI::Structure::Subscript'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$holder and $holder->isa("PPI::Structure::Subscript")
MC/DC50%1/2
$holder and $holder->isa("PPI::Structure::Subscript")
$holder
$holder->isa("PPI::Structure::Subscript")
Truth table66%2/3
A and B
A= $holderB= $holder->isa("PPI::Structure::Subscript")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 3 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 35 | my %KEEP = map { $_ => 1 } qw( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | _ a b 0 1 2 3 4 5 6 7 8 9 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | ENV INC ISA SIG ARGV ARGVOUT STDOUT STDERR STDIN | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | VERSION AUTOLOAD self class | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | # `self` and `class` are real keywords only under Perl's 5.38+ `class` feature | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | # (bareword declarations plus an implicit, never-my-declared `$self` in method | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | # bodies). As plain `my` lexicals in classic code (`my $self = shift`, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | # `my $class = shift`) they are ordinary variables and rename like any other — | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | # if a source actually enables the class feature, _uses_class_feature() freezes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | # them again so the implicit $self and the class/method/field keywords stay. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 194 | ▶ | sub _uses_class_feature { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_uses_class_feature: called CC=7 SCAR=19.7
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 194 | my ($doc) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 194 | my $s = $doc->serialize; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 194 | ▶ | return 1 if $s =~ /\buse\s+v?\s*\d\.(?:3[89]|4[0-9])\b/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 193 | ▶ | for my $inc (@{ $doc->find('PPI::Statement::Include') || [] }) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$doc->find('PPI::Statement::Include') || []
MC/DC100%1/1
$doc->find('PPI::Statement::Include') || []
$doc->find('PPI::Statement::Include')
Truth table100%2/2
A
A= $doc->find('PPI::Statement::Include')
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 114 | my $txt = $inc->content; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 114 | ▶ | next unless $txt =~ /^\s*use\s+(feature|experimental)\b/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 1 | ▶ | return 1 if $txt =~ /\bclass\b/ || $txt =~ /\b:\s*5\.(?:3[89]|4[0-9])\b/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$txt =~ /\bclass\b/ or $txt =~ /\b:\s*5\.(?:3[89]|4[0-9])\b/
MC/DC0%0/2
$txt =~ /\bclass\b/ or $txt =~ /\b:\s*5\.(?:3[89]|4[0-9])\b/
$txt =~ /\bclass\b/
$txt =~ /\b:\s*5\.(?:3[89]|4[0-9])\b/
Truth table33%1/3
A or B
A= $txt =~ /\bclass\b/B= $txt =~ /\b:\s*5\.(?:3[89]|4[0-9])\b/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 193 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | # Sub/method names that must never be renamed: magic lifetimes, the module | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | # protocol, UNIVERSAL, constructor/factory protocols that other code (or the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | # runtime) reaches by name rather than by an in-file reference, the whole tie() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | # interface (the runtime dispatches TIEHASH/FETCH/STORE/... by name from a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | # quoted package — `tie %h, __PACKAGE__` is invisible to the word scan), and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | # the serialization hooks that external modules look up by name. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 35 | my %SUBKEEP = map { $_ => 1 } qw( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | new clone DESTROY AUTOLOAD VERSION import unimport export | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | can isa DOES | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | BEGIN CHECK INIT END UNITCHECK | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | TIESCALAR TIEARRAY TIEHASH TIEHANDLE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | FETCH STORE FETCHSIZE STORESIZE EXISTS DELETE CLEAR UNTIE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | PUSH POP SHIFT UNSHIFT SPLICE EXTEND FIRSTKEY NEXTKEY SCALAR | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | WRITE PRINT PRINTF READLINE GETC READ CLOSE FILENO BINMODE EOF TELL SEEK OPEN | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | TO_JSON FREEZE THAW STORABLE_freeze STORABLE_thaw | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | # Perl keywords and builtin functions as bareword-call candidates. A sub | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | # whose name is already a keyword/builtin is never renamed (calls to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | # "map(...)", "format" etc. must keep resolving to the builtin), and generated | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | # short names are reserved away from every surviving word in the file. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 35 | my %PERL_WORDS = map { $_ => 1 } qw( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | __FILE__ __LINE__ __PACKAGE__ __SUB__ BEGIN CHECK CORE DESTROY END | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | UNITCHECK AUTOLOAD abs accept alarm and atan2 bind binmode bless break | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | caller chdir chmod chomp chop chown chr chroot close closedir cmp connect | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | continue cos crypt dbmclose dbmopen default defined delete die do dump | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | each else elsif endgrent endhostent endnetent endprotoent endpwent | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | endservent eof eq eval exec exists exit exp fc fcntl fileno flock for | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | foreach fork format formline ge getc getgrent getgrgid getgrnam | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | gethostbyaddr gethostbyname gethostent getlogin getnetbyaddr getnetbyname | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | getnetent getpeername getpgrp getppid getpriority getprotobyname | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | getprotobynumber getprotoent getpwent getpwnam getpwuid getservbyname | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | getservbyport getservent getsockname getsockopt given glob gmtime goto | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | grep gt hex if index int ioctl join keys kill last lc lcfirst le length | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | link listen local localtime lock log lstat lt m map mkdir msgctl msgget | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | msgrcv msgsnd my ne next no not oct open opendir or ord our pack package | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | pipe pop pos print printf prototype push q qq qr quotemeta qw qx rand | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | read readdir readline readlink readpipe recv redo ref rename repeat | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | require reset return reverse rewinddir rindex rmdir s say scalar seek | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | seekdir select semctl semget semop send setgrent sethostent setnetent | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | setpgrp setpriority setprotoent setpwent setservent setsockopt shift | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | shmctl shmget shmread shmwrite shutdown sin sleep socket socketpair sort | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | splice split sprintf sqrt srand stat state study sub substr symlink | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | syscall sysopen sysread sysseek system syswrite tell telldir tie tied | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | time times tr truncate uc ucfirst umask undef unless unlink unpack | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | unshift untie until use utime values vec wait waitpid wantarray warn when | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | while write x xor y | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | # Letters Perl reads as a file test after a minus: a sub renamed to `k` | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | # turns `$x - _CONST` (glued to `$x-_CONST` by the whitespace pass) into the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | # file test `$x-k`. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 35 | my %FILETEST = map { $_ => 1 } qw(r w x o R W X O e z s f d l p S b c t u g k T B A M C); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | # True when a generated short sub name must be skipped: a keyword/builtin, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | # a file-test letter, or a name already in use ($taken). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 271 | ▶ | sub _sub_short_taken { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_sub_short_taken: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 271 | my ($short, $taken) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 271 | ▶ | return $PERL_WORDS{$short} || $FILETEST{$short} || $taken->{$short}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition83%5/6
$PERL_WORDS{$short} || $FILETEST{$short} || $taken->{$short}
$PERL_WORDS{$short} or $FILETEST{$short}
MC/DC66%2/3
$PERL_WORDS{$short} || $FILETEST{$short} || $taken->{$short}
$PERL_WORDS{$short}
$FILETEST{$short}
$taken->{$short}
Truth table75%3/4
A or B || C
A= $PERL_WORDS{$short}B= $FILETEST{$short}C= $taken->{$short}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | # Packages declared in a file that loads XS code (XSLoader::load, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | # DynaLoader's bootstrap). Empty for pure-Perl files. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 60 | ▶ | sub _xs_packages { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_xs_packages: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 60 | my ($doc) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 2399 | ▶ | my $loads_xs = $doc->find_first(sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 2399 | ▶ | $_[1]->isa('PPI::Token::Word') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | && $_[1]->content =~ /^(?:XSLoader::load|(?:DynaLoader::)?bootstrap)$/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 60 | }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 60 | ▶ | return unless $loads_xs; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 1 | ▶ | return map { $_->namespace } @{ $doc->find('PPI::Statement::Package') || [] }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$doc->find('PPI::Statement::Package') || []
MC/DC0%0/1
$doc->find('PPI::Statement::Package') || []
$doc->find('PPI::Statement::Package')
Truth table50%1/2
A
A= $doc->find('PPI::Statement::Package')
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | # Names of every sub the file/bundle may legally shorten. A sub name is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | # eligible only when it survives all the guards: a plain identifier, not a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | # kept magic/protocol name, not a perl keyword/builtin, never seen inside a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | # stringy/regex token (dispatch by string would silently bypass the rename), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | # and not colliding with any word that stays in the output. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 163 | ▶ | sub _sub_eligible { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_sub_eligible: called CC=9 SCAR=22.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 163 | my ($name, $in_string_word) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 163 | ▶ | return 0 unless defined $name; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 163 | ▶ | return 0 if length($name) <= 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 157 | ▶ | return 0 unless $name =~ /^[A-Za-z_]\w*$/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 156 | ▶ | return 0 if $KEEP{$name} || $SUBKEEP{$name} || $PERL_WORDS{$name}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$KEEP{$name} or $SUBKEEP{$name} or $PERL_WORDS{$name}
$KEEP{$name} or $SUBKEEP{$name}
MC/DC100%3/3
$KEEP{$name} or $SUBKEEP{$name} or $PERL_WORDS{$name}
$KEEP{$name}
$SUBKEEP{$name}
$PERL_WORDS{$name}
Truth table100%4/4
A or B or C
A= $KEEP{$name}B= $SUBKEEP{$name}C= $PERL_WORDS{$name}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 132 | ▶ | return 0 if $in_string_word && $in_string_word->{$name}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$in_string_word and $in_string_word->{$name}
MC/DC50%1/2
$in_string_word and $in_string_word->{$name}
$in_string_word
$in_string_word->{$name}
Truth table66%2/3
A and B
A= $in_string_wordB= $in_string_word->{$name}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 129 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | # What a `*name` glob token is assigned: 'code' when the assignment installs | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | # a sub (*x = \&y, *x = sub {...}, *x = $coderef, *x = cond ? $a : $b, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | # *x{CODE} = ...), 'data' when it aliases a variable, filehandle or another | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | # glob (*x = \@y, *x = \*STDOUT, *x = *y, *x = 'y', *x{SCALAR} = ...), undef when the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | # glob is not assigned to. The bundle collector and the renamer both ask | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | # this, so a glob-installed sub and its callers are always renamed together. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 9 | ▶ | sub _glob_assign_kind { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_glob_assign_kind: called CC=19 SCAR=37.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 9 | my ($glob) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 9 | ▶ | my $next = $glob->snext_sibling or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 9 | my $slot; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | 9 | ▶ | if ($next->isa('PPI::Structure::Subscript') || $next->isa('PPI::Structure::Block')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$next->isa("PPI::Structure::Subscript") or $next->isa("PPI::Structure::Block")
MC/DC0%0/2
$next->isa("PPI::Structure::Subscript") or $next->isa("PPI::Structure::Block")
$next->isa("PPI::Structure::Subscript")
$next->isa("PPI::Structure::Block")
Truth table33%1/3
A or B
A= $next->isa("PPI::Structure::Subscript")B= $next->isa("PPI::Structure::Block")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 0 | ($slot) = $next->content =~ /^\{\s*(\w+)\s*\}$/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 0 | ▶ | $next = $next->snext_sibling or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 9 | ▶ | return unless $next->isa('PPI::Token::Operator') && $next->content eq '='; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$next->isa("PPI::Token::Operator") and $next->content eq "="
MC/DC0%0/2
$next->isa("PPI::Token::Operator") and $next->content eq "="
$next->isa("PPI::Token::Operator")
$next->content eq "="
Truth table33%1/3
A and B
A= $next->isa("PPI::Token::Operator")B= $next->content eq "="
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 9 | ▶ | return $slot eq 'CODE' ? 'code' : 'data' if defined $slot; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | 9 | ▶ | my $rhs = $next->snext_sibling or return 'code'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | 9 | ▶ | return 'data' if $rhs->isa('PPI::Token::Symbol') && $rhs->content =~ /^\*/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$rhs->isa("PPI::Token::Symbol") and $rhs->content =~ /^\*/
MC/DC0%0/2
$rhs->isa("PPI::Token::Symbol") and $rhs->content =~ /^\*/
$rhs->isa("PPI::Token::Symbol")
$rhs->content =~ /^\*/
Truth table33%1/3
A and B
A= $rhs->isa("PPI::Token::Symbol")B= $rhs->content =~ /^\*/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | # *x = 'name' aliases the glob of that name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 9 | ▶ | return 'data' if $rhs->isa('PPI::Token::Quote') || $rhs->isa('PPI::Token::Number'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$rhs->isa("PPI::Token::Quote") or $rhs->isa("PPI::Token::Number")
MC/DC50%1/2
$rhs->isa("PPI::Token::Quote") or $rhs->isa("PPI::Token::Number")
$rhs->isa("PPI::Token::Quote")
$rhs->isa("PPI::Token::Number")
Truth table66%2/3
A or B
A= $rhs->isa("PPI::Token::Quote")B= $rhs->isa("PPI::Token::Number")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | 8 | ▶ | if ($rhs->isa('PPI::Token::Cast') && $rhs->content eq '\\') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$rhs->isa("PPI::Token::Cast") and $rhs->content eq "\\"
MC/DC50%1/2
$rhs->isa("PPI::Token::Cast") and $rhs->content eq "\\"
$rhs->isa("PPI::Token::Cast")
$rhs->content eq "\\"
Truth table66%2/3
A and B
A= $rhs->isa("PPI::Token::Cast")B= $rhs->content eq "\\"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | 4 | my $target = $rhs->snext_sibling; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | 4 | ▶ | return 'data' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
$target and $target->isa("PPI::Token::Symbol") and $target->content =~ /^&/
$target and $target->isa("PPI::Token::Symbol")
MC/DC33%1/3
$target and $target->isa("PPI::Token::Symbol") and $target->content =~ /^&/
$target
$target->isa("PPI::Token::Symbol")
$target->content =~ /^&/
Truth table50%2/4
A and B and C
A= $targetB= $target->isa("PPI::Token::Symbol")C= $target->content =~ /^&/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | unless $target && $target->isa('PPI::Token::Symbol') && $target->content =~ /^&/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 6 | return 'code'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | # --------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | # Entry points: process() runs the whole minifier; _minify_doc is the shared | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | # core (disable individual passes by removing their one call below). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | # --------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | 207 | ▶ | sub process { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
process: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | 207 | my ($src, %opts) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | 207 | ▶ | my $doc = PPI::Document->new(\$src) or return $src; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | 207 | return _minify_doc($doc, %opts); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | # Minification core shared by process() and process_deps(): apply the PPI | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | # comment/POD prune and the rename/whitespace passes to an already-parsed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | # document, then optionally the rewrite pass (rewrite => 1). Returns the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | # serialized, minified string. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | 234 | ▶ | sub _minify_doc { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_minify_doc: called CC=19 SCAR=29.7
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 234 | my ($doc, %opts) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 234 | ▶ | my $rename_vars = $opts{rename_vars} // $opts{rename} // 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%5/5
($opts{"rename_vars"} // $opts{"rename"}) // 1
$opts{"rename_vars"} // $opts{"rename"}
MC/DC100%2/2
($opts{"rename_vars"} // $opts{"rename"}) // 1
$opts{"rename_vars"}
$opts{"rename"}
Truth table100%3/3
A // B
A= $opts{"rename_vars"}B= $opts{"rename"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | 234 | my $rename_subs = $opts{rename_subs}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | 234 | ▶ | my $gmap = $opts{global_rename_vars} // $opts{global_rename}; # pkg => { old=>short } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$opts{"global_rename_vars"} // $opts{"global_rename"}
MC/DC100%2/2
$opts{"global_rename_vars"} // $opts{"global_rename"}
$opts{"global_rename_vars"}
$opts{"global_rename"}
Truth table100%3/3
A // B
A= $opts{"global_rename_vars"}B= $opts{"global_rename"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | 234 | my $glex = $opts{global_lexicals}; # bundle-wide `my`/`state` names | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 234 | my $gs = $opts{global_subs}; # bundle-wide name-global sub map | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | 234 | ▶ | my $mods = $opts{global_modules} || {}; # { map, pkgs } module-rename struct | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$opts{'global_modules'} || {}
MC/DC100%1/1
$opts{'global_modules'} || {}
$opts{'global_modules'}
Truth table100%2/2
A
A= $opts{'global_modules'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | 234 | my $rename_exports = $opts{rename_exports}; # rename export/import protocol strings | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | 234 | $doc->prune('PPI::Token::Comment'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | 234 | $doc->prune('PPI::Token::Pod'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | 234 | ▶ | return $doc->serialize unless $doc->children; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | 233 | my %rename; # original name -> short name (global per file) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | 233 | my $counter = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | 233 | ▶ | if ($rename_vars) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | 194 | my %in_string; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | # Pass 1a: collect variable names used inside regex CODE regions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | # ((?{ ... }) blocks, s///e replacements) and refuse them renames — | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | # those regions are real Perl, opaque to this pass, and a renamed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | # lexical referenced there would break. Names in the interpolating | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | # pattern/replacement text are fine: _rewrite_names_in_regexes rewrites | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | # them to match the symbol renames later. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | 194 | _regex_exempt_names_doc($doc, \%in_string, undef); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | # Pass 1b: collect rename candidates from my declarations only. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | # `local $x` declares a package global (even bare: it localises | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | # $PKG::x), and `our $x` is likewise a package global; renaming a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | # global while any surviving $PKG::x reference reads it would break | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | # cross-package semantics. `my $x` is a true file lexical, never | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | # reachable as a package global, so it is always safe to rename. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | 194 | my $class_feature = _uses_class_feature($doc); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | 194 | my @decl_names = _collect_lexical_candidates($doc, \%in_string, $class_feature); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | # Pass 1c: reserve every symbol name that survives unrenamed, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | # so generated short names can never shadow or collide with them. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | 194 | my $reserved = _reserve_names($doc, $gmap); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | # Assign short names in declaration order | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | 194 | for my $name (@decl_names) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | 118 | ▶ | next if exists $rename{$name}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | 113 | my $short; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | 113 | ▶ | do { $short = name_gen($counter++) } while $KEEP{$short} || $reserved->{$short}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$KEEP{$short} or $reserved->{$short}
MC/DC100%2/2
$KEEP{$short} or $reserved->{$short}
$KEEP{$short}
$reserved->{$short}
Truth table100%3/3
A or B
A= $KEEP{$short}B= $reserved->{$short}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | 113 | $rename{$name} = $short; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | # Pass 1d: rewrite interpolated variable names inside strings so they | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | # keep agreeing with the renames applied to symbols in Pass 2. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | _rewrite_names_in_strings($doc, \%rename, $gmap, $glex, $mods) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | 194 | ▶ | if $rename_vars || $gmap || ($mods && $mods->{pkgs}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition22%2/9
$rename_vars or $gmap or $mods and $mods->{"pkgs"}
$rename_vars or $gmap
$mods and $mods->{"pkgs"}
MC/DC0%0/4
$rename_vars or $gmap or $mods and $mods->{"pkgs"}
$rename_vars
$gmap
$mods
$mods->{"pkgs"}
Truth table20%1/5
A or B or C and D
A= $rename_varsB= $gmapC= $modsD= $mods->{"pkgs"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | # Pass 1d': rewrite variables interpolated inside regex pattern / | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | # replacement text (m/.../, s/.../.../, qr(...)) the same way, so a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | # qr/\Q$query\E/i built from a now-short lexical still matches what the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | # code references, and bundle globals ($gmap) interpolated in patterns | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | # follow their renames too. Code regions ((?{ ... }), s///e | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | # replacements) are exempted in Pass 1a and never touched here. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | 194 | _rewrite_names_in_regexes($doc, \%rename, $gmap, $glex, $mods); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | # Module-prefix rewrite only (no variable renames): when variable | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | # renaming is off but namespaces move, interpolated fully-qualified | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | # globals in strings ("$App::Saisons::VERSION") and readlines must still | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | # follow the module rename. Without rename_vars no my-variable map is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | # built, so this can never per-token-rename a scalar. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | 233 | ▶ | if (!$rename_vars && $mods && $mods->{pkgs}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
not $rename_vars and $mods and $mods->{"pkgs"}
not $rename_vars and $mods
MC/DC66%2/3
not $rename_vars and $mods and $mods->{"pkgs"}
not $rename_vars
$mods
$mods->{"pkgs"}
Truth table75%3/4
not(A) and B and C
A= not $rename_varsB= $modsC= $mods->{"pkgs"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | 1 | _rewrite_names_in_strings($doc, {}, undef, undef, $mods); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | 233 | my %submap; # method/sub name -> short name | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | 233 | %submap = %{ _build_sub_map($doc, $gs, $rename_subs, $rename_exports) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | # Pass 2: strip whitespace, then rename variables, subs and module | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | # components in place. @needs_space inspects only char-class edges that | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | # the renames preserve (a shortened identifier still ends and starts \w, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | # sigils and delimiters are untouched), so the collapse and the rename | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | # are independent token walks and each stays readable on its own. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | 233 | _strip_whitespace($doc); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | 233 | _apply_renames($doc, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | rename => \%rename, gmap => $gmap, glex => $glex, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | mods => $mods, submap => \%submap, rename_vars => $rename_vars, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | rename_exports => $rename_exports); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | # Protocol-string + module-name string rewrite. Runs after the token walk | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | # so %submap is final (bundle global_subs or the file's own map). Only | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | # plain single-word / module-shaped / module-path strings are touched; any | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | # string with escapes, sigils or spaces is left alone. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | 233 | _rewrite_protocol_strings($doc, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | submap => \%submap, rename_exports => $rename_exports, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | gmap => $gmap, glex => $glex, mods => $mods); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | 233 | ▶ | _rewrite_doc($doc) if $opts{rewrite}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | 233 | return $doc->serialize; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | # --------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | # Name-policy gates. _var_renameable is THE single place that decides whether | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | # a variable name may be shortened; every collector (file lexicals here, the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | # bundler's globals in collect_bundle_globals) funnels through it. Per-version | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | # whitelists/blacklists (e.g. new keywords or class-feature names on newer | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | # perls) are added here, in one spot, via the is_global / class_feature | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | # context instead of scattered edit sites. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | # Global policy (is_global): a package global is renamed only when it can | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | # never be ambiguous with a lexical anywhere in the bundle, never appears | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | # inside opaque stringy/regex text, is not a KEEP name and not an all-caps | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | # constant. Lexical policy: `my`/`state` names rename unless one character, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | # a $^X-style special, inside a regex code region, or otherwise blocked — | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | # `self`/`class` are ordinary lexicals in classic code (my $self = shift) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | # but become keywords that must not be renamed under the 5.38+ class feature. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | 226 | ▶ | sub _var_renameable { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_var_renameable: called CC=19 SCAR=30.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | 226 | my ($name, %ctx) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | 226 | ▶ | return 0 if length($name) <= 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | 150 | ▶ | return 0 if $name =~ /\^/; # $^X / %^H / ${^...} specials | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | 149 | ▶ | return 0 if $name =~ /::/; # package globals are never renamed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | 149 | ▶ | if ($ctx{is_global}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | 16 | ▶ | return 0 if $ctx{lexicals} && $ctx{lexicals}{$name}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$ctx{"lexicals"} and $ctx{"lexicals"}{$name}
MC/DC50%1/2
$ctx{"lexicals"} and $ctx{"lexicals"}{$name}
$ctx{"lexicals"}
$ctx{"lexicals"}{$name}
Truth table66%2/3
A and B
A= $ctx{"lexicals"}B= $ctx{"lexicals"}{$name}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | 14 | ▶ | return 0 if $ctx{in_string} && $ctx{in_string}{$name}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$ctx{"in_string"} and $ctx{"in_string"}{$name}
MC/DC50%1/2
$ctx{"in_string"} and $ctx{"in_string"}{$name}
$ctx{"in_string"}
$ctx{"in_string"}{$name}
Truth table66%2/3
A and B
A= $ctx{"in_string"}B= $ctx{"in_string"}{$name}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | 13 | ▶ | return 0 if $KEEP{$name}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | 11 | ▶ | return 0 if $name =~ /^[A-Z_]+$/; # all-caps: constants / magic ($!), ... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | 8 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | 133 | ▶ | return 0 if $ctx{in_string} && $ctx{in_string}{$name}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$ctx{"in_string"} and $ctx{"in_string"}{$name}
MC/DC50%1/2
$ctx{"in_string"} and $ctx{"in_string"}{$name}
$ctx{"in_string"}
$ctx{"in_string"}{$name}
Truth table66%2/3
A and B
A= $ctx{"in_string"}B= $ctx{"in_string"}{$name}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | 127 | ▶ | return 0 if $KEEP{$name} && $name ne 'self' && $name ne 'class'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$KEEP{$name} and $name ne "self" and $name ne "class"
$KEEP{$name} and $name ne "self"
MC/DC100%3/3
$KEEP{$name} and $name ne "self" and $name ne "class"
$KEEP{$name}
$name ne "self"
$name ne "class"
Truth table100%4/4
A and B and C
A= $KEEP{$name}B= $name ne "self"C= $name ne "class"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | 118 | ▶ | return 0 if $ctx{class_feature} && ($name eq 'self' || $name eq 'class'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition16%1/6
$ctx{"class_feature"} and $name eq "self" || $name eq "class"
$name eq "self" or $name eq "class"
MC/DC0%0/3
$ctx{"class_feature"} and $name eq "self" || $name eq "class"
$ctx{"class_feature"}
$name eq "self"
$name eq "class"
Truth table25%1/4
A and B or C
A= $ctx{"class_feature"}B= $name eq "self"C= $name eq "class"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | 118 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | # Pass 1a: walk every regex token and mark the variable names used inside | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | # regex CODE regions ((?{ ... }) blocks, s///e replacements) as | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | # unrenameable. Those regions are real Perl, opaque to this pass, and a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | # renamed lexical referenced there would break. Names in the interpolating | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | # pattern/replacement text are fine: _rewrite_names_in_regexes rewrites them | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | # to match the symbol renames later. With a second hash, code-region BARE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | # WORDS freeze the sub map the same way. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | 194 | ▶ | sub _regex_exempt_names_doc { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_regex_exempt_names_doc: called CC=10 SCAR=23.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | 194 | my ($doc, $in_string, $in_string_word) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | 194 | my $tok = $doc->first_token; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | 194 | ▶ | while ($tok) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | 7696 | my $r = ref($tok); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | 7696 | ▶ | if ($r eq 'PPI::Token::Regexp::Match' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition100%6/6
$r eq "PPI::Token::Regexp::Match" or $r eq "PPI::Token::Regexp::Substitute" or $r eq "PPI::Token::QuoteLike::Regexp"
$r eq "PPI::Token::Regexp::Match" or $r eq "PPI::Token::Regexp::Substitute"
MC/DC100%3/3
$r eq "PPI::Token::Regexp::Match" or $r eq "PPI::Token::Regexp::Substitute" or $r eq "PPI::Token::QuoteLike::Regexp"
$r eq "PPI::Token::Regexp::Match"
$r eq "PPI::Token::Regexp::Substitute"
$r eq "PPI::Token::QuoteLike::Regexp"
Truth table100%4/4
A or B or C
A= $r eq "PPI::Token::Regexp::Match"B= $r eq "PPI::Token::Regexp::Substitute"C= $r eq "PPI::Token::QuoteLike::Regexp"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | || $r eq 'PPI::Token::Regexp::Substitute' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | || $r eq 'PPI::Token::QuoteLike::Regexp') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | 37 | _regex_exempt_names($in_string, $in_string_word, $r, $tok->content); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | ▶ | } elsif ($r eq 'PPI::Token::Quote::Single' | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$r eq "PPI::Token::Quote::Single" or $r eq "PPI::Token::Quote::Literal"
MC/DC100%2/2
$r eq "PPI::Token::Quote::Single" or $r eq "PPI::Token::Quote::Literal"
$r eq "PPI::Token::Quote::Single"
$r eq "PPI::Token::Quote::Literal"
Truth table100%3/3
A or B
A= $r eq "PPI::Token::Quote::Single"B= $r eq "PPI::Token::Quote::Literal"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | || $r eq 'PPI::Token::Quote::Literal') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | 87 | _string_exempt_names($in_string, $in_string_word, $tok->content); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | ▶ | } elsif ($r eq 'PPI::Token::HereDoc' | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition80%4/5
$r eq "PPI::Token::HereDoc" and not +($tok->{"_mode"} || "") =~ /^(?:interpolate|command)$/
$tok->{'_mode'} || ''
MC/DC0%0/2
$r eq "PPI::Token::HereDoc" and not +($tok->{"_mode"} || "") =~ /^(?:interpolate|command)$/
$r eq "PPI::Token::HereDoc"
$tok->{'_mode'}
Truth table66%2/3
A and not(B)
A= $r eq "PPI::Token::HereDoc"B= $tok->{'_mode'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | && ($tok->{_mode} || '') !~ /^(?:interpolate|command)$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | 2 | _string_exempt_names($in_string, $in_string_word, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | join '', $tok->heredoc); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | 7696 | $tok = $tok->next_token; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | # Names referenced with a sigil inside a NON-interpolating string are frozen | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | # like regex code regions: such strings can be eval'd as code at runtime | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | # (Sub::Defer builds its deferred subs in a q[...] template that closes over | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | # the file lexicals $undeferred / $deferred_info), and a renamed lexical | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | # referenced there would break. Interpolating strings are fine: their | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | # references are rewritten to match the renames. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | 89 | ▶ | sub _string_exempt_names { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_string_exempt_names: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | 89 | my ($in_string, $in_string_word, $text) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | 89 | ▶ | while ($text =~ /[\$\@\%]\{?([A-Za-z_]\w*)/g) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 565 | 6 | $in_string->{$1} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 566 | 6 | ▶ | $in_string_word->{$1} = 1 if $in_string_word; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 567 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 568 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 569 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 570 | # Pass 1b: collect rename candidates from my declarations only, in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 571 | # declaration order. `local $x` declares a package global (even bare: it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 572 | # localises $PKG::x), and `our $x` is likewise a package global; renaming a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 573 | # global while any surviving $PKG::x reference reads it would break | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 574 | # cross-package semantics. `my $x` is a true file lexical, never reachable | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 575 | # as a package global, so it is always safe to rename — subject to the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 576 | # shared _var_renameable gate. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 577 | 194 | ▶ | sub _collect_lexical_candidates { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_collect_lexical_candidates: called CC=11 SCAR=24.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 578 | 194 | my ($doc, $in_string, $class_feature) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 579 | 194 | my @decl_names; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 580 | 194 | my $tok = $doc->first_token; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 581 | 194 | ▶ | while ($tok) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 582 | 7696 | ▶ | if (ref($tok) eq 'PPI::Token::Word' && $tok->content eq 'my') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
ref $tok eq "PPI::Token::Word" and $tok->content eq "my"
MC/DC100%2/2
ref $tok eq "PPI::Token::Word" and $tok->content eq "my"
ref $tok eq "PPI::Token::Word"
$tok->content eq "my"
Truth table100%3/3
A and B
A= ref $tok eq "PPI::Token::Word"B= $tok->content eq "my"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | 0 | ▶ | my $next = $tok->snext_sibling or do { $tok = $tok->next_token; next }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 584 | 189 | my @syms; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 585 | 189 | ▶ | if ($next->isa('PPI::Token::Symbol')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 586 | 168 | @syms = ($next); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 587 | } elsif ($next->isa('PPI::Structure::List')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 588 | 21 | ▶ | @syms = @{ $next->find('PPI::Token::Symbol') || [] }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$next->find('PPI::Token::Symbol') || []
MC/DC0%0/1
$next->find('PPI::Token::Symbol') || []
$next->find('PPI::Token::Symbol')
Truth table50%1/2
A
A= $next->find('PPI::Token::Symbol')
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 589 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 590 | 189 | for my $sym (@syms) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 591 | 208 | ▶ | my (undef, $name) = $sym->content =~ /^([\$\@\%])(.+)$/ or next; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 592 | 208 | ▶ | push @decl_names, $name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 593 | if _var_renameable($name, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 594 | is_global => 0, class_feature => $class_feature, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 595 | in_string => $in_string); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 596 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 597 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 598 | 7696 | $tok = $tok->next_token; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 599 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 600 | 194 | return @decl_names; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 601 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 602 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 603 | # Pass 1c: reserve every symbol name that survives unrenamed, so generated | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 604 | # short names can never shadow or collide with them. Also reserves every | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 605 | # bundle-global short name: any of them may be referenced (or declared) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 606 | # unqualified in this very file, so a `my` short of the same name would | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 607 | # shadow it. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 608 | 194 | ▶ | sub _reserve_names { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_reserve_names: called CC=8 SCAR=20.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 609 | 194 | my ($doc, $gmap) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 610 | 194 | my %reserved; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 611 | 194 | my $tok = $doc->first_token; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 612 | 194 | ▶ | while ($tok) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 613 | 7696 | ▶ | if (ref($tok) eq 'PPI::Token::Symbol' || ref($tok) eq 'PPI::Token::ArrayIndex') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
ref $tok eq "PPI::Token::Symbol" or ref $tok eq "PPI::Token::ArrayIndex"
MC/DC100%2/2
ref $tok eq "PPI::Token::Symbol" or ref $tok eq "PPI::Token::ArrayIndex"
ref $tok eq "PPI::Token::Symbol"
ref $tok eq "PPI::Token::ArrayIndex"
Truth table100%3/3
A or B
A= ref $tok eq "PPI::Token::Symbol"B= ref $tok eq "PPI::Token::ArrayIndex"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 614 | 526 | my (undef, $name) = $tok->content =~ /^((?:\$#|[\$\@\%]))(.+)$/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 615 | 526 | ▶ | $reserved{$name} = 1 if defined $name && length $name; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $name and length $name
MC/DC50%1/2
defined $name and length $name
defined $name
length $name
Truth table66%2/3
A and B
A= defined $nameB= length $name
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 616 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 617 | 7696 | $tok = $tok->next_token; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 618 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 619 | 194 | ▶ | if ($gmap) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 620 | 12 | $reserved{$_} = 1 for map { values %$_ } values %{ $gmap }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 621 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 622 | 194 | return \%reserved; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 623 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 624 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 625 | # Pass 1e: build the method/sub rename map. With a bundle-wide global_subs | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 626 | # map ($gs) that map is authoritative; otherwise a name is eligible only if | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 627 | # it never appears inside a stringy/regex token (dispatch by string — | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 628 | # can(), q{...}, "$t->format" interpolation — would silently bypass the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 629 | # rename), then assigned a short name that collides with no word that | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 630 | # survives in the output. Returns a hashref (possibly empty). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 631 | 233 | ▶ | sub _build_sub_map { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_sub_map: called CC=24 SCAR=32.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 632 | 233 | my ($doc, $gs, $rename_subs, $rename_exports) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 633 | 233 | my %submap; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 634 | 233 | ▶ | if ($gs) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 635 | 40 | ▶ | %submap = %$gs if %$gs; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 636 | } elsif ($rename_subs) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 637 | 42 | my %in_string_word; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 638 | 42 | my $tok = $doc->first_token; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 639 | 42 | ▶ | while ($tok) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 640 | 1958 | my $r = ref($tok); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 641 | 1958 | ▶ | if ($r =~ /^(?:PPI::Token::Quote::(?:Double|Interpolate|Single|Literal) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 642 | |PPI::Token::QuoteLike::(?:Regexp|Words|Readline|Backtick|Command) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 643 | |PPI::Token::Regexp::(?:Match|Substitute))$/x) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 644 | # Import/export protocol words are renamed in step with the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 645 | # subs they name; they must not freeze the name (see | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 646 | # rename_exports / _protocol_site). Anything else quoting a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 647 | # name — can('x'), qw in data, template text — freezes it. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 648 | 42 | ▶ | my $protocol = $rename_exports | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition55%5/9
$rename_exports && ($r =~ /^PPI::Token::Quote::(?:Single|Double|Literal)$/ || $r eq 'PPI::Token::QuoteLike::Words') && _protocol_site($tok)
$rename_exports and $r =~ /^PPI::Token::Quote::(?:Single|Double|Literal)$/ || $r eq "PPI::Token::QuoteLike::Words"
$r =~ /^PPI::Token::Quote::(?:Single|Double|Literal)$/ or $r eq "PPI::Token::QuoteLike::Words"
MC/DC0%0/4
$rename_exports && ($r =~ /^PPI::Token::Quote::(?:Single|Double|Literal)$/ || $r eq 'PPI::Token::QuoteLike::Words') && _protocol_site($tok)
$rename_exports
$r =~ /^PPI::Token::Quote::(?:Single|Double|Literal)$/
$r eq "PPI::Token::QuoteLike::Words"
_protocol_site($tok)
Truth table33%2/6
A and B or C && D
A= $rename_exportsB= $r =~ /^PPI::Token::Quote::(?:Single|Double|Literal)$/C= $r eq "PPI::Token::QuoteLike::Words"D= _protocol_site($tok)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 649 | && ($r =~ /^PPI::Token::Quote::(?:Single|Double|Literal)$/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 650 | || $r eq 'PPI::Token::QuoteLike::Words') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 651 | && _protocol_site($tok); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 652 | 42 | ▶ | unless ($protocol) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 653 | 42 | my $c = $tok->content; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 654 | 42 | ▶ | while ($c =~ /\b([A-Za-z_]\w*)\b/g) { $in_string_word{$1} = 1 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 655 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 656 | } elsif ($r eq 'PPI::Token::HereDoc') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 657 | 1 | my @hd = $tok->heredoc; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 658 | 1 | my $c = join('', @hd); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 659 | 1 | ▶ | while ($c =~ /\b([A-Za-z_]\w*)\b/g) { $in_string_word{$1} = 1 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 660 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 661 | 1958 | $tok = $tok->next_token; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 662 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 663 | 42 | my @sub_names; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 664 | 42 | $tok = $doc->first_token; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 665 | 42 | ▶ | while ($tok) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 666 | 1958 | ▶ | if (ref($tok) eq 'PPI::Token::Word' && $tok->content eq 'sub') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
ref $tok eq "PPI::Token::Word" and $tok->content eq "sub"
MC/DC100%2/2
ref $tok eq "PPI::Token::Word" and $tok->content eq "sub"
ref $tok eq "PPI::Token::Word"
$tok->content eq "sub"
Truth table100%3/3
A and B
A= ref $tok eq "PPI::Token::Word"B= $tok->content eq "sub"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 667 | 118 | my $next = $tok->snext_sibling; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 668 | 118 | ▶ | if ($next && $next->isa('PPI::Token::Word') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
$next and $next->isa("PPI::Token::Word") and _sub_eligible($next->content, \%in_string_word)
$next and $next->isa("PPI::Token::Word")
MC/DC33%1/3
$next and $next->isa("PPI::Token::Word") and _sub_eligible($next->content, \%in_string_word)
$next
$next->isa("PPI::Token::Word")
_sub_eligible($next->content, \%in_string_word)
Truth table50%2/4
A and B and C
A= $nextB= $next->isa("PPI::Token::Word")C= _sub_eligible($next->content, \%in_string_word)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 669 | && _sub_eligible($next->content, \%in_string_word)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 670 | 94 | push @sub_names, $next->content; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 671 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 672 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 673 | 1958 | $tok = $tok->next_token; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 674 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 675 | 42 | my %reserved; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 676 | 42 | $tok = $doc->first_token; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 677 | 42 | ▶ | while ($tok) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 678 | 1958 | ▶ | $reserved{$tok->content} = 1 if ref($tok) eq 'PPI::Token::Word'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 679 | 1958 | $tok = $tok->next_token; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 680 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 681 | 42 | my $scounter = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 682 | 42 | for my $name (@sub_names) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 683 | 94 | ▶ | next if exists $submap{$name}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 684 | 94 | my $short; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 685 | 94 | ▶ | do { $short = name_gen($scounter++) } while _sub_short_taken($short, \%reserved); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 686 | 94 | $submap{$name} = $short; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 687 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 688 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 689 | 233 | return \%submap; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 690 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 691 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 692 | # Record each token's position and the current package in lexical order, so a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 693 | # later token walk can resolve an unqualified name to its package the same | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 694 | # way the symbol pass does. Returns (\%index_of_token, \@package_at_index). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 695 | 201 | ▶ | sub _token_package_index { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_token_package_index: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 696 | 201 | my ($doc) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 697 | 201 | my (%idx, @pkg); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 698 | 201 | my $pkg = 'main'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 699 | 201 | my $n = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 700 | 201 | my $t = $doc->first_token; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 701 | 201 | ▶ | while ($t) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 702 | 10026 | $idx{ refaddr($t) } = $n; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 703 | 10026 | ▶ | if (ref($t) eq 'PPI::Token::Word' && $t->content eq 'package' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition77%7/9
ref $t eq "PPI::Token::Word" and $t->content eq "package" and $t->statement and $t->statement->isa("PPI::Statement::Package")
ref $t eq "PPI::Token::Word" and $t->content eq "package" and $t->statement
ref $t eq "PPI::Token::Word" and $t->content eq "package"
MC/DC50%2/4
ref $t eq "PPI::Token::Word" and $t->content eq "package" and $t->statement and $t->statement->isa("PPI::Statement::Package")
ref $t eq "PPI::Token::Word"
$t->content eq "package"
$t->statement
$t->statement->isa("PPI::Statement::Package")
Truth table60%3/5
A and B and C and D
A= ref $t eq "PPI::Token::Word"B= $t->content eq "package"C= $t->statementD= $t->statement->isa("PPI::Statement::Package")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 704 | && $t->statement && $t->statement->isa('PPI::Statement::Package')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 705 | 100 | $pkg = $t->statement->namespace; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 706 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 707 | 10026 | $pkg[$n] = $pkg; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 708 | 10026 | $n++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 709 | 10026 | $t = $t->next_token; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 710 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 711 | 201 | return (\%idx, \@pkg); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 712 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 713 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 714 | # Pass 2 (whitespace): collapse inter-token whitespace to a single space only | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 715 | # where two neighbouring tokens would otherwise glue into different syntax | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 716 | # (needs_space); delete it everywhere else. The __END__/__DATA__ marker keeps | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 717 | # the newline that makes it a marker, both before and after it. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 718 | 233 | ▶ | sub _strip_whitespace { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_strip_whitespace: called CC=20 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 719 | 233 | my ($doc) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 720 | 233 | my $pending = 0; # heredoc openers awaiting a newline anchor | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 721 | 233 | my $tok = $doc->first_token; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 722 | 233 | ▶ | while ($tok) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 723 | 8772 | ▶ | if (ref($tok) eq 'PPI::Token::HereDoc') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 724 | 9 | $pending++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 725 | } elsif (ref($tok) eq 'PPI::Token::Whitespace') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 726 | 3682 | my $prev = $tok->previous_sibling; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 727 | 3682 | my $next = $tok->next_sibling; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 728 | 3682 | ▶ | $prev = $prev->previous_sibling while $prev && ref($prev) eq 'PPI::Token::Whitespace'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$prev and ref $prev eq "PPI::Token::Whitespace"
MC/DC100%2/2
$prev and ref $prev eq "PPI::Token::Whitespace"
$prev
ref $prev eq "PPI::Token::Whitespace"
Truth table100%3/3
A and B
A= $prevB= ref $prev eq "PPI::Token::Whitespace"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 729 | 3682 | ▶ | $next = $next->next_sibling while $next && ref($next) eq 'PPI::Token::Whitespace'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$next and ref $next eq "PPI::Token::Whitespace"
MC/DC100%2/2
$next and ref $next eq "PPI::Token::Whitespace"
$next
ref $next eq "PPI::Token::Whitespace"
Truth table100%3/3
A and B
A= $nextB= ref $next eq "PPI::Token::Whitespace"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 730 | 3682 | my $has_nl = $tok->content =~ /\n/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 731 | 3682 | ▶ | if ($prev && $prev->isa('PPI::Token::Separator') && $has_nl) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
Condition83%5/6
$prev and $prev->isa("PPI::Token::Separator") and $has_nl
$prev and $prev->isa("PPI::Token::Separator")
MC/DC66%2/3
$prev and $prev->isa("PPI::Token::Separator") and $has_nl
$prev
$prev->isa("PPI::Token::Separator")
$has_nl
Truth table75%3/4
A and B and C
A= $prevB= $prev->isa("PPI::Token::Separator")C= $has_nl
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 732 | # __END__ / __DATA__ marker: freeze the whitespace after the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 733 | # marker (skip the collapse below). The marker must finish | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 734 | # its own line, or the following data is folded into the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 735 | # marker's line — changing what <DATA> yields, and, when the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 736 | # data starts with punctuation, gluing it onto the marker | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 737 | # (`__DATA__\n{pod}` -> `__DATA__{pod}`), ending the data | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 738 | # section where it did not before. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 739 | ▶ | } elsif ($next && ($next->isa('PPI::Statement::Data') || $next->isa('PPI::Statement::End')) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition88%8/9
$next and $next->isa("PPI::Statement::Data") || $next->isa("PPI::Statement::End") and $has_nl
$next and $next->isa("PPI::Statement::Data") || $next->isa("PPI::Statement::End")
$next->isa("PPI::Statement::Data") or $next->isa("PPI::Statement::End")
MC/DC75%3/4
$next and $next->isa("PPI::Statement::Data") || $next->isa("PPI::Statement::End") and $has_nl
$next
$next->isa("PPI::Statement::Data")
$next->isa("PPI::Statement::End")
$has_nl
Truth table66%4/6
A and B or C and D
A= $nextB= $next->isa("PPI::Statement::Data")C= $next->isa("PPI::Statement::End")D= $has_nl
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 740 | && $has_nl) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 741 | # ... and the newline before it: collapsing that turns | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 742 | # `;__DATA__` into one line, and a mid-line marker is no | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 743 | # marker at all — perl only honours it at the start of a line, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 744 | # so the data section would silently vanish. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 745 | ▶ | } elsif ($pending && $has_nl) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$pending and $has_nl
MC/DC100%2/2
$pending and $has_nl
$pending
$has_nl
Truth table100%3/3
A and B
A= $pendingB= $has_nl
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 746 | # Heredoc anchor: PPI::Document::serialize emits a heredoc's | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 747 | # body + terminator at the first newline-containing token after | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 748 | # the opener. Collapsing that newline moves the body to EOF. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 749 | 9 | $tok->set_content("\n"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 750 | 9 | $pending = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 751 | ▶ | } elsif ($prev && $next && needs_space($prev, $next)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%6/6
$prev and $next and needs_space($prev, $next)
$prev and $next
MC/DC100%3/3
$prev and $next and needs_space($prev, $next)
$prev
$next
needs_space($prev, $next)
Truth table100%4/4
A and B and C
A= $prevB= $nextC= needs_space($prev, $next)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 752 | 615 | $tok->set_content(' '); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 753 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 754 | 3036 | $tok->set_content(''); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 755 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 756 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 757 | 8772 | $tok = $tok->next_token; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 758 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 759 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 760 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 761 | # Pass 2 (renames): rename symbols, subs and module components in place, one | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 762 | # token at a time so each token is rewritten exactly once. Whitespace is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 763 | # already collapsed by _strip_whitespace; the rename never changes the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 764 | # char-class edges @needs_space inspects (a shortened identifier still ends | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 765 | # and starts \w, sigils and delimiters are untouched), so the two walks can | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 766 | # safely be separate. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 767 | 233 | ▶ | sub _apply_renames { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_apply_renames: called CC=59 SCAR=41.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 768 | 233 | my ($doc, %a) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 769 | 233 | ▶ | my $rename = $a{rename} || {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$a{'rename'} || {}
MC/DC0%0/1
$a{'rename'} || {}
$a{'rename'}
Truth table50%1/2
A
A= $a{'rename'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 770 | 233 | my $gmap = $a{gmap}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 771 | 233 | my $glex = $a{glex}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 772 | 233 | ▶ | my $mods = $a{mods} || {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$a{'mods'} || {}
MC/DC0%0/1
$a{'mods'} || {}
$a{'mods'}
Truth table50%1/2
A
A= $a{'mods'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 773 | 233 | ▶ | my %submap = %{ $a{submap} || {} }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$a{'submap'} || {}
MC/DC0%0/1
$a{'submap'} || {}
$a{'submap'}
Truth table50%1/2
A
A= $a{'submap'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 774 | 233 | my $rename_vars = $a{rename_vars}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 775 | 233 | my $rename_exports = $a{rename_exports}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 776 | 233 | my $cur_pkg = 'main'; # current package for unqualified refs | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 777 | 233 | my $tok = $doc->first_token; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 778 | 233 | ▶ | while ($tok) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 779 | 8772 | my $ref = ref($tok); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 780 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 781 | 8772 | ▶ | if (%submap && $ref eq 'PPI::Token::Symbol' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 5 branches
Condition100%6/6
%submap and $ref eq "PPI::Token::Symbol" and $tok->content =~ /^&((?:[A-Za-z_]\w*::)*)([A-Za-z_]\w*)$/
%submap and $ref eq "PPI::Token::Symbol"
MC/DC100%3/3
%submap and $ref eq "PPI::Token::Symbol" and $tok->content =~ /^&((?:[A-Za-z_]\w*::)*)([A-Za-z_]\w*)$/
%submap
$ref eq "PPI::Token::Symbol"
$tok->content =~ /^&((?:[A-Za-z_]\w*::)*)([A-Za-z_]\w*)$/
Truth table100%4/4
A and B and C
A= %submapB= $ref eq "PPI::Token::Symbol"C= $tok->content =~ /^&((?:[A-Za-z_]\w*::)*)([A-Za-z_]\w*)$/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 782 | && $tok->content =~ /^&((?:[A-Za-z_]\w*::)*)([A-Za-z_]\w*)$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 783 | # &name / &Pkg::name / \&Pkg::name are direct sub references. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 784 | 4 | ▶ | if (defined(my $new = $submap{$2})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 785 | 3 | $tok->set_content('&' . $1 . $new); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 786 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 787 | ▶ | } elsif (%submap && $ref eq 'PPI::Token::Symbol' | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%9/9
%submap and $ref eq "PPI::Token::Symbol" and $tok->content =~ /^\*((?:[A-Za-z_]\w*::)*)([A-Za-z_]\w*)$/ and defined $submap{$2}
%submap and $ref eq "PPI::Token::Symbol" and $tok->content =~ /^\*((?:[A-Za-z_]\w*::)*)([A-Za-z_]\w*)$/
%submap and $ref eq "PPI::Token::Symbol"
MC/DC100%4/4
%submap and $ref eq "PPI::Token::Symbol" and $tok->content =~ /^\*((?:[A-Za-z_]\w*::)*)([A-Za-z_]\w*)$/ and defined $submap{$2}
%submap
$ref eq "PPI::Token::Symbol"
$tok->content =~ /^\*((?:[A-Za-z_]\w*::)*)([A-Za-z_]\w*)$/
defined $submap{$2}
Truth table100%5/5
A and B and C and D
A= %submapB= $ref eq "PPI::Token::Symbol"C= $tok->content =~ /^\*((?:[A-Za-z_]\w*::)*)([A-Za-z_]\w*)$/D= defined $submap{$2}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 788 | && $tok->content =~ /^\*((?:[A-Za-z_]\w*::)*)([A-Za-z_]\w*)$/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 789 | && defined($submap{$2})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 790 | # A glob named like a mapped sub (*alias = \&sub, *CONST = $code, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 791 | # local *name) is renamed in step with the calls, so the sub it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 792 | # installs and every caller agree. A data alias (*g = \@arr) is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 793 | # left alone. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 794 | 3 | ▶ | if ((_glob_assign_kind($tok) // '') ne 'data') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
_glob_assign_kind($tok) // ""
MC/DC0%0/1
_glob_assign_kind($tok) // ""
_glob_assign_kind($tok)
Truth table50%1/2
A
A= _glob_assign_kind($tok)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 795 | 3 | $tok->set_content('*' . $1 . $submap{$2}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 796 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 797 | ▶ | } elsif (($rename_vars || $gmap || $mods->{pkgs}) && ($ref eq 'PPI::Token::Symbol' || $ref eq 'PPI::Token::ArrayIndex')) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition91%11/12
$rename_vars || $gmap || $mods->{"pkgs"} and $ref eq "PPI::Token::Symbol" || $ref eq "PPI::Token::ArrayIndex"
$rename_vars or $gmap or $mods->{"pkgs"}
$rename_vars or $gmap
$ref eq "PPI::Token::Symbol" or $ref eq "PPI::Token::ArrayIndex"
MC/DC80%4/5
$rename_vars || $gmap || $mods->{"pkgs"} and $ref eq "PPI::Token::Symbol" || $ref eq "PPI::Token::ArrayIndex"
$rename_vars
$gmap
$mods->{"pkgs"}
$ref eq "PPI::Token::Symbol"
$ref eq "PPI::Token::ArrayIndex"
Truth table60%6/10
A or B or C and D or E
A= $rename_varsB= $gmapC= $mods->{"pkgs"}D= $ref eq "PPI::Token::Symbol"E= $ref eq "PPI::Token::ArrayIndex"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 798 | 520 | ▶ | my ($sigil, $name) = $tok->content =~ /^((?:\$#|[\$\@\%]))(.+)$/ or do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 799 | 2 | $tok = $tok->next_token; next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 800 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 801 | # Module rename first: $App::Saisons::VERSION -> $a::Saisons::VERSION. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 802 | # The rest of the chain re-checks the rewritten name ($gmap keys are | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 803 | # the renamed packages in a bundle). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 804 | 518 | ▶ | if ($mods->{pkgs} && $name =~ /::/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$mods->{"pkgs"} and $name =~ /::/
MC/DC100%2/2
$mods->{"pkgs"} and $name =~ /::/
$mods->{"pkgs"}
$name =~ /::/
Truth table100%3/3
A and B
A= $mods->{"pkgs"}B= $name =~ /::/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 805 | 1 | my $ren = rename_module_name($name, $mods); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 806 | 1 | ▶ | if (defined $ren && $ren ne $name) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $ren and $ren ne $name
MC/DC0%0/2
defined $ren and $ren ne $name
defined $ren
$ren ne $name
Truth table33%1/3
A and B
A= defined $renB= $ren ne $name
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 807 | 1 | $tok->set_content($sigil . $ren); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 808 | 1 | $name = $ren; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 809 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 810 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 811 | 518 | ▶ | if ($rename_vars && exists $rename->{$name}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition100%3/3
$rename_vars and exists $rename->{$name}
MC/DC100%2/2
$rename_vars and exists $rename->{$name}
$rename_vars
exists $rename->{$name}
Truth table100%3/3
A and B
A= $rename_varsB= exists $rename->{$name}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 812 | 251 | $tok->set_content($sigil . $rename->{$name}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 813 | ▶ | } elsif ($gmap && $name =~ /^(\S+?)::(\w+)$/) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$gmap and $name =~ /^(\S+?)::(\w+)$/
MC/DC100%2/2
$gmap and $name =~ /^(\S+?)::(\w+)$/
$gmap
$name =~ /^(\S+?)::(\w+)$/
Truth table100%3/3
A and B
A= $gmapB= $name =~ /^(\S+?)::(\w+)$/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 814 | # Fully-qualified $PKG::name: unambiguous, so rename whenever | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 815 | # the enclosing package's global is in the bundle map. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 816 | 2 | my ($g_pkg, $g_base) = ($1, $2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 817 | 2 | my $gopkg = _gmap_key($g_pkg, $gmap, $mods); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 818 | 2 | ▶ | if (defined(my $g_new = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$gmap->{$gopkg} && $gmap->{$gopkg}{$g_base}
MC/DC0%0/2
$gmap->{$gopkg} && $gmap->{$gopkg}{$g_base}
$gmap->{$gopkg}
$gmap->{$gopkg}{$g_base}
Truth table33%1/3
A && B
A= $gmap->{$gopkg}B= $gmap->{$gopkg}{$g_base}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 819 | $gmap->{$gopkg} && $gmap->{$gopkg}{$g_base})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 820 | 2 | $tok->set_content($sigil . $g_pkg . '::' . $g_new); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 821 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 822 | ▶ | } elsif ($gmap && !( $glex && $glex->{$name} )) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%6/6
$gmap and not $glex && $glex->{$name}
$glex && $glex->{$name}
MC/DC100%3/3
$gmap and not $glex && $glex->{$name}
$gmap
$glex
$glex->{$name}
Truth table100%4/4
A and not(B && C)
A= $gmapB= $glexC= $glex->{$name}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 823 | # Unqualified name: a package global of the current package. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 824 | # Skip it if any `my $name` anywhere in the bundle could make | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 825 | # it ambiguous. (Short names are generated to avoid every | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 826 | # bundle lexical and global, so they stay unambiguous too.) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 827 | 17 | my $opkg = _gmap_key($cur_pkg, $gmap, $mods); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 828 | 17 | ▶ | if (defined(my $g_new = $gmap->{$opkg} && $gmap->{$opkg}{$name})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$gmap->{$opkg} && $gmap->{$opkg}{$name}
MC/DC100%2/2
$gmap->{$opkg} && $gmap->{$opkg}{$name}
$gmap->{$opkg}
$gmap->{$opkg}{$name}
Truth table100%3/3
A && B
A= $gmap->{$opkg}B= $gmap->{$opkg}{$name}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 829 | 13 | $tok->set_content($sigil . $g_new); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 830 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 831 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 832 | ▶ | } elsif ($ref eq 'PPI::Token::Word' && $tok->content eq 'package' | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition77%7/9
$ref eq "PPI::Token::Word" and $tok->content eq "package" and $tok->statement and $tok->statement->isa("PPI::Statement::Package")
$ref eq "PPI::Token::Word" and $tok->content eq "package" and $tok->statement
$ref eq "PPI::Token::Word" and $tok->content eq "package"
MC/DC50%2/4
$ref eq "PPI::Token::Word" and $tok->content eq "package" and $tok->statement and $tok->statement->isa("PPI::Statement::Package")
$ref eq "PPI::Token::Word"
$tok->content eq "package"
$tok->statement
$tok->statement->isa("PPI::Statement::Package")
Truth table60%3/5
A and B and C and D
A= $ref eq "PPI::Token::Word"B= $tok->content eq "package"C= $tok->statementD= $tok->statement->isa("PPI::Statement::Package")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 833 | && $tok->statement && $tok->statement->isa('PPI::Statement::Package')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 834 | 64 | $cur_pkg = $tok->statement->namespace; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 835 | } elsif ($ref eq 'PPI::Token::Word') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 836 | # Module rename: `package App::Thing`, `App::Thing::sub(...)`, bare | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 837 | # class names — everything but the leaf components. Runs before | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 838 | # the sub rename so a qualified Pkg::sub tail is shortened on the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 839 | # already-rewritten package part; the current package is re-read so | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 840 | # unqualified $gmap lookups track the renamed namespace. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 841 | 1429 | ▶ | if ($mods->{pkgs} && $tok->content =~ /::/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$mods->{"pkgs"} and $tok->content =~ /::/
MC/DC100%2/2
$mods->{"pkgs"} and $tok->content =~ /::/
$mods->{"pkgs"}
$tok->content =~ /::/
Truth table100%3/3
A and B
A= $mods->{"pkgs"}B= $tok->content =~ /::/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 842 | 14 | my $ren = rename_module_name($tok->content, $mods); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 843 | 14 | ▶ | if (defined $ren && $ren ne $tok->content) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $ren and $ren ne $tok->content
MC/DC50%1/2
defined $ren and $ren ne $tok->content
defined $ren
$ren ne $tok->content
Truth table66%2/3
A and B
A= defined $renB= $ren ne $tok->content
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 844 | 12 | $tok->set_content($ren); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 845 | 12 | my $st = $tok->statement; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 846 | 12 | ▶ | if ($st && $st->isa('PPI::Statement::Package')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$st and $st->isa("PPI::Statement::Package")
MC/DC50%1/2
$st and $st->isa("PPI::Statement::Package")
$st
$st->isa("PPI::Statement::Package")
Truth table66%2/3
A and B
A= $stB= $st->isa("PPI::Statement::Package")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 847 | 7 | $cur_pkg = $st->namespace; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 848 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 849 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 850 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 851 | 1429 | ▶ | if (%submap) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 852 | # The module-name word of a use/require names a package, not a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 853 | # sub — never shorten it via the sub map (a pragma named in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 854 | # %USE_LITERAL_ARGS is already excluded from protocol sites). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 855 | 611 | my $ist = $tok->statement; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 856 | 611 | ▶ | my $inc_mod = $ist && $ist->isa('PPI::Statement::Include') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition77%7/9
$ist && $ist->isa('PPI::Statement::Include') && defined $ist->module && $ist->module eq $tok->content
$ist and $ist->isa("PPI::Statement::Include") and defined $ist->module
$ist and $ist->isa("PPI::Statement::Include")
MC/DC50%2/4
$ist && $ist->isa('PPI::Statement::Include') && defined $ist->module && $ist->module eq $tok->content
$ist
$ist->isa("PPI::Statement::Include")
defined $ist->module
$ist->module eq $tok->content
Truth table60%3/5
A and B and C && D
A= $istB= $ist->isa("PPI::Statement::Include")C= defined $ist->moduleD= $ist->module eq $tok->content
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 857 | && defined $ist->module && $ist->module eq $tok->content; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 858 | 611 | ▶ | if (!$inc_mod) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 859 | 561 | my $name = $tok->content; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 860 | 561 | my $new = $submap{$name}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 861 | 561 | ▶ | if (defined $new) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 862 | 162 | ▶ | if ($rename_exports && _protocol_site($tok)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
$rename_exports and _protocol_site($tok)
MC/DC0%0/2
$rename_exports and _protocol_site($tok)
$rename_exports
_protocol_site($tok)
Truth table66%2/3
A and B
A= $rename_exportsB= _protocol_site($tok)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 863 | # qw() import-list / export-table / bareword can()-arg: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 864 | # rename with no context check — these are always the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 865 | # sub name, and the last bareword of a qw() has no | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 866 | # sibling to disambiguate it. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 867 | 0 | $tok->set_content($new); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 868 | } elsif (_sub_word_context($tok, 0)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 869 | 155 | $tok->set_content($new); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 870 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 871 | ▶ | } elsif ($name =~ /^(.+)::([A-Za-z_]\w*)$/ && defined($new = $submap{$2})) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$name =~ /^(.+)::([A-Za-z_]\w*)$/ and defined($new = $submap{$2})
MC/DC100%2/2
$name =~ /^(.+)::([A-Za-z_]\w*)$/ and defined($new = $submap{$2})
$name =~ /^(.+)::([A-Za-z_]\w*)$/
defined($new = $submap{$2})
Truth table100%3/3
A and B
A= $name =~ /^(.+)::([A-Za-z_]\w*)$/B= defined($new = $submap{$2})
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 872 | # Qualified Pkg::name (PPI keeps it as one Word) — rename the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 873 | # tail only when the whole token is a sub/function reference. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 874 | 14 | ▶ | if (_sub_word_context($tok, 1)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 875 | 14 | $tok->set_content($1 . '::' . $new); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 876 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 877 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 878 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 879 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 880 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 881 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 882 | 8770 | $tok = $tok->next_token; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 883 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 884 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 885 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 886 | # The renamed form of a string that names a bundled module, either as a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 887 | # package (`App::Thing`) or a path (`App/Thing.pm`); undef if it does not | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 888 | # name one. Used for quoted strings and qw() words alike. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 889 | 12 | ▶ | sub _renamed_module_string { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_renamed_module_string: called CC=5 SCAR=16.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 890 | 12 | my ($s, $mods) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 891 | 12 | my $new; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 892 | 12 | ▶ | if ($s =~ /\A[A-Za-z_]\w*(?:\/[A-Za-z_]\w*)+\.pm\z/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 893 | 0 | $new = rename_module_path($s, $mods); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 894 | } elsif ($s =~ /\A[A-Za-z_]\w*(?:::[A-Za-z_]\w*)+\z/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 895 | 2 | $new = rename_module_name($s, $mods); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 896 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 897 | 12 | ▶ | return defined $new && $new ne $s ? $new : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $new and $new ne $s
MC/DC100%2/2
defined $new and $new ne $s
defined $new
$new ne $s
Truth table100%3/3
A and B
A= defined $newB= $new ne $s
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 898 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 899 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 900 | # Protocol-string + module-name string rewrite. Runs after the token walk so | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 901 | # %submap is final (bundle global_subs or the file's own map). Only plain | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 902 | # single-word / module-shaped / module-path strings are touched; any string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 903 | # with escapes, sigils or spaces is left alone. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 904 | 233 | ▶ | sub _rewrite_protocol_strings { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_rewrite_protocol_strings: called CC=40 SCAR=37.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 905 | 233 | my ($doc, %a) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 906 | 233 | ▶ | my $submap = $a{submap} || {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$a{'submap'} || {}
MC/DC0%0/1
$a{'submap'} || {}
$a{'submap'}
Truth table50%1/2
A
A= $a{'submap'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 907 | 233 | my $rename_exports = $a{rename_exports}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 908 | 233 | my $gmap = $a{gmap}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 909 | 233 | my $glex = $a{glex}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 910 | 233 | ▶ | my $mods = $a{mods} || {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$a{'mods'} || {}
MC/DC0%0/1
$a{'mods'} || {}
$a{'mods'}
Truth table50%1/2
A
A= $a{'mods'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 911 | 233 | ▶ | return unless (($rename_exports && %$submap) || ($mods && $mods->{pkgs})); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition88%8/9
$rename_exports and %$submap or $mods and $mods->{"pkgs"}
$rename_exports and %$submap
$mods and $mods->{"pkgs"}
MC/DC75%3/4
$rename_exports and %$submap or $mods and $mods->{"pkgs"}
$rename_exports
%$submap
$mods
$mods->{"pkgs"}
Truth table57%4/7
A and B or C and D
A= $rename_exportsB= %$submapC= $modsD= $mods->{"pkgs"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 912 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 913 | # Record each token's package so $var words in an @EXPORT_OK=qw() list | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 914 | # resolve to the current (renamed) package's bundle-global entry. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 915 | 43 | my ($pix, $ppkg) = _token_package_index($doc); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 916 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 917 | 43 | my $st = $doc->first_token; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 918 | 43 | ▶ | while ($st) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 919 | 1583 | my $sr = ref($st); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 920 | 1583 | ▶ | if ($sr eq 'PPI::Token::Quote::Single' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%6/6
$sr eq "PPI::Token::Quote::Single" or $sr eq "PPI::Token::Quote::Double" or $sr eq "PPI::Token::Quote::Literal"
$sr eq "PPI::Token::Quote::Single" or $sr eq "PPI::Token::Quote::Double"
MC/DC100%3/3
$sr eq "PPI::Token::Quote::Single" or $sr eq "PPI::Token::Quote::Double" or $sr eq "PPI::Token::Quote::Literal"
$sr eq "PPI::Token::Quote::Single"
$sr eq "PPI::Token::Quote::Double"
$sr eq "PPI::Token::Quote::Literal"
Truth table100%4/4
A or B or C
A= $sr eq "PPI::Token::Quote::Single"B= $sr eq "PPI::Token::Quote::Double"C= $sr eq "PPI::Token::Quote::Literal"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 921 | || $sr eq 'PPI::Token::Quote::Double' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 922 | || $sr eq 'PPI::Token::Quote::Literal') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 923 | 55 | my $c = $st->content; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 924 | 55 | ▶ | my ($q, $inner) = $c =~ /^(['"])(.*)\1$/s ? ($1, $2) : (undef, undef); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 925 | 55 | ▶ | if (defined $q) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 926 | 52 | my $rewritten; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 927 | 52 | ▶ | if ($rename_exports && $inner =~ /^[A-Za-z_]\w*$/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition88%8/9
$rename_exports and $inner =~ /^[A-Za-z_]\w*$/ and _protocol_site($st) and defined(my $nnew = $submap->{$inner})
$rename_exports and $inner =~ /^[A-Za-z_]\w*$/ and _protocol_site($st)
$rename_exports and $inner =~ /^[A-Za-z_]\w*$/
MC/DC75%3/4
$rename_exports and $inner =~ /^[A-Za-z_]\w*$/ and _protocol_site($st) and defined(my $nnew = $submap->{$inner})
$rename_exports
$inner =~ /^[A-Za-z_]\w*$/
_protocol_site($st)
defined(my $nnew = $submap->{$inner})
Truth table80%4/5
A and B and C and D
A= $rename_exportsB= $inner =~ /^[A-Za-z_]\w*$/C= _protocol_site($st)D= defined(my $nnew = $submap->{$inner})
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 928 | && _protocol_site($st) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 929 | && defined(my $nnew = $submap->{$inner})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 930 | 2 | $rewritten = $nnew; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 931 | } elsif ($mods->{pkgs}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 932 | 11 | $rewritten = _renamed_module_string($inner, $mods); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 933 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 934 | 52 | ▶ | $st->set_content($q . $rewritten . $q) if defined $rewritten; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 935 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 936 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 937 | ▶ | elsif ($sr eq 'PPI::Token::QuoteLike::Words' | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%9/9
$sr eq "PPI::Token::QuoteLike::Words" and $rename_exports && _protocol_site($st) || $mods->{"pkgs"}
$rename_exports and _protocol_site($st) or $mods->{"pkgs"}
$rename_exports and _protocol_site($st)
MC/DC50%2/4
$sr eq "PPI::Token::QuoteLike::Words" and $rename_exports && _protocol_site($st) || $mods->{"pkgs"}
$sr eq "PPI::Token::QuoteLike::Words"
$rename_exports
_protocol_site($st)
$mods->{"pkgs"}
Truth table66%4/6
A and B and C or D
A= $sr eq "PPI::Token::QuoteLike::Words"B= $rename_exportsC= _protocol_site($st)D= $mods->{"pkgs"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 938 | && (($rename_exports && _protocol_site($st)) || $mods->{pkgs})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 939 | # qw(import list) / qw(export table): one token holding several | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 940 | # barewords. Sub and variable names are only renamed when the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 941 | # whole literal sits at a protocol site (use list, @EXPORT* | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 942 | # assignment) — a plain `my @x = qw(foo)` is data. Package names | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 943 | # (`our @ISA = qw(Moo::Object)`) follow the module rename like | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 944 | # any other string. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 945 | 5 | ▶ | my $protocol = $rename_exports && _protocol_site($st); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$rename_exports && _protocol_site($st)
MC/DC50%1/2
$rename_exports && _protocol_site($st)
$rename_exports
_protocol_site($st)
Truth table66%2/3
A && B
A= $rename_exportsB= _protocol_site($st)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 946 | 5 | my $c = $st->content; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 947 | 5 | ▶ | if ($c =~ /^qw(.)(.*\z)/s) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 948 | # qw(DELIMS): (.) consumes the opener, so $2 is the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 949 | # body plus the trailing closer. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 950 | 5 | my $open = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 951 | 5 | my %cls = ('(' => ')', '[' => ']', '{' => '}', '<' => '>'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 952 | 5 | ▶ | my $close = $cls{$open} // $open; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$cls{$open} // $open
MC/DC0%0/2
$cls{$open} // $open
$cls{$open}
$open
Truth table33%1/3
A // B
A= $cls{$open}B= $open
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 953 | 5 | my $tail = $2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 954 | 5 | ▶ | if (substr($tail, -1) eq $close) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 955 | 5 | my $body = substr($tail, 0, length($tail) - 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 956 | 5 | ▶ | if ($body !~ /^[A-Za-z_]\w*=[A-Za-z_]\w*$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 957 | 5 | my @parts = split(/(\s+)/, $body); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 958 | 5 | my $changed; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 959 | 5 | for my $p (@parts) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 960 | 8 | ▶ | if ($p eq '' || $p =~ /^\s+$/) { next } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$p eq "" or $p =~ /^\s+$/
MC/DC50%1/2
$p eq "" or $p =~ /^\s+$/
$p eq ""
$p =~ /^\s+$/
Truth table66%2/3
A or B
A= $p eq ""B= $p =~ /^\s+$/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 961 | 6 | ▶ | if ($protocol && $p =~ /^[A-Za-z_]\w*$/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition83%5/6
$protocol and $p =~ /^[A-Za-z_]\w*$/ and defined(my $wnew = $submap->{$p})
$protocol and $p =~ /^[A-Za-z_]\w*$/
MC/DC66%2/3
$protocol and $p =~ /^[A-Za-z_]\w*$/ and defined(my $wnew = $submap->{$p})
$protocol
$p =~ /^[A-Za-z_]\w*$/
defined(my $wnew = $submap->{$p})
Truth table75%3/4
A and B and C
A= $protocolB= $p =~ /^[A-Za-z_]\w*$/C= defined(my $wnew = $submap->{$p})
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 962 | && defined(my $wnew = $submap->{$p})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 963 | 3 | $p = $wnew; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 964 | 3 | $changed = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 965 | ▶ | } elsif ($protocol && $p =~ /^\$([A-Za-z_]\w*)$/ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%4/6
$protocol and $p =~ /^\$([A-Za-z_]\w*)$/ and defined(my $vnew = _protocol_var_new_name($1, $$ppkg[$$pix{builtin::refaddr($st)}], $st, $gmap, $glex, $mods))
$protocol and $p =~ /^\$([A-Za-z_]\w*)$/
MC/DC33%1/3
$protocol and $p =~ /^\$([A-Za-z_]\w*)$/ and defined(my $vnew = _protocol_var_new_name($1, $$ppkg[$$pix{builtin::refaddr($st)}], $st, $gmap, $glex, $mods))
$protocol
$p =~ /^\$([A-Za-z_]\w*)$/
defined(my $vnew = _protocol_var_new_name($1, $$ppkg[$$pix{builtin::refaddr($st)}], $st, $gmap, $glex, $mods))
Truth table50%2/4
A and B and C
A= $protocolB= $p =~ /^\$([A-Za-z_]\w*)$/C= defined(my $vnew = _protocol_var_new_name($1, $$ppkg[$$pix{builtin::refaddr($st)}], $st, $gmap, $glex, $mods))
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 966 | && defined(my $vnew = _protocol_var_new_name( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 967 | $1, $ppkg->[ $pix->{refaddr($st)} ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 968 | $st, $gmap, $glex, $mods))) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 969 | 2 | $p = '$' . $vnew; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 970 | 2 | $changed = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 971 | ▶ | } elsif ($mods->{pkgs} | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$mods->{"pkgs"} and defined(my $mnew = _renamed_module_string($p, $mods))
MC/DC0%0/2
$mods->{"pkgs"} and defined(my $mnew = _renamed_module_string($p, $mods))
$mods->{"pkgs"}
defined(my $mnew = _renamed_module_string($p, $mods))
Truth table33%1/3
A and B
A= $mods->{"pkgs"}B= defined(my $mnew = _renamed_module_string($p, $mods))
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 972 | && defined(my $mnew = _renamed_module_string($p, $mods))) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 973 | 1 | $p = $mnew; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 974 | 1 | $changed = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 975 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 976 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 977 | 5 | ▶ | $st->set_content('qw' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 978 | . $open . join('', @parts) . $close) if $changed; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 979 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 980 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 981 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 982 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 983 | 1583 | $st = $st->next_token; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 984 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 985 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 986 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 987 | # --------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 988 | # Optional value-preserving rewrite pass. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 989 | # --------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 990 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 991 | # Optional pass that rewrites code to shorter equivalent forms, on top of the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 992 | # prune/rename/whitespace passes. Kept as its own method with a single call | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 993 | # site above so it can be disabled (rewrite => 0) or deleted wholesale (drop | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 994 | # this method and that one call) if it ever proves unsafe. Only rewrites that | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 995 | # are value-preserving are attempted: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 996 | # foreach -> for keywords are synonyms | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 997 | # m/.../ -> /.../ after =~ or !~ m is optional with / delimiters | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 998 | # `;` before `}` dropped trailing empty statement | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 999 | # `$x += 1;` -> `$x++;` (mid-block) *= 1 vs ++ differ in return value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1000 | # `$x = $x OP $y;` -> `$x OP= $y;` both assignment forms return OP= value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1001 | # `print($x);` -> `print $x;` parens dropped on builtin calls | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1002 | 35 | my %PAREN_DROP = map { $_ => 1 } qw( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1003 | print printf sprintf say warn die return exit chomp chop shift unshift | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1004 | push pop splice keys values each delete exists defined ref bless length | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1005 | substr join split reverse sort grep map scalar rand srand int sqrt abs | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1006 | exp log sin cos lc uc lcfirst ucfirst ord chr caller wantarray | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1007 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1008 | 35 | my %OP_ASSIGN = map { $_ => 1 } qw(. + - * / %); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1009 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1010 | # --------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1011 | # Stringy / regex text rewriters, so quoted text and patterns track the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1012 | # symbol renames. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1013 | # --------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1014 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1015 | # Rewrite interpolated variable references inside string-like tokens so the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1016 | # quoted text keeps resolving to the same variable after symbol renames. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1017 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1018 | # "my name is $name" -> "my name is $c" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1019 | # qq{_build_${name}} -> qq{_build_${c}} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1020 | # <<"EOF" ... $name ... -> body rewritten too | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1021 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1022 | # The symbol pass renames by NAME, not by scope (every $name in the file is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1023 | # $c once `my $name` is renamed), so the string text follows the same rule: a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1024 | # "$name" is rewritten exactly when the symbol pass rewrites that name. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1025 | # Qualified $PKG::name uses $gmap; an unqualified name uses $rename (lexical) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1026 | # or the current package's $gmap entry unless the name is a lexical anywhere | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1027 | # in the bundle ($glex). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1028 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1029 | # Names refused by Pass 1a (they appear in a regex code region) are never in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1030 | # $rename, so they stay put. Escaped dollars ("\$name" or "\\\\$name") and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1031 | # literal-only tokens (q{...}, <<'EOF', m'...') are left untouched, because | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1032 | # there the text is literal data, not a variable reference. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1033 | 195 | ▶ | sub _rewrite_names_in_strings { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_rewrite_names_in_strings: called CC=16 SCAR=27.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1034 | 195 | my ($doc, $rename, $gmap, $glex, $mods) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1035 | 195 | ▶ | return unless %$rename || ($gmap && %$gmap) || ($mods && $mods->{pkgs}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%10/12
%$rename or $gmap and %$gmap or $mods and $mods->{"pkgs"}
%$rename or $gmap and %$gmap
$gmap and %$gmap
$mods and $mods->{"pkgs"}
MC/DC60%3/5
%$rename or $gmap and %$gmap or $mods and $mods->{"pkgs"}
%$rename
$gmap
%$gmap
$mods
$mods->{"pkgs"}
Truth table50%4/8
A or B and C or D and E
A= %$renameB= $gmapC= %$gmapD= $modsE= $mods->{"pkgs"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1036 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1037 | 82 | my ($idx, $pkg) = _token_package_index($doc); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1038 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1039 | 82 | my $tok = $doc->first_token; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1040 | 82 | ▶ | while ($tok) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1041 | 4292 | my $r = ref($tok); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1042 | my $here = ($r eq 'PPI::Token::HereDoc') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1043 | 4292 | ▶ | && ($tok->{_mode} || '') =~ /^(?:interpolate|command)$/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition80%4/5
$r eq 'PPI::Token::HereDoc' && ($tok->{'_mode'} || '') =~ /^(?:interpolate|command)$/
$tok->{'_mode'} || ''
MC/DC50%1/2
$r eq 'PPI::Token::HereDoc' && ($tok->{'_mode'} || '') =~ /^(?:interpolate|command)$/
$r eq 'PPI::Token::HereDoc'
$tok->{'_mode'}
Truth table66%2/3
A && B
A= $r eq 'PPI::Token::HereDoc'B= $tok->{'_mode'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1044 | 4292 | my $quote = $r =~ /^(?:PPI::Token::Quote::(?:Double|Interpolate) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1045 | |PPI::Token::QuoteLike::(?:Readline|Backtick|Command))$/x; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1046 | 4292 | ▶ | if ($quote || $here) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$quote or $here
MC/DC100%2/2
$quote or $here
$quote
$here
Truth table100%3/3
A or B
A= $quoteB= $here
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1047 | 91 | ▶ | my $src = $quote ? $tok->content : join('', @{ $tok->{_heredoc} // [] }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$tok->{"_heredoc"} // []
MC/DC0%0/1
$tok->{"_heredoc"} // []
$tok->{"_heredoc"}
Truth table50%1/2
A
A= $tok->{"_heredoc"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1048 | 91 | ▶ | my $new = _rewrite_string_text($src, $pkg->[ $idx->{ refaddr($tok) } ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$rename || {}
MC/DC0%0/1
$rename || {}
$rename
Truth table50%1/2
A
A= $rename
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1049 | $gmap, $glex, $rename || {}, $mods); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1050 | 91 | ▶ | if ($new ne $src) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1051 | 20 | ▶ | if ($quote) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1052 | 17 | $tok->set_content($new); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1053 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1054 | 3 | @{ $tok->{_heredoc} } = split /(?<=\n)/, $new; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1055 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1056 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1057 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1058 | 4292 | $tok = $tok->next_token; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1059 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1060 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1061 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1062 | # Split a regex pattern/replacement section into ordinary text and embedded | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1063 | # code regions ((?{ ... }) / (??{ ... })). Code regions are returned tagged | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1064 | # 'code', everything else 'text'. The escaping of a following character is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1065 | # tracked so \(?{ never starts a code region. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1066 | 75 | ▶ | sub _regex_parts { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_regex_parts: called CC=19 SCAR=31.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1067 | 75 | my ($text) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1068 | 75 | my @parts; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1069 | 75 | my $i = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1070 | 75 | my $n = length $text; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1071 | 75 | my $acc = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1072 | 75 | ▶ | while ($i < $n) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1073 | 1013 | my $ch = substr($text, $i, 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1074 | 1013 | ▶ | if ($ch eq '\\') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1075 | 114 | $acc .= $ch; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1076 | 114 | $i++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1077 | 114 | ▶ | $acc .= substr($text, $i, 1) if $i < $n; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1078 | 114 | $i++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1079 | 114 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1080 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1081 | 899 | ▶ | if ($ch eq '(' && substr($text, $i + 1, 1) eq '?' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition88%8/9
$ch eq "(" and substr($text, $i + 1, 1) eq "?" and substr($text, $i + 2, 1) eq "{" || substr($text, $i + 3, 1) eq "{"
$ch eq "(" and substr($text, $i + 1, 1) eq "?"
substr($text, $i + 2, 1) eq "{" or substr($text, $i + 3, 1) eq "{"
MC/DC75%3/4
$ch eq "(" and substr($text, $i + 1, 1) eq "?" and substr($text, $i + 2, 1) eq "{" || substr($text, $i + 3, 1) eq "{"
$ch eq "("
substr($text, $i + 1, 1) eq "?"
substr($text, $i + 2, 1) eq "{"
substr($text, $i + 3, 1) eq "{"
Truth table80%4/5
A and B and C or D
A= $ch eq "("B= substr($text, $i + 1, 1) eq "?"C= substr($text, $i + 2, 1) eq "{"D= substr($text, $i + 3, 1) eq "{"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1082 | && (substr($text, $i + 2, 1) eq '{' || substr($text, $i + 3, 1) eq '{')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1083 | 1 | push @parts, ['text', $acc]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1084 | 1 | $acc = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1085 | 1 | ▶ | my $j = $i + (substr($text, $i + 3, 1) eq '{' ? 4 : 3); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1086 | 1 | my $depth = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1087 | 1 | ▶ | while ($j < $n) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1088 | 9 | my $d = substr($text, $j, 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1089 | 0 | ▶ | if ($d eq '\\') { $j += 2; next } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1090 | 0 | elsif ($d eq '{') { $depth++ } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1091 | 0 | ▶ | elsif ($d eq '}' && $depth) { $depth-- } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$d eq "}" and $depth
MC/DC0%0/2
$d eq "}" and $depth
$d eq "}"
$depth
Truth table66%2/3
A and B
A= $d eq "}"B= $depth
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1092 | 1 | ▶ | elsif ($d eq '}' && !$depth) { last } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$d eq "}" and not $depth
MC/DC50%1/2
$d eq "}" and not $depth
$d eq "}"
not $depth
Truth table66%2/3
A and not(B)
A= $d eq "}"B= not $depth
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1093 | 8 | $j++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1094 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1095 | 1 | ▶ | if ($j < $n) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1096 | 1 | $j++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1097 | 1 | ▶ | $j++ if substr($text, $j, 1) eq ')'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1098 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1099 | 1 | push @parts, ['code', substr($text, $i, $j - $i)]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1100 | 1 | $i = $j; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1101 | 1 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1102 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1103 | 898 | $acc .= $ch; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1104 | 898 | $i++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1105 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1106 | 75 | ▶ | push @parts, ['text', $acc] if length $acc; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1107 | 75 | return @parts; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1108 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1109 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1110 | # Pass 1a / bundle-collect helper: mark every variable name appearing inside a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1111 | # regex code region as unrenameable ($in_string). A pattern's | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1112 | # (?{ ... })/(??{ ... }) blocks and a s///e replacement are real Perl code; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1113 | # the minifier leaves them verbatim, so a lexical referenced there must keep | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1114 | # its name too. With a second hash, code-region BARE WORDS freeze the sub map | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1115 | # ($in_string_word) the same way — they can never be rewritten in step. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1116 | 37 | ▶ | sub _regex_exempt_names { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_regex_exempt_names: called CC=15 SCAR=30.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1117 | 37 | my ($in_string, $in_string_word, $class, $content) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1118 | 37 | ▶ | my $pr = _parse_regex($class, $content) or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1119 | 37 | ▶ | return if $pr->{single}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1120 | 36 | for my $part (_regex_parts($pr->{pat})) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1121 | 38 | ▶ | next unless $part->[0] eq 'code'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1122 | 1 | ▶ | while ($part->[1] =~ /[\$\@]\{?([A-Za-z_]\w*)/g) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1123 | 1 | $in_string->{$1} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1124 | 1 | ▶ | $in_string_word->{$1} = 1 if $in_string_word; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1125 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1126 | 1 | ▶ | if ($in_string_word) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1127 | 0 | ▶ | while ($part->[1] =~ /\b([A-Za-z_]\w*)\b/g) { $in_string_word->{$1} = 1 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1128 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1129 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1130 | 36 | ▶ | if (defined $pr->{repl} && $pr->{mods} =~ /e/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $pr->{"repl"} and $pr->{"mods"} =~ /e/
MC/DC100%2/2
defined $pr->{"repl"} and $pr->{"mods"} =~ /e/
defined $pr->{"repl"}
$pr->{"mods"} =~ /e/
Truth table100%3/3
A and B
A= defined $pr->{"repl"}B= $pr->{"mods"} =~ /e/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1131 | 1 | ▶ | while ($pr->{repl} =~ /[\$\@]\{?([A-Za-z_]\w*)/g) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1132 | 1 | $in_string->{$1} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1133 | 1 | ▶ | $in_string_word->{$1} = 1 if $in_string_word; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1134 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1135 | 1 | ▶ | if ($in_string_word) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1136 | 0 | ▶ | while ($pr->{repl} =~ /\b([A-Za-z_]\w*)\b/g) { $in_string_word->{$1} = 1 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1137 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1138 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1139 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1140 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1141 | # Rewrite variables interpolated inside every regex Match/Substitute/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1142 | # QuoteLike::Regexp token, keeping token text and code in step with both the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1143 | # file's my-field renames (%rename) and the bundle-wide global map ($gmap; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1144 | # resolved exactly like _rewrite_names_in_strings / _string_new_name). Code | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1145 | # regions, single-quoted regexes (m'...', no interpolation) and escaped | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1146 | # "$name" (\$x literal) are left exactly as-is. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1147 | 194 | ▶ | sub _rewrite_names_in_regexes { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_rewrite_names_in_regexes: called CC=10 SCAR=23.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1148 | 194 | my ($doc, $rename, $gmap, $glex, $mods) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1149 | 194 | ▶ | return unless %$rename || ($gmap && %$gmap); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
%$rename or $gmap and %$gmap
$gmap and %$gmap
MC/DC66%2/3
%$rename or $gmap and %$gmap
%$rename
$gmap
%$gmap
Truth table75%3/4
A or B and C
A= %$renameB= $gmapC= %$gmap
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1150 | # Record each token's current package so unqualified bundle globals resolve | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1151 | # ($gmap keys are the renamed package names, same as the package words). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1152 | 76 | my ($idx, $pkg) = _token_package_index($doc); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1153 | 76 | my $tok = $doc->first_token; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1154 | 76 | ▶ | while ($tok) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1155 | 4151 | my $r = ref($tok); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1156 | 4151 | ▶ | if (($r eq 'PPI::Token::Regexp::Match' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition88%8/9
$r eq "PPI::Token::Regexp::Match" || $r eq "PPI::Token::Regexp::Substitute" || $r eq "PPI::Token::QuoteLike::Regexp" and $r ne "PPI::Token::Regexp::Transliterate"
$r eq "PPI::Token::Regexp::Match" or $r eq "PPI::Token::Regexp::Substitute" or $r eq "PPI::Token::QuoteLike::Regexp"
$r eq "PPI::Token::Regexp::Match" or $r eq "PPI::Token::Regexp::Substitute"
MC/DC75%3/4
$r eq "PPI::Token::Regexp::Match" || $r eq "PPI::Token::Regexp::Substitute" || $r eq "PPI::Token::QuoteLike::Regexp" and $r ne "PPI::Token::Regexp::Transliterate"
$r eq "PPI::Token::Regexp::Match"
$r eq "PPI::Token::Regexp::Substitute"
$r eq "PPI::Token::QuoteLike::Regexp"
$r ne "PPI::Token::Regexp::Transliterate"
Truth table57%4/7
A or B or C and D
A= $r eq "PPI::Token::Regexp::Match"B= $r eq "PPI::Token::Regexp::Substitute"C= $r eq "PPI::Token::QuoteLike::Regexp"D= $r ne "PPI::Token::Regexp::Transliterate"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1157 | || $r eq 'PPI::Token::Regexp::Substitute' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1158 | || $r eq 'PPI::Token::QuoteLike::Regexp') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1159 | && $r ne 'PPI::Token::Regexp::Transliterate') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1160 | my $new = _rewrite_regex_token($r, $tok->content, $rename, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1161 | $gmap, $glex, $mods, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1162 | 30 | $pkg->[ $idx->{ refaddr($tok) } ]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1163 | 30 | ▶ | $tok->set_content($new) if defined $new; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1164 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1165 | 4151 | $tok = $tok->next_token; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1166 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1167 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1168 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1169 | # Parse a regex token's content into its parts. Returns undef when the shape | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1170 | # is not understood; otherwise a hashref with the opening keyword, the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1171 | # pattern's delimiters/text, the replacement delimiters/text (for s///), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1172 | # the trailing modifier letters, and whether the delimiter was a single quote | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1173 | # (which disables interpolation entirely). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1174 | 67 | ▶ | sub _parse_regex { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_parse_regex: called CC=21 SCAR=31.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1175 | 67 | my ($class, $c) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1176 | 67 | my $kw = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1177 | 67 | my $idx = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1178 | 67 | ▶ | if ($class eq 'PPI::Token::QuoteLike::Regexp') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1179 | 6 | $kw = 'qr'; $idx = 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1180 | } elsif ($class eq 'PPI::Token::Regexp::Substitute') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1181 | 19 | $kw = 's'; $idx = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1182 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1183 | 42 | ▶ | $kw = $c =~ /^m/ ? 'm' : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1184 | 42 | ▶ | $idx = $kw ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1185 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1186 | 67 | ▶ | $idx++ while substr($c, $idx, 1) =~ /\s/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1187 | 67 | my $open1 = substr($c, $idx, 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1188 | 67 | ▶ | return if !length $open1 || $open1 =~ /\w/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not length $open1 or $open1 =~ /\w/
MC/DC0%0/2
not length $open1 or $open1 =~ /\w/
not length $open1
$open1 =~ /\w/
Truth table33%1/3
not(A) or B
A= not length $open1B= $open1 =~ /\w/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1189 | 67 | my %pair = ('(' => ')', '[' => ']', '{' => '}', '<' => '>'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1190 | 67 | ▶ | my $close1 = exists $pair{$open1} ? $pair{$open1} : $open1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1191 | 67 | my ($pat, $i) = _regex_close_index($c, $idx + 1, $open1, $close1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1192 | 67 | ▶ | return unless defined $pat; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1193 | my $pr = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1194 | kw => $kw, open1 => $open1, close1 => $close1, pat => $pat, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1195 | open2 => '', close2 => '', repl => undef, mods => '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1196 | 67 | single => $open1 eq q{'}, paired => exists $pair{$open1}, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1197 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1198 | 67 | ▶ | if ($class eq 'PPI::Token::Regexp::Substitute') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1199 | 19 | ▶ | my $j = $pr->{paired} ? $i + 1 : $i; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1200 | 19 | ▶ | $j++ while substr($c, $j, 1) =~ /\s/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1201 | 19 | my $open2 = substr($c, $j, 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1202 | 19 | ▶ | return if !length $open2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1203 | 19 | my $paired2 = exists $pair{$open2}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1204 | 19 | ▶ | my $close2 = $paired2 ? $pair{$open2} : $open2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1205 | 19 | my ($re, $k) = _regex_close_index($c, $j + 1, $open2, $close2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1206 | 19 | ▶ | return unless defined $re; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1207 | 19 | ▶ | $pr->{open2} = $paired2 ? $open2 : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1208 | 19 | $pr->{close2} = $close2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1209 | 19 | $pr->{repl} = $re; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1210 | 19 | ▶ | $pr->{mods} = substr($c, $k + 1) || ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
substr($c, $k + 1) || ''
MC/DC100%1/1
substr($c, $k + 1) || ''
substr($c, $k + 1)
Truth table100%2/2
A
A= substr($c, $k + 1)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1211 | 19 | ▶ | $pr->{single} = 1 if $open2 eq q{'} || $open1 eq q{'}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$open2 eq "'" or $open1 eq "'"
MC/DC0%0/2
$open2 eq "'" or $open1 eq "'"
$open2 eq "'"
$open1 eq "'"
Truth table33%1/3
A or B
A= $open2 eq "'"B= $open1 eq "'"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1212 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1213 | 48 | ▶ | $pr->{mods} = substr($c, $i + 1) || ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
substr($c, $i + 1) || ''
MC/DC100%1/1
substr($c, $i + 1) || ''
substr($c, $i + 1)
Truth table100%2/2
A
A= substr($c, $i + 1)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1214 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1215 | 67 | return $pr; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1216 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1217 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1218 | # Return (pattern_text, index_of_closing_delimiter) for the section of $c | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1219 | # beginning after $from, delimited with $open/$close (paired or single). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1220 | 86 | ▶ | sub _regex_close_index { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_regex_close_index: called CC=8 SCAR=20.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1221 | 86 | my ($c, $from, $open, $close) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1222 | 86 | my $n = length $c; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1223 | 86 | my $depth = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1224 | 86 | my $esc = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1225 | 86 | ▶ | for (my $i = $from; $i < $n; $i++) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1226 | 1286 | my $ch = substr($c, $i, 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1227 | 1286 | ▶ | if ($esc) { $esc = 0; next } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1228 | 1168 | ▶ | if ($ch eq '\\') { $esc = 1; next } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1229 | 1050 | ▶ | if ($ch eq $open && $open ne $close) { $depth++; next } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$ch eq $open and $open ne $close
MC/DC100%2/2
$ch eq $open and $open ne $close
$ch eq $open
$open ne $close
Truth table100%3/3
A and B
A= $ch eq $openB= $open ne $close
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1230 | 1049 | ▶ | if ($ch eq $close) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1231 | 87 | ▶ | if ($depth) { $depth-- } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1232 | 86 | else { return (substr($c, $from, $i - $from), $i) } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1233 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1234 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1235 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1236 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1237 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1238 | # Rewrite one regex token; returns the new content or undef if nothing | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1239 | # changed. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1240 | 30 | ▶ | sub _rewrite_regex_token { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_rewrite_regex_token: called CC=7 SCAR=19.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1241 | 30 | my ($class, $content, $rename, $gmap, $glex, $mods, $pkg) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1242 | 30 | ▶ | my $pr = _parse_regex($class, $content) or return undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1243 | 30 | ▶ | return undef if $pr->{single}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1244 | 30 | my $np = _rewrite_regex_text($pr->{pat}, $rename, $gmap, $glex, $mods, $pkg); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1245 | 30 | my $nre; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1246 | 30 | ▶ | if (defined $pr->{repl}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1247 | $nre = $pr->{mods} =~ /e/ ? $pr->{repl} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1248 | 9 | ▶ | : _rewrite_regex_text($pr->{repl}, $rename, $gmap, $glex, $mods, $pkg); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1249 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1250 | 30 | my $out = $pr->{kw} . $pr->{open1} . $np . $pr->{close1}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1251 | 30 | ▶ | $out .= $pr->{open2} . $nre . $pr->{close2} if defined $nre; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1252 | 30 | $out .= $pr->{mods}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1253 | 30 | ▶ | return $out eq $content ? undef : $out; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1254 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1255 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1256 | # Rewrite interpolated $name/@name/%name (and ${name}) references in a single | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1257 | # pattern or replacement section, leaving code regions, escapes and qualified | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1258 | # names alone. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1259 | 39 | ▶ | sub _rewrite_regex_text { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_rewrite_regex_text: called CC=22 SCAR=33.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1260 | 39 | my ($text, $rename, $gmap, $glex, $mods, $pkg) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1261 | 39 | my $out = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1262 | 39 | for my $part (_regex_parts($text)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1263 | 0 | ▶ | if ($part->[0] eq 'code') { $out .= $part->[1]; next } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1264 | 39 | my $s = $part->[1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1265 | 39 | my $d = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1266 | 39 | my $i = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1267 | 39 | my $n = length $s; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1268 | 39 | ▶ | while ($i < $n) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1269 | 426 | my $ch = substr($s, $i, 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1270 | 426 | ▶ | if ($ch eq '\\') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1271 | 57 | $d .= $ch; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1272 | 57 | $i++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1273 | 57 | ▶ | $d .= substr($s, $i, 1) if $i < $n; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1274 | 57 | $i++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1275 | 57 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1276 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1277 | 369 | ▶ | if ($ch eq '$' || $ch eq '@' || $ch eq '%') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
$ch eq "\$" or $ch eq "\@" or $ch eq "%"
$ch eq "\$" or $ch eq "\@"
MC/DC33%1/3
$ch eq "\$" or $ch eq "\@" or $ch eq "%"
$ch eq "\$"
$ch eq "\@"
$ch eq "%"
Truth table50%2/4
A or B or C
A= $ch eq "\$"B= $ch eq "\@"C= $ch eq "%"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1278 | 20 | my $start = $i; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1279 | 20 | my $sig = $ch; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1280 | 20 | $i++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1281 | 0 | ▶ | if ($ch eq '$' && substr($s, $i, 1) eq '#') { $sig = '$#'; $i++ } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$ch eq "\$" and substr($s, $i, 1) eq "#"
MC/DC0%0/2
$ch eq "\$" and substr($s, $i, 1) eq "#"
$ch eq "\$"
substr($s, $i, 1) eq "#"
Truth table33%1/3
A and B
A= $ch eq "\$"B= substr($s, $i, 1) eq "#"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1282 | 20 | my $braced = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1283 | 20 | ▶ | if (substr($s, $i, 1) eq '{' && substr($s, $i + 1, 1) =~ /[A-Za-z_]/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
substr($s, $i, 1) eq "{" and substr($s, $i + 1, 1) =~ /[A-Za-z_]/
MC/DC0%0/2
substr($s, $i, 1) eq "{" and substr($s, $i + 1, 1) =~ /[A-Za-z_]/
substr($s, $i, 1) eq "{"
substr($s, $i + 1, 1) =~ /[A-Za-z_]/
Truth table33%1/3
A and B
A= substr($s, $i, 1) eq "{"B= substr($s, $i + 1, 1) =~ /[A-Za-z_]/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1284 | 0 | $braced = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1285 | 0 | $i++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1286 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1287 | 20 | my $ws = $i; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1288 | 20 | ▶ | while ($i < $n && substr($s, $i, 1) =~ /[A-Za-z0-9_]/) { $i++ } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$i < $n and substr($s, $i, 1) =~ /[A-Za-z0-9_]/
MC/DC100%2/2
$i < $n and substr($s, $i, 1) =~ /[A-Za-z0-9_]/
$i < $n
substr($s, $i, 1) =~ /[A-Za-z0-9_]/
Truth table100%3/3
A and B
A= $i < $nB= substr($s, $i, 1) =~ /[A-Za-z0-9_]/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1289 | 20 | my $w = substr($s, $ws, $i - $ws); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1290 | 20 | ▶ | $i++ if $braced && substr($s, $i, 1) eq '}'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$braced and substr($s, $i, 1) eq "}"
MC/DC0%0/2
$braced and substr($s, $i, 1) eq "}"
$braced
substr($s, $i, 1) eq "}"
Truth table33%1/3
A and B
A= $bracedB= substr($s, $i, 1) eq "}"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1291 | 20 | ▶ | if (length $w) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1292 | 15 | my $nn = _string_new_name($pkg, $gmap, $glex, $rename, $w, $mods); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1293 | 15 | ▶ | if (defined $nn && $nn ne $w) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $nn and $nn ne $w
MC/DC50%1/2
defined $nn and $nn ne $w
defined $nn
$nn ne $w
Truth table66%2/3
A and B
A= defined $nnB= $nn ne $w
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1294 | 13 | ▶ | $d .= $sig . ($braced ? '{' : '') . $nn . ($braced ? '}' : ''); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1295 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1296 | 2 | $d .= substr($s, $start, $i - $start); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1297 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1298 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1299 | 5 | $d .= substr($s, $start, $i - $start); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1300 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1301 | 20 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1302 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1303 | 349 | $d .= $ch; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1304 | 349 | $i++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1305 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1306 | 39 | $out .= $d; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1307 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1308 | 39 | return $out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1309 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1310 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1311 | # Map a "$name" inside string text to its new name, mirroring the symbol | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1312 | # pass's name-based decisions. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1313 | 38 | ▶ | sub _string_new_name { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_string_new_name: called CC=23 SCAR=34.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1314 | 38 | my ($pkg, $gmap, $glex, $rename, $full, $mods) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1315 | 38 | ▶ | my ($qual, $base) = $full =~ /^(.*)::([^:]+)$/ ? ($1, $2) : (undef, $full); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1316 | 38 | ▶ | if (defined $qual) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1317 | 3 | ▶ | if ($gmap) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1318 | 2 | my $ge = $gmap->{$qual}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1319 | 2 | ▶ | if ($ge && $ge->{$base}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$ge and $ge->{$base}
MC/DC0%0/2
$ge and $ge->{$base}
$ge
$ge->{$base}
Truth table33%1/3
A and B
A= $geB= $ge->{$base}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1320 | 0 | return $ge->{$base}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1321 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1322 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1323 | # Module rename moved the namespace ($App::Saisons::VERSION -> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1324 | # $a::Saisons::VERSION when App::Saisons -> a::b): the bundle's global | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1325 | # map is keyed on the renamed package, so resolve the new qualifier | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1326 | # first when this string text lives under a renamed package. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1327 | 3 | ▶ | if ($gmap && $mods->{pkgs} && $qual =~ /::/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
$gmap and $mods->{"pkgs"} and $qual =~ /::/
$gmap and $mods->{"pkgs"}
MC/DC33%1/3
$gmap and $mods->{"pkgs"} and $qual =~ /::/
$gmap
$mods->{"pkgs"}
$qual =~ /::/
Truth table50%2/4
A and B and C
A= $gmapB= $mods->{"pkgs"}C= $qual =~ /::/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1328 | 2 | my $rq = rename_module_name($qual, $mods); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1329 | 2 | ▶ | if (my $re = $gmap->{$rq}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1330 | 1 | ▶ | return $re->{$base} if $re->{$base}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1331 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1332 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1333 | # Reverse direction (original-keyed map + renamed qualifier in hand): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1334 | # the module rename has already run on the token, so the qualifier is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1335 | # the renamed name while the map still uses the original package. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1336 | 2 | ▶ | if ($gmap && (my $oq = _gmap_key($qual, $gmap, $mods))) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$gmap and my $oq = _gmap_key($qual, $gmap, $mods)
MC/DC50%1/2
$gmap and my $oq = _gmap_key($qual, $gmap, $mods)
$gmap
my $oq = _gmap_key($qual, $gmap, $mods)
Truth table66%2/3
A and B
A= $gmapB= my $oq = _gmap_key($qual, $gmap, $mods)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1337 | return $gmap->{$oq}{$base} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1338 | 1 | ▶ | if $oq ne $qual && exists $gmap->{$oq} && $gmap->{$oq}{$base}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$oq ne $qual and exists $gmap->{$oq} and $gmap->{$oq}{$base}
$oq ne $qual and exists $gmap->{$oq}
MC/DC0%0/3
$oq ne $qual and exists $gmap->{$oq} and $gmap->{$oq}{$base}
$oq ne $qual
exists $gmap->{$oq}
$gmap->{$oq}{$base}
Truth table25%1/4
A and B and C
A= $oq ne $qualB= exists $gmap->{$oq}C= $gmap->{$oq}{$base}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1339 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1340 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1341 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1342 | 35 | ▶ | return $rename->{$base} if $rename && defined $rename->{$base}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$rename and defined $rename->{$base}
MC/DC50%1/2
$rename and defined $rename->{$base}
$rename
defined $rename->{$base}
Truth table66%2/3
A and B
A= $renameB= defined $rename->{$base}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1343 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1344 | # First try the current package directly; if the module rename has | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1345 | # already run on the statement (renamed $cur_pkg / $ppkg against an | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1346 | # original-keyed map), fall back through the reverse map. `exists` | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1347 | # guards prevent autovivifying bogus empty entries for absent keys. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1348 | 6 | my $opkg = _gmap_key($pkg, $gmap, $mods); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1349 | return $gmap->{$opkg}{$base} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1350 | if $gmap | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1351 | && exists $gmap->{$opkg} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1352 | && !( $glex && $glex->{$base} ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1353 | 6 | ▶ | && $gmap->{$opkg}{$base}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%8/12
$gmap and exists $gmap->{$opkg} and not $glex && $glex->{$base} and $gmap->{$opkg}{$base}
$gmap and exists $gmap->{$opkg} and not $glex && $glex->{$base}
$gmap and exists $gmap->{$opkg}
$glex && $glex->{$base}
MC/DC20%1/5
$gmap and exists $gmap->{$opkg} and not $glex && $glex->{$base} and $gmap->{$opkg}{$base}
$gmap
exists $gmap->{$opkg}
$glex
$glex->{$base}
$gmap->{$opkg}{$base}
Truth table42%3/7
A and B and not(C && D) and E
A= $gmapB= exists $gmap->{$opkg}C= $glexD= $glex->{$base}E= $gmap->{$opkg}{$base}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1354 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1355 | 3 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1356 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1357 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1358 | # The bundle-global map may be keyed either on the original package names | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1359 | # (collect_bundle_globals output, direct process() callers) or on the renamed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1360 | # names (bin/slimpack re-keys it before processing each source). Resolve a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1361 | # possibly-renamed package name to whichever key the caller's map uses: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1362 | # direct key first, then the reverse map (renamed name in hand, original-keyed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1363 | # map), then the forward module rename (original name in hand, renamed-keyed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1364 | # map, as in Pass 1 string/regex rewriting which runs before the module rename | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1365 | # has rewritten the package words). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1366 | 26 | ▶ | sub _gmap_key { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_gmap_key: called CC=11 SCAR=24.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1367 | 26 | my ($pkg, $gmap, $mods) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1368 | 26 | ▶ | return $pkg unless $gmap; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1369 | 23 | ▶ | return $pkg if exists $gmap->{$pkg}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1370 | 12 | ▶ | if ($mods) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1371 | 12 | ▶ | return $mods->{rev}{$pkg} if $mods->{rev} && $mods->{rev}{$pkg}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$mods->{"rev"} and $mods->{"rev"}{$pkg}
MC/DC100%2/2
$mods->{"rev"} and $mods->{"rev"}{$pkg}
$mods->{"rev"}
$mods->{"rev"}{$pkg}
Truth table100%3/3
A and B
A= $mods->{"rev"}B= $mods->{"rev"}{$pkg}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1372 | 3 | ▶ | if ($mods->{pkgs} && @{ $mods->{pkgs} } && $pkg =~ /::/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
$mods->{"pkgs"} and @{$mods->{"pkgs"};} and $pkg =~ /::/
$mods->{"pkgs"} and @{$mods->{"pkgs"};}
MC/DC33%1/3
$mods->{"pkgs"} and @{$mods->{"pkgs"};} and $pkg =~ /::/
$mods->{"pkgs"}
@{$mods->{"pkgs"};}
$pkg =~ /::/
Truth table50%2/4
A and B and C
A= $mods->{"pkgs"}B= @{$mods->{"pkgs"};}C= $pkg =~ /::/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1373 | 2 | my $r = rename_module_name($pkg, $mods); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1374 | 2 | ▶ | return $r if $r ne $pkg && exists $gmap->{$r}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$r ne $pkg and exists $gmap->{$r}
MC/DC0%0/2
$r ne $pkg and exists $gmap->{$r}
$r ne $pkg
exists $gmap->{$r}
Truth table33%1/3
A and B
A= $r ne $pkgB= exists $gmap->{$r}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1375 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1376 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1377 | 1 | return $pkg; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1378 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1379 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1380 | # New name for a "$var"-shaped word inside an export/import qw() list at a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1381 | # protocol site. The variable is a bundle global of the current (renamed) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1382 | # package (@EXPORT_OK=qw($x)) or of the imported module (use Pkg qw($x)); the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1383 | # resolution delegates to _string_new_name (module-name remap for the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1384 | # qualifier included). Returns undef when the name is not a renameable | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1385 | # bundle global. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1386 | 2 | ▶ | sub _protocol_var_new_name { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_protocol_var_new_name: called CC=8 SCAR=22.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1387 | 2 | my ($name, $pkg, $st, $gmap, $glex, $mods) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1388 | 2 | my $qual; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1389 | 2 | ▶ | if ($st && $st->statement && $st->statement->isa('PPI::Statement::Include') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition55%5/9
$st and $st->statement and $st->statement->isa("PPI::Statement::Include") and $st->statement->type eq "use"
$st and $st->statement and $st->statement->isa("PPI::Statement::Include")
$st and $st->statement
MC/DC25%1/4
$st and $st->statement and $st->statement->isa("PPI::Statement::Include") and $st->statement->type eq "use"
$st
$st->statement
$st->statement->isa("PPI::Statement::Include")
$st->statement->type eq "use"
Truth table40%2/5
A and B and C and D
A= $stB= $st->statementC= $st->statement->isa("PPI::Statement::Include")D= $st->statement->type eq "use"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1390 | && $st->statement->type eq 'use') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1391 | 1 | my $m = $st->statement->module; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1392 | 1 | ▶ | $qual = $m if defined $m && length $m; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $m and length $m
MC/DC0%0/2
defined $m and length $m
defined $m
length $m
Truth table33%1/3
A and B
A= defined $mB= length $m
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1393 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1394 | 2 | ▶ | my $full = defined $qual ? "${qual}::$name" : $name; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1395 | 2 | return _string_new_name($pkg, $gmap, $glex, {}, $full, $mods); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1396 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1397 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1398 | # Substitute interpolated "$var"/"${var}"/"@var"/"%var" references inside an | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1399 | # opaque token's text. Escaped dollars (odd run of backslashes before the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1400 | # sigil) stay literal and are preserved. Returns the rewritten text. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1401 | 91 | ▶ | sub _rewrite_string_text { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_rewrite_string_text: called CC=12 SCAR=29.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1402 | 91 | my ($src, $pkg, $gmap, $glex, $rename, $mods) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1403 | 91 | my $guard = qr/(?<!\\)(?:\\{2})*\K/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1404 | 91 | my $var = qr/([\$\@%])(\{?)((?:[A-Za-z_]\w*::)*[A-Za-z_]\w+)(\}?)/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1405 | # ${ \ $name ... } style deref interpolation (e.g. "${\$spec->{builder}}"): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1406 | # rename the inner variable name, preserving the ${\ form exactly. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1407 | 91 | $src =~ s! $guard ([\$\@%])\{\\([\$\@%])([A-Za-z_]\w*) !{ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1408 | 0 | my ($sig, $isig, $iname) = ($1, $2, $3); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1409 | 0 | my $new = _string_new_name($pkg, $gmap, $glex, $rename, $iname, $mods); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1410 | 0 | ▶ | defined $new ? $sig.'{\\'.$isig.$new : $&; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1411 | }!gex; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1412 | 91 | $src =~ s{ $guard $var }{ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1413 | 21 | my ($sig, $op, $full, $cl) = ($1, $2, $3, $4); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1414 | 21 | my $new = _string_new_name($pkg, $gmap, $glex, $rename, $full, $mods); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1415 | 21 | ▶ | defined $new && $sig.$op.$new.$cl || $&; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%4/6
defined $new && $sig . $op . $new . $cl || $&
defined $new and $sig . $op . $new . $cl
MC/DC0%0/3
defined $new && $sig . $op . $new . $cl || $&
defined $new
$sig . $op . $new . $cl
$&
Truth table40%2/5
A and B || C
A= defined $newB= $sig . $op . $new . $clC= $&
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1416 | }gex; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1417 | # Module rename of a fully-qualified global in interpolating text | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1418 | # ("$App::Saisons::VERSION" -> "$a::Saisons::VERSION"): the namespace | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1419 | # prefix follows the package rename even when the base name is exempt from | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1420 | # variable renaming (all-caps, package globals, ...). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1421 | 91 | ▶ | if ($mods && $mods->{pkgs}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$mods and $mods->{"pkgs"}
MC/DC50%1/2
$mods and $mods->{"pkgs"}
$mods
$mods->{"pkgs"}
Truth table66%2/3
A and B
A= $modsB= $mods->{"pkgs"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1422 | 4 | my $mvar = qr/([\$\@%])(\{?)((?:[A-Za-z_]\w*::)+[A-Za-z_]\w+)(\}?)/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1423 | 4 | $src =~ s{ $guard $mvar }{ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1424 | 1 | my ($sig, $op, $full, $cl) = ($1, $2, $3, $4); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1425 | 1 | my ($qual, $base) = $full =~ /^(.*)::([^:]+)$/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1426 | 1 | ▶ | my $rq = defined $qual ? rename_module_name($qual, $mods) : $qual; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1427 | 1 | ▶ | if (defined $rq && $rq ne $qual) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $rq and $rq ne $qual
MC/DC0%0/2
defined $rq and $rq ne $qual
defined $rq
$rq ne $qual
Truth table33%1/3
A and B
A= defined $rqB= $rq ne $qual
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1428 | 1 | my $nb = $base; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1429 | 1 | ▶ | if ($gmap && exists $gmap->{$rq} && $gmap->{$rq}{$base}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$gmap and exists $gmap->{$rq} and $gmap->{$rq}{$base}
$gmap and exists $gmap->{$rq}
MC/DC0%0/3
$gmap and exists $gmap->{$rq} and $gmap->{$rq}{$base}
$gmap
exists $gmap->{$rq}
$gmap->{$rq}{$base}
Truth table25%1/4
A and B and C
A= $gmapB= exists $gmap->{$rq}C= $gmap->{$rq}{$base}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1430 | 0 | $nb = $gmap->{$rq}{$base}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1431 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1432 | 1 | $sig . $op . $rq . '::' . $nb . $cl; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1433 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1434 | 0 | $&; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1435 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1436 | }gex; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1437 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1438 | 91 | return $src; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1439 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1440 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1441 | 30 | ▶ | sub _rewrite_doc { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_rewrite_doc: called CC=26 SCAR=32.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1442 | 30 | my ($doc) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1443 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1444 | # first_token-style walk that skips (already-collapsed) whitespace tokens | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1445 | 30 | my $tok = $doc->first_token; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1446 | 30 | ▶ | while ($tok) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1447 | 1256 | ▶ | if (ref($tok) eq 'PPI::Token::Word' && $tok->content eq 'foreach') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition100%3/3
ref $tok eq "PPI::Token::Word" and $tok->content eq "foreach"
MC/DC100%2/2
ref $tok eq "PPI::Token::Word" and $tok->content eq "foreach"
ref $tok eq "PPI::Token::Word"
$tok->content eq "foreach"
Truth table100%3/3
A and B
A= ref $tok eq "PPI::Token::Word"B= $tok->content eq "foreach"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1448 | # foreach after an arrow or brace is a method name / hash key | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1449 | # ($o->foreach, ->{foreach}), not the loop keyword, so only rewrite | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1450 | # it in any other position. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1451 | 9 | my $prev = $tok->previous_token; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1452 | 9 | ▶ | $prev = $prev->previous_token while $prev && $prev->isa('PPI::Token::Whitespace'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$prev and $prev->isa("PPI::Token::Whitespace")
MC/DC100%2/2
$prev and $prev->isa("PPI::Token::Whitespace")
$prev
$prev->isa("PPI::Token::Whitespace")
Truth table100%3/3
A and B
A= $prevB= $prev->isa("PPI::Token::Whitespace")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1453 | 9 | ▶ | $tok->set_content('for') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition88%8/9
$prev and $prev->content eq "->" || $prev->content eq "{" || $prev->content eq "::"
$prev->content eq "->" or $prev->content eq "{" or $prev->content eq "::"
$prev->content eq "->" or $prev->content eq "{"
MC/DC75%3/4
$prev and $prev->content eq "->" || $prev->content eq "{" || $prev->content eq "::"
$prev
$prev->content eq "->"
$prev->content eq "{"
$prev->content eq "::"
Truth table80%4/5
A and B or C or D
A= $prevB= $prev->content eq "->"C= $prev->content eq "{"D= $prev->content eq "::"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1454 | unless $prev && ($prev->content eq '->' || $prev->content eq '{' || $prev->content eq '::'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1455 | ▶ | } elsif ($tok->isa('PPI::Token::Regexp::Match') && $tok->content =~ /^m\//) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$tok->isa("PPI::Token::Regexp::Match") and $tok->content =~ m[^m/]
MC/DC100%2/2
$tok->isa("PPI::Token::Regexp::Match") and $tok->content =~ m[^m/]
$tok->isa("PPI::Token::Regexp::Match")
$tok->content =~ m[^m/]
Truth table100%3/3
A and B
A= $tok->isa("PPI::Token::Regexp::Match")B= $tok->content =~ m[^m/]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1456 | 3 | my $prev = $tok->previous_token; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1457 | 3 | ▶ | $prev = $prev->previous_token while $prev && $prev->isa('PPI::Token::Whitespace'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$prev and $prev->isa("PPI::Token::Whitespace")
MC/DC50%1/2
$prev and $prev->isa("PPI::Token::Whitespace")
$prev
$prev->isa("PPI::Token::Whitespace")
Truth table66%2/3
A and B
A= $prevB= $prev->isa("PPI::Token::Whitespace")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1458 | 3 | ▶ | $tok->set_content(substr $tok->content, 1) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition44%4/9
$prev and $prev->isa("PPI::Token::Operator") and $prev->content eq "=~" || $prev->content eq "!~"
$prev and $prev->isa("PPI::Token::Operator")
$prev->content eq "=~" or $prev->content eq "!~"
MC/DC0%0/4
$prev and $prev->isa("PPI::Token::Operator") and $prev->content eq "=~" || $prev->content eq "!~"
$prev
$prev->isa("PPI::Token::Operator")
$prev->content eq "=~"
$prev->content eq "!~"
Truth table40%2/5
A and B and C or D
A= $prevB= $prev->isa("PPI::Token::Operator")C= $prev->content eq "=~"D= $prev->content eq "!~"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1459 | if $prev && $prev->isa('PPI::Token::Operator') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1460 | && ($prev->content eq '=~' || $prev->content eq '!~'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1461 | ▶ | } elsif ($tok->isa('PPI::Token::Structure') && $tok->content eq ';') { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$tok->isa("PPI::Token::Structure") and $tok->content eq ";"
MC/DC100%2/2
$tok->isa("PPI::Token::Structure") and $tok->content eq ";"
$tok->isa("PPI::Token::Structure")
$tok->content eq ";"
Truth table100%3/3
A and B
A= $tok->isa("PPI::Token::Structure")B= $tok->content eq ";"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1462 | 118 | my $next = $tok->next_token; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1463 | 118 | ▶ | $next = $next->next_token while $next && $next->isa('PPI::Token::Whitespace'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$next and $next->isa("PPI::Token::Whitespace")
MC/DC100%2/2
$next and $next->isa("PPI::Token::Whitespace")
$next
$next->isa("PPI::Token::Whitespace")
Truth table100%3/3
A and B
A= $nextB= $next->isa("PPI::Token::Whitespace")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1464 | 118 | ▶ | $tok->set_content('') if $next && $next->content eq '}'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$next and $next->content eq "}"
MC/DC100%2/2
$next and $next->content eq "}"
$next
$next->content eq "}"
Truth table100%3/3
A and B
A= $nextB= $next->content eq "}"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1465 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1466 | 1256 | $tok = $tok->next_token; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1467 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1468 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1469 | 30 | ▶ | for my $stmt (@{ $doc->find('PPI::Statement') || [] }) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$doc->find('PPI::Statement') || []
MC/DC0%0/1
$doc->find('PPI::Statement') || []
$doc->find('PPI::Statement')
Truth table50%1/2
A
A= $doc->find('PPI::Statement')
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1470 | 208 | _rewrite_incdec($stmt); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1471 | 208 | _rewrite_opassign($stmt); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1472 | 208 | _rewrite_parendrop($stmt); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1473 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1474 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1475 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1476 | 208 | ▶ | sub _rewrite_incdec { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_rewrite_incdec: called CC=15 SCAR=28.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1477 | 208 | my ($stmt) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1478 | 208 | ▶ | return unless $stmt->isa('PPI::Statement'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1479 | 208 | my @k = grep { !$_->isa('PPI::Token::Whitespace') } $stmt->children; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1480 | 208 | ▶ | return unless @k == 4; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1481 | 20 | ▶ | return unless $k[0]->isa('PPI::Token::Symbol') || $k[0]->isa('PPI::Token::ArrayIndex'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$k[0]->isa("PPI::Token::Symbol") or $k[0]->isa("PPI::Token::ArrayIndex")
MC/DC50%1/2
$k[0]->isa("PPI::Token::Symbol") or $k[0]->isa("PPI::Token::ArrayIndex")
$k[0]->isa("PPI::Token::Symbol")
$k[0]->isa("PPI::Token::ArrayIndex")
Truth table66%2/3
A or B
A= $k[0]->isa("PPI::Token::Symbol")B= $k[0]->isa("PPI::Token::ArrayIndex")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1482 | 13 | ▶ | return unless $k[1]->isa('PPI::Token::Operator') && $k[1]->content =~ /^[+-]=$/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$k[1]->isa("PPI::Token::Operator") and $k[1]->content =~ /^[+-]=$/
MC/DC100%2/2
$k[1]->isa("PPI::Token::Operator") and $k[1]->content =~ /^[+-]=$/
$k[1]->isa("PPI::Token::Operator")
$k[1]->content =~ /^[+-]=$/
Truth table100%3/3
A and B
A= $k[1]->isa("PPI::Token::Operator")B= $k[1]->content =~ /^[+-]=$/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1483 | 5 | ▶ | return unless $k[2]->isa('PPI::Token::Number') && $k[2]->content eq '1'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$k[2]->isa("PPI::Token::Number") and $k[2]->content eq 1
MC/DC0%0/2
$k[2]->isa("PPI::Token::Number") and $k[2]->content eq 1
$k[2]->isa("PPI::Token::Number")
$k[2]->content eq 1
Truth table33%1/3
A and B
A= $k[2]->isa("PPI::Token::Number")B= $k[2]->content eq 1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1484 | 5 | ▶ | return unless $k[3]->isa('PPI::Token::Structure') && $k[3]->content eq ';'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$k[3]->isa("PPI::Token::Structure") and $k[3]->content eq ";"
MC/DC0%0/2
$k[3]->isa("PPI::Token::Structure") and $k[3]->content eq ";"
$k[3]->isa("PPI::Token::Structure")
$k[3]->content eq ";"
Truth table33%1/3
A and B
A= $k[3]->isa("PPI::Token::Structure")B= $k[3]->content eq ";"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1485 | # `$x += 1` returns the new value but `$x++` the old one, so only rewrite | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1486 | # statements that are NOT the last one of their enclosing block: the value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1487 | # of any non-final statement is always discarded (void context). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1488 | 5 | my $next = $stmt->next_sibling; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1489 | 5 | ▶ | $next = $next->next_sibling while $next && $next->isa('PPI::Token::Whitespace'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$next and $next->isa("PPI::Token::Whitespace")
MC/DC50%1/2
$next and $next->isa("PPI::Token::Whitespace")
$next
$next->isa("PPI::Token::Whitespace")
Truth table66%2/3
A and B
A= $nextB= $next->isa("PPI::Token::Whitespace")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1490 | 5 | ▶ | return unless $next; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1491 | 5 | ▶ | $k[1]->set_content($k[1]->content eq '+=' ? '++' : '--'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1492 | 5 | $k[2]->set_content(''); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1493 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1494 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1495 | 208 | ▶ | sub _rewrite_opassign { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_rewrite_opassign: called CC=14 SCAR=27.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1496 | 208 | my ($stmt) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1497 | 208 | ▶ | return unless $stmt->isa('PPI::Statement'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1498 | 208 | my @k = grep { !$_->isa('PPI::Token::Whitespace') } $stmt->children; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1499 | 208 | ▶ | return unless @k == 5 || (@k == 6 && $k[5]->isa('PPI::Token::Structure') && $k[5]->content eq ';'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition88%8/9
@k == 5 or @k == 6 and $k[5]->isa("PPI::Token::Structure") and $k[5]->content eq ";"
@k == 6 and $k[5]->isa("PPI::Token::Structure") and $k[5]->content eq ";"
@k == 6 and $k[5]->isa("PPI::Token::Structure")
MC/DC75%3/4
@k == 5 or @k == 6 and $k[5]->isa("PPI::Token::Structure") and $k[5]->content eq ";"
@k == 5
@k == 6
$k[5]->isa("PPI::Token::Structure")
$k[5]->content eq ";"
Truth table80%4/5
A or B and C and D
A= @k == 5B= @k == 6C= $k[5]->isa("PPI::Token::Structure")D= $k[5]->content eq ";"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1500 | 48 | ▶ | return unless $k[0]->isa('PPI::Token::Symbol') || $k[0]->isa('PPI::Token::ArrayIndex'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$k[0]->isa("PPI::Token::Symbol") or $k[0]->isa("PPI::Token::ArrayIndex")
MC/DC50%1/2
$k[0]->isa("PPI::Token::Symbol") or $k[0]->isa("PPI::Token::ArrayIndex")
$k[0]->isa("PPI::Token::Symbol")
$k[0]->isa("PPI::Token::ArrayIndex")
Truth table66%2/3
A or B
A= $k[0]->isa("PPI::Token::Symbol")B= $k[0]->isa("PPI::Token::ArrayIndex")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1501 | 9 | ▶ | return unless $k[1]->isa('PPI::Token::Operator') && $k[1]->content eq '='; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$k[1]->isa("PPI::Token::Operator") and $k[1]->content eq "="
MC/DC50%1/2
$k[1]->isa("PPI::Token::Operator") and $k[1]->content eq "="
$k[1]->isa("PPI::Token::Operator")
$k[1]->content eq "="
Truth table66%2/3
A and B
A= $k[1]->isa("PPI::Token::Operator")B= $k[1]->content eq "="
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1502 | 8 | ▶ | return unless $k[2]->isa(ref $k[0]) && $k[2]->content eq $k[0]->content; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$k[2]->isa(ref $k[0]) and $k[2]->content eq $k[0]->content
MC/DC50%1/2
$k[2]->isa(ref $k[0]) and $k[2]->content eq $k[0]->content
$k[2]->isa(ref $k[0])
$k[2]->content eq $k[0]->content
Truth table66%2/3
A and B
A= $k[2]->isa(ref $k[0])B= $k[2]->content eq $k[0]->content
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1503 | 5 | ▶ | return unless $k[3]->isa('PPI::Token::Operator') && $OP_ASSIGN{$k[3]->content}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$k[3]->isa("PPI::Token::Operator") and $OP_ASSIGN{$k[3]->content}
MC/DC0%0/2
$k[3]->isa("PPI::Token::Operator") and $OP_ASSIGN{$k[3]->content}
$k[3]->isa("PPI::Token::Operator")
$OP_ASSIGN{$k[3]->content}
Truth table33%1/3
A and B
A= $k[3]->isa("PPI::Token::Operator")B= $OP_ASSIGN{$k[3]->content}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1504 | # Both `$x = $x OP $y` and `$x OP= $y` return $x OP $y, so the rewrite is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1505 | # value-preserving in any context. The RHS is restricted (by the @k shape | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1506 | # above) to a single token, ruling out precedence surprises. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1507 | 5 | $k[1]->set_content($k[3]->content . '='); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1508 | 5 | $k[2]->set_content(''); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1509 | 5 | $k[3]->set_content(''); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1510 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1511 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1512 | 208 | ▶ | sub _rewrite_parendrop { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_rewrite_parendrop: called CC=14 SCAR=26.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1513 | 208 | my ($stmt) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1514 | 208 | ▶ | return unless $stmt->isa('PPI::Statement'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1515 | 208 | my @k = grep { !$_->isa('PPI::Token::Whitespace') } $stmt->children; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1516 | 208 | ▶ | return unless @k == 2 || (@k == 3 && $k[2]->isa('PPI::Token::Structure') && $k[2]->content eq ';'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%9/9
@k == 2 or @k == 3 and $k[2]->isa("PPI::Token::Structure") and $k[2]->content eq ";"
@k == 3 and $k[2]->isa("PPI::Token::Structure") and $k[2]->content eq ";"
@k == 3 and $k[2]->isa("PPI::Token::Structure")
MC/DC100%4/4
@k == 2 or @k == 3 and $k[2]->isa("PPI::Token::Structure") and $k[2]->content eq ";"
@k == 2
@k == 3
$k[2]->isa("PPI::Token::Structure")
$k[2]->content eq ";"
Truth table100%5/5
A or B and C and D
A= @k == 2B= @k == 3C= $k[2]->isa("PPI::Token::Structure")D= $k[2]->content eq ";"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1517 | 65 | ▶ | return unless $k[0]->isa('PPI::Token::Word') && $PAREN_DROP{$k[0]->content}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$k[0]->isa("PPI::Token::Word") and $PAREN_DROP{$k[0]->content}
MC/DC100%2/2
$k[0]->isa("PPI::Token::Word") and $PAREN_DROP{$k[0]->content}
$k[0]->isa("PPI::Token::Word")
$PAREN_DROP{$k[0]->content}
Truth table100%3/3
A and B
A= $k[0]->isa("PPI::Token::Word")B= $PAREN_DROP{$k[0]->content}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1518 | 29 | ▶ | return unless $k[1]->isa('PPI::Structure::List'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1519 | # Start/end must be exactly the call's argument list (statement-terminal | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1520 | # above), and the first argument must be a plain scalar/array/hash variable | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1521 | # so the keyword can never glue onto a literal ('print 1' -> print1). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1522 | 18 | my $t = $k[1]->start->next_token; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1523 | 0 | ▶ | while ($t && $t->isa('PPI::Token::Whitespace')) { $t = $t->next_token } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$t and $t->isa("PPI::Token::Whitespace")
MC/DC0%0/2
$t and $t->isa("PPI::Token::Whitespace")
$t
$t->isa("PPI::Token::Whitespace")
Truth table33%1/3
A and B
A= $tB= $t->isa("PPI::Token::Whitespace")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1524 | 18 | ▶ | return unless $t && ($t->isa('PPI::Token::Symbol') || $t->isa('PPI::Token::ArrayIndex')); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
$t and $t->isa("PPI::Token::Symbol") || $t->isa("PPI::Token::ArrayIndex")
$t->isa("PPI::Token::Symbol") or $t->isa("PPI::Token::ArrayIndex")
MC/DC33%1/3
$t and $t->isa("PPI::Token::Symbol") || $t->isa("PPI::Token::ArrayIndex")
$t
$t->isa("PPI::Token::Symbol")
$t->isa("PPI::Token::ArrayIndex")
Truth table50%2/4
A and B or C
A= $tB= $t->isa("PPI::Token::Symbol")C= $t->isa("PPI::Token::ArrayIndex")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1525 | 14 | $k[1]->start->set_content(' '); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1526 | 14 | $k[1]->finish->set_content(''); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1527 | 14 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1528 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1529 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1530 | 16 | ▶ | sub minify_file { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
minify_file: called CC=4 SCAR=14.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1531 | 16 | my ($path, %opts) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1532 | 16 | ▶ | open my $fh, '<', $path or die "Cannot read $path: $!"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1533 | 15 | my $src = do { local $/; <$fh> }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1534 | 15 | close $fh; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1535 | # The #! line is a PPI comment, so process() strips it like any other; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1536 | # a minified script must stay runnable, so put it back. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1537 | 15 | my ($bang) = $src =~ m{^(\#![^\n]*(?:\n|\z))}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1538 | 15 | my $min = process($src, %opts); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1539 | 15 | ▶ | return $bang && $min !~ /^\#/ ? $bang . $min : $min; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$bang and not $min =~ /^\#/
MC/DC0%0/2
$bang and not $min =~ /^\#/
$bang
not $min =~ /^\#/
Truth table33%1/3
A and not(B)
A= $bangB= not $min =~ /^\#/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1540 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1541 | # Extract the statically-declared module dependencies from Perl source. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1542 | # Returns a list of module names found via `use`, `require`, `use base`, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1543 | # `use parent`, and string-form `require "Foo/Bar.pm"`. Pragmas (strict, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1544 | # warnings, lib, etc.) are skipped. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1545 | # Minify and extract dependencies in a single PPI parse. Returns | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1546 | # ($minified, @deps) where the minified string is what process() would return | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1547 | # and @deps is what module_deps() would return on the same source. Like | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1548 | # process(), a source that PPI cannot parse is passed through unchanged and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1549 | # yields no dependencies. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1550 | 27 | ▶ | sub process_deps { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
process_deps: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1551 | 27 | my ($src, %opts) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1552 | 27 | my $doc = PPI::Document->new(\$src); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1553 | 27 | ▶ | return ($src) unless $doc; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1554 | 27 | my @deps = _deps_from_document($doc); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1555 | 27 | my $min = _minify_doc($doc, %opts); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1556 | 27 | return ($min, @deps); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1557 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1558 | # Bundle-aware global renaming: given the sources of every module that will | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1559 | # end up in one bundle, build a package => { old => short } map renaming the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1560 | # `our`-declared package globals. Safe precisely because the whole dependency | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1561 | # graph is packed together, so "another module might reference $PKG::x" no | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1562 | # longer applies: every qualified reference in the bundle is rewritten too. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1563 | # Returns ($map, $lexicals, $subs_map, $mods) where $lexicals is every my/state | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1564 | # name seen (used to leave ambiguous unqualified references alone), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1565 | # $subs_map is the bundle-wide method-rename map (see global_subs in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1566 | # process()), and $mods is the module-rename struct | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1567 | # ({ map => { component => short }, pkgs => [longest-first package names] }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1568 | # renaming namespace components of the bundled packages (rename_module_name). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1569 | # An optional trailing hashref selects behaviour: rename_exports => 1 records | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1570 | # import/export protocol words (use ... qw(), @EXPORT_OK = qw(...), can('x')) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1571 | # as eligible for renaming instead of freezing them (see global_subs + | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1572 | # rename_exports in process()). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1573 | 27 | ▶ | sub collect_bundle_globals { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
collect_bundle_globals: called CC=33 SCAR=35.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1574 | 27 | my @args = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1575 | 27 | my %opts; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1576 | 27 | ▶ | if (ref $args[-1] eq 'HASH') { %opts = %{ pop @args } } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1577 | 27 | my @sources = @args; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1578 | 27 | my (%globals, %lexicals, %in_string, %in_string_word, %subs, %words, %pkgs, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1579 | %data_globs, %xs_pkgs, %mod_in_string); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1580 | 27 | for my $src (@sources) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1581 | 60 | ▶ | next unless defined $src; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1582 | 60 | ▶ | my $doc = PPI::Document->new(\$src) or next; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1583 | _collect_bundle_globals_doc($doc, \%globals, \%lexicals, \%in_string, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1584 | \%in_string_word, \%subs, \%words, \%pkgs, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1585 | \%data_globs, $opts{rename_exports}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1586 | 60 | \%mod_in_string); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1587 | 60 | $xs_pkgs{$_} = 1 for _xs_packages($doc); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1588 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1589 | # An XS module finds its compiled code by package name, so it and every | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1590 | # package under it keep their names. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1591 | 27 | for my $p (keys %pkgs) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1592 | 47 | ▶ | delete $pkgs{$p} if grep { $p eq $_ || index($p, "${_}::") == 0 } keys %xs_pkgs; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$p eq $_ || index($p, "${_}::") == 0
MC/DC100%2/2
$p eq $_ || index($p, "${_}::") == 0
$p eq $_
index($p, "${_}::") == 0
Truth table100%3/3
A || B
A= $p eq $_B= index($p, "${_}::") == 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1593 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1594 | 27 | my @disallowed = (keys %lexicals, keys %in_string); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1595 | 27 | my %disallowed = map { $_ => 1 } @disallowed; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1596 | 27 | my %map; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1597 | 27 | my $counter = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1598 | 27 | for my $pkg (sort keys %globals) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1599 | 13 | for my $name (sort keys %{ $globals{$pkg} }) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1600 | 18 | ▶ | next unless _var_renameable($name, is_global => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1601 | lexicals => \%lexicals, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1602 | in_string => \%in_string); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1603 | 8 | my $short; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1604 | 8 | ▶ | do { $short = name_gen($counter++) } while $KEEP{$short} || $disallowed{$short}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$KEEP{$short} or $disallowed{$short}
MC/DC50%1/2
$KEEP{$short} or $disallowed{$short}
$KEEP{$short}
$disallowed{$short}
Truth table66%2/3
A or B
A= $KEEP{$short}B= $disallowed{$short}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1605 | 8 | $map{$pkg}{$name} = $short; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1606 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1607 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1608 | # Bundle-wide, name-global sub/method map (see global_subs in process()). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1609 | # One pool of short names shared by every module, reserved away from every | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1610 | # word that survives anywhere in the bundle. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1611 | 27 | my %subs_map; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1612 | 27 | my $scounter = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1613 | 27 | for my $name (sort keys %subs) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1614 | 45 | ▶ | next unless _sub_eligible($name, \%in_string_word); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1615 | 35 | ▶ | next if $data_globs{$name}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1616 | 34 | my $short; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1617 | 34 | ▶ | do { $short = name_gen($scounter++) } while _sub_short_taken($short, \%words); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1618 | 34 | $subs_map{$name} = $short; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1619 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1620 | # Module-rename struct: every namespace component of a declared bundled | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1621 | # package — the leaf included, since the bundle is closed and the loader's | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1622 | # %INC keys are rewritten with the same component map — gets a short name, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1623 | # reserved away from every surviving word and from the global/sub short | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1624 | # names. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1625 | 27 | my %modreserved = (%KEEP, %PERL_WORDS, %words, %lexicals, %in_string_word); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1626 | 27 | $modreserved{$_} = 1 for map { values %$_ } values %map; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1627 | 27 | $modreserved{$_} = 1 for values %subs_map; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1628 | 27 | my %modmap; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1629 | 27 | my $mcounter = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1630 | 27 | for my $p (sort { length $b <=> length $a } keys %pkgs) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1631 | 45 | ▶ | next unless $p =~ /::/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1632 | 25 | my @pc = split /::/, $p; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1633 | 25 | for (@pc) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1634 | 52 | ▶ | next if defined $modmap{$_}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1635 | # A component of a qualified name mentioned inside a string stays: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1636 | # the string may be eval'd as code (Sub::Defer's q[...] template | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1637 | # says `package Sub::Defer;`), and strings are never rewritten to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1638 | # follow module renames. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1639 | 45 | ▶ | next if $mod_in_string{$_}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1640 | 41 | my $short; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1641 | 81 | do { $short = name_gen($mcounter++) } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1642 | 41 | ▶ | while $KEEP{$short} || $PERL_WORDS{$short} || $modreserved{$short}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$KEEP{$short} or $PERL_WORDS{$short} or $modreserved{$short}
$KEEP{$short} or $PERL_WORDS{$short}
MC/DC66%2/3
$KEEP{$short} or $PERL_WORDS{$short} or $modreserved{$short}
$KEEP{$short}
$PERL_WORDS{$short}
$modreserved{$short}
Truth table75%3/4
A or B or C
A= $KEEP{$short}B= $PERL_WORDS{$short}C= $modreserved{$short}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1643 | 41 | $modmap{$_} = $short; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1644 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1645 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1646 | 27 | my %modinfo; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1647 | 27 | ▶ | if (%modmap) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1648 | 17 | $modinfo{map} = \%modmap; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1649 | 17 | $modinfo{pkgs} = [ sort { length $b <=> length $a } keys %pkgs ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1650 | # Reverse package mapping (renamed => original). Full pipeline builds | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1651 | # are re-keyed to the renamed names (see bin/slimpack), but direct | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1652 | # process() callers keep the original keys, so string/word rewriters | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1653 | # need to resolve a already-renamed namespace back to its source. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1654 | 17 | my %rev; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1655 | 17 | for my $p (keys %pkgs) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1656 | 34 | my $r = rename_module_name($p, \%modinfo); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1657 | 34 | ▶ | $rev{$r} = $p if defined $r && $r ne $p; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $r and $r ne $p
MC/DC50%1/2
defined $r and $r ne $p
defined $r
$r ne $p
Truth table66%2/3
A and B
A= defined $rB= $r ne $p
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1658 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1659 | 17 | ▶ | $modinfo{rev} = \%rev if %rev; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1660 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1661 | 27 | return (\%map, \%lexicals, \%subs_map, \%modinfo); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1662 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1663 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1664 | # Single-source half of collect_bundle_globals(). One linear token walk: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1665 | # remembers the current package, records `our`/`my`/`state` declarations from | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1666 | # PPI::Statement::Variable tokens, flags names that appear inside opaque | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1667 | # (stringy/regex) tokens so nothing embedded in text is ever renamed, records | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1668 | # `sub` definitions for the bundle-wide method-rename map, and notes every | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1669 | # bare word in the source so generated short method names never collide with | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1670 | # anything that survives. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1671 | 60 | ▶ | sub _collect_bundle_globals_doc { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_collect_bundle_globals_doc: called CC=66 SCAR=53.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1672 | 60 | my ($doc, $globals, $lexicals, $in_string, $in_string_word, $subs, $words, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1673 | $pkgs, $data_globs, $rexport, $mod_in_string) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1674 | 60 | my $cur_pkg = 'main'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1675 | 60 | my %seen_stmt; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1676 | 60 | my $tok = $doc->first_token; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1677 | 60 | ▶ | while ($tok) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1678 | 2016 | my $r = ref($tok); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1679 | 2016 | ▶ | $words->{$tok->content} = 1 if $r eq 'PPI::Token::Word'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1680 | 2016 | ▶ | if ($r eq 'PPI::Token::Word' && $tok->content eq 'package' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 6 branches
Condition77%7/9
$r eq "PPI::Token::Word" and $tok->content eq "package" and $tok->statement and $tok->statement->isa("PPI::Statement::Package")
$r eq "PPI::Token::Word" and $tok->content eq "package" and $tok->statement
$r eq "PPI::Token::Word" and $tok->content eq "package"
MC/DC50%2/4
$r eq "PPI::Token::Word" and $tok->content eq "package" and $tok->statement and $tok->statement->isa("PPI::Statement::Package")
$r eq "PPI::Token::Word"
$tok->content eq "package"
$tok->statement
$tok->statement->isa("PPI::Statement::Package")
Truth table60%3/5
A and B and C and D
A= $r eq "PPI::Token::Word"B= $tok->content eq "package"C= $tok->statementD= $tok->statement->isa("PPI::Statement::Package")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1681 | && $tok->statement && $tok->statement->isa('PPI::Statement::Package')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1682 | 48 | $cur_pkg = $tok->statement->namespace; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1683 | 48 | ▶ | $pkgs->{$cur_pkg} = 1 if defined $cur_pkg && length $cur_pkg; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $cur_pkg and length $cur_pkg
MC/DC0%0/2
defined $cur_pkg and length $cur_pkg
defined $cur_pkg
length $cur_pkg
Truth table33%1/3
A and B
A= defined $cur_pkgB= length $cur_pkg
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1684 | ▶ | } elsif ($r eq 'PPI::Token::Word' && $tok->content =~ /^(?:my|state|our)$/ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition77%7/9
$r eq "PPI::Token::Word" and $tok->content =~ /^(?:my|state|our)$/ and $tok->statement and not $seen_stmt{$tok->statement}++
$r eq "PPI::Token::Word" and $tok->content =~ /^(?:my|state|our)$/ and $tok->statement
$r eq "PPI::Token::Word" and $tok->content =~ /^(?:my|state|our)$/
MC/DC50%2/4
$r eq "PPI::Token::Word" and $tok->content =~ /^(?:my|state|our)$/ and $tok->statement and not $seen_stmt{$tok->statement}++
$r eq "PPI::Token::Word"
$tok->content =~ /^(?:my|state|our)$/
$tok->statement
not $seen_stmt{$tok->statement}++
Truth table60%3/5
A and B and C and not(D)
A= $r eq "PPI::Token::Word"B= $tok->content =~ /^(?:my|state|our)$/C= $tok->statementD= not $seen_stmt{$tok->statement}++
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1685 | && $tok->statement && !$seen_stmt{$tok->statement}++) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1686 | 47 | my $st = $tok->statement; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1687 | 47 | my ($type, @names); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1688 | 47 | ▶ | if ($st->isa('PPI::Statement::Variable')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1689 | 44 | $type = $st->type; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1690 | 44 | for my $v ($st->variables) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1691 | 44 | ▶ | my ($sigil, $n) = $v =~ /^([\$\@\%])(.+)$/ or next; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1692 | 44 | ▶ | push @names, $n if $n !~ /::/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1693 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1694 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1695 | # Postfix declarations (`return if our $ready`) are classified by | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1696 | # PPI as PPI::Statement::Break rather than Variable, so ->variables | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1697 | # is unavailable and they were silently never collected. Grab the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1698 | # first symbol (or parenthesised list) after the keyword only; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1699 | # anything after an operator (`if our $x or $y`) is a read of a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1700 | # package global, not a declaration, and must not be collected. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1701 | 3 | $type = $tok->content; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1702 | 3 | my $next = $tok->snext_sibling; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1703 | my @syms = $next && $next->isa('PPI::Token::Symbol') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1704 | ? ($next) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1705 | : $next && $next->isa('PPI::Structure::List') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1706 | 0 | ▶ | ? @{ $next->find('PPI::Token::Symbol') // [] } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition12%1/8
$next and $next->isa("PPI::Token::Symbol")
$next and $next->isa("PPI::Structure::List")
$next->find("PPI::Token::Symbol") // []
MC/DC0%0/2
$next and $next->isa("PPI::Token::Symbol")
$next
$next->isa("PPI::Token::Symbol")
MC/DC0%0/2
$next and $next->isa("PPI::Structure::List")
$next
$next->isa("PPI::Structure::List")
MC/DC0%0/1
$next->find("PPI::Token::Symbol") // []
$next->find("PPI::Token::Symbol")
Truth table33%1/3
A and B
A= $nextB= $next->isa("PPI::Token::Symbol")
Truth table0%0/3
A and B
A= $nextB= $next->isa("PPI::Structure::List")
Truth table0%0/2
A
A= $next->find("PPI::Token::Symbol")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1707 | : (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1708 | 3 | for my $sym (@syms) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1709 | 3 | ▶ | my ($sigil, $n) = $sym->content =~ /^([\$\@\%])(.+)$/ or next; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1710 | 3 | ▶ | push @names, $n if $n !~ /::/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1711 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1712 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1713 | 47 | for my $n (@names) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1714 | 47 | ▶ | $lexicals->{$n} = 1 if $type eq 'my' || $type eq 'state'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$type eq "my" or $type eq "state"
MC/DC50%1/2
$type eq "my" or $type eq "state"
$type eq "my"
$type eq "state"
Truth table66%2/3
A or B
A= $type eq "my"B= $type eq "state"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1715 | 47 | ▶ | $globals->{$cur_pkg}{$n} = 1 if $type eq 'our'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1716 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1717 | ▶ | } elsif ($r eq 'PPI::Token::Word' && $tok->content eq 'sub') { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$r eq "PPI::Token::Word" and $tok->content eq "sub"
MC/DC100%2/2
$r eq "PPI::Token::Word" and $tok->content eq "sub"
$r eq "PPI::Token::Word"
$tok->content eq "sub"
Truth table100%3/3
A and B
A= $r eq "PPI::Token::Word"B= $tok->content eq "sub"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1718 | 45 | my $next = $tok->snext_sibling; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1719 | 45 | ▶ | if ($next && $next->isa('PPI::Token::Word')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$next and $next->isa("PPI::Token::Word")
MC/DC50%1/2
$next and $next->isa("PPI::Token::Word")
$next
$next->isa("PPI::Token::Word")
Truth table66%2/3
A and B
A= $nextB= $next->isa("PPI::Token::Word")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1720 | 42 | my $n = $next->content; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1721 | 42 | $n =~ s/^.*:://; # sub Pkg::name -> name (name-global map) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1722 | 42 | $subs->{$n} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1723 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1724 | ▶ | } elsif ($r eq 'PPI::Token::Symbol' | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$r eq "PPI::Token::Symbol" and $tok->content =~ /^\*((?:[A-Za-z_]\w*::)*)([A-Za-z_]\w*)$/
MC/DC100%2/2
$r eq "PPI::Token::Symbol" and $tok->content =~ /^\*((?:[A-Za-z_]\w*::)*)([A-Za-z_]\w*)$/
$r eq "PPI::Token::Symbol"
$tok->content =~ /^\*((?:[A-Za-z_]\w*::)*)([A-Za-z_]\w*)$/
Truth table100%3/3
A and B
A= $r eq "PPI::Token::Symbol"B= $tok->content =~ /^\*((?:[A-Za-z_]\w*::)*)([A-Za-z_]\w*)$/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1725 | && $tok->content =~ /^\*((?:[A-Za-z_]\w*::)*)([A-Za-z_]\w*)$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1726 | # A glob assignment that installs a sub (*alias = \&sub, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1727 | # *CONST = $coderef, *x = sub {...}) defines a sub name like | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1728 | # `sub name` does, so record it in the sub map; _apply_renames | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1729 | # renames the glob in step with its callers. A name also used as | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1730 | # a data alias (*g = \@arr) anywhere in the bundle is never | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1731 | # renamed, since the map is name-global. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1732 | 6 | ▶ | my $kind = _glob_assign_kind($tok) // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
_glob_assign_kind($tok) // ""
MC/DC0%0/1
_glob_assign_kind($tok) // ""
_glob_assign_kind($tok)
Truth table50%1/2
A
A= _glob_assign_kind($tok)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1733 | 6 | ▶ | $subs->{$2} = 1 if $kind eq 'code'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1734 | 6 | ▶ | $data_globs->{$2} = 1 if $kind eq 'data'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1735 | ▶ | } elsif ($r eq 'PPI::Token::Regexp::Match' | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%2/6
$r eq "PPI::Token::Regexp::Match" or $r eq "PPI::Token::Regexp::Substitute" or $r eq "PPI::Token::QuoteLike::Regexp"
$r eq "PPI::Token::Regexp::Match" or $r eq "PPI::Token::Regexp::Substitute"
MC/DC0%0/3
$r eq "PPI::Token::Regexp::Match" or $r eq "PPI::Token::Regexp::Substitute" or $r eq "PPI::Token::QuoteLike::Regexp"
$r eq "PPI::Token::Regexp::Match"
$r eq "PPI::Token::Regexp::Substitute"
$r eq "PPI::Token::QuoteLike::Regexp"
Truth table25%1/4
A or B or C
A= $r eq "PPI::Token::Regexp::Match"B= $r eq "PPI::Token::Regexp::Substitute"C= $r eq "PPI::Token::QuoteLike::Regexp"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1736 | || $r eq 'PPI::Token::Regexp::Substitute' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1737 | || $r eq 'PPI::Token::QuoteLike::Regexp') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1738 | # Regex pattern/replacement TEXT is rewritten in step with the name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1739 | # renames (_rewrite_names_in_regexes), so only names inside opaque | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1740 | # code regions ((?{ }), s///e) freeze the variable. Bare words in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1741 | # pattern text are literals (never rewritable) and still freeze the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1742 | # sub map. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1743 | 0 | _regex_exempt_names($in_string, $in_string_word, $r, $tok->content); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1744 | 0 | my $pr = _parse_regex($r, $tok->content); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1745 | 0 | ▶ | if ($pr && !$pr->{single}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$pr and not $pr->{"single"}
MC/DC0%0/2
$pr and not $pr->{"single"}
$pr
not $pr->{"single"}
Truth table0%0/3
A and not(B)
A= $prB= not $pr->{"single"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1746 | 0 | for my $part (_regex_parts($pr->{pat})) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1747 | 0 | ▶ | next unless $part->[0] eq 'text'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1748 | 0 | ▶ | while ($part->[1] =~ /\b([A-Za-z_]\w*)\b/g) { $in_string_word->{$1} = 1 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1749 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1750 | 0 | ▶ | if (defined $pr->{repl} && $pr->{mods} !~ /e/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $pr->{"repl"} and not $pr->{"mods"} =~ /e/
MC/DC0%0/2
defined $pr->{"repl"} and not $pr->{"mods"} =~ /e/
defined $pr->{"repl"}
not $pr->{"mods"} =~ /e/
Truth table0%0/3
A and not(B)
A= defined $pr->{"repl"}B= not $pr->{"mods"} =~ /e/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1751 | 0 | ▶ | while ($pr->{repl} =~ /\b([A-Za-z_]\w*)\b/g) { $in_string_word->{$1} = 1 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1752 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1753 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1754 | } elsif ($r =~ /^PPI::Token::(?:Quote::(?:Interpolate|Double|Single|Literal)|QuoteLike::(?:Readline|Backtick|Command|Words)|HereDoc)$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1755 | 62 | my $str = $tok->content; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1756 | 62 | ▶ | $str .= join('', $tok->heredoc) if $r eq 'PPI::Token::HereDoc' && $tok->can('heredoc'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$r eq "PPI::Token::HereDoc" and $tok->can("heredoc")
MC/DC0%0/2
$r eq "PPI::Token::HereDoc" and $tok->can("heredoc")
$r eq "PPI::Token::HereDoc"
$tok->can("heredoc")
Truth table33%1/3
A and B
A= $r eq "PPI::Token::HereDoc"B= $tok->can("heredoc")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1757 | # A qualified name in a NON-interpolating string freezes its | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1758 | # components in the module map: the string may be eval'd as code | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1759 | # (Sub::Defer's q[...] template says `package Sub::Defer;`), and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1760 | # unlike interpolating text these strings are never rewritten to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1761 | # follow module renames. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1762 | 62 | ▶ | if ($mod_in_string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition57%8/14
$mod_in_string and $r eq "PPI::Token::Quote::Single" || $r eq "PPI::Token::Quote::Literal" || $r eq "PPI::Token::HereDoc" && !(($tok->{"_mode"} || "") =~ /^(?:interpolate|command)$/)
$r eq "PPI::Token::Quote::Single" or $r eq "PPI::Token::Quote::Literal" or $r eq "PPI::Token::HereDoc" and not +($tok->{"_mode"} || "") =~ /^(?:interpolate|command)$/
$r eq "PPI::Token::Quote::Single" or $r eq "PPI::Token::Quote::Literal"
$r eq "PPI::Token::HereDoc" and not +($tok->{"_mode"} || "") =~ /^(?:interpolate|command)$/
$tok->{'_mode'} || ''
MC/DC40%2/5
$mod_in_string and $r eq "PPI::Token::Quote::Single" || $r eq "PPI::Token::Quote::Literal" || $r eq "PPI::Token::HereDoc" && !(($tok->{"_mode"} || "") =~ /^(?:interpolate|command)$/)
$mod_in_string
$r eq "PPI::Token::Quote::Single"
$r eq "PPI::Token::Quote::Literal"
$r eq "PPI::Token::HereDoc"
$tok->{'_mode'}
Truth table50%3/6
A and B or C or D and not(E)
A= $mod_in_stringB= $r eq "PPI::Token::Quote::Single"C= $r eq "PPI::Token::Quote::Literal"D= $r eq "PPI::Token::HereDoc"E= $tok->{'_mode'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1763 | && ($r eq 'PPI::Token::Quote::Single' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1764 | || $r eq 'PPI::Token::Quote::Literal' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1765 | || ($r eq 'PPI::Token::HereDoc' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1766 | && ($tok->{_mode} || '') !~ /^(?:interpolate|command)$/))) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1767 | 28 | ▶ | while ($str =~ /\b((?:[A-Za-z_]\w*::)+[A-Za-z_]\w*)\b/g) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1768 | 2 | $mod_in_string->{$_} = 1 for split /::/, $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1769 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1770 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1771 | # With rename_exports, protocol words AND $-exported variables (use | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1772 | # import lists, @EXPORT_OK qw lists, can('x') strings) are renamed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1773 | # in step with the sub/variable they name, so they do not freeze it. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1774 | 62 | ▶ | my $protocol = $rexport | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%9/9
$rexport && ($r =~ /^PPI::Token::Quote::(?:Single|Double|Literal)$/ || $r eq 'PPI::Token::QuoteLike::Words') && _protocol_site($tok)
$rexport and $r =~ /^PPI::Token::Quote::(?:Single|Double|Literal)$/ || $r eq "PPI::Token::QuoteLike::Words"
$r =~ /^PPI::Token::Quote::(?:Single|Double|Literal)$/ or $r eq "PPI::Token::QuoteLike::Words"
MC/DC50%2/4
$rexport && ($r =~ /^PPI::Token::Quote::(?:Single|Double|Literal)$/ || $r eq 'PPI::Token::QuoteLike::Words') && _protocol_site($tok)
$rexport
$r =~ /^PPI::Token::Quote::(?:Single|Double|Literal)$/
$r eq "PPI::Token::QuoteLike::Words"
_protocol_site($tok)
Truth table66%4/6
A and B or C && D
A= $rexportB= $r =~ /^PPI::Token::Quote::(?:Single|Double|Literal)$/C= $r eq "PPI::Token::QuoteLike::Words"D= _protocol_site($tok)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1775 | && ($r =~ /^PPI::Token::Quote::(?:Single|Double|Literal)$/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1776 | || $r eq 'PPI::Token::QuoteLike::Words') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1777 | && _protocol_site($tok); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1778 | 62 | ▶ | if (!$protocol) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1779 | 58 | ▶ | while ($str =~ /[\$\@]\{?(\w{2,})\b/g) { $in_string->{$1} = 1 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1780 | 58 | ▶ | while ($str =~ /\b([A-Za-z_]\w*)\b/g) { $in_string_word->{$1} = 1 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1781 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1782 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1783 | 2016 | $tok = $tok->next_token; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1784 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1785 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1786 | # Extract the statically-declared module dependencies from an already-parsed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1787 | # PPI document. Shared by module_deps() and process_deps() so both report the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1788 | # same dependency list. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1789 | 36 | ▶ | sub _deps_from_document { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_deps_from_document: called CC=24 SCAR=33.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1790 | 36 | my ($doc) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1791 | 36 | my @deps; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1792 | 36 | ▶ | my $incs = $doc->find('PPI::Statement::Include') || []; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$doc->find('PPI::Statement::Include') || []
MC/DC100%1/1
$doc->find('PPI::Statement::Include') || []
$doc->find('PPI::Statement::Include')
Truth table100%2/2
A
A= $doc->find('PPI::Statement::Include')
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1793 | 36 | for my $i (@$incs) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1794 | 53 | my $type = $i->type; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1795 | 53 | ▶ | next unless defined $type && ($type eq 'use' || $type eq 'require'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
defined $type and $type eq "use" || $type eq "require"
$type eq "use" or $type eq "require"
MC/DC0%0/3
defined $type and $type eq "use" || $type eq "require"
defined $type
$type eq "use"
$type eq "require"
Truth table50%2/4
A and B or C
A= defined $typeB= $type eq "use"C= $type eq "require"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1796 | 53 | my $mod = $i->module; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1797 | 53 | ▶ | if (defined $mod && length $mod) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
defined $mod and length $mod
MC/DC50%1/2
defined $mod and length $mod
defined $mod
length $mod
Truth table66%2/3
A and B
A= defined $modB= length $mod
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1798 | 50 | ▶ | if ($mod eq 'parent' || $mod eq 'base') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$mod eq "parent" or $mod eq "base"
MC/DC100%2/2
$mod eq "parent" or $mod eq "base"
$mod eq "parent"
$mod eq "base"
Truth table100%3/3
A or B
A= $mod eq "parent"B= $mod eq "base"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1799 | 2 | for my $tok ($i->arguments) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1800 | 2 | ▶ | if ($tok->isa('PPI::Token::QuoteLike::Words')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1801 | 1 | push @deps, $tok->literal; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1802 | } elsif ($tok->isa('PPI::Token::Quote')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1803 | 1 | my $str = $tok->string; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1804 | 1 | ▶ | push @deps, $str if defined $str && length $str; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $str and length $str
MC/DC0%0/2
defined $str and length $str
defined $str
length $str
Truth table33%1/3
A and B
A= defined $strB= length $str
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1805 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1806 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1807 | 2 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1808 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1809 | 48 | ▶ | next if $i->pragma; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1810 | 21 | push @deps, $mod; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1811 | } elsif ($type eq 'require') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1812 | 2 | for my $tok ($i->schildren) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1813 | 6 | ▶ | next unless $tok->isa('PPI::Token::Quote') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$tok->isa("PPI::Token::Quote") or $tok->isa("PPI::Token::HereDoc")
MC/DC50%1/2
$tok->isa("PPI::Token::Quote") or $tok->isa("PPI::Token::HereDoc")
$tok->isa("PPI::Token::Quote")
$tok->isa("PPI::Token::HereDoc")
Truth table66%2/3
A or B
A= $tok->isa("PPI::Token::Quote")B= $tok->isa("PPI::Token::HereDoc")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1814 | || $tok->isa('PPI::Token::HereDoc'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1815 | 1 | ▶ | my $str = $tok->string // next; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$tok->string // (next)
MC/DC0%0/1
$tok->string // (next)
$tok->string
Truth table50%1/2
A
A= $tok->string
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1816 | 1 | ▶ | next unless $str =~ s{\.pm$}{}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1817 | 1 | $str =~ s{/}{::}g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1818 | 1 | ▶ | push @deps, $str if length $str && $str !~ /[\$\@\%\$\{]/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
length $str and not $str =~ /[\$\@\%\$\{]/
MC/DC0%0/2
length $str and not $str =~ /[\$\@\%\$\{]/
length $str
not $str =~ /[\$\@\%\$\{]/
Truth table33%1/3
A and not(B)
A= length $strB= not $str =~ /[\$\@\%\$\{]/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1819 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1820 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1821 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1822 | 36 | return @deps; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1823 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1824 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1825 | 9 | ▶ | sub module_deps { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
module_deps: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1826 | 9 | my ($src) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1827 | 9 | ▶ | my $doc = PPI::Document->new(\$src) // die "PPI parse failed"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
"PPI::Document"->new(\$src) // die("PPI parse failed")
MC/DC0%0/1
"PPI::Document"->new(\$src) // die("PPI parse failed")
"PPI::Document"->new(\$src)
Truth table50%1/2
A
A= "PPI::Document"->new(\$src)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1828 | 9 | return _deps_from_document($doc); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1829 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1830 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1831 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1832 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1833 | App::SlimPacker::Minify - PPI-based Perl source minifier and bundle-aware renaming engine | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1834 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1835 | =head1 VERSION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1836 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1837 | Version 0.07 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1838 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1839 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1840 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1841 | use App::SlimPacker::Minify qw(process minify_file); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1842 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1843 | my $min = minify_file('lib/My/Module.pm'); # read a file and minify it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1844 | my $min = process($source); # same, from a string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1845 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1846 | my $min = process($source, rename_subs => 1); # also rename subs/methods | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1847 | my $min = process($source, rename_vars => 0); # only strip comments, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1848 | # POD and whitespace | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1849 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1850 | Given | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1851 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1852 | package My::Greeter; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1853 | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1854 | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1855 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1856 | # Build a greeter | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1857 | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1858 | my ($class, %args) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1859 | return bless {%args}, $class; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1860 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1861 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1862 | sub greeting_for { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1863 | my ($self, $name) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1864 | return "Hello, $name!"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1865 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1866 | 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1867 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1868 | C<< process($source, rename_subs => 1) >> returns | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1869 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1870 | package My::Greeter;use strict;use warnings;sub new{my($c,%d)=@_;return bless{%d},$c;}sub a{my($e,$f)=@_;return "Hello, $f!";}1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1871 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1872 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1873 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1874 | A PPI-based minifier for Perl source. It removes comments, POD and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1875 | whitespace and renames C<my> variables to short names. It can also rename | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1876 | subs, methods, C<our> globals and package names. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1877 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1878 | A single file can only be renamed so far: a sub or package name may be used | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1879 | by other files. When you minify a whole program at once, as L<slimpack> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1880 | does, L</collect_bundle_globals(@sources)> collects names across all files | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1881 | so they can be renamed consistently. See L</EXAMPLES>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1882 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1883 | L<App::SlimPacker> re-exports all of these functions. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1884 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1885 | =head1 EXAMPLES | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1886 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1887 | =head2 Minifying several files together | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1888 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1889 | use Path::Tiny (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1890 | use App::SlimPacker::Minify | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1891 | qw(process collect_bundle_globals rename_module_name rename_module_path); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1892 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1893 | my %src = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1894 | 'My/Greeter.pm' => Path::Tiny::path('lib/My/Greeter.pm')->slurp_utf8, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1895 | 'main.pl' => Path::Tiny::path('main.pl')->slurp_utf8, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1896 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1897 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1898 | my ($globals, $lexicals, $subs, $modules) = collect_bundle_globals(values %src); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1899 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1900 | # $globals is keyed by package name, which module renaming changes too | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1901 | my %globals = map { rename_module_name($_, $modules) => $globals->{$_} } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1902 | keys %{ $globals }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1903 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1904 | for my $file (sort keys %src) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1905 | my $min = process($src{$file}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1906 | rename_subs => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1907 | global_rename => \%globals, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1908 | global_lexicals => $lexicals, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1909 | global_subs => $subs, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1910 | global_modules => $modules, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1911 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1912 | # package names changed, so the file names must too: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1913 | # My/Greeter.pm -> c/d.pm, main.pl stays main.pl | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1914 | my $out = Path::Tiny::path('out', rename_module_path($file, $modules)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1915 | $out->parent->mkpath; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1916 | $out->spew_utf8($min); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1917 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1918 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1919 | With a C<main.pl> of | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1920 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1921 | use My::Greeter; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1922 | my $greeter = My::Greeter->new; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1923 | print $greeter->greeting_for('world'), "\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1924 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1925 | this writes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1926 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1927 | # out/c/d.pm | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1928 | package c::d;...sub a{my($e,$f)=@_;return "Hello, $f!";}1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1929 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1930 | # out/main.pl | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1931 | use c::d;my$c=c::d->new;print$c->a('world'),"\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1932 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1933 | and C<perl -Iout out/main.pl> still prints C<Hello, world!>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1934 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1935 | =head1 FUNCTIONS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1936 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1937 | =head2 process($source, %options) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1938 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1939 | Minifies Perl source code using PPI. Returns the minified string. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1940 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1941 | Options: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1942 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1943 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1944 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1945 | =item rename_vars => 0|1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1946 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1947 | Rename C<my> variables to short names (C<a>, C<b>, ... C<aa>, ...). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1948 | Enabled by default. Set to C<0> to keep variable names intact (useful for | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1949 | C<fatlib> core modules). Alias: C<rename>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1950 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1951 | =item rewrite => 0|1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1952 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1953 | Apply an additional, optional pass that rewrites code into shorter equivalent | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1954 | forms. Disabled by default. The rewrites are all value-preserving and built | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1955 | as a self-contained, removable step so the whole pass can be switched off | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1956 | (C<rewrite => 0>) or deleted (the C<_rewrite_doc> method and its one call site | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1957 | in C<_minify_doc>) if it ever causes problems. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1958 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1959 | Currently: C<foreach> -> C<for>; C<m/.../> -> C</.../> when preceded by | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1960 | C<=~> or C<!~> (the C<m> is optional with C</> delimiters); trailing C<;> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1961 | before a closing C<}> is dropped; a C<$x += 1;> statement in a non-final | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1962 | position becomes C<$x++;> (and C<->= 1> -> C<-->); C<$x = $x OP $y;> with a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1963 | single-token RHS becomes C<$x OP= $y;> for C<. + - * / %>; and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1964 | parentheses are dropped from statement-terminal builtin calls that take a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1965 | variable argument (C<print($x)>, C<return($y)>, C<push(@a, $x)>). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1966 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1967 | =item global_rename_vars => \%map | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1968 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1969 | Alias: C<global_rename>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1970 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1971 | =item global_rename => \%map | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1972 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1973 | Also rename package globals using a map built by | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1974 | L</collect_bundle_globals(@sources)>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1975 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1976 | =item global_lexicals => \%lexicals | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1977 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1978 | Bundle-wide set of C<my>/C<state> names, used to leave an unqualified | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1979 | reference untouched when a lexical of the same name exists anywhere in the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1980 | bundle. Returned as the second value of | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1981 | L</collect_bundle_globals(@sources)>; only meaningful together with | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1982 | C<global_rename>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1983 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1984 | =item rename_subs => 0|1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1985 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1986 | Rename sub and method names to short names as well. Off by default here; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1987 | L<slimpack> and L<minify> turn it on unless given C<--no-rename-subs>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1988 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1989 | =item global_subs => \%subs | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1990 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1991 | Bundle-wide C<< name => short_name >> map for L</rename_subs>, returned as | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1992 | the third value of L</collect_bundle_globals(@sources)>. Passing it renames | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1993 | the subs it lists even without C<rename_subs>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1994 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1995 | =item global_modules => \%modinfo | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1996 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1997 | Rename package names (C<My::Greeter> becomes C<c::d>) using the struct | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1998 | returned as the fourth value of L</collect_bundle_globals(@sources)>. There | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1999 | is no separate on/off option: packages are renamed when this is passed. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2000 | L<slimpack> passes it unless given C<--no-rename-modules>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2001 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2002 | =item rename_exports => 0|1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2003 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2004 | Extend L</rename_subs> to the export/import protocol. Off by default. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2005 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2006 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2007 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2008 | =head2 process_deps($source, %options) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2009 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2010 | Minifies and resolves dependencies in a single PPI parse. Returns | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2011 | C<< ($minified, @deps) >> where C<$minified> is what L</process($source, %options)> would return | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2012 | for the same source and C<@deps> is what L</module_deps($source)> would return. Use it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2013 | when both quantities are needed for the same file to avoid parsing it twice; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2014 | this is what the bundler does for every reachable module. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2015 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2016 | =head2 collect_bundle_globals(@sources) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2017 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2018 | Returns C<< ($map, $lexicals, $subs, $modinfo) >> for bundle-aware renaming. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2019 | C<@sources> is the original text of every module that will land in one bundle | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2020 | (the boot program included). C<$lexicals> is a hashref of every C<my>/C<state> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2021 | name found anywhere in those sources. C<$map> is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2022 | C<< package => { global_name => short_name } >> describing a rename of the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2023 | C<our>-declared package globals, sized to fit the longest name in the bundle. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2024 | Postfix declarations like C<return if our $flag> are covered too: PPI classifies | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2025 | them as an ordinary statement (L<PPI::Statement::Break>) rather than a variable | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2026 | declaration, so they are picked up from the keyword's first symbol instead. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2027 | Feed both back into L</process($source, %options)> (and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2028 | L</process_deps($source, %options)>) as C<global_rename> / C<global_lexicals>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2029 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2030 | Renaming package globals is only safe when the bundle knows its whole | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2031 | dependency graph: minifying a single file on its own leaves C<our> globals | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2032 | alone, but every module packed together can agree on one short name. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2033 | Referenced from an interpolating string, the quotation is rewritten to match. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2034 | C<$VERSION>, C<$AUTOLOAD>, C<@ISA>, ALL_CAPS, control-variable (C<$^...>) and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2035 | single-character names are never renamed, and a global is skipped if its name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2036 | is a C<my> lexical anywhere in the bundle. The generated short names avoid | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2037 | every bundle lexical and reserved name, so an unqualified reference can never | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2038 | become ambiguous. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2039 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2040 | C<$subs> is a flat C<< name => short_name >> hash for L</rename_subs>, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2041 | collected the same way as L</process($source, %options)> but over all | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2042 | C<@sources> at once, so cross-module calls keep agreeing on one short name. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2043 | Short names avoid every Perl keyword, all C<sub> names seen in C<@sources>, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2044 | and every word appearing inside a string-like token (so a runtime string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2045 | dispatch can never alias a renamed sub). Does not renumber: the C<rename_subs> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2046 | pass over each module consumes slots from the same C<name_gen> sequence as the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2047 | variable pass. Pass it to L</process($source, %options)> / | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2048 | L</process_deps($source, %options)> as C<global_subs>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2049 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2050 | C<$modinfo> is the module-rename struct for C<global_modules>: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2051 | C<< { map => { component => short }, pkgs => [ package names, longest first ] } >>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2052 | Every namespace component of a declared bundled package gets a short name, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2053 | the leaf included (the loader's C<%INC> keys are rewritten from the same | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2054 | map). Pass it to L</process($source, %options)> / | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2055 | L</process_deps($source, %options)> as C<global_modules>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2056 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2057 | An optional trailing hashref selects behaviour: C<< rename_exports => 1 >> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2058 | records import/export protocol words (C<use ... qw()>, C<@EXPORT_OK = qw(...)>, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2059 | C<can('x')>) as C<sub>-rename candidates instead of freezing them, matching the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2060 | C<rename_exports> option of L</process($source, %options)>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2061 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2062 | =head3 rename_module_name($name, $modinfo) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2063 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2064 | Helper for C<global_modules>: given a Perl-style class name (C<App::Saisons>, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2065 | C<App::Saisons::UI::something>) and the C<$modinfo> struct, returns the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2066 | renamed form if the name matches one of the declared bundles, the original | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2067 | text otherwise. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2068 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2069 | The name matches when it is a declared package, a C<Pkg::...> prefix of one | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2070 | (a renamed prefix plus an untouched tail, e.g. C<bk::bl::UI::Foo>), or a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2071 | strict namespace ancestor of one (C<App::Saisons> given C<App::Saisons::UI>). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2072 | A declared package maps every component, the leaf included (see | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2073 | C<global_modules>); ancestors map every component too and tails keep whatever | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2074 | came after the matched prefix. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2075 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2076 | Note C<$modinfo-E<gt>{pkgs}> must be sorted longest-first for correct | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2077 | matching; L</collect_bundle_globals(@sources)> produces it that way. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2078 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2079 | =head2 minify_file($path, %options) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2080 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2081 | Reads the file at C<$path> and runs it through L</process($source, %options)> with the given | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2082 | options. Dies if the file cannot be read. Returns the minified string. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2083 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2084 | A leading C<#!> shebang line is preserved: C<process> strips it as a comment, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2085 | and a minified script must stay runnable. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2086 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2087 | =head2 module_deps($source) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2088 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2089 | Returns a list of module names statically declared as dependencies in the given | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2090 | Perl source. Extracts modules from C<use>, C<require>, C<use base>, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2091 | C<use parent>, and string-form C<require "Foo/Bar.pm">. Pragmas (C<strict>, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2092 | C<warnings>, C<lib>, etc.) are skipped. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2093 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2094 | =head2 name_gen($n) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2095 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2096 | Returns a short variable name for the index C<$n>: C<0> -> C<a>, C<1> -> C<b>, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2097 | C<25> -> C<z>, C<26> -> C<aa>, etc. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2098 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2099 | =head2 needs_space($left_token, $right_token) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2100 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2101 | Returns 1 if a space is needed between two PPI tokens to prevent them from | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2102 | merging into a single token, 0 otherwise. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2103 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2104 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2105 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2106 | Nicolas Mendoza, C<< <mendoza at pvv.ntnu.no> >> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2107 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2108 | =head1 LICENSE AND COPYRIGHT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2109 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2110 | This software is licensed under the Artistic License 2.0. See the F<LICENSE> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2111 | file in this distribution for the full text. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2112 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2113 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2114 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2115 | L<App::SlimPacker>, L<slimpack>, L<PPI> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2116 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2117 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2118 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2119 | 35 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||