File Coverage

blib/lib/Lingua/Numending.pm
Criterion Covered Total %
statement 27 28 96.4
branch 3 4 75.0
condition 9 15 60.0
subroutine 6 6 100.0
pod 1 1 100.0
total 46 54 85.1


line stmt bran cond sub pod time code
1             package Lingua::Numending;
2 8     8   37163 use utf8;
  8         96  
  8         182  
3 8     8   533 use 5.006;
  8         30  
  8         370  
4 8     8   52 use strict;
  8         27  
  8         442  
5 8     8   52 use warnings;
  8         19  
  8         780  
6            
7             =head1 NAME
8            
9             Lingua::Numending - Package generates morphological end of units.
10            
11             =head1 VERSION
12            
13             Version 0.01
14            
15             =cut
16            
17             our $VERSION = '0.01';
18            
19             =head1 DESCRIPTION
20            
21             Lingua :: Numending is a Perl module that provides provides the
22             formation of morphological endings of any units for the East Slavic group of languages (Russian, Ukrainian, Belarusian).
23            
24             =head1 SYNOPSIS
25            
26             # load module
27             use Lingua::Numending qw(cyr_units);
28            
29             #Examples for the Russian language
30             #Units: часы (hours)
31             printf cyr_units (72, "часов час часа");
32             # 72 часа
33             # Transliteration of above line is: 72 hours
34            
35             #Units: минуты (minutes)
36             printf cyr_units (30, "минут минута минуты");
37             # 30 минут
38             # Transliteration of above line is: 30 minutes
39            
40             #Units: секунды (seconds)
41             printf cyr_units (3, "секунд секунда секунды");
42             # 3 секунды
43             # Transliteration of above line is: 3 seconds
44            
45             #Units: страницы (pages)
46             printf cyr_units (20, "страниц страница страницы");
47             # 20 страниц
48             # Transliteration of above line is: 20 pages
49            
50             #Units: рисунки (drawings)
51             printf cyr_units (5, "рисунков рисунок рисунка");
52             # 5 рисунков
53             # Transliteration of above line is: 5 drawings
54            
55             #Units: рубли (rubles)
56             printf cyr_units (200, "рублей рубль рубля");
57             # 200 рублей
58             # Transliteration of above line is: 200 rubles
59            
60             #Examples for the Ukrainian language
61             #Units: часы (hours)
62             printf cyr_units (72, "годин година години");
63             # 72 години
64             # Transliteration of above line is: 72 hours
65            
66             #Units: минуты (minutes)
67             printf cyr_units (30, "хвилин хвилина хвилини");
68             # 30 хвилин
69             # Transliteration of above line is: 30 minutes
70            
71             #Units: секунды (seconds)
72             printf cyr_units (3, "секунд секунда секунди");
73             # 3 секунди
74             # Transliteration of above line is: 3 seconds
75            
76             #Units: страницы (pages)
77             printf cyr_units (20, "сторiнок сторiнка сторiнки");
78             # 20 сторiнок
79             # Transliteration of above line is: 20 pages
80            
81             #Units: рисунки (drawings)
82             printf cyr_units (5, "малюнкiв малюнок малюнка");
83             # 5 малюнкiв
84             # Transliteration of above line is: 5 drawing
85            
86             #Units: рубли (rubles)
87             printf cyr_units (200, "рублiв рубль рубля");
88             # 200 рублiв
89             # Transliteration of above line is: 200 rubles
90            
91             #Examples for the Belarusian language
92             #Units: часы (hours)
93             printf cyr_units (72, "гадзiн гадзiна гадзiны");
94             # 72 гадзiны
95             # Transliteration of above line is: 72 hours
96            
97             #Units: минуты (minutes)
98             printf cyr_units (30, "хвiлiн хвiлiна хвiлiны");
99             # 30 хвiлiн
100             # Transliteration of above line is: 30 minutes
101            
102             #Units: секунды (seconds)
103             printf cyr_units (3, "секунд секунда секунды");
104             # 3 секунды
105             # Transliteration of above line is: 3 seconds
106            
107             #Units: страницы (pages)
108             printf cyr_units (20, "старонак старонка старонкi");
109             # 20 старонак
110             # Transliteration of above line is: 20 pages
111            
112             #Units: рисунки (drawings)
113             printf cyr_units (5, "малюнкаў малюнак малюнка");
114             # 5 малюнкаў
115             # Transliteration of above line is: 5 drawings
116            
117             #Units: рубли (rubles)
118             printf cyr_units (200, "рублёў рубель рубля");
119             # 200 рублёў
120             # Transliteration of above line is: 200 rubles
121            
122             =head1 FUNCTIONS
123            
124             =head2 cyr_units
125            
126             English ending 's' plural in Cyrillic languages correspond to different endings and
127             package makes the right choice.
128            
129             Function calculates and returns the category to which the number relates.
130             All three categories.
131            
132             To tell time, say a number such as один, два, три, etc. + час/часа/часов.
133            
134             If the category number 1, use "час" for the word hour.
135            
136             If the category number 2, use "часа" for the word hours.
137            
138             If the category number 0, use "часов" for the word hours.
139            
140             =cut
141            
142             # Exporter module to export names
143 8     8   50 use Exporter qw(import);
  8         13  
  8         2912  
