Table/LineBreak.pm

filter: Statementstmt 98.3% 58 / 59 Branchbran 88.4% 23 / 26 Conditioncond 88.8% 8 / 9 MC/DCmcdc 80.0% 4 / 5 Subroutinesub 90.0% 9 / 10 Podpod 0.0% 0 / 4 totaltotal 90.2% 102 / 113 CC 17 SCAR 18.7
CC
17
Cov
95%
break
11.0
next
6.0
init
2.1
CRAP 6.5
« Table/HashBase.pm ↑ Summary Table/Util.pm »
1 package Term::Table::LineBreak;
2 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 6 our $VERSION = '0.018';
6  
7 6 ▶use Carp qw/croak/;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 6 ▶use Scalar::Util qw/blessed/;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 6 ▶use Term::Table::Util qw/uni_length/;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 6 ▶use Term::Table::HashBase qw/string gcstring _len _parts idx/;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 sub init {
14 140 ▶ my $self = shift;
Subroutine init: called CC=2 SCAR=7.2
Pod undocumented
15  
16 croak "string is a required attribute"
17 140 ▶ unless defined $self->{+STRING};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"string"} 0 140 140
18 }
19  
20 0 ▶sub columns { uni_length($_[0]->{+STRING}) }
Subroutine columns: not called CC=1 SCAR=6.9
Pod undocumented
21  
22 sub break {
23 140 ▶ my $self = shift;
Subroutine break: called CC=11 SCAR=24.0
Pod undocumented
24 140 my ($len) = @_;
25  
26 140 $self->{+_LEN} = $len;
27  
28 140 $self->{+IDX} = 0;
29 140 my $str = $self->{+STRING} . ""; # Force stringification
30  
31 140 my @parts;
32 140 my @chars = split //, $str;
33 140 ▶ while (@chars) {
Branch: 1 branch
BranchTrueFalseTotal
if (@chars) 264 140 404
34 264 my $size = 0;
35 264 my $part = '';
36 264 ▶ until ($size == $len) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($size == $len) 1826 194 2020
37 1826 my $char = shift @chars;
38 1826 ▶ $char = '' unless defined $char;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $char 68 1758 1826
39  
40 1826 my $l = uni_length("$char");
41 1826 ▶ last unless $l;
Branch: 1 branch
BranchTrueFalseTotal
unless $l 69 1757 1826
42  
43 1757 ▶ last if $char eq "\n";
Branch: 1 branch
BranchTrueFalseTotal
if $char eq "\n" 0 1757 1757
44  
45 1757 ▶ if ($size + $l > $len) {
Branch: 1 branch
BranchTrueFalseTotal
if ($size + $l > $len) 1 1756 1757
46 1 unshift @chars => $char;
47 1 last;
48 }
49  
50 1756 $size += $l;
51 1756 $part .= $char;
52 }
53  
54 # If we stopped just before a newline, grab it
55 264 ▶ shift @chars if $size == $len && @chars && $chars[0] eq "\n";
Branch: 1 branch
BranchTrueFalseTotal
if $size == $len and @chars and $chars[0] eq "\n" 14 250 264
Condition100%6/6
$size == $len and @chars and $chars[0] eq "\n"
!ll&&!rl&&r
13511514
$size == $len and @chars
!ll&&!rl&&r
7065129
MC/DC100%3/3
$size == $len and @chars and $chars[0] eq "\n"
$size == $len @chars $chars[0] eq "\n"
Truth table100%4/4
A and B and C
A= $size == $lenB= @charsC= $chars[0] eq "\n"
ABCresult
0XX0
10X0
1100
1111
56  
57 264 ▶ until ($size == $len) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($size == $len) 429 264 693
58 429 $part .= ' ';
59 429 $size += 1;
60 }
61 264 push @parts => $part;
62 }
63  
64 140 $self->{+_PARTS} = \@parts;
65 }
66  
67 sub next {
68 495 ▶ my $self = shift;
Subroutine next: called CC=6 SCAR=18.0
Pod undocumented
69  
70 495 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 476 19 495
71 476 my ($len) = @_;
72 476 ▶ $self->break($len) if !$self->{+_LEN} || $self->{+_LEN} != $len;
Branch: 1 branch
BranchTrueFalseTotal
if not $self->{"_len"} or $self->{"_len"} != $len 136 340 476
Condition66%2/3
not $self->{"_len"} or $self->{"_len"} != $len
l!l&&r!l&&!r
1360340
MC/DC50%1/2
not $self->{"_len"} or $self->{"_len"} != $len
not $self->{"_len"} $self->{"_len"} != $len
Truth table66%2/3
not(A) or B
A= not $self->{"_len"}B= $self->{"_len"} != $len
ABresult
1X1
011
000
73 }
74 else {
75 croak "String has not yet been broken"
76 19 ▶ unless $self->{+_PARTS};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"_parts"} 0 19 19
77 }
78  
79 495 my $idx = $self->{+IDX}++;
80 495 my $parts = $self->{+_PARTS};
81  
82 495 ▶ return undef if $idx >= @$parts;
Branch: 1 branch
BranchTrueFalseTotal
if $idx >= @$parts 231 264 495
83 264 return $parts->[$idx];
84 }
85  
86 6 1;
87  
88 __END__
« Table/HashBase.pm ↑ Summary Table/Util.pm »