blib/lib/Time/Duration/es.pm

filter: Statementstmt 95.1% 59 / 62 Branchbran 86.3% 19 / 22 Conditioncond 83.3% 10 / 12 MC/DCmcdc 66.6% 2 / 3 Subroutinesub 83.3% 15 / 18 Podpod 0.0% 0 / 13 totaltotal 80.7% 105 / 130 SCAR 29.0
CC
18
Cov
92%
_render
6.0
interval
5.0
duration_exact
4.4
CRAP 18.2
↑ Summary
1 package Time::Duration::es;
2 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 3 our $VERSION = '0.01';
6  
7 3 ▶use base qw(Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 our @EXPORT = qw( later later_exact earlier earlier_exact
9 ago ago_exact from_now from_now_exact
10 duration duration_exact concise );
11 3 our @EXPORT_OK = ('interval', @EXPORT);
12  
13 3 ▶use Time::Duration qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 3 our $MILLISECOND = 0;
16  
17 sub concise ($) {
18 29 ▶ my $string = $_[0];
Subroutine concise: called CC=1 SCAR=0.0
Pod undocumented
19 29 $string =~ tr/,//d;
20 29 $string =~ s/\by\b//;
21 29 $string =~ s/\b(año|día|hora|minuto|segundo)s?\b/substr($1,0,1)/eg;
22 29 $string =~ s/\b(milisegundo)s?\b/ms/g;
23 29 $string =~ s/\s*(\d+)\s*/$1/g;
24  
25 # dirty hack to restore prefixed intervals
26 29 $string =~ s/en([0-9])/en $1/; # en matches momento
27 29 $string =~ s/hace/hace /;
28  
29 29 return $string;
30 }
31  
32 sub later { # ' earlier', ' later', 'right then'
33 68 ▶ interval( $_[0], $_[1], '%s antes', '%s después', 'al momento'); }
Subroutine later: called CC=1 SCAR=0.0
Pod undocumented
34 sub later_exact { # ' earlier', ' later', 'right then'
35 31 ▶ interval_exact($_[0], $_[1], '%s antes', '%s después', 'al momento'); }
Subroutine later_exact: called CC=1 SCAR=0.0
Pod undocumented
36 sub earlier { # ' later', ' earlier', 'right then'
37 6 ▶ interval( $_[0], $_[1], '%s después', '%s antes', 'al momento'); }
Subroutine earlier: called CC=1 SCAR=0.0
Pod undocumented
38 sub earlier_exact { # ' later', ' earlier', 'right then'
39 0 ▶ interval_exact($_[0], $_[1], '%s después', '%s antes', 'al momento'); }
Subroutine earlier_exact: not called CC=1 SCAR=6.9
Pod undocumented
40 sub ago { # ' from now', ' ago', 'right now'
41 11 ▶ interval( $_[0], $_[1], 'en %s', 'hace %s', 'ahora'); }
Subroutine ago: called CC=1 SCAR=0.0
Pod undocumented
42 sub ago_exact { # ' from now', ' ago', 'right now'
43 0 ▶ interval_exact($_[0], $_[1], 'en %s', 'hace %s', 'ahora'); }
Subroutine ago_exact: not called CC=1 SCAR=6.9
Pod undocumented
44 sub from_now { # ' ago', ' from now', 'right now'
45 6 ▶ interval( $_[0], $_[1], 'hace %s', 'en %s', 'ahora'); }
Subroutine from_now: called CC=1 SCAR=0.0
Pod undocumented
46 sub from_now_exact { # ' ago', ' from now', 'right now'
47 0 ▶ interval_exact($_[0], $_[1], 'hace %s', 'en %s', 'ahora'); }
Subroutine from_now_exact: not called CC=1 SCAR=6.9
Pod undocumented
48  
49 sub duration_exact {
50 2 ▶ my $span = $_[0]; # interval in seconds
Subroutine duration_exact: called CC=4 SCAR=14.9
Pod undocumented
51 2 ▶ my $precision = int($_[1] || 0) || 2; # precision (default: 2)
Condition50%2/4
int($_[1] || 0) || 2
l!l
02
$_[1] || 0
l!l
02
MC/DC0%0/1
int($_[1] || 0) || 2
$_[1]
Truth table50%1/2
A
A= $_[1]
Aresult
11
00
52 2 ▶ return '0 segundos' unless $span;
Branch: 1 branch
BranchTrueFalseTotal
unless $span 0 2 2
53 2 _render('%s',
54 Time::Duration::_separate(abs $span));
55 }
56  
57 sub duration {
58 16 ▶ my $span = $_[0]; # interval in seconds
Subroutine duration: called CC=4 SCAR=13.9
Pod undocumented
59 16 ▶ my $precision = int($_[1] || 0) || 2; # precision (default: 2)
Condition100%4/4
int($_[1] || 0) || 2
l!l
214
$_[1] || 0
l!l
214
MC/DC100%1/1
int($_[1] || 0) || 2
$_[1]
Truth table100%2/2
A
A= $_[1]
Aresult
11
00
60 16 ▶ return '0 segundos' unless $span;
Branch: 1 branch
BranchTrueFalseTotal
unless $span 2 14 16
61 14 _render('%s',
62 Time::Duration::_approximate($precision,
63 Time::Duration::_separate(abs $span)));
64 }
65  
66 sub interval_exact {
67 31 ▶ my $span = $_[0]; # interval, in seconds
Subroutine interval_exact: called CC=3 SCAR=11.1
Pod undocumented
68 # precision is ignored
69 31 ▶ my $direction = ($span <= -1) ? $_[2] # what a neg number gets
Branch: 2 branches
BranchTrueFalseTotal
$span <= -1 ? : 0 31 31
$span >= 1 ? : 30 1 31
70 : ($span >= 1) ? $_[3] # what a pos number gets
71 : return $_[4]; # what zero gets
72 30 _render($direction,
73 Time::Duration::_separate($span));
74 }
75  
76 sub interval {
77 91 ▶ my $span = $_[0]; # interval, in seconds
Subroutine interval: called CC=5 SCAR=16.1
Pod undocumented
78 91 ▶ my $precision = int($_[1] || 0) || 2; # precision (default: 2)
Condition100%4/4
int($_[1] || 0) || 2
l!l
3259
$_[1] || 0
l!l
3259
MC/DC100%1/1
int($_[1] || 0) || 2
$_[1]
Truth table100%2/2
A
A= $_[1]
Aresult
11
00
79 91 ▶ my $direction = ($span <= -1) ? $_[2] # what a neg number gets
Branch: 2 branches
BranchTrueFalseTotal
$span <= -1 ? : 10 81 91
$span >= 1 ? : 71 10 81
80 : ($span >= 1) ? $_[3] # what a pos number gets
81 : return $_[4]; # what zero gets
82 81 _render($direction,
83 Time::Duration::_approximate($precision,
84 Time::Duration::_separate($span)));
85 }
86  
87 3 my %en2es = (
88 second => ['segundo', 'segundos'],
89 minute => ['minuto' , 'minutos' ],
90 hour => ['hora' , 'horas' ],
91 day => ['día' , 'días' ],
92 year => ['año' , 'años' ],
93 );
94  
95 sub _render {
96 # Make it into Spanish
97 127 ▶ my $direction = shift @_;
Subroutine _render: called CC=6 SCAR=17.9
98 my @wheel = map
99 {
100 127 ( $_->[1] == 0) ? () # zero wheels
101 635 ▶ : $_->[1] . ' ' . $en2es{ $_->[0] }[ $_->[1] == 1 ? 0 : 1 ]
Branch: 2 branches
BranchTrueFalseTotal
$_->[1] == 0 ? : 377 258 635
$_->[1] == 1 ? : 110 148 258
102 }
103  
104 @_;
105  
106 127 ▶ return 'ahora' unless @wheel; # sanity
Branch: 1 branch
BranchTrueFalseTotal
unless @wheel 0 127 127
107 127 my $result;
108 127 ▶ if(@wheel == 1) {
Branch: 2 branches
BranchTrueFalseTotal
if (@wheel == 1) { } 51 76 127
elsif (@wheel == 2) { } 37 39 76
109 51 $result = $wheel[0];
110 } elsif(@wheel == 2) {
111 37 $result = "$wheel[0] y $wheel[1]";
112 } else {
113 39 $wheel[-1] = "y $wheel[-1]";
114 39 $result = join q{, }, @wheel;
115 }
116 127 return sprintf($direction, $result);
117 }
118  
119 3 1;
120 __END__
↑ Summary