Table/Cell.pm

filter: Statementstmt 100% 58 / 58 Branchbran 75.0% 9 / 12 Conditioncond 76.9% 20 / 26 MC/DCmcdc 50.0% 8 / 16 Subroutinesub 100% 17 / 17 Podpod 0.0% 0 / 11 totaltotal 80.0% 112 / 140 CC 17 SCAR 10.9
CC
17
Cov
91%
value_width
6.0
show_char
4.6
border_left_width
3.0
CRAP 3.0
« Table/Util.pm ↑ Summary Table/Spacer.pm »
1 package Term::Table::Cell;
2 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 5 our $VERSION = '0.016';
6  
7 5 ▶use Term::Table::LineBreak();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 5 ▶use Term::Table::Util qw/uni_length/;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 5 ▶use List::Util qw/sum/;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 5 ▶use Term::Table::HashBase qw/value border_left border_right _break _widths border_color value_color reset_color/;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 5 my %CHAR_MAP = (
15 # Special case, \n should render as \n, but also actually do the newline thing
16 "\n" => "\\n\n",
17  
18 "\a" => '\\a',
19 "\b" => '\\b',
20 "\e" => '\\e',
21 "\f" => '\\f',
22 "\r" => '\\r',
23 "\t" => '\\t',
24 " " => ' ',
25 );
26  
27 sub init {
28 138 ▶ my $self = shift;
Subroutine init: called CC=2 SCAR=6.9
Pod undocumented
29  
30 # Stringify
31 138 ▶ $self->{+VALUE} = defined $self->{+VALUE} ? "$self->{+VALUE}" : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'value'} ? : 133 5 138
32 }
33  
34 sub char_id {
35 33 ▶ my $class = shift;
Subroutine char_id: called CC=1 SCAR=0.0
Pod undocumented
36 33 my ($char) = @_;
37 33 return "\\N{U+" . sprintf("\%X", ord($char)) . "}";
38 }
39  
40 sub show_char {
41 190 ▶ my $class = shift;
Subroutine show_char: called CC=4 SCAR=15.2
Pod undocumented
42 190 my ($char, %props) = @_;
43 190 ▶ return $char if $props{no_newline} && $char eq "\n";
Branch: 1 branch
BranchTrueFalseTotal
if $props{"no_newline"} and $char eq "\n" 0 190 190
Condition33%1/3
$props{"no_newline"} and $char eq "\n"
!ll&&!rl&&r
19000
MC/DC0%0/2
$props{"no_newline"} and $char eq "\n"
$props{"no_newline"} $char eq "\n"
Truth table33%1/3
A and B
A= $props{"no_newline"}B= $char eq "\n"
ABresult
0X0
100
111
44 190 ▶ return $CHAR_MAP{$char} || $class->char_id($char);
Condition66%2/3
$CHAR_MAP{$char} || $class->char_id($char)
l!l&&r!l&&!r
158320
MC/DC0%0/2
$CHAR_MAP{$char} || $class->char_id($char)
$CHAR_MAP{$char} $class->char_id($char)
Truth table66%2/3
A || B
A= $CHAR_MAP{$char}B= $class->char_id($char)
ABresult
1X1
011
000
45 }
46  
47 sub sanitize {
48 142 ▶ my $self = shift;
Subroutine sanitize: called CC=1 SCAR=0.0
Pod undocumented
49 142 $self->{+VALUE} =~ s/([\s\t\p{Zl}\p{C}\p{Zp}])/$self->show_char($1)/ge; # All whitespace except normal space
50 }
51  
52 sub mark_tail {
53 141 ▶ my $self = shift;
Subroutine mark_tail: called CC=2 SCAR=7.1
Pod undocumented
54 141 ▶ $self->{+VALUE} =~ s/([\s\t\p{Zl}\p{C}\p{Zp}])$/$1 eq ' ' ? $self->char_id($1) : $self->show_char($1, no_newline => 1)/se;
Branch: 1 branch
BranchTrueFalseTotal
$1 eq ' ' ? : 1 0 1
55 }
56  
57 sub value_width {
58 141 ▶ my $self = shift;
Subroutine value_width: called CC=6 SCAR=18.0
Pod undocumented
59  
60 141 ▶ my $w = $self->{+_WIDTHS} ||= {};
Condition50%1/2
$self->{"_widths"} ||= {}
l!l
1410
MC/DC0%0/1
$self->{"_widths"} ||= {}
$self->{"_widths"}
Truth table50%1/2
A
A= $self->{"_widths"}
Aresult
11
00
61 141 ▶ return $w->{value} if defined $w->{value};
Branch: 1 branch
BranchTrueFalseTotal
if defined $w->{"value"} 0 141 141
62  
63 141 my @parts = split /(\n)/, $self->{+VALUE};
64  
65 141 my $max = 0;
66 141 ▶ while (@parts) {
Branch: 1 branch
BranchTrueFalseTotal
if (@parts) 137 141 278
67 137 my $text = shift @parts;
68 137 ▶ my $sep = shift @parts || '';
Condition100%2/2
shift @parts || ''
l!l
8129
MC/DC100%1/1
shift @parts || ''
shift @parts
Truth table100%2/2
A
A= shift @parts
Aresult
11
00
69 137 my $len = uni_length("$text");
70 137 ▶ $max = $len if $len > $max;
Branch: 1 branch
BranchTrueFalseTotal
if $len > $max 130 7 137
71 }
72  
73 141 return $w->{value} = $max;
74 }
75  
76 sub border_left_width {
77 617 ▶ my $self = shift;
Subroutine border_left_width: called CC=3 SCAR=11.0
Pod undocumented
78 617 ▶ $self->{+_WIDTHS}->{left} ||= uni_length($self->{+BORDER_LEFT} || '');
Condition100%5/5
$self->{"_widths"}{"left"} ||= uni_length($self->{"border_left"} || "")
l!l&&r!l&&!r
204593
$self->{'border_left'} || ''
l!l
4593
MC/DC100%2/2
$self->{"_widths"}{"left"} ||= uni_length($self->{"border_left"} || "")
$self->{"_widths"}{"left"} uni_length($self->{"border_left"} || "")
MC/DC100%1/1
$self->{'border_left'} || ''
$self->{'border_left'}
Truth table100%3/3
A ||= B
A= $self->{"_widths"}{"left"}B= uni_length($self->{"border_left"} || "")
ABresult
1X1
011
000
Truth table100%2/2
A
A= $self->{'border_left'}
Aresult
11
00
79 }
80  
81 sub border_right_width {
82 617 ▶ my $self = shift;
Subroutine border_right_width: called CC=3 SCAR=11.0
Pod undocumented
83 617 ▶ $self->{+_WIDTHS}->{right} ||= uni_length($self->{+BORDER_RIGHT} || '');
Condition100%5/5
$self->{"_widths"}{"right"} ||= uni_length($self->{"border_right"} || "")
l!l&&r!l&&!r
204593
$self->{'border_right'} || ''
l!l
4593
MC/DC100%2/2
$self->{"_widths"}{"right"} ||= uni_length($self->{"border_right"} || "")
$self->{"_widths"}{"right"} uni_length($self->{"border_right"} || "")
MC/DC100%1/1
$self->{'border_right'} || ''
$self->{'border_right'}
Truth table100%3/3
A ||= B
A= $self->{"_widths"}{"right"}B= uni_length($self->{"border_right"} || "")
ABresult
1X1
011
000
Truth table100%2/2
A
A= $self->{'border_right'}
Aresult
11
00
84 }
85  
86 sub width {
87 141 ▶ my $self = shift;
Subroutine width: called CC=2 SCAR=7.0
Pod undocumented
88 141 ▶ $self->{+_WIDTHS}->{all} ||= sum(map { $self->$_ } qw/value_width border_left_width border_right_width/);
Condition66%2/3
$self->{"_widths"}{"all"} ||= &sum(map({$self->$_;} "value_width", "border_left_width", "border_right_width"))
l!l&&r!l&&!r
012912
MC/DC50%1/2
$self->{"_widths"}{"all"} ||= &sum(map({$self->$_;} "value_width", "border_left_width", "border_right_width"))
$self->{"_widths"}{"all"} &sum(map({$self->$_;} "value_width", "border_left_width", "border_right_width"))
Truth table66%2/3
A ||= B
A= $self->{"_widths"}{"all"}B= &sum(map({$self->$_;} "value_width", "border_left_width", "border_right_width"))
ABresult
1X1
011
000
89 }
90  
91 sub break {
92 476 ▶ my $self = shift;
Subroutine break: called CC=2 SCAR=7.1
Pod undocumented
93 476 ▶ $self->{+_BREAK} ||= Term::Table::LineBreak->new(string => $self->{+VALUE});
Condition66%2/3
$self->{"_break"} ||= "Term::Table::LineBreak"->new("string", $self->{"value"})
l!l&&r!l&&!r
3401360
MC/DC0%0/2
$self->{"_break"} ||= "Term::Table::LineBreak"->new("string", $self->{"value"})
$self->{"_break"} "Term::Table::LineBreak"->new("string", $self->{"value"})
Truth table66%2/3
A ||= B
A= $self->{"_break"}B= "Term::Table::LineBreak"->new("string", $self->{"value"})
ABresult
1X1
011
000
94 }
95  
96 sub reset {
97 136 ▶ my $self = shift;
Subroutine reset: called CC=1 SCAR=0.0
Pod undocumented
98 136 delete $self->{+_BREAK};
99 }
100  
101 5 1;
102  
103 __END__
« Table/Util.pm ↑ Summary Table/Spacer.pm »