| 1 | package String::Approx; | ||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||
| 3 | 7 | require v5.8.0; | |||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||
| 5 | 7 | $VERSION = '3.28'; | |||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||
| 7 | 7 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 8 | 7 | local $^W = 1; | |||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||
| 10 | 7 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 11 | 7 | ▶ | use vars qw($VERSION @ISA @EXPORT @EXPORT_OK); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||
| 13 | 7 | require Exporter; | |||||||||||||||||||||||||||||||||||||
| 14 | 7 | require DynaLoader; | |||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||
| 16 | 7 | @ISA = qw(Exporter DynaLoader); | |||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||
| 18 | 7 | @EXPORT_OK = qw(amatch asubstitute aindex aslice arindex | |||||||||||||||||||||||||||||||||||||
| 19 | adist adistr adistword adistrword); | ||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||
| 21 | 7 | bootstrap String::Approx $VERSION; | |||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||
| 23 | 7 | my $CACHE_MAX = 1000; # high water mark | |||||||||||||||||||||||||||||||||||||
| 24 | 7 | my $CACHE_PURGE = 0.75; # purge this much of the least used | |||||||||||||||||||||||||||||||||||||
| 25 | 7 | my $CACHE_N_PURGE; # purge this many of the least used | |||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||
| 27 | 7 | ▶ | sub cache_n_purge () { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
cache_n_purge: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 28 | 7 | $CACHE_N_PURGE = $CACHE_MAX * $CACHE_PURGE; | |||||||||||||||||||||||||||||||||||||
| 29 | 7 | ▶ | $CACHE_N_PURGE = 1 if $CACHE_N_PURGE < 1; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 30 | 7 | return $CACHE_N_PURGE; | |||||||||||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||
| 33 | 7 | cache_n_purge(); | |||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||
| 35 | 0 | ▶ | sub cache_max (;$) { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
cache_max: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 36 | 0 | ▶ | if (@_ == 0) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 37 | 0 | return $CACHE_MAX; | |||||||||||||||||||||||||||||||||||||
| 38 | } else { | ||||||||||||||||||||||||||||||||||||||
| 39 | 0 | $CACHE_MAX = shift; | |||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||
| 41 | 0 | ▶ | $CACHE_MAX = 0 if $CACHE_MAX < 0; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 42 | 0 | cache_n_purge(); | |||||||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||
| 45 | 0 | ▶ | sub cache_purge (;$) { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
cache_purge: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 46 | 0 | ▶ | if (@_ == 0) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 47 | 0 | return $CACHE_PURGE; | |||||||||||||||||||||||||||||||||||||
| 48 | } else { | ||||||||||||||||||||||||||||||||||||||
| 49 | 0 | $CACHE_PURGE = shift; | |||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||
| 51 | 0 | ▶ | if ($CACHE_PURGE < 0) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||
| 52 | 0 | $CACHE_PURGE = 0; | |||||||||||||||||||||||||||||||||||||
| 53 | } elsif ($CACHE_PURGE > 1) { | ||||||||||||||||||||||||||||||||||||||
| 54 | 0 | $CACHE_PURGE = 1; | |||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||
| 56 | 0 | cache_n_purge(); | |||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||
| 59 | 7 | my %_simple; | |||||||||||||||||||||||||||||||||||||
| 60 | my %_simple_usage_count; | ||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||
| 62 | 0 | ▶ | sub _cf_simple { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_cf_simple: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||
| 63 | 0 | my $P = shift; | |||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||
| 65 | my @usage = | ||||||||||||||||||||||||||||||||||||||
| 66 | 0 | sort { $_simple_usage_count{$a} <=> $_simple_usage_count{$b} } | |||||||||||||||||||||||||||||||||||||
| 67 | 0 | grep { $_ ne $P } | |||||||||||||||||||||||||||||||||||||
| 68 | keys %_simple_usage_count; | ||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||
| 70 | # Make room, delete the least used entries. | ||||||||||||||||||||||||||||||||||||||
| 71 | 0 | $#usage = $CACHE_N_PURGE - 1; | |||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||
| 73 | 0 | delete @_simple_usage_count{@usage}; | |||||||||||||||||||||||||||||||||||||
| 74 | 0 | delete @_simple{@usage}; | |||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||
| 77 | 41 | ▶ | sub _simple { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_simple: called CC=4 SCAR=14.2
| |||||||||||||||||||||||||||||||||||||||
| 78 | 41 | my $P = shift; | |||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||
| 80 | 41 | my $_simple = new(__PACKAGE__, $P); | |||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||
| 82 | 41 | ▶ | if ($CACHE_MAX) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 83 | 41 | ▶ | $_simple{$P} = $_simple unless exists $_simple{$P}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||
| 85 | 41 | $_simple_usage_count{$P}++; | |||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||
| 87 | 41 | ▶ | if (keys %_simple_usage_count > $CACHE_MAX) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 88 | 0 | _cf_simple($P); | |||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||
| 92 | 41 | return ( $_simple ); | |||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||
| 95 | 44 | ▶ | sub _parse_param { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_parse_param: called CC=14 SCAR=26.6
| |||||||||||||||||||||||||||||||||||||||
| 96 | 7 | ▶ | use integer; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||
| 98 | 44 | my ($n, @param) = @_; | |||||||||||||||||||||||||||||||||||||
| 99 | 44 | my %param; | |||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||
| 101 | 44 | foreach (@param) { | |||||||||||||||||||||||||||||||||||||
| 102 | 52 | ▶ | while ($_ ne '') { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 103 | 58 | s/^\s+//; | |||||||||||||||||||||||||||||||||||||
| 104 | 58 | ▶ | if (s/^([IDS]\s*)?(\d+)(\s*%)?//) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 8 branches
| |||||||||||||||||||||||||||||||||||||||
| 105 | 33 | ▶ | my $k = defined $3 ? (($2-1) * $n) / 100 + ($2 ? 1 : 0) : $2; | ||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||
| 107 | 33 | ▶ | if (defined $1) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 108 | 14 | $param{$1} = $k; | |||||||||||||||||||||||||||||||||||||
| 109 | } else { | ||||||||||||||||||||||||||||||||||||||
| 110 | 19 | $param{k} = $k; | |||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||
| 112 | } elsif (s/^initial_position\W+(\d+)\b//) { | ||||||||||||||||||||||||||||||||||||||
| 113 | 5 | $param{'initial_position'} = $1; | |||||||||||||||||||||||||||||||||||||
| 114 | } elsif (s/^final_position\W+(\d+)\b//) { | ||||||||||||||||||||||||||||||||||||||
| 115 | 4 | $param{'final_position'} = $1; | |||||||||||||||||||||||||||||||||||||
| 116 | } elsif (s/^position_range\W+(\d+)\b//) { | ||||||||||||||||||||||||||||||||||||||
| 117 | 0 | $param{'position_range'} = $1; | |||||||||||||||||||||||||||||||||||||
| 118 | } elsif (s/^minimal_distance\b//) { | ||||||||||||||||||||||||||||||||||||||
| 119 | 5 | $param{'minimal_distance'} = 1; | |||||||||||||||||||||||||||||||||||||
| 120 | } elsif (s/^i//) { | ||||||||||||||||||||||||||||||||||||||
| 121 | 7 | $param{ i } = 1; | |||||||||||||||||||||||||||||||||||||
| 122 | } elsif (s/^g//) { | ||||||||||||||||||||||||||||||||||||||
| 123 | 3 | $param{ g } = 1; | |||||||||||||||||||||||||||||||||||||
| 124 | } elsif (s/^\?//) { | ||||||||||||||||||||||||||||||||||||||
| 125 | 1 | $param{'?'} = 1; | |||||||||||||||||||||||||||||||||||||
| 126 | } else { | ||||||||||||||||||||||||||||||||||||||
| 127 | 0 | warn "unknown parameter: '$_'\n"; | |||||||||||||||||||||||||||||||||||||
| 128 | 0 | return; | |||||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||
| 133 | 44 | return %param; | |||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||
| 136 | 7 | my %_param_key; | |||||||||||||||||||||||||||||||||||||
| 137 | 7 | my %_parsed_param; | |||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||
| 139 | 7 | my %_complex; | |||||||||||||||||||||||||||||||||||||
| 140 | 7 | my %_complex_usage_count; | |||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||
| 142 | 0 | ▶ | sub _cf_complex { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_cf_complex: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||
| 143 | 0 | my $P = shift; | |||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||
| 145 | my @usage = | ||||||||||||||||||||||||||||||||||||||
| 146 | sort { $_complex_usage_count{$a} <=> | ||||||||||||||||||||||||||||||||||||||
| 147 | 0 | $_complex_usage_count{$b} } | |||||||||||||||||||||||||||||||||||||
| 148 | 0 | grep { $_ ne $P } | |||||||||||||||||||||||||||||||||||||
| 149 | keys %_complex_usage_count; | ||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||
| 151 | # Make room, delete the least used entries. | ||||||||||||||||||||||||||||||||||||||
| 152 | 0 | $#usage = $CACHE_N_PURGE - 1; | |||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||
| 154 | 0 | delete @_complex_usage_count{@usage}; | |||||||||||||||||||||||||||||||||||||
| 155 | 0 | delete @_complex{@usage}; | |||||||||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||
| 158 | 84 | ▶ | sub _complex { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_complex: called CC=19 SCAR=29.5
| |||||||||||||||||||||||||||||||||||||||
| 159 | 84 | my ($P, @param) = @_; | |||||||||||||||||||||||||||||||||||||
| 160 | 84 | unshift @param, length $P; | |||||||||||||||||||||||||||||||||||||
| 161 | 84 | my $param = "@param"; | |||||||||||||||||||||||||||||||||||||
| 162 | 84 | my $_param_key; | |||||||||||||||||||||||||||||||||||||
| 163 | my %param; | ||||||||||||||||||||||||||||||||||||||
| 164 | 84 | my $complex; | |||||||||||||||||||||||||||||||||||||
| 165 | 84 | my $is_new; | |||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||
| 167 | 84 | ▶ | unless (exists $_param_key{$param}) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 168 | 44 | %param = _parse_param(@param); | |||||||||||||||||||||||||||||||||||||
| 169 | 44 | $_parsed_param{$param} = { %param }; | |||||||||||||||||||||||||||||||||||||
| 170 | 44 | $_param_key{$param} = join(" ", %param); | |||||||||||||||||||||||||||||||||||||
| 171 | } else { | ||||||||||||||||||||||||||||||||||||||
| 172 | 40 | %param = %{ $_parsed_param{$param} }; | |||||||||||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||
| 175 | 84 | $_param_key = $_param_key{$param}; | |||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||
| 177 | 84 | ▶ | if ($CACHE_MAX) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 178 | 84 | ▶ | if (exists $_complex{$P}->{$_param_key}) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 179 | 37 | $complex = $_complex{$P}->{$_param_key}; | |||||||||||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||
| 183 | 84 | ▶ | unless (defined $complex) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 184 | 47 | ▶ | if (exists $param{'k'}) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 185 | 19 | $complex = new(__PACKAGE__, $P, $param{k}); | |||||||||||||||||||||||||||||||||||||
| 186 | } else { | ||||||||||||||||||||||||||||||||||||||
| 187 | 28 | $complex = new(__PACKAGE__, $P); | |||||||||||||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||||||||||||
| 189 | 47 | ▶ | $_complex{$P}->{$_param_key} = $complex if $CACHE_MAX; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 190 | 47 | $is_new = 1; | |||||||||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||
| 193 | 84 | ▶ | if ($is_new) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 194 | 47 | ▶ | $complex->set_greedy unless exists $param{'?'}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||
| 196 | $complex->set_insertions($param{'I'}) | ||||||||||||||||||||||||||||||||||||||
| 197 | 47 | ▶ | if exists $param{'I'}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 198 | $complex->set_deletions($param{'D'}) | ||||||||||||||||||||||||||||||||||||||
| 199 | 47 | ▶ | if exists $param{'D'}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 200 | $complex->set_substitutions($param{'S'}) | ||||||||||||||||||||||||||||||||||||||
| 201 | 47 | ▶ | if exists $param{'S'}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||
| 203 | $complex->set_caseignore_slice | ||||||||||||||||||||||||||||||||||||||
| 204 | 47 | ▶ | if exists $param{'i'}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||
| 206 | $complex->set_text_initial_position($param{'initial_position'}) | ||||||||||||||||||||||||||||||||||||||
| 207 | 47 | ▶ | if exists $param{'initial_position'}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||
| 209 | $complex->set_text_final_position($param{'final_position'}) | ||||||||||||||||||||||||||||||||||||||
| 210 | 47 | ▶ | if exists $param{'final_position'}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||
| 212 | $complex->set_text_position_range($param{'position_range'}) | ||||||||||||||||||||||||||||||||||||||
| 213 | 47 | ▶ | if exists $param{'position_range'}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||
| 215 | $complex->set_minimal_distance($param{'minimal_distance'}) | ||||||||||||||||||||||||||||||||||||||
| 216 | 47 | ▶ | if exists $param{'minimal_distance'}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||
| 219 | 84 | ▶ | if ($CACHE_MAX) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 220 | 84 | $_complex_usage_count{$P}->{$_param_key}++; | |||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||
| 222 | # If our cache overfloweth. | ||||||||||||||||||||||||||||||||||||||
| 223 | 84 | ▶ | if (scalar keys %_complex_usage_count > $CACHE_MAX) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 224 | 0 | _cf_complex($P); | |||||||||||||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||
| 228 | 84 | return ( $complex, %param ); | |||||||||||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||
| 231 | 0 | ▶ | sub cache_disable { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
cache_disable: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 232 | 0 | cache_max(0); | |||||||||||||||||||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||||
| 235 | 0 | ▶ | sub cache_flush_all { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
cache_flush_all: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 236 | 0 | my $old_purge = cache_purge(); | |||||||||||||||||||||||||||||||||||||
| 237 | 0 | cache_purge(1); | |||||||||||||||||||||||||||||||||||||
| 238 | 0 | _cf_simple(''); | |||||||||||||||||||||||||||||||||||||
| 239 | 0 | _cf_complex(''); | |||||||||||||||||||||||||||||||||||||
| 240 | 0 | cache_purge($old_purge); | |||||||||||||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||
| 243 | 48 | ▶ | sub amatch { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
amatch: called CC=13 SCAR=25.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 244 | 48 | my $P = shift; | |||||||||||||||||||||||||||||||||||||
| 245 | 48 | ▶ | return 1 unless length $P; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 246 | my $a = ((@_ && ref $_[0] eq 'ARRAY') ? | ||||||||||||||||||||||||||||||||||||||
| 247 | 45 | ▶ | _complex($P, @{ shift(@_) }) : _simple($P))[0]; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@_ and ref $_[0] eq "ARRAY"
MC/DC100%2/2
@_ and ref $_[0] eq "ARRAY"
@_
ref $_[0] eq "ARRAY"
Truth table100%3/3
A and B
A= @_B= ref $_[0] eq "ARRAY"
| |||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||
| 249 | 45 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 250 | 41 | ▶ | if (wantarray) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 251 | 12 | return grep { $a->match($_) } @_; | |||||||||||||||||||||||||||||||||||||
| 252 | } else { | ||||||||||||||||||||||||||||||||||||||
| 253 | 29 | foreach (@_) { | |||||||||||||||||||||||||||||||||||||
| 254 | 29 | ▶ | return 1 if $a->match($_); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||||||||||||
| 256 | 8 | return 0; | |||||||||||||||||||||||||||||||||||||
| 257 | } | ||||||||||||||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||||||||||||
| 259 | 4 | ▶ | if (defined $_) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 260 | 3 | ▶ | if (wantarray) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 261 | 0 | ▶ | return $a->match($_) ? $_ : undef; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 262 | } else { | ||||||||||||||||||||||||||||||||||||||
| 263 | 3 | ▶ | return 1 if $a->match($_); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||||||||||||
| 266 | 3 | ▶ | return $a->match($_) if defined $_; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||
| 268 | 1 | warn "amatch: \$_ is undefined: what are you matching?\n"; | |||||||||||||||||||||||||||||||||||||
| 269 | 1 | return; | |||||||||||||||||||||||||||||||||||||
| 270 | } | ||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||
| 272 | 117 | ▶ | sub _find_substitute { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_find_substitute: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 273 | 117 | my ($ri, $rs, $i, $s, $S, $rn) = @_; | |||||||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||||||
| 275 | 117 | push @{ $ri }, $i; | |||||||||||||||||||||||||||||||||||||
| 276 | 117 | push @{ $rs }, $s; | |||||||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||||||||
| 278 | 117 | my $pre = substr($_, 0, $i); | |||||||||||||||||||||||||||||||||||||
| 279 | 117 | my $old = substr($_, $i, $s); | |||||||||||||||||||||||||||||||||||||
| 280 | 117 | my $suf = substr($_, $i + $s); | |||||||||||||||||||||||||||||||||||||
| 281 | 117 | my $new = $S; | |||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||
| 283 | 117 | $new =~ s/\$\`/$pre/g; | |||||||||||||||||||||||||||||||||||||
| 284 | 117 | $new =~ s/\$\&/$old/g; | |||||||||||||||||||||||||||||||||||||
| 285 | 117 | $new =~ s/\$\'/$suf/g; | |||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||
| 287 | 117 | push @{ $rn }, $new; | |||||||||||||||||||||||||||||||||||||
| 288 | } | ||||||||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||||||||
| 290 | 116 | ▶ | sub _do_substitute { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_do_substitute: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||
| 291 | 116 | my ($rn, $ri, $rs, $rS) = @_; | |||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||
| 293 | 116 | my $d = 0; | |||||||||||||||||||||||||||||||||||||
| 294 | 116 | my $n = $_; | |||||||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||||||||
| 296 | 116 | foreach my $i (0..$#$rn) { | |||||||||||||||||||||||||||||||||||||
| 297 | 117 | substr($n, $ri->[$i] + $d, $rs->[$i]) = $rn->[$i]; | |||||||||||||||||||||||||||||||||||||
| 298 | 117 | $d += length($rn->[$i]) - $rs->[$i]; | |||||||||||||||||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||||||
| 301 | 116 | push @{ $rS }, $n; | |||||||||||||||||||||||||||||||||||||
| 302 | } | ||||||||||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||||||||||
| 304 | 11 | ▶ | sub asubstitute { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
asubstitute: called CC=17 SCAR=29.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 305 | 11 | my $P = shift; | |||||||||||||||||||||||||||||||||||||
| 306 | 11 | my $S = shift; | |||||||||||||||||||||||||||||||||||||
| 307 | my ($a, %p) = | ||||||||||||||||||||||||||||||||||||||
| 308 | (@_ && ref $_[0] eq 'ARRAY') ? | ||||||||||||||||||||||||||||||||||||||
| 309 | 11 | ▶ | _complex($P, @{ shift(@_) }) : _simple($P); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@_ and ref $_[0] eq "ARRAY"
MC/DC100%2/2
@_ and ref $_[0] eq "ARRAY"
@_
ref $_[0] eq "ARRAY"
Truth table100%3/3
A and B
A= @_B= ref $_[0] eq "ARRAY"
| |||||||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||||||
| 311 | 11 | my ($i, $s, @i, @s, @n, @S); | |||||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||||||
| 313 | 11 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||
| 314 | 9 | ▶ | if (exists $p{ g }) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 315 | 1 | foreach (@_) { | |||||||||||||||||||||||||||||||||||||
| 316 | 29 | @s = @i = @n = (); | |||||||||||||||||||||||||||||||||||||
| 317 | 29 | ▶ | while (($i, $s) = $a->slice_next($_)) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 318 | 12 | ▶ | if (defined $i) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 319 | 12 | _find_substitute(\@i, \@s, $i, $s, $S, \@n); | |||||||||||||||||||||||||||||||||||||
| 320 | } | ||||||||||||||||||||||||||||||||||||||
| 321 | } | ||||||||||||||||||||||||||||||||||||||
| 322 | 29 | ▶ | _do_substitute(\@n, \@i, \@s, \@S) if @n; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 323 | } | ||||||||||||||||||||||||||||||||||||||
| 324 | } else { | ||||||||||||||||||||||||||||||||||||||
| 325 | 8 | foreach (@_) { | |||||||||||||||||||||||||||||||||||||
| 326 | 232 | @s = @i = @n = (); | |||||||||||||||||||||||||||||||||||||
| 327 | 232 | ($i, $s) = $a->slice($_); | |||||||||||||||||||||||||||||||||||||
| 328 | 232 | ▶ | if (defined $i) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 329 | 104 | _find_substitute(\@i, \@s, $i, $s, $S, \@n); | |||||||||||||||||||||||||||||||||||||
| 330 | 104 | _do_substitute(\@n, \@i, \@s, \@S); | |||||||||||||||||||||||||||||||||||||
| 331 | } | ||||||||||||||||||||||||||||||||||||||
| 332 | } | ||||||||||||||||||||||||||||||||||||||
| 333 | } | ||||||||||||||||||||||||||||||||||||||
| 334 | 9 | return @S; | |||||||||||||||||||||||||||||||||||||
| 335 | } elsif (defined $_) { | ||||||||||||||||||||||||||||||||||||||
| 336 | 1 | ▶ | if (exists $p{ g }) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 337 | 0 | ▶ | while (($i, $s) = $a->slice_next($_)) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 338 | 0 | ▶ | if (defined $i) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 339 | 0 | _find_substitute(\@i, \@s, $i, $s, $S, \@n); | |||||||||||||||||||||||||||||||||||||
| 340 | } | ||||||||||||||||||||||||||||||||||||||
| 341 | } | ||||||||||||||||||||||||||||||||||||||
| 342 | 0 | ▶ | _do_substitute(\@n, \@i, \@s, \@S) if @n; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 343 | } else { | ||||||||||||||||||||||||||||||||||||||
| 344 | 1 | ($i, $s) = $a->slice($_); | |||||||||||||||||||||||||||||||||||||
| 345 | 1 | ▶ | if (defined $i) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 346 | 1 | _find_substitute(\@i, \@s, $i, $s, $S, \@n); | |||||||||||||||||||||||||||||||||||||
| 347 | 1 | _do_substitute(\@n, \@i, \@s, \@S); | |||||||||||||||||||||||||||||||||||||
| 348 | } | ||||||||||||||||||||||||||||||||||||||
| 349 | } | ||||||||||||||||||||||||||||||||||||||
| 350 | 1 | return $_ = $n[0]; | |||||||||||||||||||||||||||||||||||||
| 351 | } else { | ||||||||||||||||||||||||||||||||||||||
| 352 | 1 | warn "asubstitute: \$_ is undefined: what are you substituting?\n"; | |||||||||||||||||||||||||||||||||||||
| 353 | 1 | return; | |||||||||||||||||||||||||||||||||||||
| 354 | } | ||||||||||||||||||||||||||||||||||||||
| 355 | } | ||||||||||||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||||||||||||
| 357 | 23 | ▶ | sub aindex { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
aindex: called CC=7 SCAR=22.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 358 | 23 | my $P = shift; | |||||||||||||||||||||||||||||||||||||
| 359 | 23 | ▶ | return 0 unless length $P; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 360 | my $a = ((@_ && ref $_[0] eq 'ARRAY') ? | ||||||||||||||||||||||||||||||||||||||
| 361 | 21 | ▶ | _complex($P, @{ shift(@_) }) : _simple($P))[0]; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@_ and ref $_[0] eq "ARRAY"
MC/DC50%1/2
@_ and ref $_[0] eq "ARRAY"
@_
ref $_[0] eq "ARRAY"
Truth table66%2/3
A and B
A= @_B= ref $_[0] eq "ARRAY"
| |||||||||||||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||||||||||||
| 363 | 21 | $a->set_greedy; # The *first* match, thank you. | |||||||||||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||||||||||||
| 365 | 21 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 366 | 21 | ▶ | if (wantarray) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 367 | 0 | return map { $a->index($_) } @_; | |||||||||||||||||||||||||||||||||||||
| 368 | } else { | ||||||||||||||||||||||||||||||||||||||
| 369 | 21 | return $a->index($_[0]); | |||||||||||||||||||||||||||||||||||||
| 370 | } | ||||||||||||||||||||||||||||||||||||||
| 371 | } | ||||||||||||||||||||||||||||||||||||||
| 372 | 0 | ▶ | return $a->index($_) if defined $_; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||||||||
| 374 | 0 | warn "aindex: \$_ is undefined: what are you indexing?\n"; | |||||||||||||||||||||||||||||||||||||
| 375 | 0 | return; | |||||||||||||||||||||||||||||||||||||
| 376 | } | ||||||||||||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||||||||||
| 378 | 45 | ▶ | sub aslice { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
aslice: called CC=6 SCAR=20.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 379 | 45 | my $P = shift; | |||||||||||||||||||||||||||||||||||||
| 380 | 45 | ▶ | return (0, 0) unless length $P; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 381 | my $a = ((@_ && ref $_[0] eq 'ARRAY') ? | ||||||||||||||||||||||||||||||||||||||
| 382 | 45 | ▶ | _complex($P, @{ shift(@_) }) : _simple($P))[0]; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@_ and ref $_[0] eq "ARRAY"
MC/DC50%1/2
@_ and ref $_[0] eq "ARRAY"
@_
ref $_[0] eq "ARRAY"
Truth table66%2/3
A and B
A= @_B= ref $_[0] eq "ARRAY"
| |||||||||||||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||||||||||||
| 384 | 45 | $a->set_greedy; # The *first* match, thank you. | |||||||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||||||||
| 386 | 45 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 387 | 45 | return map { [ $a->slice($_) ] } @_; | |||||||||||||||||||||||||||||||||||||
| 388 | } | ||||||||||||||||||||||||||||||||||||||
| 389 | 0 | ▶ | return $a->slice($_) if defined $_; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||||||||||||
| 391 | 0 | warn "aslice: \$_ is undefined: what are you slicing?\n"; | |||||||||||||||||||||||||||||||||||||
| 392 | 0 | return; | |||||||||||||||||||||||||||||||||||||
| 393 | } | ||||||||||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||||||||
| 395 | 39 | ▶ | sub _adist { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_adist: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||
| 396 | 39 | my $s0 = shift; | |||||||||||||||||||||||||||||||||||||
| 397 | 39 | my $s1 = shift; | |||||||||||||||||||||||||||||||||||||
| 398 | 39 | my ($aslice) = aslice($s0, ['minimal_distance', @_], $s1); | |||||||||||||||||||||||||||||||||||||
| 399 | 39 | my ($index, $size, $distance) = @$aslice; | |||||||||||||||||||||||||||||||||||||
| 400 | 39 | my ($l0, $l1) = map { length } ($s0, $s1); | |||||||||||||||||||||||||||||||||||||
| 401 | 39 | ▶ | return $l0 <= $l1 ? $distance : -$distance; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 402 | } | ||||||||||||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||||||||||||
| 404 | 19 | ▶ | sub adist { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
adist: called CC=8 SCAR=20.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 405 | 19 | my $a0 = shift; | |||||||||||||||||||||||||||||||||||||
| 406 | 19 | my $a1 = shift; | |||||||||||||||||||||||||||||||||||||
| 407 | 19 | ▶ | if (length($a0) == 0) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 408 | 2 | return length($a1); | |||||||||||||||||||||||||||||||||||||
| 409 | } | ||||||||||||||||||||||||||||||||||||||
| 410 | 17 | ▶ | if (length($a1) == 0) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 411 | 2 | return length($a0); | |||||||||||||||||||||||||||||||||||||
| 412 | } | ||||||||||||||||||||||||||||||||||||||
| 413 | 0 | ▶ | my @m = ref $_[0] eq 'ARRAY' ? @{shift()} : (); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 414 | 15 | ▶ | if (ref $a0 eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||
| 415 | 6 | ▶ | if (ref $a1 eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 416 | 1 | return [ map { adist($a0, $_, @m) } @{$a1} ]; | |||||||||||||||||||||||||||||||||||||
| 417 | } else { | ||||||||||||||||||||||||||||||||||||||
| 418 | 5 | return [ map { _adist($_, $a1, @m) } @{$a0} ]; | |||||||||||||||||||||||||||||||||||||
| 419 | } | ||||||||||||||||||||||||||||||||||||||
| 420 | } elsif (ref $a1 eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||
| 421 | 1 | return [ map { _adist($a0, $_, @m) } @{$a1} ]; | |||||||||||||||||||||||||||||||||||||
| 422 | } else { | ||||||||||||||||||||||||||||||||||||||
| 423 | 8 | ▶ | if (wantarray) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 424 | 1 | return map { _adist($a0, $_, @m) } ($a1, @_); | |||||||||||||||||||||||||||||||||||||
| 425 | } else { | ||||||||||||||||||||||||||||||||||||||
| 426 | 7 | return _adist($a0, $a1, @m); | |||||||||||||||||||||||||||||||||||||
| 427 | } | ||||||||||||||||||||||||||||||||||||||
| 428 | } | ||||||||||||||||||||||||||||||||||||||
| 429 | } | ||||||||||||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||||||||||||
| 431 | 4 | ▶ | sub adistr { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
adistr: called CC=11 SCAR=36.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 432 | 4 | my $a0 = shift; | |||||||||||||||||||||||||||||||||||||
| 433 | 4 | my $a1 = shift; | |||||||||||||||||||||||||||||||||||||
| 434 | 4 | ▶ | my @m = ref $_[0] eq 'ARRAY' ? shift : (); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 435 | 4 | ▶ | if (ref $a0 eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||
| 436 | 0 | ▶ | if (ref $a1 eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 437 | 0 | my $l0 = length(); | |||||||||||||||||||||||||||||||||||||
| 438 | 0 | return $l0 ? [ map { adist($a0, $_, @m) } | |||||||||||||||||||||||||||||||||||||
| 439 | 0 | ▶ | @{$a1} ] : | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 440 | [ ]; | ||||||||||||||||||||||||||||||||||||||
| 441 | } else { | ||||||||||||||||||||||||||||||||||||||
| 442 | 0 | return [ map { my $l0 = length(); | |||||||||||||||||||||||||||||||||||||
| 443 | 0 | ▶ | $l0 ? _adist($_, $a1, @m) / $l0 : undef | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 444 | 0 | } @{$a0} ]; | |||||||||||||||||||||||||||||||||||||
| 445 | } | ||||||||||||||||||||||||||||||||||||||
| 446 | } elsif (ref $a1 eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||
| 447 | 0 | my $l0 = length($a0); | |||||||||||||||||||||||||||||||||||||
| 448 | 0 | ▶ | return [] unless $l0; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 449 | 0 | return [ map { _adist($a0, $_, @m) / $l0 } @{$a1} ]; | |||||||||||||||||||||||||||||||||||||
| 450 | } else { | ||||||||||||||||||||||||||||||||||||||
| 451 | 4 | my $l0 = length($a0); | |||||||||||||||||||||||||||||||||||||
| 452 | 4 | ▶ | if (wantarray) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 453 | 1 | ▶ | return map { $l0 ? _adist($a0, $_, @m) / $l0 : undef } ($a1, @_); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 454 | } else { | ||||||||||||||||||||||||||||||||||||||
| 455 | 3 | ▶ | return undef unless $l0; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 456 | 3 | return _adist($a0, $a1, @m) / $l0; | |||||||||||||||||||||||||||||||||||||
| 457 | } | ||||||||||||||||||||||||||||||||||||||
| 458 | } | ||||||||||||||||||||||||||||||||||||||
| 459 | } | ||||||||||||||||||||||||||||||||||||||
| 460 | |||||||||||||||||||||||||||||||||||||||
| 461 | 0 | ▶ | sub adistword { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
adistword: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 462 | 0 | return adist($_[0], $_[1], ['position_range=0']); | |||||||||||||||||||||||||||||||||||||
| 463 | } | ||||||||||||||||||||||||||||||||||||||
| 464 | |||||||||||||||||||||||||||||||||||||||
| 465 | 0 | ▶ | sub adistrword { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
adistrword: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 466 | 0 | return adistr($_[0], $_[1], ['position_range=0']); | |||||||||||||||||||||||||||||||||||||
| 467 | } | ||||||||||||||||||||||||||||||||||||||
| 468 | |||||||||||||||||||||||||||||||||||||||
| 469 | 3 | ▶ | sub arindex { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
arindex: called CC=10 SCAR=33.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 470 | 3 | my $P = shift; | |||||||||||||||||||||||||||||||||||||
| 471 | 3 | my $l = length $P; | |||||||||||||||||||||||||||||||||||||
| 472 | 3 | ▶ | return 0 unless $l; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 473 | 3 | my $R = reverse $P; | |||||||||||||||||||||||||||||||||||||
| 474 | my $a = ((@_ && ref $_[0] eq 'ARRAY') ? | ||||||||||||||||||||||||||||||||||||||
| 475 | 0 | ▶ | _complex($R, @{ shift(@_) }) : _simple($R))[0]; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@_ and ref $_[0] eq "ARRAY"
MC/DC0%0/2
@_ and ref $_[0] eq "ARRAY"
@_
ref $_[0] eq "ARRAY"
Truth table33%1/3
A and B
A= @_B= ref $_[0] eq "ARRAY"
| |||||||||||||||||||||||||||||||||||||||
| 476 | |||||||||||||||||||||||||||||||||||||||
| 477 | 3 | $a->set_greedy; # The *first* match, thank you. | |||||||||||||||||||||||||||||||||||||
| 478 | |||||||||||||||||||||||||||||||||||||||
| 479 | 3 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 480 | 3 | ▶ | if (wantarray) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 481 | return map { | ||||||||||||||||||||||||||||||||||||||
| 482 | 0 | my $aindex = $a->index(scalar reverse()); | |||||||||||||||||||||||||||||||||||||
| 483 | 0 | ▶ | $aindex == -1 ? $aindex : (length($_) - $aindex - $l); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 484 | } @_; | ||||||||||||||||||||||||||||||||||||||
| 485 | } else { | ||||||||||||||||||||||||||||||||||||||
| 486 | 3 | my $aindex = $a->index(scalar reverse $_[0]); | |||||||||||||||||||||||||||||||||||||
| 487 | 3 | ▶ | return $aindex == -1 ? $aindex : (length($_[0]) - $aindex - $l); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 488 | } | ||||||||||||||||||||||||||||||||||||||
| 489 | } | ||||||||||||||||||||||||||||||||||||||
| 490 | 0 | ▶ | if (defined $_) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 491 | 0 | my $aindex = $a->index(scalar reverse()); | |||||||||||||||||||||||||||||||||||||
| 492 | 0 | ▶ | return $aindex == -1 ? $aindex : (length($_) - $aindex - $l); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 493 | } | ||||||||||||||||||||||||||||||||||||||
| 494 | |||||||||||||||||||||||||||||||||||||||
| 495 | 0 | warn "arindex: \$_ is undefined: what are you indexing?\n"; | |||||||||||||||||||||||||||||||||||||
| 496 | 0 | return; | |||||||||||||||||||||||||||||||||||||
| 497 | } | ||||||||||||||||||||||||||||||||||||||
| 498 | |||||||||||||||||||||||||||||||||||||||
| 499 | 7 | 1; | |||||||||||||||||||||||||||||||||||||
| 500 | __END__ | ||||||||||||||||||||||||||||||||||||||