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