blib/lib/List/ToHumanString.pm

filter: Statementstmt 100% 32 / 32 Branchbran 100% 12 / 12 Conditioncond 66.6% 4 / 6 MC/DCmcdc 50.0% 2 / 4 Subroutinesub 100% 5 / 5 Podpod 100% 1 / 1 totaltotal 93.3% 56 / 60 CC 9 SCAR 14.5
CC
9
Cov
96%
_combine_list_to_string
6.0
to_human_string
4.0
BEGIN
1.0
CRAP 4.3
↑ Summary
1 package List::ToHumanString;
2  
3 4 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 4 our $VERSION = '1.003002'; # VERSION
8  
9 4 require Exporter;
10 4 our @ISA = qw(Exporter);
11 4 our @EXPORT = qw(to_human_string);
12 4 our $Extra_Comma = 1;
13 4 our $Separator = '|';
14  
15 8 ▶sub _combine_list_to_string {
Subroutine _combine_list_to_string: called CC=6 SCAR=18.0
16 8 my @list = @_;
17  
18 8 ▶ @list = grep defined && /\S/, @list;
Condition33%1/3
defined $_ && /\S/
!ll&&!rl&&r
0018
MC/DC0%0/2
defined $_ && /\S/
defined $_ /\S/
Truth table33%1/3
A && B
A= defined $_B= /\S/
ABresult
0X0
100
111
19  
20 8 ▶ if ( not @list ) {
Branch: 3 branches
BranchTrueFalseTotal
if (not @list) { } 1 7 8
elsif (@list == 1) { } 1 6 7
elsif (@list == 2) { } 3 3 6
21 1 return '';
22 }
23 elsif ( @list == 1 ) {
24 1 return "$list[0]";
25 }
26 elsif ( @list == 2 ) {
27 3 return "$list[0]" . ' and ' . "$list[1]";
28 }
29 else {
30 3 ▶ return join ', ', map "$_",
Branch: 1 branch
BranchTrueFalseTotal
$List::ToHumanString::Extra_Comma ? : 2 1 3
31 $Extra_Comma
32 ? ( @list[0..$#list-1], 'and ' . $list[-1] )
33 : ( @list[0..$#list-2], $list[-2] . ' and ' . $list[-1] )
34 }
35 }
36  
37 20 ▶sub to_human_string {
Subroutine to_human_string: called CC=4 SCAR=13.9
Pod documented
38 20 my ( $string, @list ) = @_;
39  
40 20 ▶ @list = grep defined && /\S/, @list;
Condition100%3/3
defined $_ && /\S/
!ll&&!rl&&r
71234
MC/DC100%2/2
defined $_ && /\S/
defined $_ /\S/
Truth table100%3/3
A && B
A= defined $_B= /\S/
ABresult
0X0
100
111
41  
42 20 ▶ my $replacement_index = ( @list == 1 ? 0 : 1 );
Branch: 1 branch
BranchTrueFalseTotal
@list == 1 ? : 7 13 20
43 20 $string=~
44 s%
45 { ( [^}]* \Q$Separator\E [^}]* ) }
46 %
47 14 ( split /\Q$Separator\E/, $1, 2 )[ $replacement_index ];
48 %gex;
49  
50 20 my $re = qr/\Q$Separator\Elist\Q$Separator\E/;
51 20 ▶ if ( $string =~ /$re/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($string =~ /$re/) 8 12 20
52 8 my $human_list = _combine_list_to_string( @list );
53 8 $string =~ s/$re/$human_list/g;
54 }
55  
56 20 return $string;
57 }
58  
59  
60 4 1;
61  
62 __END__
↑ Summary