144             # The names are placed in the array and they will be added to the namespace of the calling package
145             our @EXPORT_OK = qw(cyr_units);
146            
147             sub cyr_units{
148 6     6 1 44 my $count = shift @_;
149 6         15 my $temp_str = shift @_;
150 6         33 my @words = split / /, $temp_str;
151 6         12 my $number;
152 6         16 my $dec = $count %10;
153 6         12 my $sot = $count %100;
154 6 50 33     91 if ( ($dec == 1) && ($sot != 11) ) {$number = 1}
  0 100 100     0  
      66        
      66        
      33        
155 2         3 elsif ( ($dec >= 2) && ($dec <= 4) && ($sot != 12) && ($sot != 13) && ($sot != 14) ) { $number = 2} # категория номер 2;
  4         10  
156             else {$number = 0};
157 6         12 my $str = $_;
158 6         23 $str = join " ", $count, $words[$number];
159 6         23 return $str;
160             }
161            
162             =head1 AUTHOR
163            
164             Dariya Kirillova, C<< >>
165            
166             =head1 SUPPORT
167            
168             You can find documentation for this module with the perldoc command.
169            
170             perldoc Lingua::Numending
171            
172             =head1 LICENSE AND COPYRIGHT
173            
174             Copyright 2015 Dariya Kirillova.
175            
176             This program is free software; you can redistribute it and/or modify it
177             under the terms of the the Artistic License (2.0). You may obtain a
178             copy of the full license at:
179            
180             L
181            
182             Any use, modification, and distribution of the Standard or Modified
183             Versions is governed by this Artistic License. By using, modifying or
184             distributing the Package, you accept this license. Do not use, modify,
185             or distribute the Package, if you do not accept this license.
186            
187             If your Modified Version has been derived from a Modified Version made
188             by someone other than you, you are nevertheless required to ensure that
189             your Modified Version complies with the requirements of this license.
190            
191             This license does not grant you the right to use any trademark, service
192             mark, tradename, or logo of the Copyright Holder.
193            
194             This license includes the non-exclusive, worldwide, free-of-charge
195             patent license to make, have made, use, offer to sell, sell, import and
196             otherwise transfer the Package with respect to any patent claims
197             licensable by the Copyright Holder that are necessarily infringed by the
198             Package. If you institute patent litigation (including a cross-claim or
199             counterclaim) against any party alleging that the Package constitutes
200             direct or contributory patent infringement, then this Artistic License
201             to you shall terminate on the date that such litigation is filed.
202            
203             Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER
204             AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
205             THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
206             PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY
207             YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR
208             CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR
209             CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE,
210             EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
211            
212            
213             =cut
214            
215             1; # End of Lingua::Numending