blib/lib/Tie/Plural.pm

filter: Statementstmt 100% 32 / 32 Branchbran 100% 10 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod 100% 1 / 1 totaltotal 100% 50 / 50 CC 9 SCAR 17.6
CC
9
Cov
100%
plural
9.0
BEGIN
1.0
BEGIN
1.0
CRAP 5.8
↑ Summary
1 =for gpg
2 -----BEGIN PGP SIGNED MESSAGE-----
3 Hash: SHA1
4  
5 =head1 NAME
6  
7 Tie::Plural - Select a string variant based on a quantity.
8  
9 =head1 VERSION
10  
11 This documentation describes version 0.01 of Plural.pm, January 07, 2005.
12  
13 =cut
14  
15 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 package Tie::Plural;
17 1 $Tie::Plural::VERSION = '0.01';
18 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 # If exporting symbols:
21 1 ▶use Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 1 ▶use vars qw/@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS %pl/;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 1 @ISA = qw/Exporter/;
24 1 @EXPORT = qw/%pl/;
25 1 @EXPORT_OK = qw/plural/;
26 1 %EXPORT_TAGS = (all => [@EXPORT, @EXPORT_OK]);
27  
28 1 tie %pl, 'Tie::Plural';
29  
30 sub plural ($;$$$)
31 6 ▶{
Subroutine plural: called CC=9 SCAR=22.0
Pod documented
32 6 my ($num, $plural, $sing, $zero) = @_;
33  
34 6 ▶ defined or $_ = '' for $sing;
Branch: 1 branch
BranchTrueFalseTotal
defined $_ or $_ = "" 1 5 6
35 6 ▶ defined or $_ = 's' for $plural;
Branch: 1 branch
BranchTrueFalseTotal
defined $_ or $_ = "s" 2 4 6
36 6 ▶ defined or $_ = $plural for $zero;
Branch: 1 branch
BranchTrueFalseTotal
defined $_ or $_ = $plural 1 5 6
37  
38 6 ▶ my $s = $num==0? $zero : $num==1? $sing : $plural;
Branch: 2 branches
BranchTrueFalseTotal
$num == 0 ? : 1 5 6
$num == 1 ? : 1 4 5
39 6 return $s;
40 }
41  
42 sub TIEHASH
43 1 ▶{
Subroutine TIEHASH: called CC=1 SCAR=0.0
44 1 my $class = shift;
45 1 my $dummy; # not used;
46 1 bless \$dummy, $class;
47 }
48  
49 sub FETCH
50 6 ▶{
Subroutine FETCH: called CC=1 SCAR=0.0
51 6 my $self = shift;
52 6 my $key = shift;
53  
54 6 my ($n, $p, $s, $z) = split $;, $key;
55 6 return plural ($n, $p, $s, $z);
56 }
57  
58  
59 1 1;
60 __END__
↑ Summary