| 1 | package App::Greple::Regions; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 172 | ▶ | use v5.24; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 172 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 172 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 172 | eval { warnings->unimport('experimental::regex_sets') }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 172 | eval { warnings->unimport('experimental::vlb') }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 172 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 172 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 172 | $Data::Dumper::Sortkeys = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 172 | ▶ | use Exporter 'import'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 172 | our @EXPORT = qw(REGION_INSIDE REGION_OUTSIDE | |||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | REGION_UNION REGION_INTERSECT | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | match_regions | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | classify_regions | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | select_regions | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | filter_regions | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | merge_regions | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | reverse_regions | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | match_borders | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | borders_to_regions | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 172 | our %EXPORT_TAGS = ( ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 172 | our @EXPORT_OK = qw(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 172 | ▶ | use constant { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 172 | REGION_AREA_MASK => 1, | |||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | REGION_INSIDE => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | REGION_OUTSIDE => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | REGION_SET_MASK => 2, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | REGION_INTERSECT => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | REGION_UNION => 2, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 172 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 11 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 11 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 11 | my $obj = bless { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | FLAG => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | SPEC => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | }, $class; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 11 | ▶ | $obj->configure(@_) if @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 11 | $obj; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 11 | ▶ | sub configure { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
configure: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 11 | my $obj = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 11 | ▶ | while (@_ >= 2) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 22 | $obj->{$_[0]} = $_[1]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 22 | splice @_, 0, 2; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 11 | ▶ | sub spec { $_[0]->{SPEC} } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
spec: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 46 | ▶ | sub flag { $_[0]->{FLAG} } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
flag: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 46 | ▶ | sub is_x { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_x: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 46 | my($p, $mask, $set) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 46 | ▶ | ((ref $p ? $p->flag : $p) & $mask) == $set; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 11 | ▶ | sub is_union { is_x $_[0], REGION_SET_MASK, REGION_UNION } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_union: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 11 | ▶ | sub is_intersect { is_x $_[0], REGION_SET_MASK, REGION_INTERSECT } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_intersect: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 22 | ▶ | sub is_inside { is_x $_[0], REGION_AREA_MASK, REGION_INSIDE } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_inside: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 2 | ▶ | sub is_outside { is_x $_[0], REGION_AREA_MASK, REGION_OUTSIDE } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_outside: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 172 | package App::Greple::Regions::Holder { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 166 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 166 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 166 | bless [], $class; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 11 | ▶ | sub append { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
append: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 11 | my $obj = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 11 | push @$obj, App::Greple::Regions->new(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 304 | ▶ | sub regions { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
regions: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 304 | my $obj = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 304 | @$obj; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 152 | ▶ | sub union { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
union: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 152 | grep { $_->is_union } shift->regions; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 152 | ▶ | sub intersect { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
intersect: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 152 | grep { $_->is_intersect } shift->regions; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 212 | ▶ | sub match_regions { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
match_regions: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 212 | my %arg = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 212 | ▶ | my $pattern = $arg{pattern} // croak "Parameter error"; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$arg{"pattern"} // croak("Parameter error")
MC/DC0%0/1
$arg{"pattern"} // croak("Parameter error")
$arg{"pattern"}
Truth table50%1/2
A
A= $arg{"pattern"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 212 | ▶ | my $regex = ref $pattern eq 'Regexp' ? $pattern : qr/$pattern/m; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 212 | ▶ | return &match_regions_by_group($regex, $arg{index}) if $arg{group}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 200 | my @regions; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 172 | ▶ | no warnings 'utf8'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 200 | ▶ | while (/$regex/gp) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | ## | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | ## Using $-[0]/$+[0] is extremely slow with UTF-8 text. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | ## Still not fixed in Perl 5.34. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | ## https://qiita.com/kaz-utashiro/items/2facc87ea9ba25e81cd9 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | ## | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 1550 | my $pos = pos(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 1550 | push @regions, [ $pos - length(${^MATCH}), $pos ]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 200 | @regions; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 12 | ▶ | sub match_regions_by_group { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
match_regions_by_group: called CC=7 SCAR=19.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 12 | my($regex, $index) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 12 | my @regions; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 172 | ▶ | no warnings 'utf8'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 12 | ▶ | while (/$regex/g) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 11 | ▶ | if (@- == 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 1 | push @regions, [ $-[0], $+[0] ]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | ▶ | push @{$regions[-1]}, 0 if $index | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 10 | for my $i (1 .. $#-) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 16 | ▶ | $-[$i] // next; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$-[$i] // (next)
MC/DC0%0/1
$-[$i] // (next)
$-[$i]
Truth table50%1/2
A
A= $-[$i]
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 16 | push @regions, [ $-[$i], $+[$i] ]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 16 | ▶ | push @{$regions[-1]}, $i - 1 if $index | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 12 | @regions; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 209 | ▶ | sub classify_regions { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
classify_regions: called CC=11 SCAR=24.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 209 | ▶ | my $opt = ref $_[0] eq 'HASH' ? shift : {}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 209 | ▶ | $opt->{strict} and goto &classify_regions_strict; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 208 | my @list = @{+shift}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 208 | my @by = @{+shift}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 208 | my @table; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 208 | for my $i (keys @by) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 1369 | my($from, $to) = $by[$i]->@*; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 1369 | ▶ | while (@list and $list[0][1] < $from) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@list and $list[0][1] < $from
MC/DC100%2/2
@list and $list[0][1] < $from
@list
$list[0][1] < $from
Truth table100%3/3
A and B
A= @listB= $list[0][1] < $from
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 348 | shift @list; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 1369 | ▶ | while (@list and $list[0][1] == $from and $list[0][0] < $from) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
@list and $list[0][1] == $from and $list[0][0] < $from
@list and $list[0][1] == $from
MC/DC0%0/3
@list and $list[0][1] == $from and $list[0][0] < $from
@list
$list[0][1] == $from
$list[0][0] < $from
Truth table75%3/4
A and B and C
A= @listB= $list[0][1] == $fromC= $list[0][0] < $from
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 0 | shift @list; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 1369 | my $t = $table[$i] = []; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 1369 | ▶ | for (my $i = 0; ($i < @list) and ($list[$i][0] < $to); $i++) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$i < @list and $list[$i][0] < $to
MC/DC100%2/2
$i < @list and $list[$i][0] < $to
$i < @list
$list[$i][0] < $to
Truth table100%3/3
A and B
A= $i < @listB= $list[$i][0] < $to
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 520 | push @$t, [ $list[$i]->@* ]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 208 | @table; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 1 | ▶ | sub classify_regions_strict { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
classify_regions_strict: called CC=7 SCAR=22.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 1 | my @list = @{+shift}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 1 | my @by = @{+shift}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 1 | my @table; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 1 | for my $i (keys @by) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 1 | my($from, $to) = $by[$i]->@*; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 1 | ▶ | while (@list and $list[0][0] < $from) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@list and $list[0][0] < $from
MC/DC0%0/2
@list and $list[0][0] < $from
@list
$list[0][0] < $from
Truth table33%1/3
A and B
A= @listB= $list[0][0] < $from
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | shift @list; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 1 | my $t = $table[$i] = []; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 1 | ▶ | while (@list and $list[0][0] < $to and $list[0][1] <= $to) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
@list and $list[0][0] < $to and $list[0][1] <= $to
@list and $list[0][0] < $to
MC/DC0%0/3
@list and $list[0][0] < $to and $list[0][1] <= $to
@list
$list[0][0] < $to
$list[0][1] <= $to
Truth table25%1/4
A and B and C
A= @listB= $list[0][0] < $toC= $list[0][1] <= $to
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 0 | push @$t, shift @list; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 1 | @table; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 13 | ▶ | sub select_regions { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
select_regions: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 13 | ▶ | my $opt = ref $_[0] eq 'HASH' ? shift : {}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 13 | my($list, $by, $flag) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 13 | my($inside, $outside) = ([], []); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 13 | ▶ | my $target = is_inside($flag) ? $inside : $outside; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 13 | ▶ | my $overlap = $opt->{strict} ? [] : $target; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 13 | filter_regions($list, $by, $inside, $overlap, $outside); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 13 | @$target; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | ## | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | ## Split @input into @inside, @overlap, @outside by @filter and return | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | ## their pointers. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | ## | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | ## 4th and 5th result is corresponding entry of @filter for @inside | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | ## and @overlap. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | ## | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 13 | ▶ | sub filter_regions { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
filter_regions: called CC=15 SCAR=27.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 13 | my @input = @{+shift}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 13 | my @filter = @{+shift}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 13 | ▶ | my($inside, $overlap, $outside) = (shift//[], shift//[], shift//[]); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%3/6
shift() // []
shift() // []
shift() // []
MC/DC0%0/1
shift() // []
shift()
MC/DC0%0/1
shift() // []
shift()
MC/DC0%0/1
shift() // []
shift()
Truth table50%1/2
A
A= shift()
Truth table50%1/2
A
A= shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 13 | my($inside_match, $overlap_match) = ([], []); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 13 | ▶ | while (my($i, $range) = each @filter) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 105 | my($from, $to) = @$range; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 105 | ▶ | while (@input and $input[0][0] < $from and $input[0][1] <= $from) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
@input and $input[0][0] < $from and $input[0][1] <= $from
@input and $input[0][0] < $from
MC/DC100%3/3
@input and $input[0][0] < $from and $input[0][1] <= $from
@input
$input[0][0] < $from
$input[0][1] <= $from
Truth table100%4/4
A and B and C
A= @inputB= $input[0][0] < $fromC= $input[0][1] <= $from
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 51 | push @$outside, shift @input; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 105 | ▶ | while (@input and $input[0][0] < $from) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@input and $input[0][0] < $from
MC/DC100%2/2
@input and $input[0][0] < $from
@input
$input[0][0] < $from
Truth table100%3/3
A and B
A= @inputB= $input[0][0] < $from
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 2 | push @$overlap, shift @input; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 2 | push @$overlap_match, $range; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 105 | ▶ | while (@input and $input[0][0] < $to and $input[0][1] <= $to) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
@input and $input[0][0] < $to and $input[0][1] <= $to
@input and $input[0][0] < $to
MC/DC66%2/3
@input and $input[0][0] < $to and $input[0][1] <= $to
@input
$input[0][0] < $to
$input[0][1] <= $to
Truth table75%3/4
A and B and C
A= @inputB= $input[0][0] < $toC= $input[0][1] <= $to
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 68 | push @$inside, shift @input; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 68 | push @$inside_match, $range; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 105 | ▶ | while (@input and $input[0][0] < $to) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@input and $input[0][0] < $to
MC/DC0%0/2
@input and $input[0][0] < $to
@input
$input[0][0] < $to
Truth table66%2/3
A and B
A= @inputB= $input[0][0] < $to
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 0 | push @$overlap, shift @input; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 0 | push @$overlap_match, $range; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 13 | push @$outside, splice @input; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 13 | ($inside, $overlap, $outside, $inside_match, $overlap_match); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 411 | ▶ | sub merge_regions { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
merge_regions: called CC=16 SCAR=33.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 411 | ▶ | my $option = ref $_[0] eq 'HASH' ? shift : {}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 411 | my $nojoin = $option->{nojoin}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 0 | ▶ | my @in = $option->{destructive} ? @_ : map { [ @$_ ] } @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 411 | ▶ | unless ($option->{nosort}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 411 | ▶ | @in = sort({$a->[0] <=> $b->[0] || $b->[1] <=> $a->[1] | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
$App::Greple::Regions::a->[0] <=> $App::Greple::Regions::b->[0] || $App::Greple::Regions::b->[1] <=> $App::Greple::Regions::a->[1] || (@$a > 2 ? $App::Greple::Regions::a->[2] <=> $App::Greple::Regions::b->[2] : 0)
$App::Greple::Regions::a->[0] <=> $App::Greple::Regions::b->[0] or $App::Greple::Regions::b->[1] <=> $App::Greple::Regions::a->[1]
MC/DC33%1/3
$App::Greple::Regions::a->[0] <=> $App::Greple::Regions::b->[0] || $App::Greple::Regions::b->[1] <=> $App::Greple::Regions::a->[1] || (@$a > 2 ? $App::Greple::Regions::a->[2] <=> $App::Greple::Regions::b->[2] : 0)
$App::Greple::Regions::a->[0] <=> $App::Greple::Regions::b->[0]
$App::Greple::Regions::b->[1] <=> $App::Greple::Regions::a->[1]
(@$a > 2 ? $App::Greple::Regions::a->[2] <=> $App::Greple::Regions::b->[2] : 0)
Truth table50%2/4
A or B || C
A= $App::Greple::Regions::a->[0] <=> $App::Greple::Regions::b->[0]B= $App::Greple::Regions::b->[1] <=> $App::Greple::Regions::a->[1]C= (@$a > 2 ? $App::Greple::Regions::a->[2] <=> $App::Greple::Regions::b->[2] : 0)
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | || (@$a > 2 ? $a->[2] <=> $b->[2] : 0) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | } @in); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 411 | my @out; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 411 | ▶ | push(@out, shift @in) if @in; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 411 | ▶ | while (@in) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 1472 | my $top = shift @in; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 1472 | ▶ | if ($out[-1][1] > $top->[0]) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 209 | ▶ | $out[-1][1] = $top->[1] if $out[-1][1] < $top->[1]; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | ▶ | elsif (!$nojoin | |||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition22%2/9
not $nojoin and $out[-1][1] == $top->[0] and @$top < 3 || $out[-1][2] == $top->[2]
not $nojoin and $out[-1][1] == $top->[0]
@$top < 3 or $out[-1][2] == $top->[2]
MC/DC0%0/4
not $nojoin and $out[-1][1] == $top->[0] and @$top < 3 || $out[-1][2] == $top->[2]
not $nojoin
$out[-1][1] == $top->[0]
@$top < 3
$out[-1][2] == $top->[2]
Truth table20%1/5
not(A) and B and C or D
A= not $nojoinB= $out[-1][1] == $top->[0]C= @$top < 3D= $out[-1][2] == $top->[2]
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | and $out[-1][1] == $top->[0] | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | ## | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | ## don't connect regions in different pattern group | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | ## | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | and (@$top < 3 or $out[-1][2] == $top->[2]) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 0 | ▶ | $out[-1][1] = $top->[1] if $out[-1][1] < $top->[1]; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 1263 | push @out, $top; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 411 | @out; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 172 | ▶ | use List::Util qw(pairs); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 12 | ▶ | sub reverse_regions { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
reverse_regions: called CC=4 SCAR=14.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 12 | ▶ | my $option = ref $_[0] eq 'HASH' ? shift : {}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 12 | my($from, $max) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 12 | ▶ | my @reverse = pairs 0, map(@{$_}[0,1], @$from), $max // length; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$max // length $_
MC/DC0%0/2
$max // length $_
$max
length $_
Truth table33%1/3
A // B
A= $maxB= length $_
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 12 | ▶ | return @reverse if $option->{leave_empty}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 9 | grep { $_->[0] != $_->[1] } @reverse | |||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 127 | ▶ | sub match_borders { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
match_borders: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 127 | my $regex = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 127 | my @border = (0); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 127 | ▶ | while (/$regex/gp) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 3169 | my $pos = pos(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 3169 | for my $i ($pos - length(${^MATCH}), $pos) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 6338 | ▶ | push @border, $i if $border[-1] != $i; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 127 | ▶ | push @border, length if $border[-1] != length; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 127 | @border; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 0 | ▶ | sub borders_to_regions { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
borders_to_regions: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 0 | ▶ | return () if @_ < 2; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 0 | map { [ $_[$_-1], $_[$_] ] } 1..$#_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 172 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||