| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
##============================================================================== |
|
2
|
|
|
|
|
|
|
## Text::Pluralize - simple pluralization routine |
|
3
|
|
|
|
|
|
|
##============================================================================== |
|
4
|
|
|
|
|
|
|
## $Id: Pluralize.pm,v 1.1 2007/08/08 02:14:03 kevin Exp $ |
|
5
|
|
|
|
|
|
|
##============================================================================== |
|
6
|
|
|
|
|
|
|
require 5.006001; |
|
7
|
|
|
|
|
|
|
package Text::Pluralize; |
|
8
|
1
|
|
|
1
|
|
19578
|
use strict; |
|
|
1
|
|
|
|
|
4
|
|
|
|
1
|
|
|
|
|
36
|
|
|
9
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
35
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '1.1'; |
|
11
|
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
4
|
use base qw(Exporter); |
|
|
1
|
|
|
|
|
6
|
|
|
|
1
|
|
|
|
|
537
|
|
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
##============================================================================== |
|
15
|
|
|
|
|
|
|
## Exported Items |
|
16
|
|
|
|
|
|
|
##============================================================================== |
|
17
|
|
|
|
|
|
|
our @EXPORT = qw(pluralize); |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
##<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< |
|
20
|
|
|
|
|
|
|
##============================================================================== |
|
21
|
|
|
|
|
|
|
## pluralize |
|
22
|
|
|
|
|
|
|
##============================================================================== |
|
23
|
|
|
|
|
|
|
sub pluralize ($$;@) { |
|
24
|
25
|
|
|
25
|
1
|
1025
|
my ($template, $count) = splice @_, 0, 2; |
|
25
|
25
|
|
|
|
|
29
|
my $output = ''; |
|
26
|
25
|
|
|
|
|
24
|
my $control_count = 0; |
|
27
|
|
|
|
|
|
|
|
|
28
|
25
|
|
|
|
|
113
|
while ( |
|
29
|
|
|
|
|
|
|
$template =~ / |
|
30
|
|
|
|
|
|
|
^([^({]*) ## leading string up to a ( or { |
|
31
|
|
|
|
|
|
|
((?: ## either |
|
32
|
|
|
|
|
|
|
\([^|)}]*[)}] ## ( string ) |
|
33
|
|
|
|
|
|
|
| ## or |
|
34
|
|
|
|
|
|
|
[({][^|]* ## ( or { up to the first | |
|
35
|
|
|
|
|
|
|
(?:\|[^|)}]*)+ ## one or more | followed by non-|, ), or } |
|
36
|
|
|
|
|
|
|
[)}] ## closing ) or } |
|
37
|
|
|
|
|
|
|
)) |
|
38
|
|
|
|
|
|
|
(.*)$ ## and then the rest of the string |
|
39
|
|
|
|
|
|
|
/xs |
|
40
|
|
|
|
|
|
|
) { |
|
41
|
49
|
|
|
|
|
48
|
++$control_count; |
|
42
|
49
|
|
|
|
|
71
|
$output .= $1; |
|
43
|
49
|
|
|
|
|
69
|
$template = $3; |
|
44
|
49
|
|
|
|
|
58
|
my $pattern = $2; |
|
45
|
49
|
|
|
|
|
43
|
my @alternatives; |
|
46
|
49
|
100
|
|
|
|
167
|
if ($pattern =~ /^\((.*)[)}]$/) { |
|
|
|
50
|
|
|
|
|
|
|
47
|
35
|
|
|
|
|
85
|
@alternatives = split /\|/, $1; |
|
48
|
35
|
50
|
|
|
|
76
|
push @alternatives, '' if $1 =~ /\|$/; |
|
49
|
35
|
100
|
|
|
|
60
|
unshift @alternatives, '' if @alternatives == 1; |
|
50
|
35
|
|
|
|
|
49
|
unshift @alternatives, $alternatives[-1]; |
|
51
|
|
|
|
|
|
|
} elsif ($pattern =~ /^\{(.*)[})]$/) { |
|
52
|
14
|
|
|
|
|
42
|
@alternatives = split /\|/, $1; |
|
53
|
14
|
100
|
|
|
|
40
|
push @alternatives, '' if $1 =~ /\|$/; |
|
54
|
|
|
|
|
|
|
} else { |
|
55
|
0
|
|
|
|
|
0
|
$output .= $pattern; |
|
56
|
0
|
|
|
|
|
0
|
--$control_count; |
|
57
|
0
|
|
|
|
|
0
|
next; |
|
58
|
|
|
|
|
|
|
} |
|
59
|
49
|
100
|
100
|
|
|
158
|
if ($count >= $#alternatives || $count < 0) { |
|
60
|
26
|
|
|
|
|
105
|
$output .= $alternatives[-1]; |
|
61
|
|
|
|
|
|
|
} else { |
|
62
|
23
|
|
|
|
|
104
|
$output .= $alternatives[$count]; |
|
63
|
|
|
|
|
|
|
} |
|
64
|
|
|
|
|
|
|
} |
|
65
|
25
|
|
|
|
|
26
|
$output .= $template; |
|
66
|
|
|
|
|
|
|
|
|
67
|
25
|
100
|
100
|
|
|
94
|
if ($control_count == 0 && $count != 1) { |
|
68
|
3
|
|
|
|
|
4
|
$output .= 's'; |
|
69
|
|
|
|
|
|
|
} |
|
70
|
|
|
|
|
|
|
|
|
71
|
25
|
100
|
|
|
|
78
|
$output = sprintf $output, $count, @_ if $output =~ /%/; |
|
72
|
|
|
|
|
|
|
|
|
73
|
25
|
|
|
|
|
97
|
return $output; |
|
74
|
|
|
|
|
|
|
} |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
##>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
1; |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
__END__ |