| 1 | 25 | ▶ | use 5.016; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 25 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 25 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | package App::AnteREPL::Shorthand; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 25 | ▶ | use Text::Balanced qw(extract_bracketed extract_quotelike); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 25 | my %keyword; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | # Ask this Perl about its own keywords without compiling any user code. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 191 | ▶ | sub perl_keyword { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
perl_keyword: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 191 | my ($name) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 191 | ▶ | return $keyword{$name} if exists $keyword{$name}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 60 | local $@; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 60 | ▶ | return $keyword{$name} = eval { my $prototype = prototype "CORE::$name"; 1 } ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 31 | ▶ | sub _fail { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_fail: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 31 | die "Ambiguous shorthand: $_[0]. Try EVAL with explicit Perl syntax.\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 348 | ▶ | sub _trim { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_trim: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 348 | my ($text) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 348 | $text =~ s/\A\s+|\s+\z//g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 348 | return $text; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 761 | ▶ | sub _starts_quote { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_starts_quote: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 761 | my ($text) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 761 | ▶ | return $text =~ /\A['"`]/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$text =~ /\A['"`]/u || $text =~ /\A(?:qq|qw|qx|qr|q|m|s|tr|y)(?=\s|[^\w\s])\s*(?!=>)\S/u
MC/DC100%2/2
$text =~ /\A['"`]/u || $text =~ /\A(?:qq|qw|qx|qr|q|m|s|tr|y)(?=\s|[^\w\s])\s*(?!=>)\S/u
$text =~ /\A['"`]/u
$text =~ /\A(?:qq|qw|qx|qr|q|m|s|tr|y)(?=\s|[^\w\s])\s*(?!=>)\S/u
Truth table100%3/3
A || B
A= $text =~ /\A['"`]/uB= $text =~ /\A(?:qq|qw|qx|qr|q|m|s|tr|y)(?=\s|[^\w\s])\s*(?!=>)\S/u
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | || $text =~ /\A(?:qq|qw|qx|qr|q|m|s|tr|y)(?=\s|[^\w\s])\s*(?!=>)\S/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 88 | ▶ | sub _quote { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_quote: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 88 | my ($text) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 88 | local $@; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 88 | my ($quote) = extract_quotelike("$text", ''); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 88 | ▶ | _fail('unclosed quoted value') unless defined $quote && length $quote; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $quote and length $quote
MC/DC50%1/2
defined $quote and length $quote
defined $quote
length $quote
Truth table66%2/3
A and B
A= defined $quoteB= length $quote
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 84 | return $quote; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 46 | ▶ | sub _group { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_group: called CC=13 SCAR=26.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 46 | my ($text) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 46 | my $open = substr($text, 0, 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 46 | ▶ | if ($open eq '(') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 19 | local $@; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 19 | my ($group) = extract_bracketed("$text", q{()[]{}'"`q}, ''); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 19 | ▶ | return $group if defined $group && length $group; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $group and length $group
MC/DC0%0/2
defined $group and length $group
defined $group
length $group
Truth table33%1/3
A and B
A= defined $groupB= length $group
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | ▶ | _fail($@ =~ /Mismatched/ ? 'mismatched expression delimiters' : 'unclosed parenthesized expression'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 27 | ▶ | my $close = $open eq '[' ? ']' : '}'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 27 | my $position = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 27 | ▶ | while ($position < length $text) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 122 | my $rest = substr($text, $position); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 122 | my $char = substr($rest, 0, 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 122 | ▶ | return substr($text, 0, $position + 1) if $char eq $close; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 101 | ▶ | _fail('mismatched container delimiters') if $char =~ /[)\]}]/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | ▶ | if ($rest =~ /\A\$[A-Za-z_][A-Za-z0-9_]*/) { $position += length $&; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 16 | elsif (_starts_quote($rest)) { $position += length _quote($rest); } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 3 | elsif ($char =~ /[([{]/) { $position += length _group($rest); } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 23 | elsif ($rest =~ /\A[\p{L}_][\p{L}\p{N}_]*/) { $position += length $&; } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 57 | else { ++$position; } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 3 | _fail('unclosed container'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | # Split only at the requested top-level separator. Perl expressions enclosed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | # in parentheses are opaque: this scanner never compiles or evaluates them. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 111 | ▶ | sub _split { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_split: called CC=8 SCAR=20.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 111 | my ($text, $separator) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 111 | my @parts; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 111 | my ($start, $position) = (0, 0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 111 | ▶ | while ($position < length $text) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 621 | my $rest = substr($text, $position); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 621 | my $char = substr($rest, 0, 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 621 | ▶ | if ($rest =~ /\A\$[A-Za-z_][A-Za-z0-9_]*/) { $position += length $&; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 6 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 47 | elsif (_starts_quote($rest)) { $position += length _quote($rest); } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | elsif ($char =~ /[([{]/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 30 | $position += length _group($rest); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | elsif ($char =~ /[)\]}]/) { _fail('unexpected closing delimiter'); } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | elsif (substr($rest, 0, length $separator) eq $separator) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 93 | push @parts, substr($text, $start, $position - $start); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 93 | $position += length $separator; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 93 | $start = $position; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 153 | elsif ($rest =~ /\A[\p{L}_][\p{L}\p{N}_]*/) { $position += length $&; } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 294 | else { ++$position; } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 102 | push @parts, substr($text, $start); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 102 | return @parts; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 108 | ▶ | sub _value { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_value: called CC=14 SCAR=26.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 108 | my ($text) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 108 | $text = _trim($text); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 108 | ▶ | _fail('a value is missing') unless length $text; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 107 | ▶ | return 'undef' if $text eq 'undef'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 106 | ▶ | return "'$text'" if $text =~ /\A[\p{L}_][\p{L}\p{N}_]*\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 55 | ▶ | return $text if $text =~ /\A[+-]?(?:(?:0|[1-9][0-9]*)(?:\.[0-9]*)?|\.[0-9]+)(?:[eE][+-]?[0-9]+)?\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 48 | ▶ | return $text if $text =~ /\A\$[A-Za-z_][A-Za-z0-9_]*\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 45 | ▶ | if (_starts_quote($text)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 25 | my $quote = _quote($text); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 25 | ▶ | return $quote if _trim(substr($text, length $quote)) eq ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | _fail('a quoted value must occupy the whole item'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 20 | ▶ | if ($text =~ /\A[([{]/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 13 | my $group = _group($text); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 13 | my $rest = substr($text, length $group); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 13 | ▶ | _fail('a container or parenthesized expression must occupy the whole item') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
defined $group and length $group and _trim($rest) eq ""
defined $group and length $group
MC/DC33%1/3
defined $group and length $group and _trim($rest) eq ""
defined $group
length $group
_trim($rest) eq ""
Truth table50%2/4
A and B and C
A= defined $groupB= length $groupC= _trim($rest) eq ""
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | unless defined $group && length $group && _trim($rest) eq ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 12 | my $open = substr($group, 0, 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 12 | ▶ | return $group if $open eq '('; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 5 | my $body = substr($group, 1, length($group) - 2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 5 | ▶ | return '[' . _array($body) . ']' if $open eq '['; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 2 | return '{' . _hash($body) . '}'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 7 | _fail("cannot read value '$text'; quote literal text or parenthesize a Perl expression"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 56 | ▶ | sub _items { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_items: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 56 | my ($text) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 56 | ▶ | return () unless length _trim($text); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 52 | my @items = _split($text, ','); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 50 | ▶ | pop @items if @items > 1 && _trim($items[-1]) eq ''; # One trailing comma. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@items > 1 and _trim($items[-1]) eq ""
MC/DC100%2/2
@items > 1 and _trim($items[-1]) eq ""
@items > 1
_trim($items[-1]) eq ""
Truth table100%3/3
A and B
A= @items > 1B= _trim($items[-1]) eq ""
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 50 | ▶ | _fail('a value is missing between commas') if grep { _trim($_) eq '' } @items; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 48 | return @items; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 39 | ▶ | sub _array { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_array: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 39 | my ($text) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 39 | return join ', ', map { _value($_) } _items($text); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 17 | ▶ | sub _hash { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_hash: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 17 | my ($text) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 17 | my @pairs; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 17 | for my $item (_items($text)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 24 | my @pair = _split($item, '=>'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 24 | ▶ | _fail('each hash item needs exactly one key => value pair') unless @pair == 2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 22 | ▶ | _fail('hash keys cannot be container literals') if _trim($pair[0]) =~ /\A[\[{]/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | # A pair always has one key and one value. Arrays belong in [...]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | # parenthesized expressions in these two positions use scalar context. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 21 | push @pairs, 'scalar(' . _value($pair[0]) . ') => scalar(' . _value($pair[1]) . ')'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 13 | return join ', ', @pairs; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 63 | ▶ | sub _definition { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_definition: called CC=8 SCAR=20.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 63 | my ($type, $name, $body) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 63 | ▶ | if ($type eq 's') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 12 | ▶ | _fail('a function body is missing; try E s name return expression') unless $body =~ /\S/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 11 | ▶ | _fail("'$name' is a Perl keyword; choose another function name") if perl_keyword($name); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 10 | return "sub $name {\n$body\n}"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 51 | ▶ | return '@' . $name . ' = (' . _array($body) . ');' if $type eq 'a'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 22 | ▶ | return '$' . $name . ' = [' . _array($body) . '];' if $type eq 'ar'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 15 | ▶ | return '%' . $name . ' = (' . _hash($body) . ');' if $type eq 'h'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 6 | ▶ | return '$' . $name . ' = {' . _hash($body) . '};' if $type eq 'hr'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | die "Unknown internal shorthand type\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 744 | ▶ | sub explicit { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
explicit: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 744 | my ($class, $line) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 744 | ▶ | return unless $line =~ /\A\s*E(!?)\s+(s|a|ar|h|hr)(?=\s|\z)(.*)\z/s; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 58 | my ($force, $type, $tail) = ($1, $2, $3); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 58 | ▶ | $tail =~ s/;\s*\z// if $type ne 's'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 58 | ▶ | _fail("$type needs a plain destination name, without a sigil") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | unless $tail =~ /\A\s+([A-Za-z_][A-Za-z0-9_]*)(?:\s+(.*))?\z/s; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 52 | ▶ | my ($name, $body) = ($1, defined $2 ? $2 : ''); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 52 | return { code=>_definition($type, $name, $body), type=>$type, name=>$name, force=>$force, label=>'E' }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 421 | ▶ | sub _implicit_candidate { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_implicit_candidate: called CC=8 SCAR=20.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 421 | my ($line, $is_function) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 421 | ▶ | return unless $line =~ /\A\s*([a-z_][A-Za-z0-9_]*)(!?)\s+(.+)\z/s; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 161 | my ($name, $force, $body) = ($1, $2, $3); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 161 | ▶ | return if perl_keyword($name) || (!$force && $is_function && $is_function->($name)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%9/9
perl_keyword($name) or not $force and $is_function and &$is_function($name)
not $force and $is_function and &$is_function($name)
not $force and $is_function
MC/DC100%4/4
perl_keyword($name) or not $force and $is_function and &$is_function($name)
perl_keyword($name)
not $force
$is_function
&$is_function($name)
Truth table100%5/5
A or not(B) and C and D
A= perl_keyword($name)B= not $forceC= $is_functionD= &$is_function($name)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 18 | ▶ | return if $body =~ /\A=>/; # Perl's autoquoted hash key, not a destination. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 17 | ▶ | return unless $body =~ /,|=>/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 15 | return ($name, $body, $force); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 237 | ▶ | sub implicit { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
implicit: called CC=5 SCAR=16.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 237 | my ($class, $line, $is_function) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 237 | my ($name, $body, $force) = _implicit_candidate($line, $is_function); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 237 | ▶ | return unless defined $name; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 11 | $body =~ s/;\s*\z//; # One optional statement terminator, outside the values. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 11 | my @commas = _split($body, ','); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 11 | my @arrows = _split($body, '=>'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 11 | ▶ | return unless @commas > 1 || @arrows > 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@commas > 1 or @arrows > 1
MC/DC0%0/2
@commas > 1 or @arrows > 1
@commas > 1
@arrows > 1
Truth table33%1/3
A or B
A= @commas > 1B= @arrows > 1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 11 | ▶ | my $type = @arrows > 1 ? 'h' : 'a'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 11 | return { code=>_definition($type, $name, $body), type=>$type, name=>$name, force=>$force, label=>$name }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 193 | ▶ | sub needs_more { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
needs_more: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 193 | my ($class, $line, $is_function) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 193 | my $body; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 193 | ▶ | if ($line =~ /\A\s*E!?\s+(?:a|ar|h|hr)\s+[A-Za-z_][A-Za-z0-9_]*\s+(.*)\z/s) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 9 | $body = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 184 | else { (undef, $body) = _implicit_candidate($line, $is_function); } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 193 | ▶ | return unless defined $body; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 13 | local $@; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 13 | my $ok = eval { _split($body, ','); 1 }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 13 | ▶ | return !$ok && $@ =~ /unclosed/ ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not $ok and $@ =~ /unclosed/u
MC/DC100%2/2
not $ok and $@ =~ /unclosed/u
not $ok
$@ =~ /unclosed/u
Truth table100%3/3
not(A) and B
A= not $okB= $@ =~ /unclosed/u
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 25 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||