line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package List::ToHumanString; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
83473
|
use 5.006; |
|
3
|
|
|
|
|
13
|
|
|
3
|
|
|
|
|
140
|
|
4
|
3
|
|
|
3
|
|
21
|
use strict; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
112
|
|
5
|
3
|
|
|
3
|
|
16
|
use warnings; |
|
3
|
|
|
|
|
16
|
|
|
3
|
|
|
|
|
1681
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '1.002'; |
8
|
|
|
|
|
|
|
require Exporter; |
9
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
10
|
|
|
|
|
|
|
our @EXPORT = qw(to_human_string); |
11
|
|
|
|
|
|
|
our $Extra_Comma = 1; |
12
|
|
|
|
|
|
|
our $Separator = '|'; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub _combine_list_to_string { |
15
|
8
|
|
|
8
|
|
19
|
my @list = @_; |
16
|
|
|
|
|
|
|
|
17
|
8
|
|
33
|
|
|
147
|
@list = grep defined && /\S/, @list; |
18
|
|
|
|
|
|
|
|
19
|
8
|
100
|
|
|
|
42
|
if ( not @list ) { |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
20
|
1
|
|
|
|
|
4
|
return ''; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
elsif ( @list == 1 ) { |
23
|
1
|
|
|
|
|
4
|
return "$list[0]"; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
elsif ( @list == 2 ) { |
26
|
3
|
|
|
|
|
18
|
return "$list[0]" . ' and ' . "$list[1]"; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
else { |
29
|
3
|
100
|
|
|
|
36
|
return join ', ', map "$_", |
30
|
|
|
|
|
|
|
$Extra_Comma |
31
|
|
|
|
|
|
|
? ( @list[0..$#list-1], 'and ' . $list[-1] ) |
32
|
|
|
|
|
|
|
: ( @list[0..$#list-2], $list[-2] . ' and ' . $list[-1] ) |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub to_human_string { |
37
|
20
|
|
|
20
|
1
|
484
|
my ( $string, @list ) = @_; |
38
|
|
|
|
|
|
|
|
39
|
20
|
|
100
|
|
|
248
|
@list = grep defined && /\S/, @list; |
40
|
|
|
|
|
|
|
|
41
|
20
|
100
|
|
|
|
64
|
my $replacement_index = ( @list == 1 ? 0 : 1 ); |
42
|
20
|
|
|
|
|
244
|
$string=~ |
43
|
|
|
|
|
|
|
s% |
44
|
|
|
|
|
|
|
{ ( [^}]* \Q$Separator\E [^}]* ) } |
45
|
|
|
|
|
|
|
% |
46
|
14
|
|
|
|
|
89
|
( split /\Q$Separator\E/, $1, 2 )[ $replacement_index ]; |
47
|
|
|
|
|
|
|
%gex; |
48
|
|
|
|
|
|
|
|
49
|
20
|
|
|
|
|
133
|
my $re = qr/\Q$Separator\Elist\Q$Separator\E/; |
50
|
20
|
100
|
|
|
|
100
|
if ( $string =~ /$re/ ) { |
51
|
8
|
|
|
|
|
25
|
my $human_list = _combine_list_to_string( @list ); |
52
|
8
|
|
|
|
|
67
|
$string =~ s/$re/$human_list/g; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
20
|
|
|
|
|
145
|
return $string; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
1; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
__END__ |