blib/lib/Text/Bidi/Selection.pm

filter: Statementstmt 100% 55 / 55 Branchbran 100% 24 / 24 Conditioncond 96.3% 26 / 27 MC/DCmcdc 93.3% 14 / 15 Subroutinesub 100% 7 / 7 Podpod 100% 3 / 3 totaltotal 98.4% 129 / 131 CC 29 SCAR 25.8
CC
29
Cov
99%
new
17.0
logical_ranges
13.0
BEGIN
1.0
CRAP 13.2
↑ Summary blib/lib/Text/Bidi/private.pm »
1 2 ▶use 5.10.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 package Text::Bidi::Selection;
6 # ABSTRACT: Map visual selections to original logical text
7 2 $Text::Bidi::Selection::VERSION = '3.01';
8 2 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10  
11 29 ▶sub new {
Subroutine new: called CC=17 SCAR=28.3
Pod documented
12 29 my $class = shift;
13 29 ▶ croak 'Expected named arguments' if @_ % 2;
Branch: 1 branch
BranchTrueFalseTotal
if @_ % 2 1 28 29
14 28 my %args = @_;
15 28 for my $name (keys %args) {
16 56 ▶ croak "Unknown argument: $name"
Branch: 1 branch
BranchTrueFalseTotal
unless $name eq "text" or $name eq "visual_to_logical" 1 55 56
Condition100%3/3
$name eq "text" or $name eq "visual_to_logical"
l!l&&r!l&&!r
27281
MC/DC100%2/2
$name eq "text" or $name eq "visual_to_logical"
$name eq "text" $name eq "visual_to_logical"
Truth table100%3/3
A or B
A= $name eq "text"B= $name eq "visual_to_logical"
ABresult
1X1
011
000
17 unless $name eq 'text' || $name eq 'visual_to_logical';
18 }
19 27 ▶ croak 'text must be a defined string' if !defined($args{text}) || ref($args{text});
Branch: 1 branch
BranchTrueFalseTotal
if not defined $args{"text"} or ref $args{"text"} 2 25 27
Condition100%3/3
not defined $args{"text"} or ref $args{"text"}
l!l&&r!l&&!r
1125
MC/DC100%2/2
not defined $args{"text"} or ref $args{"text"}
not defined $args{"text"} ref $args{"text"}
Truth table100%3/3
not(A) or B
A= not defined $args{"text"}B= ref $args{"text"}
ABresult
1X1
011
000
20 25 my $input = $args{visual_to_logical};
21 25 ▶ my $entries = ref($input) ? eval { [@$input] } : undef;
Branch: 1 branch
BranchTrueFalseTotal
ref $input ? : 23 2 25
22 25 ▶ croak 'visual_to_logical must be an array reference' unless defined $entries;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $entries 3 22 25
23 22 my $length = length($args{text});
24 22 my @map;
25 22 for my $entry (@$entries) {
26 137 ▶ my @indices = !defined($entry) ? () : ref($entry) eq 'ARRAY' ? @$entry : ($entry);
Branch: 2 branches
BranchTrueFalseTotal
!defined($entry) ? : 3 134 137
ref $entry eq 'ARRAY' ? : 9 125 134
27 137 for my $index (@indices) {
28 135 ▶ croak 'Map offsets must be non-negative integers within text'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $index and not ref $index and $index =~ /\A[0-9]+\z/ and $index < $length 6 129 135
Condition100%9/9
defined $index and not ref $index and $index =~ /\A[0-9]+\z/ and $index < $length
!ll&&!rl&&r
51129
defined $index and not ref $index and $index =~ /\A[0-9]+\z/
!ll&&!rl&&r
23130
defined $index and not ref $index
!ll&&!rl&&r
11133
MC/DC100%4/4
defined $index and not ref $index and $index =~ /\A[0-9]+\z/ and $index < $length
defined $index not ref $index $index =~ /\A[0-9]+\z/ $index < $length
Truth table100%5/5
A and not(B) and C and D
A= defined $indexB= not ref $indexC= $index =~ /\A[0-9]+\z/D= $index < $length
ABCDresult
0XXX0
10XX0
110X0
11100
11111
29 unless defined($index) && !ref($index) && $index =~ /\A[0-9]+\z/
30 && $index < $length;
31 }
32 131 push @map, [map { 0 + $_ } @indices];
33 }
34 16 return bless { text => $args{text}, map => \@map }, $class;
35 }
36  
37  
38 46 ▶sub logical_ranges {
Subroutine logical_ranges: called CC=13 SCAR=25.7
Pod documented
39 46 my $self = shift;
40 46 ▶ croak 'Expected visual start and end offsets' unless @_ == 2;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 2 2 44 46
41 44 my ($start, $end) = @_;
42 44 for my $offset ($start, $end) {
43 86 ▶ croak 'Visual offsets must be non-negative integers'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $offset and not ref $offset and $offset =~ /\A[0-9]+\z/ 4 82 86
Condition83%5/6
defined $offset and not ref $offset and $offset =~ /\A[0-9]+\z/
!ll&&!rl&&r
1382
defined $offset and not ref $offset
!ll&&!rl&&r
1085
MC/DC66%2/3
defined $offset and not ref $offset and $offset =~ /\A[0-9]+\z/
defined $offset not ref $offset $offset =~ /\A[0-9]+\z/
Truth table75%3/4
A and not(B) and C
A= defined $offsetB= not ref $offsetC= $offset =~ /\A[0-9]+\z/
ABCresult
0XX0
10X0
1100
1111
44 unless defined($offset) && !ref($offset) && $offset =~ /\A[0-9]+\z/;
45 }
46 40 ($start, $end) = (0 + $start, 0 + $end);
47 croak 'Visual range must satisfy 0 <= start <= end <= map length'
48 40 ▶ if $start > $end || $end > @{$self->{map}};
Branch: 1 branch
BranchTrueFalseTotal
if $start > $end or $end > @{$self->{"map"};} 3 37 40
Condition100%3/3
$start > $end or $end > @{$self->{"map"};}
l!l&&r!l&&!r
1237
MC/DC100%2/2
$start > $end or $end > @{$self->{"map"};}
$start > $end $end > @{$self->{"map"};}
Truth table100%3/3
A or B
A= $start > $endB= $end > @{$self->{"map"};}
ABresult
1X1
011
000
49 37 my %selected;
50 37 for my $visual ($start..$end - 1) {
51 89 $selected{$_} = 1 for @{$self->{map}[$visual]};
52 }
53 37 my @ranges;
54 37 for my $logical (sort { $a <=> $b } keys %selected) {
55 84 ▶ if (@ranges && $ranges[-1][1] == $logical) {
Branch: 1 branch
BranchTrueFalseTotal
if (@ranges and $ranges[-1][1] == $logical) { } 47 37 84
Condition100%3/3
@ranges and $ranges[-1][1] == $logical
!ll&&!rl&&r
30747
MC/DC100%2/2
@ranges and $ranges[-1][1] == $logical
@ranges $ranges[-1][1] == $logical
Truth table100%3/3
A and B
A= @rangesB= $ranges[-1][1] == $logical
ABresult
0X0
100
111
56 47 ++$ranges[-1][1];
57 } else {
58 37 push @ranges, [$logical, $logical + 1];
59 }
60 }
61 37 return \@ranges;
62 }
63  
64  
65 26 ▶sub selected_text {
Subroutine selected_text: called CC=1 SCAR=0.0
Pod documented
66 26 my $self = shift;
67 26 my $ranges = $self->logical_ranges(@_);
68 22 return join '', map { substr($self->{text}, $_->[0], $_->[1] - $_->[0]) } @$ranges;
69 }
70  
71  
72 2 1;
73  
74 __END__
↑ Summary blib/lib/Text/Bidi/private.pm »