| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 47 | 35 | @alternatives = split /\|/, $1; | |||||||||||||||||||||||||||
| 48 | 35 | ▶ | push @alternatives, '' if $1 =~ /\|$/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | 35 | ▶ | unshift @alternatives, '' if @alternatives == 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | 35 | unshift @alternatives, $alternatives[-1]; | |||||||||||||||||||||||||||
| 51 | } elsif ($pattern =~ /^\{(.*)[})]$/) { | ||||||||||||||||||||||||||||
| 52 | 14 | @alternatives = split /\|/, $1; | |||||||||||||||||||||||||||
| 53 | 14 | ▶ | push @alternatives, '' if $1 =~ /\|$/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 54 | } else { | ||||||||||||||||||||||||||||
| 55 | 0 | $output .= $pattern; | |||||||||||||||||||||||||||
| 56 | 0 | --$control_count; | |||||||||||||||||||||||||||
| 57 | 0 | next; | |||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | 49 | ▶ | if ($count >= $#alternatives || $count < 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$count >= $#alternatives or $count < 0
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
| |||||||||||||||||||||||||||||
| 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
Condition100%3/3
$control_count == 0 and $count != 1
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
| |||||||||||||||||||||||||||||
| 68 | 3 | $output .= 's'; | |||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 25 | ▶ | $output = sprintf $output, $count, @_ if $output =~ /%/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 25 | return $output; | |||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | ##>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 1 | 1; | |||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | __END__ | ||||||||||||||||||||||||||||