blib/lib/Text/Pluralize.pm

filter: Statementstmt 92.5% 37 / 40 Branchbran 88.8% 16 / 18 Conditioncond 100% 6 / 6 MC/DCmcdc 100% 4 / 4 Subroutinesub 100% 4 / 4 Podpod 100% 1 / 1 totaltotal 93.1% 68 / 73 CC 12 SCAR 22.9
CC
12
Cov
92%
pluralize
12.1
BEGIN
1.0
BEGIN
1.0
CRAP 9.9
↑ Summary
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 1 require 5.006001;
7 package Text::Pluralize;
8 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 our $VERSION = '1.1';
11  
12 1 ▶use base qw(Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 ##==============================================================================
15 ## Exported Items
16 ##==============================================================================
17 1 our @EXPORT = qw(pluralize);
18  
19 ##<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
20 ##==============================================================================
21 ## pluralize
22 ##==============================================================================
23 25 ▶sub pluralize ($$;@) {
Subroutine pluralize: called CC=12 SCAR=25.0
Pod documented
24 25 my ($template, $count) = splice @_, 0, 2;
25 25 my $output = '';
26 25 my $control_count = 0;
27  
28 25 ▶ while (
Branch: 1 branch
BranchTrueFalseTotal
if ($template =~ / ^([^({]*) ## leading string up to a ( or { ((?: ## either \([^|)}]*[)}] ## ( string ) | ## or [({][^|]* ## ( or { up to the first | (?:\|[^|)}]*)+ ## one or more | followed by non-|, ), or } [)}] ## closing ) or } )) (.*)$ ## and then the rest of the string /sx) 49 25 74
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 ++$control_count;
42 49 $output .= $1;
43 49 $template = $3;
44 49 my $pattern = $2;
45 49 my @alternatives;
46 49 ▶ if ($pattern =~ /^\((.*)[)}]$/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($pattern =~ /^\((.*)[)}]$/) { } 35 14 49
elsif ($pattern =~ /^\{(.*)[})]$/) { } 14 0 14
47 35 @alternatives = split /\|/, $1;
48 35 ▶ push @alternatives, '' if $1 =~ /\|$/;
Branch: 1 branch
BranchTrueFalseTotal
if $1 =~ /\|$/ 0 35 35
49 35 ▶ unshift @alternatives, '' if @alternatives == 1;
Branch: 1 branch
BranchTrueFalseTotal
if @alternatives == 1 11 24 35
50 35 unshift @alternatives, $alternatives[-1];
51 } elsif ($pattern =~ /^\{(.*)[})]$/) {
52 14 @alternatives = split /\|/, $1;
53 14 ▶ push @alternatives, '' if $1 =~ /\|$/;
Branch: 1 branch
BranchTrueFalseTotal
if $1 =~ /\|$/ 4 10 14
54 } else {
55 0 $output .= $pattern;
56 0 --$control_count;
57 0 next;
58 }
59 49 ▶ if ($count >= $#alternatives || $count < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($count >= $#alternatives or $count < 0) { } 26 23 49
Condition100%3/3
$count >= $#alternatives or $count < 0
l!l&&r!l&&!r
161023
MC/DC100%2/2
$count >= $#alternatives or $count < 0
$count >= $#alternatives $count < 0
Truth table100%3/3
A or B
A= $count >= $#alternativesB= $count < 0
ABresult
1X1
011
000
60 26 $output .= $alternatives[-1];
61 } else {
62 23 $output .= $alternatives[$count];
63 }
64 }
65 25 $output .= $template;
66  
67 25 ▶ if ($control_count == 0 && $count != 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($control_count == 0 and $count != 1) 3 22 25
Condition100%3/3
$control_count == 0 and $count != 1
!ll&&!rl&&r
2113
MC/DC100%2/2
$control_count == 0 and $count != 1
$control_count == 0 $count != 1
Truth table100%3/3
A and B
A= $control_count == 0B= $count != 1
ABresult
0X0
100
111
68 3 $output .= 's';
69 }
70  
71 25 ▶ $output = sprintf $output, $count, @_ if $output =~ /%/;
Branch: 1 branch
BranchTrueFalseTotal
if $output =~ /%/ 9 16 25
72  
73 25 return $output;
74 }
75  
76 ##>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
77  
78 1 1;
79  
80 __END__
↑ Summary