blib/lib/Term/Vspark.pm

filter: Statementstmt 94.7% 54 / 57 Branchbran 50.0% 6 / 12 Conditioncond 50.0% 8 / 16 MC/DCmcdc 11.1% 1 / 9 Subroutinesub 100% 9 / 9 Podpod 33.3% 1 / 3 totaltotal 74.5% 79 / 106 CC 15 SCAR 21.5
CC
15
Cov
80%
show_graph
15.5
show_bar
4.0
max_label_width
2.0
CRAP 8.5
↑ Summary Build »
1 package Term::Vspark;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use POSIX;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use Carp qw{ croak };
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 2 use Sub::Exporter -setup => {
10 'exports' => [ 'show_bar', 'show_graph', ],
11 2 ▶};
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 2 our @ISA = qw();
14  
15 2 our $VERSION = 0.31;
16  
17 sub show_bar {
18 6 ▶ my $num = shift || 0;
Subroutine show_bar: called CC=4 SCAR=14.0
Pod undocumented
Condition100%2/2
shift() || 0
l!l
51
MC/DC100%1/1
shift() || 0
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
19 6 ▶ my $max = shift || 0;
Condition50%1/2
shift() || 0
l!l
60
MC/DC0%0/1
shift() || 0
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
20 6 ▶ my $columns = shift || 0;
Condition50%1/2
shift() || 0
l!l
60
MC/DC0%0/1
shift() || 0
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
21  
22 6 my @graph = qw{ ▏ ▎ ▍ ▌ ▋ ▊ ▉ █ };
23 6 my $bar_num = ceil( $num * ( scalar(@graph) * $columns ) ) / $max;
24  
25 6 my $str = $graph[-1] x ( int($bar_num / scalar(@graph) ) );
26 6 $str .= $graph[ ceil($bar_num % (scalar(@graph) ) ) ];
27  
28 6 return $str;
29 }
30  
31 sub show_graph {
32 1 ▶ my %args = @_;
Subroutine show_graph: called CC=11 SCAR=27.4
Pod documented
33  
34 1 ▶ if ( ref $args{'values'} ne 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $args{"values"} ne "ARRAY") 0 1 1
35 0 croak 'values is not an ArrayRef';
36 }
37  
38 1 ▶ if ( $args{'labels'} && ( ref $args{'labels'} ne 'ARRAY' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"labels"} and ref $args{"labels"} ne "ARRAY") 0 1 1
Condition33%1/3
$args{"labels"} and ref $args{"labels"} ne "ARRAY"
!ll&&!rl&&r
010
MC/DC0%0/2
$args{"labels"} and ref $args{"labels"} ne "ARRAY"
$args{"labels"} ref $args{"labels"} ne "ARRAY"
Truth table33%1/3
A and B
A= $args{"labels"}B= ref $args{"labels"} ne "ARRAY"
ABresult
0X0
100
111
39 0 croak 'labels is not an ArrayRef';
40 }
41  
42 1 ▶ my $max = $args{'max'} || 1;
Condition50%1/2
$args{'max'} || 1
l!l
10
MC/DC0%0/1
$args{'max'} || 1
$args{'max'}
Truth table50%1/2
A
A= $args{'max'}
Aresult
11
00
43 1 ▶ my $columns = $args{'columns'} || 1;
Condition50%1/2
$args{'columns'} || 1
l!l
10
MC/DC0%0/1
$args{'columns'} || 1
$args{'columns'}
Truth table50%1/2
A
A= $args{'columns'}
Aresult
11
00
44 1 ▶ my @labels = @{ $args{'labels'} || [] };
Branch: 1 branch
BranchTrueFalseTotal
$args{"labels"} or [] 0 1 1
45 1 my @values = @{ $args{'values'} };
46  
47 1 ▶ if ( $args{'labels'} && ( scalar @labels != scalar @values ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"labels"} and scalar @labels != scalar @values) 0 1 1
Condition33%1/3
$args{"labels"} and scalar @labels != scalar @values
!ll&&!rl&&r
010
MC/DC0%0/2
$args{"labels"} and scalar @labels != scalar @values
$args{"labels"} scalar @labels != scalar @values
Truth table33%1/3
A and B
A= $args{"labels"}B= scalar @labels != scalar @values
ABresult
0X0
100
111
48 0 croak 'the number of labels and values must be equal';
49 }
50  
51 1 my $label_width = max_label_width( @labels );
52 1 my $bar_width = $columns - $label_width - 2;
53 1 my $str = q{};
54  
55 1 for my $value (@values) {
56 6 my $label = shift @labels;
57 6 my $bar = show_bar($value, $max, $bar_width);
58  
59 6 ▶ $str .= sprintf('%' . $label_width . "s ", $label) if defined $label;
Branch: 1 branch
BranchTrueFalseTotal
if defined $label 6 0 6
60 6 $str .= $bar . "\n";
61 }
62  
63 1 return $str;
64 }
65  
66 sub max_label_width {
67 1 ▶ my @labels = @_;
Subroutine max_label_width: called CC=2 SCAR=7.0
Pod undocumented
68 1 ▶ return 0 if scalar @labels == 0;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @labels == 0 0 1 1
69  
70 1 my $max_width = (sort { $a <=> $b } map { length($_) } @labels)[-1];
71 1 return $max_width + 1;
72 }
73  
74 2 1;
75 __END__
↑ Summary Build »