| 1 | # ############################################################################ Otakar Smrz, 2003/01/23 | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 3 | # Mapper Engine Class ##################################################################### 2003/06/19 | ||||||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||||||
| 5 | package Encode::Mapper; | ||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 8 | our $VERSION = '14.1'; | |||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 8 | ▶ | use 5.008; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 8 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 8 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 8 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 8 | ▶ | use bytes; # ensures splitting into one-byte tokens .. lexically scoped | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 8 | our %options; # records of options per package .. global register | |||||||||||||||||||||||||||||||||||||||||||||
| 20 | 8 | our %option; # options of the caller package .. used with local | |||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 13 | ▶ | sub import { # enforces setting of options | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
import: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 13 | my $cls = shift @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 25 | 13 | ▶ | $cls->options(@_) if @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 1 | ▶ | sub whisper ($) { # module's internal function | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
whisper: called CC=2 SCAR=7.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 1 | ▶ | carp shift unless $option{'silent'}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 158302 | ▶ | sub verify_rule ($$) { # module's internal function | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
verify_rule: called CC=12 SCAR=35.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 158302 | ▶ | unless (defined $_[0] and $_[0] ne '') { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $_[0] and $_[0] ne ""
MC/DC0%0/2
defined $_[0] and $_[0] ne ""
defined $_[0]
$_[0] ne ""
Truth table33%1/3
A and B
A= defined $_[0]B= $_[0] ne ""
| |||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | whisper "Rule's LHS is empty, rule ignored"; | |||||||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 158302 | ▶ | unless (defined $_[1]) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | whisper "Rule's RHS is undefined, rule ignored"; | |||||||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 158302 | ▶ | if (UNIVERSAL::isa($_[1], 'ARRAY')) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 130977 | ▶ | unless (defined $_[1]->[0]) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | whisper "Rule's RHS is undefined, rule ignored"; | |||||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 130977 | ▶ | unless (ref \$_[1]->[0] eq 'SCALAR' or UNIVERSAL::isa($_[1]->[0], 'CODE')) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref \$_[1][0] eq "SCALAR" or UNIVERSAL::isa($_[1][0], "CODE")
MC/DC0%0/2
ref \$_[1][0] eq "SCALAR" or UNIVERSAL::isa($_[1][0], "CODE")
ref \$_[1][0] eq "SCALAR"
UNIVERSAL::isa($_[1][0], "CODE")
Truth table66%2/3
A or B
A= ref \$_[1][0] eq "SCALAR"B= UNIVERSAL::isa($_[1][0], "CODE")
| |||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | whisper "Rule's RHS is neither literal nor subroutine reference, rule ignored"; | |||||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 130977 | ▶ | unless (defined $_[1]->[1] and length $_[1]->[1] < length $_[0]) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $_[1][1] and length $_[1][1] < length $_[0]
MC/DC0%0/2
defined $_[1][1] and length $_[1][1] < length $_[0]
defined $_[1][1]
length $_[1][1] < length $_[0]
Truth table33%1/3
A and B
A= defined $_[1][1]B= length $_[1][1] < length $_[0]
| |||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | whisper "Rule type '\$A => [\$X, \$Y], length \$A > length \$Y' misused, considering it '\$A => \$X'"; | |||||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | $_[1] = $_[1]->[0]; | |||||||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 60 | ▶ | elsif (ref \$_[1] ne 'SCALAR' and not UNIVERSAL::isa($_[1], 'CODE')) { | |||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
ref \$_[1] ne "SCALAR" and not UNIVERSAL::isa($_[1], "CODE")
MC/DC0%0/2
ref \$_[1] ne "SCALAR" and not UNIVERSAL::isa($_[1], "CODE")
ref \$_[1] ne "SCALAR"
not UNIVERSAL::isa($_[1], "CODE")
Truth table66%2/3
A and not(B)
A= ref \$_[1] ne "SCALAR"B= not UNIVERSAL::isa($_[1], "CODE")
| |||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | whisper "Rule's RHS is neither literal nor subroutine reference, rule ignored"; | |||||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 158302 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 27 | ▶ | sub options ($%) { # options for general compilation of Mappers | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
options: called CC=22 SCAR=31.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 27 | my $cls = shift @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 71 | 27 | my ($i, $opt, %opt); | |||||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 27 | ▶ | my $caller = caller 0; $caller = caller 1 if $caller eq __PACKAGE__; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 27 | ▶ | my @returns = exists $options{$caller} ? %{$options{$caller}} : (); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 27 | ▶ | while (@_) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 52 | $opt = lc shift @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 52 | ▶ | if ($opt =~ /^\:/) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 28 | ▶ | $opt eq ':others' and $opt{'others'} = sub { shift } and next; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
Condition66%2/3
$opt eq ":others" and $opt{"others"} = sub {
shift();
}
MC/DC50%1/2
$opt eq ":others" and $opt{"others"} = sub {
shift();
}
$opt eq ":others"
$opt{"others"} = sub {
shift();
}
Truth table66%2/3
A and B
A= $opt eq ":others"B= $opt{"others"} = sub {
shift();
}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 18 | ▶ | $opt eq ':silent' and $opt{'silent'} = 1 and next; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$opt eq ":silent" and $opt{"silent"} = 1
MC/DC100%1/1
$opt eq ":silent" and $opt{"silent"} = 1
$opt eq ":silent"
Truth table100%2/2
A
A= $opt eq ":silent"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 8 | ▶ | $opt eq ':join' and $opt{'join'} = ''; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 84 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 24 | $opt =~ /^\-*(.*)$/; | |||||||||||||||||||||||||||||||||||||||||||||
| 86 | 24 | $opt{$1} = shift @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||||||
| 90 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 27 | ▶ | local $option{'silent'} = exists $opt{'silent'} ? $opt{'silent'} : $options{$caller}{'silent'}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 27 | ▶ | if (defined $opt{'complement'} and UNIVERSAL::isa($opt{'complement'}, 'ARRAY')) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $opt{"complement"} and UNIVERSAL::isa($opt{"complement"}, "ARRAY")
MC/DC50%1/2
defined $opt{"complement"} and UNIVERSAL::isa($opt{"complement"}, "ARRAY")
defined $opt{"complement"}
UNIVERSAL::isa($opt{"complement"}, "ARRAY")
Truth table66%2/3
A and B
A= defined $opt{"complement"}B= UNIVERSAL::isa($opt{"complement"}, "ARRAY")
| |||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 1 | ▶ | for ($i = 0; $i < @{$opt{'complement'}}; $i += 2) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 2 | verify_rule $opt{'complement'}->[$i], $opt{'complement'}->[$i + 1]; | |||||||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 27 | ▶ | if (defined $opt{'override'} and UNIVERSAL::isa($opt{'override'}, 'ARRAY')) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $opt{"override"} and UNIVERSAL::isa($opt{"override"}, "ARRAY")
MC/DC50%1/2
defined $opt{"override"} and UNIVERSAL::isa($opt{"override"}, "ARRAY")
defined $opt{"override"}
UNIVERSAL::isa($opt{"override"}, "ARRAY")
Truth table66%2/3
A and B
A= defined $opt{"override"}B= UNIVERSAL::isa($opt{"override"}, "ARRAY")
| |||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 3 | ▶ | for ($i = 0; $i < @{$opt{'override'}}; $i += 2) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 1551 | verify_rule $opt{'override'}->[$i], $opt{'override'}->[$i + 1]; | |||||||||||||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 27 | ▶ | if (defined $opt{'others'} and not $option{'silent'}) { # see whisper | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $opt{"others"} and not $Encode::Mapper::option{"silent"}
MC/DC0%0/2
defined $opt{"others"} and not $Encode::Mapper::option{"silent"}
defined $opt{"others"}
not $Encode::Mapper::option{"silent"}
Truth table66%2/3
A and not(B)
A= defined $opt{"others"}B= not $Encode::Mapper::option{"silent"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | ▶ | if (UNIVERSAL::isa($opt{'others'}, 'CODE')) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | carp "The subroutine will be called with the 'other' LHS parameter to get the rule's RHS"; | |||||||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 109 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | carp "The scalar value will become the RHS of each 'other' LHS"; | |||||||||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 27 | ▶ | return %opt unless defined $cls; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 16 | $options{$caller}{$_} = $opt{$_} foreach keys %opt; | |||||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 16 | return @returns; | |||||||||||||||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 8 | *new = *compile{'CODE'}; # provides the 'new' constructor .. the 'compile' method | |||||||||||||||||||||||||||||||||||||||||||||
| 124 | # *new = \&compile; # might be known at compile-time | ||||||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 15 | ▶ | sub compile ($@) { # returns Mapper .. modified Aho-Corasick and Boyer-Moore search engine | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
compile: called CC=42 SCAR=37.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 15 | my $cls = shift @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 129 | 15 | my (@tree, @bell, @skip, @queue, %redef); | |||||||||||||||||||||||||||||||||||||||||||||
| 130 | 15 | my ($q, $r, $s, $t, $i, $token, $trick); | |||||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 15 | my ($null_list, $null_hash) = ([], {}); # references to empties need not consume unique memory | |||||||||||||||||||||||||||||||||||||||||||||
| 133 | 15 | my ($no_code, $no_list) = (1, 1); # optimization indicators | |||||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 15 | ▶ | local %option = exists $options{caller 0} ? %{$options{caller 0}} : (); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 136 | # options be local due to verify_rule and whisper | ||||||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 15 | ▶ | if (UNIVERSAL::isa($_[0], 'ARRAY')) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 11 | %option = (%option, options undef, @{shift @_}); | |||||||||||||||||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 141 | elsif (UNIVERSAL::isa($_[0], 'HASH')) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | %option = (%option, options undef, %{shift @_}); | |||||||||||||||||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 15 | $skip[0] = undef; # never ever used .. fix the number of list elements equal | |||||||||||||||||||||||||||||||||||||||||||||
| 146 | 15 | $bell[0] = $null_list; # important .. depth-wise inheritation of the lists | |||||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 15 | ▶ | if (defined $option{'complement'}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 1 | ▶ | for ($i = 0; $i < @{$option{'complement'}}; $i += 2) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 2 | $q = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 2 | foreach $token (split //, $option{'complement'}->[$i]) { | |||||||||||||||||||||||||||||||||||||||||||||
| 154 | 2 | ▶ | $tree[$q]->{$token} = ++$r unless defined $tree[$q]->{$token}; # increment $r ^^ | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 2 | $q = $tree[$q]->{$token}; | |||||||||||||||||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 2 | ▶ | $tree[$q] = {} unless defined $tree[$q]; # define trees correctly, economize below | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 2 | ▶ | whisper "Redefining the mapping for '" . $option{'complement'}->[$i] . "'" if defined $bell[$q]; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 2 | $bell[$q] = [ $option{'complement'}->[$i + 1] ]; | |||||||||||||||||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 15 | ▶ | for ($i = 0; $i < @_; $i += 2) { # generate $tree[$q] transition function and initial $bell[$q] | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 156749 | ▶ | next unless verify_rule $_[$i], $_[$i + 1]; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 156749 | $q = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 156749 | foreach $token (split //, $_[$i]) { | |||||||||||||||||||||||||||||||||||||||||||||
| 173 | 945101 | ▶ | $tree[$q]->{$token} = ++$r unless defined $tree[$q]->{$token}; # increment $r ^^ | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 945101 | $q = $tree[$q]->{$token}; | |||||||||||||||||||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 156749 | ▶ | $tree[$q] = {} unless defined $tree[$q]; # define trees correctly, economize below | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 156749 | ▶ | whisper "Redefining the mapping for '$_[$i]'" if $redef{$q}++; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 156749 | $bell[$q] = [ $_[$i + 1] ]; | |||||||||||||||||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 15 | ▶ | if (defined $option{'override'}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 10 | ▶ | for ($i = 0; $i < @{$option{'override'}}; $i += 2) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 5170 | $q = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 5170 | foreach $token (split //, $option{'override'}->[$i]) { | |||||||||||||||||||||||||||||||||||||||||||||
| 190 | 10350 | ▶ | $tree[$q]->{$token} = ++$r unless defined $tree[$q]->{$token}; # increment $r ^^ | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 10350 | $q = $tree[$q]->{$token}; | |||||||||||||||||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 5170 | ▶ | $tree[$q] = {} unless defined $tree[$q]; # define trees correctly, economize below | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 5170 | ▶ | whisper "Redefining the mapping for '" . $option{'override'}->[$i] . "'" if $redef{$q}++; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 5170 | $bell[$q] = [ $option{'override'}->[$i + 1] ]; | |||||||||||||||||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 15 | foreach $token (map { chr } 0x00..0xFF) { | |||||||||||||||||||||||||||||||||||||||||||||
| 203 | 3840 | ▶ | unless (defined $tree[0]->{$token}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 3283 | ▶ | unless (defined $option{'others'}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 898 | $tree[0]->{$token} = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 207 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 2385 | $tree[0]->{$token} = ++$r; # increment $r ^^ | |||||||||||||||||||||||||||||||||||||||||||||
| 209 | 2385 | $tree[$r] = {}; # define trees correctly | |||||||||||||||||||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 3840 | $q = $tree[0]->{$token}; # including existing prefixes | |||||||||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 3840 | ▶ | unless ($q == 0) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 2942 | ▶ | unless (defined $bell[$q]) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 2458 | ▶ | if (not defined $option{'others'}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 12 | $bell[$q] = $bell[0]; | |||||||||||||||||||||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 220 | elsif (UNIVERSAL::isa($option{'others'}, 'CODE')) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 2446 | $bell[$q] = [ $option{'others'}->($token) ]; | |||||||||||||||||||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 223 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 0 | $bell[$q] = [ $option{'others'} ]; | |||||||||||||||||||||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 2942 | $skip[$q] = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 2942 | push @queue, $q; | |||||||||||||||||||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 15 | ▶ | while (@queue) { # generate $skip[$q] backward function and complete $bell[$q] | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 188058 | $q = shift @queue; | |||||||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 188058 | foreach $token (keys %{$tree[$q]}) { | |||||||||||||||||||||||||||||||||||||||||||||
| 238 | 185116 | $t = $tree[$q]->{$token}; | |||||||||||||||||||||||||||||||||||||||||||||
| 239 | 185116 | push @queue, $t; | |||||||||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 185116 | ▶ | if (defined $bell[$t]) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 161435 | $skip[$t] = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 161435 | ▶ | if (UNIVERSAL::isa($bell[$t]->[0], 'ARRAY')) { # shortening property of the rules | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 134568 | $s = $skip[$t]; | |||||||||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 134568 | foreach $trick (split //, $bell[$t]->[0]->[1]) { | |||||||||||||||||||||||||||||||||||||||||||||
| 248 | 327467 | ▶ | until (defined $tree[$s]->{$trick}) { # loops only if not in the root ^^ | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 114135 | push @{$bell[$t]}, @{$bell[$s]}; | |||||||||||||||||||||||||||||||||||||||||||||
| 250 | 114135 | $s = $skip[$s]; | |||||||||||||||||||||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 327467 | $s = $tree[$s]->{$trick}; | |||||||||||||||||||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 134568 | $skip[$t] = $s; | |||||||||||||||||||||||||||||||||||||||||||||
| 256 | 134568 | $bell[$t]->[0] = $bell[$t]->[0]->[0]; | |||||||||||||||||||||||||||||||||||||||||||||
| 257 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 259 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 23681 | $s = $skip[$q]; | |||||||||||||||||||||||||||||||||||||||||||||
| 261 | 23681 | $bell[$t] = [ @{$bell[$q]} ]; # unique reference quite important ^^ | |||||||||||||||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 23681 | ▶ | until (defined $tree[$s]->{$token}) { # extremely tricky ... | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 6147 | push @{$bell[$t]}, @{$bell[$s]}; | |||||||||||||||||||||||||||||||||||||||||||||
| 265 | 6147 | $s = $skip[$s]; | |||||||||||||||||||||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 23681 | $skip[$t] = $tree[$s]->{$token}; | |||||||||||||||||||||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 270 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 188058 | ▶ | $tree[$q] = $null_hash unless keys %{$tree[$q]}; # economize with memory | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 273 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 15 | ▶ | for ($q = 1; $q < @bell; $q++) { # optimize the bell function for $q > 0 | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 188058 | ▶ | if (grep { UNIVERSAL::isa($_, 'CODE') } @{$bell[$q]}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 8 | $no_code = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 279 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 280 | elsif (defined $option{'join'}) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 0 | $bell[$q] = join $option{'join'}, @{$bell[$q]}; | |||||||||||||||||||||||||||||||||||||||||||||
| 282 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||
| 283 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 188058 | ▶ | if (@{$bell[$q]} == 1) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 68344 | $bell[$q] = $bell[$q]->[0]; | |||||||||||||||||||||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 288 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 119714 | ▶ | $bell[$q] = $null_list if @{$bell[$q]} == 0; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 119714 | $no_list = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 291 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 292 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||||||||||
| 294 | return bless { | ||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 'current' => 0, | ||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 'tree' => \@tree, | ||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 'bell' => \@bell, | ||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 'skip' => \@skip, | ||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 'null' => { 'list' => $null_list, 'hash' => $null_hash }, | ||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 15 | 'join' => $option{'join'}, | |||||||||||||||||||||||||||||||||||||||||||||
| 301 | 'no_code' => $no_code, | ||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 'no_list' => $no_list, | ||||||||||||||||||||||||||||||||||||||||||||||
| 303 | }, $cls; | ||||||||||||||||||||||||||||||||||||||||||||||
| 304 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 18 | ▶ | sub process ($@) { # returns the list of search results performed by Mapper | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
process: called CC=9 SCAR=22.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 18 | my $obj = shift @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 309 | 18 | my (@returns, $phrase, $token, $q); | |||||||||||||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 18 | $q = $obj->{'current'}; | |||||||||||||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 18 | ▶ | if ($obj->{'no_list'}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 7 | foreach $phrase (@_) { | |||||||||||||||||||||||||||||||||||||||||||||
| 315 | 118 | foreach $token (split //, $phrase) { | |||||||||||||||||||||||||||||||||||||||||||||
| 316 | 724 | ▶ | until (defined $obj->{'tree'}[$q]->{$token}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 496 | push @returns, $obj->{'bell'}[$q]; | |||||||||||||||||||||||||||||||||||||||||||||
| 318 | 496 | $q = $obj->{'skip'}[$q]; | |||||||||||||||||||||||||||||||||||||||||||||
| 319 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 724 | $q = $obj->{'tree'}[$q]->{$token}; | |||||||||||||||||||||||||||||||||||||||||||||
| 321 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 322 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 323 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 324 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 11 | foreach $phrase (@_) { | |||||||||||||||||||||||||||||||||||||||||||||
| 326 | 21 | foreach $token (split //, $phrase) { | |||||||||||||||||||||||||||||||||||||||||||||
| 327 | 572 | ▶ | until (defined $obj->{'tree'}[$q]->{$token}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 328 | push @returns, ref $obj->{'bell'}[$q] eq 'ARRAY' ? | ||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 386 | ▶ | @{$obj->{'bell'}[$q]} : $obj->{'bell'}[$q]; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 386 | $q = $obj->{'skip'}[$q]; | |||||||||||||||||||||||||||||||||||||||||||||
| 331 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 572 | $q = $obj->{'tree'}[$q]->{$token}; | |||||||||||||||||||||||||||||||||||||||||||||
| 333 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 334 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 335 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 18 | $obj->{'current'} = $q; | |||||||||||||||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 18 | return @returns; | |||||||||||||||||||||||||||||||||||||||||||||
| 340 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 18 | ▶ | sub recover ($;$$) { # returns the 'in-progress' search result and resets Mapper | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
recover: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 18 | my ($obj, $r, $q) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 345 | 18 | my (@returns); | |||||||||||||||||||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 18 | ▶ | $q = $obj->{'current'} unless defined $q; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 18 | ▶ | if ($obj->{'no_list'}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 7 | ▶ | until ($q == 0) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 7 | push @returns, $obj->{'bell'}[$q]; | |||||||||||||||||||||||||||||||||||||||||||||
| 352 | 7 | $q = $obj->{'skip'}[$q]; | |||||||||||||||||||||||||||||||||||||||||||||
| 353 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 354 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 355 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 11 | ▶ | until ($q == 0) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 357 | push @returns, ref $obj->{'bell'}[$q] eq 'ARRAY' ? | ||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 13 | ▶ | @{$obj->{'bell'}[$q]} : $obj->{'bell'}[$q]; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 13 | $q = $obj->{'skip'}[$q]; | |||||||||||||||||||||||||||||||||||||||||||||
| 360 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 361 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 18 | ▶ | $obj->{'current'} = defined $r ? $r : 0; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 18 | return @returns; | |||||||||||||||||||||||||||||||||||||||||||||
| 366 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 0 | ▶ | sub compute ($@) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
compute: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 0 | my $obj = shift @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 371 | 0 | my (@returns, $phrase, $token, $q); | |||||||||||||||||||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||||||||||||||||||||
| 373 | 0 | $obj->recover(); | |||||||||||||||||||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||||||||||||||||||||
| 375 | 0 | foreach $phrase (@_) { | |||||||||||||||||||||||||||||||||||||||||||||
| 376 | 0 | foreach $token (split //, $phrase) { | |||||||||||||||||||||||||||||||||||||||||||||
| 377 | 0 | push @returns, [$token, $obj->{'current'}]; | |||||||||||||||||||||||||||||||||||||||||||||
| 378 | 0 | push @{$returns[-1]}, [$obj->process($token)]; | |||||||||||||||||||||||||||||||||||||||||||||
| 379 | 0 | $q = $obj->{'current'}; | |||||||||||||||||||||||||||||||||||||||||||||
| 380 | 0 | push @{$returns[-1]}, $q, $obj->{'bell'}[$q], $obj->{'skip'}[$q]; | |||||||||||||||||||||||||||||||||||||||||||||
| 381 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 382 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||||||||||||||||||||
| 384 | 0 | push @returns, ['recover', $obj->{'current'}]; | |||||||||||||||||||||||||||||||||||||||||||||
| 385 | 0 | push @{$returns[-1]}, [$obj->recover()]; | |||||||||||||||||||||||||||||||||||||||||||||
| 386 | 0 | $q = $obj->{'current'}; | |||||||||||||||||||||||||||||||||||||||||||||
| 387 | 0 | ▶ | push @{$returns[-1]}, $q, $obj->{'bell'}[$q], ($q == 0 ? 'undef' : $obj->{'skip'}[$q]); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||||||||||||||||
| 389 | 0 | return @returns; | |||||||||||||||||||||||||||||||||||||||||||||
| 390 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||||||||||||||||
| 393 | 0 | ▶ | sub dumper ($;$) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dumper: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 394 | 0 | my ($obj, $ref) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||||||||||||||||
| 396 | 0 | ▶ | $ref = ['L', 'H', 'mapper'] unless defined $ref; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||||||||||||||||||||
| 398 | 0 | require Data::Dumper; | |||||||||||||||||||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 0 | return Data::Dumper->new([$obj->{'null'}{'list'}, $obj->{'null'}{'hash'}, $obj], $ref); | |||||||||||||||||||||||||||||||||||||||||||||
| 401 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||||||||||||||||||||
| 404 | 0 | ▶ | sub describe ($;$) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
describe: not called CC=17 SCAR=57.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 0 | my ($obj, $ref) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 406 | 0 | my ($q, $nodes, $edges, $skips, $bells, $paths, $lists); | |||||||||||||||||||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||||||||||||||||||||
| 408 | 0 | $nodes = @{$obj->{'tree'}}; | |||||||||||||||||||||||||||||||||||||||||||||
| 409 | 0 | $edges = []; | |||||||||||||||||||||||||||||||||||||||||||||
| 410 | 0 | $lists = []; | |||||||||||||||||||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||||||||||||||||||||
| 412 | 0 | ▶ | if ($obj->{'no_list'}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 413 | 0 | ▶ | for ($q = 0; $q < @{$obj->{'tree'}}; $q++) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 414 | 0 | $lists->[$q * 3] = scalar %{$obj->{'tree'}[$q]}; | |||||||||||||||||||||||||||||||||||||||||||||
| 415 | 0 | $lists->[$q * 3] =~ m{^([0-9]+)(?:/([0-9]+))?$}; | |||||||||||||||||||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||||||||||||||||||||
| 417 | 0 | $edges->[0] += scalar keys %{$obj->{'tree'}[$q]}; | |||||||||||||||||||||||||||||||||||||||||||||
| 418 | 0 | $lists->[$q * 3] .= " " . keys %{$obj->{'tree'}[$q]}; | |||||||||||||||||||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||||||||||||||||||||
| 420 | 0 | ▶ | if (defined $2) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 421 | 0 | $edges->[1] += $1; | |||||||||||||||||||||||||||||||||||||||||||||
| 422 | 0 | $edges->[2] += $2; | |||||||||||||||||||||||||||||||||||||||||||||
| 423 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 424 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 425 | 0 | ▶ | $paths++ unless $1; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 426 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||||||||||||||||||||
| 428 | 0 | ▶ | $lists->[$q * 3 + 1] = $obj->{'bell'}[$q] eq "" ? 0 : 1; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 429 | 0 | $bells += $lists->[$q * 3 + 1]; | |||||||||||||||||||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||||||||||||||||||||
| 431 | 0 | ▶ | next if $q == 0; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||||||||||||||||||||
| 433 | 0 | $lists->[$obj->{'skip'}[$q] * 3 + 2]++; | |||||||||||||||||||||||||||||||||||||||||||||
| 434 | 0 | ▶ | $skips++ unless $obj->{'skip'}[$q] == 0; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 435 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 436 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 437 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 438 | 0 | ▶ | for ($q = 0; $q < @{$obj->{'tree'}}; $q++) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 439 | 0 | $lists->[$q * 3] = scalar %{$obj->{'tree'}[$q]}; | |||||||||||||||||||||||||||||||||||||||||||||
| 440 | 0 | $lists->[$q * 3] =~ m{^([0-9]+)(?:/([0-9]+))?$}; | |||||||||||||||||||||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||||||||||||||||||||
| 442 | 0 | $edges->[0] += scalar keys %{$obj->{'tree'}[$q]}; | |||||||||||||||||||||||||||||||||||||||||||||
| 443 | 0 | $lists->[$q * 3] .= " " . keys %{$obj->{'tree'}[$q]}; | |||||||||||||||||||||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||||||||||||||||||||
| 445 | 0 | ▶ | if (defined $2) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 446 | 0 | $edges->[1] += $1; | |||||||||||||||||||||||||||||||||||||||||||||
| 447 | 0 | $edges->[2] += $2; | |||||||||||||||||||||||||||||||||||||||||||||
| 448 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 449 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 450 | 0 | ▶ | $paths++ unless $1; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 451 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 452 | |||||||||||||||||||||||||||||||||||||||||||||||
| 453 | 0 | ▶ | $lists->[$q * 3 + 1] = ref $obj->{'bell'}[$q] eq 'ARRAY' ? scalar @{$obj->{'bell'}[$q]} : 1; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 454 | 0 | $bells += $lists->[$q * 3 + 1]; | |||||||||||||||||||||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||||||||||||||||||||
| 456 | 0 | ▶ | next if $q == 0; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||||||||||||||||||||
| 458 | 0 | $lists->[$obj->{'skip'}[$q] * 3 + 2]++; | |||||||||||||||||||||||||||||||||||||||||||||
| 459 | 0 | ▶ | $skips++ unless $obj->{'skip'}[$q] == 0; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 460 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 461 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||||||||||||||||||||
| 463 | 0 | my $return = {'nodes' => $nodes, 'edges' => $edges->[0], 'slots' => $edges->[1] . "/" . $edges->[2], | |||||||||||||||||||||||||||||||||||||||||||||
| 464 | 'skips' => $skips, 'bells' => $bells, 'paths' => $paths, 'lists' => $lists}; | ||||||||||||||||||||||||||||||||||||||||||||||
| 465 | |||||||||||||||||||||||||||||||||||||||||||||||
| 466 | 0 | ▶ | if (defined $ref) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 467 | 0 | ▶ | $ref = *STDERR if ref $ref ne 'GLOB'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 468 | 0 | ▶ | print $ref ( join ", ", map { ( defined $return->{$_} ? $return->{$_} : 'undef' ) . " " . $_ } | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 469 | 0 | grep { $_ ne 'lists' } keys %{$return} ) . "\n"; | |||||||||||||||||||||||||||||||||||||||||||||
| 470 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||||||||||||||||||||
| 472 | 0 | return $return; | |||||||||||||||||||||||||||||||||||||||||||||
| 473 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 474 | |||||||||||||||||||||||||||||||||||||||||||||||
| 475 | |||||||||||||||||||||||||||||||||||||||||||||||
| 476 | 6 | ▶ | sub encode ($$$;$) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
encode: called CC=14 SCAR=33.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 477 | 6 | my ($cls, $text, $encoder, $enc) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 478 | 6 | my ($mapper, $join); | |||||||||||||||||||||||||||||||||||||||||||||
| 479 | |||||||||||||||||||||||||||||||||||||||||||||||
| 480 | 6 | ▶ | local %option = exists $options{caller 0} ? %{$options{caller 0}} : (); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 481 | # options be local due to whisper | ||||||||||||||||||||||||||||||||||||||||||||||
| 482 | |||||||||||||||||||||||||||||||||||||||||||||||
| 483 | 6 | require Encode; | |||||||||||||||||||||||||||||||||||||||||||||
| 484 | |||||||||||||||||||||||||||||||||||||||||||||||
| 485 | 6 | ▶ | unless (Encode::is_utf8($text)) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 486 | 0 | whisper "The input text is not in Perl's internal utf8 .. note only, might be fine"; | |||||||||||||||||||||||||||||||||||||||||||||
| 487 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||||||||||||||||||||
| 489 | 6 | ▶ | if ($enc) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 490 | 0 | ▶ | unless (Encode::resolve_alias($enc)) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 491 | 0 | carp "Cannot resolve the proposed '$enc' encoding"; | |||||||||||||||||||||||||||||||||||||||||||||
| 492 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||
| 493 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 494 | |||||||||||||||||||||||||||||||||||||||||||||||
| 495 | 0 | $text = Encode::encode($enc, $text); | |||||||||||||||||||||||||||||||||||||||||||||
| 496 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 497 | |||||||||||||||||||||||||||||||||||||||||||||||
| 498 | 6 | ▶ | if (not UNIVERSAL::isa($encoder, 'ARRAY') or grep { defined $_ and not $_->isa($cls) } @{$encoder}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
not UNIVERSAL::isa($encoder, "ARRAY") or grep {defined $_ and not $_->isa($cls);} @{$encoder;}
defined $_ && !$_->isa($cls)
MC/DC0%0/2
not UNIVERSAL::isa($encoder, "ARRAY") or grep {defined $_ and not $_->isa($cls);} @{$encoder;}
not UNIVERSAL::isa($encoder, "ARRAY")
grep {defined $_ and not $_->isa($cls);} @{$encoder;}
MC/DC0%0/2
defined $_ && !$_->isa($cls)
defined $_
!$_->isa($cls)
Truth table33%1/3
not(A) or B
A= not UNIVERSAL::isa($encoder, "ARRAY")B= grep {defined $_ and not $_->isa($cls);} @{$encoder;}
Truth table66%2/3
A && not(B)
A= defined $_B= !$_->isa($cls)
| |||||||||||||||||||||||||||||||||||||||||||||||
| 499 | 0 | carp "Expecting a reference to an array of '$cls' objects"; | |||||||||||||||||||||||||||||||||||||||||||||
| 500 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||
| 501 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 502 | |||||||||||||||||||||||||||||||||||||||||||||||
| 503 | 6 | foreach $mapper (@{$encoder}) { | |||||||||||||||||||||||||||||||||||||||||||||
| 504 | 10 | ▶ | last unless defined $mapper; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 505 | |||||||||||||||||||||||||||||||||||||||||||||||
| 506 | $join = defined $mapper->{'join'} ? $mapper->{'join'} : | ||||||||||||||||||||||||||||||||||||||||||||||
| 507 | 6 | ▶ | defined $option{'join'} ? $option{'join'} : ""; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 508 | |||||||||||||||||||||||||||||||||||||||||||||||
| 509 | 6 | ▶ | if ($mapper->{'no_code'}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 510 | 6 | $text = join $join, $mapper->process($text), $mapper->recover(); | |||||||||||||||||||||||||||||||||||||||||||||
| 511 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 512 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 513 | $text = join $join, map { | ||||||||||||||||||||||||||||||||||||||||||||||
| 514 | 0 | ▶ | UNIVERSAL::isa($_, 'CODE') ? $_->() : $_ | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 515 | } $mapper->process($text), $mapper->recover(); | ||||||||||||||||||||||||||||||||||||||||||||||
| 516 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 517 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 518 | |||||||||||||||||||||||||||||||||||||||||||||||
| 519 | 6 | return $text; | |||||||||||||||||||||||||||||||||||||||||||||
| 520 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 521 | |||||||||||||||||||||||||||||||||||||||||||||||
| 522 | |||||||||||||||||||||||||||||||||||||||||||||||
| 523 | 3 | ▶ | sub decode ($$$;$) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
decode: called CC=14 SCAR=31.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 524 | 3 | my ($cls, $text, $decoder, $enc) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 525 | 3 | my ($mapper, $join); | |||||||||||||||||||||||||||||||||||||||||||||
| 526 | |||||||||||||||||||||||||||||||||||||||||||||||
| 527 | 3 | ▶ | local %option = exists $options{caller 0} ? %{$options{caller 0}} : (); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 528 | # options be local due to tradition ^^ | ||||||||||||||||||||||||||||||||||||||||||||||
| 529 | |||||||||||||||||||||||||||||||||||||||||||||||
| 530 | 3 | require Encode; | |||||||||||||||||||||||||||||||||||||||||||||
| 531 | |||||||||||||||||||||||||||||||||||||||||||||||
| 532 | 3 | ▶ | $enc = 'utf8' unless $enc; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 533 | |||||||||||||||||||||||||||||||||||||||||||||||
| 534 | 3 | ▶ | unless (Encode::resolve_alias($enc)) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 535 | 0 | carp "Cannot resolve the proposed '$enc' encoding"; | |||||||||||||||||||||||||||||||||||||||||||||
| 536 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||
| 537 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 538 | |||||||||||||||||||||||||||||||||||||||||||||||
| 539 | 3 | ▶ | if (not UNIVERSAL::isa($decoder, 'ARRAY') or grep { defined $_ and not $_->isa($cls) } @{$decoder}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
not UNIVERSAL::isa($decoder, "ARRAY") or grep {defined $_ and not $_->isa($cls);} @{$decoder;}
defined $_ && !$_->isa($cls)
MC/DC0%0/2
not UNIVERSAL::isa($decoder, "ARRAY") or grep {defined $_ and not $_->isa($cls);} @{$decoder;}
not UNIVERSAL::isa($decoder, "ARRAY")
grep {defined $_ and not $_->isa($cls);} @{$decoder;}
MC/DC0%0/2
defined $_ && !$_->isa($cls)
defined $_
!$_->isa($cls)
Truth table33%1/3
not(A) or B
A= not UNIVERSAL::isa($decoder, "ARRAY")B= grep {defined $_ and not $_->isa($cls);} @{$decoder;}
Truth table66%2/3
A && not(B)
A= defined $_B= !$_->isa($cls)
| |||||||||||||||||||||||||||||||||||||||||||||||
| 540 | 0 | carp "Expecting a reference to an array of $cls objects"; | |||||||||||||||||||||||||||||||||||||||||||||
| 541 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||
| 542 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 543 | |||||||||||||||||||||||||||||||||||||||||||||||
| 544 | 3 | foreach $mapper (@{$decoder}) { | |||||||||||||||||||||||||||||||||||||||||||||
| 545 | 9 | ▶ | last unless defined $mapper; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 546 | |||||||||||||||||||||||||||||||||||||||||||||||
| 547 | $join = defined $mapper->{'join'} ? $mapper->{'join'} : | ||||||||||||||||||||||||||||||||||||||||||||||
| 548 | 7 | ▶ | defined $option{'join'} ? $option{'join'} : ""; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 549 | |||||||||||||||||||||||||||||||||||||||||||||||
| 550 | 7 | ▶ | if ($mapper->{'no_code'}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 551 | 7 | $text = join $join, $mapper->process($text), $mapper->recover(); | |||||||||||||||||||||||||||||||||||||||||||||
| 552 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 553 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 554 | $text = join $join, map { | ||||||||||||||||||||||||||||||||||||||||||||||
| 555 | 0 | ▶ | UNIVERSAL::isa($_, 'CODE') ? $_->() : $_ | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 556 | } $mapper->process($text), $mapper->recover(); | ||||||||||||||||||||||||||||||||||||||||||||||
| 557 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 558 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 559 | |||||||||||||||||||||||||||||||||||||||||||||||
| 560 | 3 | ▶ | return Encode::is_utf8($text) ? $text : Encode::decode($enc, $text); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 561 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 562 | |||||||||||||||||||||||||||||||||||||||||||||||
| 563 | |||||||||||||||||||||||||||||||||||||||||||||||
| 564 | 8 | 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 565 | |||||||||||||||||||||||||||||||||||||||||||||||
| 566 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||