blib/lib/Lingua/SPA/Numeros.pm

filter: Statementstmt 97.6% 249 / 255 Branchbran 91.8% 136 / 148 Conditioncond 92.8% 26 / 28 MC/DCmcdc 87.5% 14 / 16 Subroutinesub 100% 29 / 29 Podpod 100% 17 / 17 totaltotal 95.5% 471 / 493 SCAR 44.9
CC
88
Cov
95%
parse_num
15.0
real
12.2
ordinal_simple
9.0
CRAP 88.8
↑ Summary
1 # For Emacs: -*- mode:cperl; mode:folding; coding:utf-8; -*-
2 #
3 # Jose Luis Rey Barreira (C) 2001-2009
4 #
5  
6 package Lingua::SPA::Numeros;
7 # ABSTRACT: Number 2 word conversion in SPA.
8  
9 # {{{ use block
10  
11 4 ▶use 5.10.1;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 4 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 4 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 # }}}
19 # {{{ variables declarations
20  
21 4 our $VERSION = 0.0682;
22  
23  
24 4 our @EXPORT_OK = qw( $MALE $FEMALE $NEUTRAL $MALE $FEMALE $NEUTRAL);
25  
26 4 ▶no warnings; ## no critic
Subroutine BEGIN: called CC=1 SCAR=0.0
27 4 our $MALE => 'o';
28 4 our $FEMALE => 'a';
29 4 our $NEUTRAL => '';
30 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
31  
32 4 use fields qw/ ACENTOS MAYUSCULAS UNMIL HTML DECIMAL SEPARADORES GENERO
33 4 ▶ POSITIVO NEGATIVO FORMATO /;
Subroutine BEGIN: called CC=1 SCAR=0.0
34  
35 4 my %opt_alias = qw(
36 ACCENTS ACENTOS
37 UPPERCASE MAYUSCULAS
38 SEPARATORS SEPARADORES
39 GENDER GENERO
40 POSITIVE POSITIVO
41 NEGATIVE NEGATIVO
42 FORMAT FORMATO );
43  
44 4 my %new_defaults = (
45 ACENTOS => 1,
46 MAYUSCULAS => 0,
47 UNMIL => 1,
48 HTML => 0,
49 DECIMAL => '.',
50 SEPARADORES => '_',
51 GENERO => $MALE,
52 POSITIVO => '',
53 NEGATIVO => 'menos',
54 FORMATO => 'con %02d ctms.',
55 );
56  
57 # }}}
58 # {{{ new
59  
60 sub new {
61 5 ▶ my $self = shift;
Subroutine new: called CC=3 SCAR=11.0
Pod documented
62 5 ▶ unless ( ref $self ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $self) 4 1 5
63 4 $self = fields::new($self);
64 }
65  
66 #%$self = (%new_defaults, @_);
67 { # Compatibility conversion of SEXO into GENERO
68 5 my %opts = ( %new_defaults, @_ );
69 5 ▶ if ( $opts{'SEXO'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{"SEXO"}) 1 4 5
70 1 $opts{'GENERO'} = $opts{'SEXO'};
71 1 delete $opts{'SEXO'};
72 }
73 5 %$self = %opts
74 }
75 5 return $self;
76 }
77  
78 # }}}
79 # {{{ cardinal
80  
81 sub cardinal {
82 20899 ▶ my $self = shift;
Subroutine cardinal: called CC=6 SCAR=17.9
Pod documented
83 20899 my $num = shift;
84 20899 my ( $sgn, $ent, $frc, $exp ) = parse_num( $num, $self->{'DECIMAL'}, $self->{'SEPARADORES'} );
85 20899 my @words = cardinal_simple( $ent, $exp, $self->{'UNMIL'}, $self->{'GENERO'} );
86 20899 ▶ if (@words) {
Branch: 1 branch
BranchTrueFalseTotal
if (@words) { } 20898 1 20899
87 20898 ▶ unshift @words, $self->{'NEGATIVO'} if $sgn < 0 and $self->{'NEGATIVO'};
Branch: 1 branch
BranchTrueFalseTotal
if $sgn < 0 and $self->{"NEGATIVO"} 5 20893 20898
Condition66%2/3
$sgn < 0 and $self->{"NEGATIVO"}
!ll&&!rl&&r
2089305
MC/DC50%1/2
$sgn < 0 and $self->{"NEGATIVO"}
$sgn < 0 $self->{"NEGATIVO"}
Truth table66%2/3
A and B
A= $sgn < 0B= $self->{"NEGATIVO"}
ABresult
0X0
100
111
88 20898 ▶ unshift @words, $self->{'POSITIVO'} if $sgn > 0 and $self->{'POSITIVO'};
Branch: 1 branch
BranchTrueFalseTotal
if $sgn > 0 and $self->{"POSITIVO"} 1 20897 20898
Condition100%3/3
$sgn > 0 and $self->{"POSITIVO"}
!ll&&!rl&&r
5208921
MC/DC100%2/2
$sgn > 0 and $self->{"POSITIVO"}
$sgn > 0 $self->{"POSITIVO"}
Truth table100%3/3
A and B
A= $sgn > 0B= $self->{"POSITIVO"}
ABresult
0X0
100
111
89 20898 return $self->retval( join( " ", @words ) );
90 }
91 else {
92 1 return $self->retval('cero');
93 }
94 }
95  
96 # }}}
97 # {{{ real
98  
99 sub real {
100 10456 ▶ my $self = shift;
Subroutine real: called CC=12 SCAR=25.0
Pod documented
101 10456 my ( $num, $genf, $genm ) = @_;
102 10456 my ( $sgn, $ent, $frc, $exp ) = parse_num( $num, $self->{'DECIMAL'}, $self->{'SEPARADORES'} );
103  
104 10455 my $gen = $self->{'GENERO'};
105 10455 ▶ $genf = $gen unless defined $genf;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $genf 10455 0 10455
106 10455 ▶ $genm = $genf unless defined $genm;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $genm 10455 0 10455
107  
108 # Convertir la parte entera ajustando el sexo
109 #my @words = cardinal_simple($ent, $exp, $self->{'UNMIL'}, $gen);
110  
111 # Traducir la parte decimal de acuerdo al formato
112 10455 for ( $self->{'FORMATO'} ) {
113 10455 ▶ /%([0-9]*)s/ && do {
Branch: 1 branch
BranchTrueFalseTotal
/%([0-9]*)s/ and do { $frc = substr(0 x $exp . $frc, 0, $1) if $1; $frc = join(" ", fraccion_simple($frc, $exp, $self->{"UNMIL"}, $genf, $genm)); $frc = $frc ? sprintf($self->{"FORMATO"}, $frc) : ""; last } 7 10448 10455
114  
115 # Textual, se traduce según el genero
116 7 ▶ $frc = substr( '0' x $exp . $frc, 0, $1 ) if $1;
Branch: 1 branch
BranchTrueFalseTotal
if $1 0 7 7
117 7 $frc = join( " ", fraccion_simple( $frc, $exp, $self->{'UNMIL'}, $genf, $genm ) );
118 7 ▶ $frc = $frc ? sprintf( $self->{'FORMATO'}, $frc ) : '';
Branch: 1 branch
BranchTrueFalseTotal
$frc ? : 7 0 7
119 7 last;
120 };
121 10448 ▶ /%([0-9]*)d/ && do {
Branch: 1 branch
BranchTrueFalseTotal
/%([0-9]*)d/ and do { $frc = substr(0 x $exp . $frc, 0, $1); $frc = sprintf($self->{"FORMATO"}, $frc); last } 10447 1 10448
122  
123 # Numérico, se da formato a los dígitos
124 10447 $frc = substr( '0' x $exp . $frc, 0, $1 );
125 10447 $frc = sprintf( $self->{'FORMATO'}, $frc );
126 10447 last;
127 };
128 1 do {
129  
130 # Sin formato, se ignoran los decimales
131 1 $frc = '';
132 1 last;
133 };
134 }
135 10455 ▶ if ($ent) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ent) { } 10454 1 10455
136 10454 ▶ $ent = $self->cardinal( ( $sgn < 0 ? '-' : '+' ) . $ent );
Branch: 1 branch
BranchTrueFalseTotal
$sgn < 0 ? : 5 10449 10454
137 }
138 else {
139 1 $ent = 'cero';
140 }
141 10455 ▶ $ent .= ' ' . $frc if $ent and $frc;
Branch: 1 branch
BranchTrueFalseTotal
if $ent and $frc 10454 1 10455
Condition66%2/3
$ent and $frc
!ll&&!rl&&r
0110454
MC/DC50%1/2
$ent and $frc
$ent $frc
Truth table66%2/3
A and B
A= $entB= $frc
ABresult
0X0
100
111
142 10455 return $self->retval($ent);
143 }
144  
145 # }}}
146 # {{{ ordinal
147  
148 sub ordinal {
149 10448 ▶ my $self = shift;
Subroutine ordinal: called CC=4 SCAR=14.5
Pod documented
150 10448 my $num = shift;
151 10448 my ( $sgn, $ent, $frc, $exp ) = parse_num( $num, $self->{'DECIMAL'}, $self->{'SEPARADORES'} );
152  
153 10448 ▶ croak "Ordinal negativo" if $sgn < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $sgn < 0 1 10447 10448
154 10447 ▶ carp "Ordinal con decimales" if $frc;
Branch: 1 branch
BranchTrueFalseTotal
if $frc 0 10447 10447
155  
156 10447 ▶ if ( $ent =~ /^0*$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ent =~ /^0*$/) 0 10447 10447
157 0 carp "Ordinal cero";
158 0 return '';
159 }
160  
161 10447 my $text = join( " ", ordinal_simple( $ent, $exp, $self->{'GENERO'} ) );
162  
163 10446 return $self->retval($text);
164 }
165  
166 # }}}
167  
168 { # Build the accessors
169 4 my @a = @_;
170 4 my %names = ( ( map { $_ => $_ } keys %new_defaults ), %opt_alias );
171 4 ▶ while ( my ( $opt, $alias ) = each %names ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %names) 68 4 72
172 68 $opt = lc $opt;
173 4 ▶ no strict 'refs'; ## no critic
Subroutine BEGIN: called CC=1 SCAR=0.0
174 *$opt = sub {
175 24 ▶ my $self = shift;
Subroutine __ANON__: called CC=2 SCAR=9.2
176 24 ▶ return $self->{$alias} unless @a;
Branch: 1 branch
BranchTrueFalseTotal
unless @a 24 0 24
177 0 $self->{$alias} = shift @a;
178 0 return $self;
179 }
180 68 }
181 }
182  
183 # }}}
184  
185 #####################################################################
186 #
187 # Soporte para números CARDINALES
188 #
189 ####################################################################
190 # {{{ variable declarations II
191  
192 4 my @cardinal_30 = qw/ cero un dos tres cuatro cinco seis siete ocho nueve diez
193 once doce trece catorce quince dieciséis diecisiete dieciocho diecinueve
194 veinte veintiun veintidós veintitrés veinticuatro veinticinco veintiséis
195 veintisiete veintiocho veintinueve /;
196  
197 4 my @cardinal_dec = qw/
198 0 1 2 treinta cuarenta cincuenta sesenta setenta ochenta noventa /;
199  
200 4 my @cardinal_centenas = (
201 "", qw/
202 ciento doscientos trescientos cuatrocientos quinientos
203 seiscientos setecientos ochocientos novecientos /
204 );
205  
206 4 my @cardinal_megas = (
207 "", qw/ m b tr cuatr quint sext sept oct non dec undec
208 dudec tredec cuatordec quindec sexdec sepdec octodec novendec vigint /
209 );
210  
211 4 my $MAX_DIGITS = 6 * @cardinal_megas;
212  
213 # }}}
214 # {{{ cardinal_e2
215  
216 sub cardinal_e2 {
217 142592 ▶ my ( $n, $nn ) = @_;
Subroutine cardinal_e2: called CC=4 SCAR=13.9
Pod documented
218  
219 142592 ▶ return if $n == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $n == 0 306 142286 142592
220 142286 ▶ do { push @$nn, $cardinal_30[$n]; return } if $n < 30;
Branch: 1 branch
BranchTrueFalseTotal
if ($n < 30) 83959 58327 142286
221 58327 $n =~ /^(.)(.)$/;
222 58327 ▶ push @$nn, $cardinal_30[$2], "y" if $2;
Branch: 1 branch
BranchTrueFalseTotal
if $2 51847 6480 58327
223 58327 push @$nn, $cardinal_dec[$1];
224  
225 58327 return;
226 }
227  
228 # }}}
229 # {{{ cardinal_e3
230  
231 sub cardinal_e3 {
232 145267 ▶ my ( $n, $nn ) = @_;
Subroutine cardinal_e3: called CC=4 SCAR=13.9
Pod documented
233  
234 145267 ▶ return if $n == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $n == 0 1588 143679 145267
235 143679 ▶ $n == 100 and do { push @$nn, "cien"; return };
Branch: 1 branch
BranchTrueFalseTotal
$n == 100 and do { push @$nn, "cien"; return } 1087 142592 143679
236 142592 cardinal_e2( $n % 100, $nn );
237 142592 ▶ $n >= 100 and push @$nn, $cardinal_centenas[ int( $n / 100 ) ];
Branch: 1 branch
BranchTrueFalseTotal
$n >= 100 and push @$nn, $cardinal_centenas[int $n / 100] 68834 73758 142592
238  
239 142592 return;
240 }
241  
242 # }}}
243 # {{{ cardinal_e6
244  
245 sub cardinal_e6 {
246 83763 ▶ my ( $n, $nn, $mag, $un_mil, $postfix ) = @_;
Subroutine cardinal_e6: called CC=6 SCAR=17.9
Pod documented
247  
248 83763 ▶ return if $n == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $n == 0 7140 76623 83763
249 76623 ▶ push @$nn, $cardinal_megas[$mag] . $postfix->[ $n == 1 ] if $mag;
Branch: 1 branch
BranchTrueFalseTotal
if $mag 27314 49309 76623
250 76623 cardinal_e3( $n % 1000, $nn );
251 76623 my $n3 = int( $n / 1000 );
252 76623 ▶ if ($n3) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n3) 50786 25837 76623
253 50786 push @$nn, "mil";
254 50786 ▶ cardinal_e3( $n3, $nn ) if $n3 != 1 or $un_mil;
Branch: 1 branch
BranchTrueFalseTotal
if $n3 != 1 or $un_mil 49921 865 50786
Condition100%3/3
$n3 != 1 or $un_mil
l!l&&r!l&&!r
48985936865
MC/DC100%2/2
$n3 != 1 or $un_mil
$n3 != 1 $un_mil
Truth table100%3/3
A or B
A= $n3 != 1B= $un_mil
ABresult
1X1
011
000
255 }
256  
257 76623 return;
258 }
259  
260 # }}}
261 # {{{ cardinal_generic
262  
263 sub cardinal_generic {
264 34388 ▶ my ( $n, $exp, $fmag, $gen ) = @_;
Subroutine cardinal_generic: called CC=6 SCAR=17.9
Pod documented
265 34388 ▶ $gen //= '';
Condition100%2/2
$gen //= ""
l!l
2213412254
MC/DC100%1/1
$gen //= ""
$gen
Truth table100%2/2
A
A= $gen
Aresult
11
00
266  
267 34388 $n =~ s/^0*//; # eliminar ceros a la izquierda
268 34388 ▶ return () unless $n;
Branch: 1 branch
BranchTrueFalseTotal
unless $n 2 34386 34388
269 34386 ▶ croak("Fuera de rango") if length($n) + $exp > $MAX_DIGITS;
Branch: 1 branch
BranchTrueFalseTotal
if length($n) + $exp > $MAX_DIGITS 3 34383 34386
270 34383 $n .= "0" x ( $exp % 6 ); # agregar ceros a la derecha
271 34383 my $mag = int( $exp / 6 );
272 34383 my @group = ();
273 34383 ▶ $fmag->( $1, \@group, $mag++ ) while $n =~ s/(.{1,6})$//x;
Branch: 1 branch
BranchTrueFalseTotal
$n =~ s/(.{1,6})$//x and do { &$fmag($1, \@group, $mag++) } 66723 34383 101106
274 34383 ▶ $group[0] .= $gen if $group[0] =~ /un$/;
Branch: 1 branch
BranchTrueFalseTotal
if $group[0] =~ /un$/ 3981 30402 34383
275 34383 return reverse @group;
276 }
277  
278 # }}}
279 # {{{ cardinal_simple
280  
281 sub cardinal_simple {
282 33160 ▶ my ( $n, $exp, $un_mil, $gen ) = @_;
Subroutine cardinal_simple: called CC=3 SCAR=11.0
Pod documented
283  
284 33160 ▶ $un_mil = $un_mil ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$un_mil ? : 31853 1307 33160
285 33160 ▶ $gen = $NEUTRAL unless $gen;
Branch: 1 branch
BranchTrueFalseTotal
unless $gen 12254 20906 33160
286 my $format = sub {
287 65498 ▶ cardinal_e6( $_[0], $_[1], $_[2], $un_mil, [ 'illones', 'illón' ] );
Subroutine __ANON__: called CC=1 SCAR=0.0
288 33160 };
289 33160 return cardinal_generic( $n, $exp, $format, $gen );
290 }
291  
292  
293 # }}}
294 # {{{ fraccion_mag_prefix
295  
296 sub fraccion_mag_prefix {
297 1244 ▶ my ( $mag, $gp ) = @_;
Subroutine fraccion_mag_prefix: called CC=5 SCAR=16.1
Pod documented
298  
299 1244 ▶ return "" unless $mag;
Branch: 1 branch
BranchTrueFalseTotal
unless $mag 0 1244 1244
300 1244 ▶ return "décim" . $gp if $mag == 1;
Branch: 1 branch
BranchTrueFalseTotal
if $mag == 1 8 1236 1244
301 1236 ▶ return "centésim" . $gp if $mag == 2;
Branch: 1 branch
BranchTrueFalseTotal
if $mag == 2 8 1228 1236
302 my $format = sub {
303 1225 ▶ cardinal_e6( $_[0], $_[1], $_[2], 0, [ 'illon', 'illon' ] );
Subroutine __ANON__: called CC=1 SCAR=0.0
304 1228 };
305 1228 my @name = cardinal_generic( 1, $mag, $format, "" );
306 1225 ▶ shift @name unless $mag % 6;
Branch: 1 branch
BranchTrueFalseTotal
unless $mag % 6 198 1027 1225
307 1225 return join( "", @name, "ésim", $gp );
308 }
309  
310 # }}}
311 # {{{ fraccion_simple
312  
313 sub fraccion_simple {
314 1247 ▶ my ( $n, $exp, $un_mil, $gen, $ngen ) = @_;
Subroutine fraccion_simple: called CC=5 SCAR=16.1
Pod documented
315  
316 1247 $n =~ s/0*$//; # eliminar 0 a la derecha
317 1247 ▶ return () if $n == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $n == 0 0 1247 1247
318 1247 ▶ $ngen = $gen unless defined $ngen;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ngen 1240 7 1247
319 1247 $exp = -$exp + length $n; # adjust exponent
320 1247 ▶ croak("Fuera de rango") if $exp > $MAX_DIGITS;
Branch: 1 branch
BranchTrueFalseTotal
if $exp > $MAX_DIGITS 3 1244 1247
321 1244 ▶ $gen .= "s" unless $n =~ /^0*1$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $n =~ /^0*1$/ 7 1237 1244
322 1244 return ( cardinal_simple( $n, 0, $un_mil, $ngen ), fraccion_mag_prefix( $exp, $gen ) );
323 }
324  
325 #####################################################################
326 #
327 # Soporte para números ORDINALES
328 #
329 ####################################################################
330 # {{{ variable declarations III
331  
332 4 my @ordinal_13 = (
333 '', qw/ primer_ segund_ tercer_ cuart_ quint_ sext_
334 séptim_ octav_ noven_ décim_ undécim_ duodécim_ /
335 );
336  
337 4 my @ordinal_dec = qw/ 0 1 vi tri cuadra quicua sexa septua octo nona /;
338  
339 4 my @ordinal_cen = qw/ 0 c duoc tric cuadring quing sexc septig octing noning /;
340  
341 # }}}
342 # {{{ ordinal_e2
343  
344 sub ordinal_e2 {
345 20526 ▶ my ( $n, $nn ) = @_;
Subroutine ordinal_e2: called CC=9 SCAR=22.0
Pod documented
346  
347 20526 ▶ return if $n == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $n == 0 304 20222 20526
348 20222 ▶ if ( $n < 13 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n < 13) 5162 15060 20222
349 5162 push @$nn, $ordinal_13[$n];
350 5162 return;
351 }
352 15060 $n =~ /^(.)(.)$/;
353 15060 my $lo = $ordinal_13[$2];
354 15060 ▶ if ( $1 <= 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($1 <= 2) 7212 7848 15060
355 7212 ▶ my $name = $2
Branch: 3 branches
BranchTrueFalseTotal
$2 ? : 6736 476 7212
$1 == 1 ? : 2852 3884 6736
$1 == 1 ? : 0 476 476
356 ? ( $1 == 1 ? 'decimo' : 'vigesimo' )
357 : ( $1 == 1 ? 'décim_' : 'vigésim_' );
358 7212 ▶ $name =~ s/o$// if $2 == 8; # special case vowels colapsed
Branch: 1 branch
BranchTrueFalseTotal
if $2 == 8 792 6420 7212
359 7212 push @$nn, $name . $lo;
360 7212 return;
361 }
362 7848 ▶ push @$nn, $lo if $2;
Branch: 1 branch
BranchTrueFalseTotal
if $2 6976 872 7848
363 7848 push @$nn, $ordinal_dec[$1] . 'gésim_';
364 7848 return;
365 }
366  
367 # }}}
368 # {{{ ordinal_e3
369  
370 sub ordinal_e3 {
371 20634 ▶ my ( $n, $nn ) = @_;
Subroutine ordinal_e3: called CC=3 SCAR=11.0
Pod documented
372  
373 20634 ▶ return if $n == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $n == 0 108 20526 20634
374 20526 ordinal_e2( $n % 100, $nn );
375 20526 ▶ push @$nn, $ordinal_cen[ int( $n / 100 ) ] . 'entésim_' if $n > 99;
Branch: 1 branch
BranchTrueFalseTotal
if $n > 99 14725 5801 20526
376  
377 20526 return;
378 }
379  
380 # }}}
381 # {{{ ordinal_e6
382  
383 sub ordinal_e6 {
384 21154 ▶ my ( $n, $nn, $mag ) = @_;
Subroutine ordinal_e6: called CC=5 SCAR=16.1
Pod documented
385  
386 21154 ▶ return if $n == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $n == 0 520 20634 21154
387 20634 ▶ push @$nn, $cardinal_megas[$mag] . 'illonésim_' if $mag;
Branch: 1 branch
BranchTrueFalseTotal
if $mag 0 20634 20634
388 20634 ordinal_e3( $n % 1000, $nn );
389 20634 my $n3 = int( $n / 1000 );
390 20634 ▶ if ($n3) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n3) 18863 1771 20634
391 18863 ▶ if ( $n3 > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n3 > 1) { } 18723 140 18863
392 18723 my $pos = @$nn; # keep pos to adjust number
393 18723 cardinal_e3( $n3, $nn ); # this is not a typo, its cardinal
394 18723 $nn->[$pos] .= 'milésim_';
395 }
396 else {
397 140 push @$nn, "milésim_";
398 }
399 }
400  
401 20634 return;
402 }
403  
404 # }}}
405 # {{{ ordinal_simple
406  
407 sub ordinal_simple {
408 21396 ▶ my ( $n, $exp, $gen ) = @_;
Subroutine ordinal_simple: called CC=9 SCAR=22.0
Pod documented
409  
410 21396 $n =~ s/^0*//; # eliminar ceros a la izquierda
411 21396 ▶ return () unless $n;
Branch: 1 branch
BranchTrueFalseTotal
unless $n 1 21395 21396
412 21395 ▶ croak("Fuera de rango") if length($n) + $exp > $MAX_DIGITS;
Branch: 1 branch
BranchTrueFalseTotal
if length($n) + $exp > $MAX_DIGITS 1 21394 21395
413 21394 $n .= "0" x ( $exp % 6 ); # agregar ceros a la derecha
414 21394 my $mag = int( $exp / 6 );
415  
416 21394 my @group = ();
417 21394 ▶ if ( $mag == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mag == 0) 21154 240 21394
418 21154 $n =~ s/(.{1,6})$//x;
419 21154 ordinal_e6( $1, \@group, $mag++ );
420 }
421  
422 21394 ▶ while ( $n =~ s/(.{1,6})$//x ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n =~ s/(.{1,6})$//x) 22520 21394 43914
423 22520 ▶ if ( $1 == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($1 == 0) 4940 17580 22520
424 4940 $mag++;
425 4940 next;
426 }
427 17580 my $words = [];
428 17580 ▶ if ( $1 == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($1 == 1) { } 540 17040 17580
429 540 push @$words, '';
430 }
431 else {
432 17040 cardinal_e6( $1, $words, 0, 0, [] );
433 }
434 17580 $words->[0] .= $cardinal_megas[ $mag++ ] . 'illonésim_';
435 17580 push @group, @$words;
436 }
437  
438 21394 ▶ unless ($gen) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($gen) 0 21394 21394
439 0 $group[0] =~ s/r_$/r/; # Ajustar neutros en 1er, 3er, etc.
440 0 $gen = $MALE;
441 }
442 21394 s/_/$gen/g for @group;
443 21394 return reverse @group;
444 }
445  
446 # }}}
447 # {{{ parse_num
448  
449 sub parse_num {
450 41839 ▶ my ( $num, $dec, $sep ) = @_;
Subroutine parse_num: called CC=15 SCAR=27.1
Pod documented
451  
452 # Eliminar blancos y separadores
453 41839 $num =~ s/[\s\Q$sep\E]//g;
454 41839 ▶ $dec = '\\' . $dec if $dec eq '.';
Branch: 1 branch
BranchTrueFalseTotal
if $dec eq "." 41834 5 41839
455 41839 ▶ my ( $sgn, $int, $frc, $exp ) = $num =~ /^
Branch: 1 branch
BranchTrueFalseTotal
() = $num =~ /^ ([+-]?) (?= \d | $dec\d ) # signo (\d*) # parte entera (?: $dec (\d*) )? # parte decimal (?: [Ee] ([+-]?\d+) )? # exponente $/x or croak("Error de sintaxis") 1 41838 41839
456 ([+-]?) (?= \d | $dec\d ) # signo
457 (\d*) # parte entera
458 (?: $dec (\d*) )? # parte decimal
459 (?: [Ee] ([+-]?\d+) )? # exponente
460 $/x or croak("Error de sintaxis");
461  
462 41838 ▶ $sgn = $sgn eq '-' ? -1 : 1; # ajustar signo
Branch: 1 branch
BranchTrueFalseTotal
$sgn eq '-' ? : 22 41816 41838
463 41838 ▶ return ( $sgn, $int || 0, $frc || 0, $exp ) unless $exp ||= 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $exp ||= 0 41805 33 41838
Condition100%6/6
$exp ||= 0
l!l
3341805
$int || 0
l!l
418032
$frc || 0
l!l
1045631349
MC/DC100%1/1
$exp ||= 0
$exp
MC/DC100%1/1
$int || 0
$int
MC/DC100%1/1
$frc || 0
$frc
Truth table100%2/2
A
A= $exp
Aresult
11
00
Truth table100%2/2
A
A= $int
Aresult
11
00
Truth table100%2/2
A
A= $frc
Aresult
11
00
464  
465 33 ▶ $int ||= '';
Condition100%2/2
$int ||= ""
l!l
312
MC/DC100%1/1
$int ||= ""
$int
Truth table100%2/2
A
A= $int
Aresult
11
00
466 33 ▶ $frc ||= '';
Condition100%2/2
$frc ||= ""
l!l
267
MC/DC100%1/1
$frc ||= ""
$frc
Truth table100%2/2
A
A= $frc
Aresult
11
00
467  
468 # reducir la magnitud del exponente
469 33 ▶ if ( $exp > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($exp > 0) { } 12 21 33
470 12 ▶ if ( $exp > length $frc ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($exp > length $frc) { } 4 8 12
471 4 $exp -= length $frc;
472 4 $int .= $frc;
473 4 $frc = '';
474 }
475 else {
476 8 $int .= substr( $frc, 0, $exp );
477 8 $frc = substr( $frc, $exp );
478 8 $exp = 0;
479 }
480 }
481 else {
482 21 ▶ if ( -$exp > length $int ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-$exp > length $int) { } 4 17 21
483 4 $exp += length $int;
484 4 $frc = $int . $frc;
485 4 $int = '';
486 }
487 else {
488 17 $frc = substr( $int, $exp + length $int ) . $frc;
489 17 $int = substr( $int, 0, $exp + length $int );
490 17 $exp = 0;
491 }
492 }
493 33 ▶ return ( $sgn, $int || 0, $frc || 0, $exp );
Condition100%4/4
$int || 0
l!l
258
$frc || 0
l!l
267
MC/DC100%1/1
$int || 0
$int
MC/DC100%1/1
$frc || 0
$frc
Truth table100%2/2
A
A= $int
Aresult
11
00
Truth table100%2/2
A
A= $frc
Aresult
11
00
494 }
495  
496 # }}}
497 # {{{ retval
498  
499 sub retval {
500 41800 ▶ my $self = shift;
Subroutine retval: called CC=4 SCAR=13.9
Pod documented
501 41800 my $rv = shift;
502 41800 ▶ if ( $self->{ACENTOS} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'ACENTOS'}) { } 41794 6 41800
503 41794 ▶ if ( $self->{HTML} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"HTML"}) 4 41790 41794
504 4 $rv =~ s/([áéíóú])/&$1acute;/g;
505 4 $rv =~ tr/áéíóú/aeiou/;
506 }
507 }
508 else {
509 6 $rv =~ tr/áéíóú/aeiou/;
510 }
511 41800 ▶ return $self->{MAYUSCULAS} ? uc $rv : $rv;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'MAYUSCULAS'} ? : 6 41794 41800
512 }
513  
514 # }}}
515  
516 4 1;
517 __END__
↑ Summary