File Coverage

blib/lib/Acme/Lingua/EN/Inflect/Modern.pm
Criterion Covered Total %
statement 31 31 100.0
branch 6 8 75.0
condition n/a
subroutine 10 10 100.0
pod n/a
total 47 49 95.9


line stmt bran cond sub pod time code
1 11     11   7173 use strict;
  11         18  
  11         367  
2 11     11   56 use warnings;
  11         17  
  11         884  
3             package Acme::Lingua::EN::Inflect::Modern;
4             $Acme::Lingua::EN::Inflect::Modern::VERSION = '0.006';
5 11     11   9717 use parent qw(Exporter);
  11         3439  
  11         50  
6             # ABSTRACT: modernize Lingua::EN::Inflect rule's
7              
8 11     11   17420 use Lingua::EN::Inflect 1.86 ();
  11         250442  
  11         769  
9 11     11   11197 use Sub::Override 0.07;
  11         10278  
  11         432  
10              
11 11     11   818 BEGIN { our %EXPORT_TAGS = %Lingua::EN::Inflect::EXPORT_TAGS };
12              
13             Exporter::export_ok_tags(qw( ALL ));
14              
15             # =head1 SYNOPSIS
16             #
17             # Lingua::EN::Inflect is great for converting singular word's to plural's, but
18             # does not always match modern usage. This module corrects the most common
19             # case's.
20             #
21             # See L for information on using this module, which has an
22             # identical interface.
23             #
24             # =cut
25              
26             my %todo = map { map { $_ => 1 } @$_ }
27             values %Lingua::EN::Inflect::EXPORT_TAGS;
28              
29             for my $routine (keys %todo) {
30 11     11   71 no strict 'refs';
  11         22  
  11         1185  
31             *{__PACKAGE__ . '::' . $routine} = sub {
32 142     142   67283 my $override = Sub::Override->new(
33             'Lingua::EN::Inflect::_PL_noun' => \&_PL_noun
34             );
35              
36 142         6037 Lingua::EN::Inflect->can($routine)->(@_);
37             };
38             }
39              
40             my $original_PL_noun;
41 11     11   2490 BEGIN { $original_PL_noun = \&Lingua::EN::Inflect::_PL_noun; }
42              
43             sub _PL_noun {
44 124     124   1378 my ($word, $number) = @_;
45              
46 124         333 my $plural = $original_PL_noun->($word, $number);
47              
48 124 50       69572 return $plural if $plural eq 'his';
49 124 50       275 return $plural if $plural eq 'us';
50              
51 124 100       469 if ($word =~ /es$/) {
    100          
52 5         42 $plural =~ s/e(s$|s\|)/'$1/;
53             } elsif ($word =~ /y$/) {
54 21         189 $plural =~ s/(?:ie|y)?(s$|s\|)/y'$1/;
55             } else {
56 98         657 $plural =~ s/(s$|s\|)/'$1/;
57             }
58              
59 124         514 return $plural;
60             }
61              
62             # =head1 BUG'S
63             #
64             # Please report any bug's or feature request's via the GitHub issue tracker at
65             # L. I will be
66             # notified, and then you'll automatically be notified of progress on
67             # your bug as I make change's.
68             #
69             # =cut
70              
71             1;
72              
73             __END__