| line | stmt | bran | cond | sub | pod | time | code | 
| 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 |  |  | 1 |  | 713 | use strict; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 122 |  | 
| 16 |  |  |  |  |  |  | package Tie::Plural; | 
| 17 |  |  |  |  |  |  | $Tie::Plural::VERSION = '0.01'; | 
| 18 | 1 |  |  | 1 |  | 6 | use Carp; | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 87 |  | 
| 19 |  |  |  |  |  |  |  | 
| 20 |  |  |  |  |  |  | # If exporting symbols: | 
| 21 | 1 |  |  | 1 |  | 5 | use Exporter; | 
|  | 1 |  |  |  |  | 4 |  | 
|  | 1 |  |  |  |  | 41 |  | 
| 22 | 1 |  |  | 1 |  | 5 | use vars qw/@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS %pl/; | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 401 |  | 
| 23 |  |  |  |  |  |  | @ISA         = qw/Exporter/; | 
| 24 |  |  |  |  |  |  | @EXPORT      = qw/%pl/; | 
| 25 |  |  |  |  |  |  | @EXPORT_OK   = qw/plural/; | 
| 26 |  |  |  |  |  |  | %EXPORT_TAGS = (all => [@EXPORT, @EXPORT_OK]); | 
| 27 |  |  |  |  |  |  |  | 
| 28 |  |  |  |  |  |  | tie %pl, 'Tie::Plural'; | 
| 29 |  |  |  |  |  |  |  | 
| 30 |  |  |  |  |  |  | sub plural ($;$$$) | 
| 31 |  |  |  |  |  |  | { | 
| 32 | 6 |  |  | 6 | 1 | 10 | my ($num, $plural, $sing, $zero) = @_; | 
| 33 |  |  |  |  |  |  |  | 
| 34 | 6 |  | 100 |  |  | 24 | defined or $_ = ''      for $sing; | 
| 35 | 6 |  | 100 |  |  | 21 | defined or $_ = 's'     for $plural; | 
| 36 | 6 |  | 100 |  |  | 18 | defined or $_ = $plural for $zero; | 
| 37 |  |  |  |  |  |  |  | 
| 38 | 6 | 100 |  |  |  | 20 | my $s = $num==0? $zero : $num==1? $sing : $plural; | 
|  |  | 100 |  |  |  |  |  | 
| 39 | 6 |  |  |  |  | 30 | return $s; | 
| 40 |  |  |  |  |  |  | } | 
| 41 |  |  |  |  |  |  |  | 
| 42 |  |  |  |  |  |  | sub TIEHASH | 
| 43 |  |  |  |  |  |  | { | 
| 44 | 1 |  |  | 1 |  | 3 | my $class = shift; | 
| 45 | 1 |  |  |  |  | 1 | my $dummy;  # not used; | 
| 46 | 1 |  |  |  |  | 3 | bless \$dummy, $class; | 
| 47 |  |  |  |  |  |  | } | 
| 48 |  |  |  |  |  |  |  | 
| 49 |  |  |  |  |  |  | sub FETCH | 
| 50 |  |  |  |  |  |  | { | 
| 51 | 6 |  |  | 6 |  | 55 | my $self = shift; | 
| 52 | 6 |  |  |  |  | 9 | my $key  = shift; | 
| 53 |  |  |  |  |  |  |  | 
| 54 | 6 |  |  |  |  | 31 | my ($n, $p, $s, $z) = split $;, $key; | 
| 55 | 6 |  |  |  |  | 15 | return plural ($n, $p, $s, $z); | 
| 56 |  |  |  |  |  |  | } | 
| 57 |  |  |  |  |  |  |  | 
| 58 |  |  |  |  |  |  |  | 
| 59 |  |  |  |  |  |  | 1; | 
| 60 |  |  |  |  |  |  | __END__ |