blib/lib/Lingua/SPA/Numeros.pm

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