Yath/Term.pm

filter: Statementstmt 88.1% 37 / 42 Branchbran 56.2% 9 / 16 Conditioncond 50.0% 3 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 85.7% 6 / 7 Podpod 100% 1 / 1 totaltotal 73.6% 56 / 76 CC 13 SCAR 23.2
CC
13
Cov
77%
fit_to_width
15.2
BEGIN
2.3
__ANON__
2.0
CRAP 10.2
« Yath.pm ↑ Summary Yath/HashBase.pm »
1 package Getopt::Yath::Term;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 our $VERSION = '2.000008';
6  
7 1 our @EXPORT = qw/color USE_COLOR term_size fit_to_width/;
8 1 ▶use Importer Importer => 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 ▶use Term::Table::Util qw/term_size/;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 BEGIN {
13 1 ▶ if (eval { require Term::ANSIColor; 1 }) {
Subroutine BEGIN: called CC=2 SCAR=8.1
Branch: 1 branch
BranchTrueFalseTotal
if (eval { do { require Term::ANSIColor; 1 } }) { } 1 0 1
14 1 *USE_COLOR = sub() { 1 };
15 1 *color = \&Term::ANSIColor::color;
16 }
17 else {
18 0 *USE_COLOR = sub() { 0 };
19 0 ▶ *color = sub { '' };
Subroutine __ANON__: not called CC=1 SCAR=6.9
20 }
21 }
22  
23 sub fit_to_width {
24 31 ▶ my ($join, $text, %params) = @_;
Subroutine fit_to_width: called CC=12 SCAR=27.2
Pod documented
25  
26 31 my $prefix = $params{prefix};
27 31 my $width = $params{width};
28 31 ▶ unless (defined $width) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $width) 31 0 31
29 31 $width = term_size() - 20;
30 31 ▶ $width = 80 unless $width && $width >= 80;
Branch: 1 branch
BranchTrueFalseTotal
unless $width and $width >= 80 0 31 31
Condition33%1/3
$width and $width >= 80
!ll&&!rl&&r
0031
MC/DC0%0/2
$width and $width >= 80
$width $width >= 80
Truth table33%1/3
A and B
A= $widthB= $width >= 80
ABresult
0X0
100
111
31 }
32  
33 31 ▶ my @parts = ref($text) ? @$text : split /\s+/, $text;
Branch: 1 branch
BranchTrueFalseTotal
ref $text ? : 0 31 31
34  
35 31 my @out;
36  
37 31 my $line = "";
38 31 for my $part (@parts) {
39 161 ▶ my $new = $line ? "$line$join$part" : $part;
Branch: 1 branch
BranchTrueFalseTotal
$line ? : 130 31 161
40  
41 161 ▶ if ($line && length($new) > $width) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line and length $new > $width) { } 0 161 161
Condition66%2/3
$line and length $new > $width
!ll&&!rl&&r
311300
MC/DC0%0/2
$line and length $new > $width
$line length $new > $width
Truth table66%2/3
A and B
A= $lineB= length $new > $width
ABresult
0X0
100
111
42 0 push @out => $line;
43 0 $line = $part;
44 }
45 else {
46 161 $line = $new;
47 }
48 }
49 31 ▶ push @out => $line if $line;
Branch: 1 branch
BranchTrueFalseTotal
if $line 31 0 31
50  
51 31 ▶ if(defined $prefix) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $prefix) 31 0 31
52 31 $_ =~ s/^/ /gm for @out;
53 }
54  
55 31 return join "\n" => @out;
56 }
57  
58 1 1;
59  
60 __END__
« Yath.pm ↑ Summary Yath/HashBase.pm »