C/Util.pm

filter: Statementstmt 43.4% 30 / 69 Branchbran 0.0% 0 / 48 Conditioncond 0.0% 0 / 19 MC/DCmcdc 0.0% 0 / 11 Subroutinesub 80.0% 8 / 10 Podpod 0.0% 0 / 2 totaltotal 23.9% 38 / 159 CC 32 SCAR 60.2
CC
32
Cov
22%
get_locale
650.0
get_fmt_tok
72.0
BEGIN
1.0
CRAP 410.6
↑ Summary P.pm »
1 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 package Time::C::Util;
4 9 $Time::C::Util::VERSION = '0.024';
5 # ABSTRACT: Utility functions for Time::C and friends.
6  
7 9 ▶use Carp qw/ croak /;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 9 ▶use Data::Munge qw/ slurp /;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 9 ▶use File::Share qw/ dist_file /;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 9 ▶use Function::Parameters qw/ :strict /;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 9 ▶use Exporter qw/ import /;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 9 ▶use JSON::MaybeXS;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 9 our @EXPORT_OK = qw/ get_fmt_tok get_locale /;
15  
16 9 my $loc_db;
17  
18 0 ▶fun get_fmt_tok ($fmt, $pos) {
Subroutine get_fmt_tok: not called CC=8 SCAR=42.8
Pod undocumented
Branch: 2 branches
BranchTrueFalseTotal
@_ < 2 and Function::Parameters::_croak('Too few arguments for fun get_fmt_tok (expected 2, got ' . @_ . ')') 0 0 0
@_ > 2 and Function::Parameters::_croak('Too many arguments for fun get_fmt_tok (expected 2, got ' . @_ . ')') 0 0 0
19 0 ▶ return undef if $pos >= length $fmt;
Branch: 1 branch
BranchTrueFalseTotal
if $pos >= length $fmt 0 0 0
20  
21 0 ▶ my $tok_len = substr($fmt, $pos, 1) eq '%' ? 2 : 1;
Branch: 1 branch
BranchTrueFalseTotal
substr($fmt, $pos, 1) eq '%' ? : 0 0 0
22  
23 0 my $tok = substr $fmt, $pos, $tok_len;
24  
25 0 ▶ while (($tok eq '%O') or ($tok eq '%E') or ($tok eq '%-')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tok eq "%O" or $tok eq "%E" or $tok eq "%-") 0 0 0
Condition0%0/6
$tok eq "%O" or $tok eq "%E" or $tok eq "%-"
l!l&&r!l&&!r
000
$tok eq "%O" or $tok eq "%E"
l!l&&r!l&&!r
000
MC/DC0%0/3
$tok eq "%O" or $tok eq "%E" or $tok eq "%-"
$tok eq "%O" $tok eq "%E" $tok eq "%-"
Truth table0%0/4
A or B or C
A= $tok eq "%O"B= $tok eq "%E"C= $tok eq "%-"
ABCresult
1XX1
01X1
0011
0000
26 0 $tok .= substr($fmt, $pos + $tok_len, 1); $tok_len++;
27 }
28  
29 0 $_[1] = $pos + $tok_len;
30 0 return $tok;
31 9 }
32  
33 0 ▶fun get_locale($type, $locale) {
Subroutine get_locale: not called CC=25 SCAR=64.8
Pod undocumented
Branch: 2 branches
BranchTrueFalseTotal
@_ < 2 and Function::Parameters::_croak('Too few arguments for fun get_locale (expected 2, got ' . @_ . ')') 0 0 0
@_ > 2 and Function::Parameters::_croak('Too many arguments for fun get_locale (expected 2, got ' . @_ . ')') 0 0 0
34 0 ▶ if (not defined $loc_db) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $loc_db) 0 0 0
35 0 my $fn = dist_file('Time-C', 'locale.db');
36 0 ▶ open my $fh, '<', $fn
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $fn or croak("Could not open ${fn}: $!") 0 0 0
37 or croak "Could not open $fn: $!";
38 0 $loc_db = decode_json slurp $fh;
39 }
40  
41 0 my $ret;
42 0 ▶ if ($type eq 'weekdays') {
Branch: 14 branches
BranchTrueFalseTotal
if ($type eq 'weekdays') { } 0 0 0
elsif ($type eq 'weekdays_abbr') { } 0 0 0
elsif ($type eq 'months') { } 0 0 0
elsif ($type eq 'months_abbr') { } 0 0 0
elsif ($type eq 'am_pm') { } 0 0 0
elsif ($type eq 'datetime') { } 0 0 0
elsif ($type eq 'date') { } 0 0 0
elsif ($type eq 'time') { } 0 0 0
elsif ($type eq 'time_ampm') { } 0 0 0
elsif ($type eq 'era') { } 0 0 0
elsif ($type eq 'era_datetime') { } 0 0 0
elsif ($type eq 'era_time') { } 0 0 0
elsif ($type eq 'era_date') { } 0 0 0
elsif ($type eq 'digits') { } 0 0 0
43 0 $ret = $loc_db->{days}->{$locale};
44 } elsif ($type eq 'weekdays_abbr') {
45 0 $ret = $loc_db->{days_abbr}->{$locale};
46 } elsif ($type eq 'months') {
47 0 $ret = $loc_db->{months}->{$locale};
48 } elsif ($type eq 'months_abbr') {
49 0 $ret = $loc_db->{months_abbr}->{$locale};
50 } elsif ($type eq 'am_pm') {
51 0 $ret = $loc_db->{am_pm}->{$locale};
52 } elsif ($type eq 'datetime') {
53 0 $ret = $loc_db->{d_t_fmt}->{$locale};
54 } elsif ($type eq 'date') {
55 0 $ret = $loc_db->{d_fmt}->{$locale};
56 } elsif ($type eq 'time') {
57 0 $ret = $loc_db->{t_fmt}->{$locale};
58 } elsif ($type eq 'time_ampm') {
59 0 $ret = $loc_db->{r_fmt}->{$locale};
60 } elsif ($type eq 'era') {
61 0 ▶ $ret = $loc_db->{era}->{$locale} // [];
Condition0%0/2
$loc_db->{"era"}{$locale} // []
l!l
00
MC/DC0%0/1
$loc_db->{"era"}{$locale} // []
$loc_db->{"era"}{$locale}
Truth table0%0/2
A
A= $loc_db->{"era"}{$locale}
Aresult
11
00
62 } elsif ($type eq 'era_datetime') {
63 0 ▶ $ret = $loc_db->{era_d_t_fmt}->{$locale} // $loc_db->{d_t_fmt}->{$locale};
Condition0%0/3
$loc_db->{"era_d_t_fmt"}{$locale} // $loc_db->{"d_t_fmt"}{$locale}
l!l&&r!l&&!r
000
MC/DC0%0/2
$loc_db->{"era_d_t_fmt"}{$locale} // $loc_db->{"d_t_fmt"}{$locale}
$loc_db->{"era_d_t_fmt"}{$locale} $loc_db->{"d_t_fmt"}{$locale}
Truth table0%0/3
A // B
A= $loc_db->{"era_d_t_fmt"}{$locale}B= $loc_db->{"d_t_fmt"}{$locale}
ABresult
1X1
011
000
64 } elsif ($type eq 'era_time') {
65 0 ▶ $ret = $loc_db->{era_t_fmt}->{$locale} // $loc_db->{t_fmt}->{$locale};
Condition0%0/3
$loc_db->{"era_t_fmt"}{$locale} // $loc_db->{"t_fmt"}{$locale}
l!l&&r!l&&!r
000
MC/DC0%0/2
$loc_db->{"era_t_fmt"}{$locale} // $loc_db->{"t_fmt"}{$locale}
$loc_db->{"era_t_fmt"}{$locale} $loc_db->{"t_fmt"}{$locale}
Truth table0%0/3
A // B
A= $loc_db->{"era_t_fmt"}{$locale}B= $loc_db->{"t_fmt"}{$locale}
ABresult
1X1
011
000
66 } elsif ($type eq 'era_date') {
67 0 ▶ $ret = $loc_db->{era_d_fmt}->{$locale} // $loc_db->{d_fmt}->{$locale};
Condition0%0/3
$loc_db->{"era_d_fmt"}{$locale} // $loc_db->{"d_fmt"}{$locale}
l!l&&r!l&&!r
000
MC/DC0%0/2
$loc_db->{"era_d_fmt"}{$locale} // $loc_db->{"d_fmt"}{$locale}
$loc_db->{"era_d_fmt"}{$locale} $loc_db->{"d_fmt"}{$locale}
Truth table0%0/3
A // B
A= $loc_db->{"era_d_fmt"}{$locale}B= $loc_db->{"d_fmt"}{$locale}
ABresult
1X1
011
000
68 } elsif ($type eq 'digits') {
69 0 ▶ $ret = $loc_db->{alt_digits}->{$locale} // [];
Condition0%0/2
$loc_db->{"alt_digits"}{$locale} // []
l!l
00
MC/DC0%0/1
$loc_db->{"alt_digits"}{$locale} // []
$loc_db->{"alt_digits"}{$locale}
Truth table0%0/2
A
A= $loc_db->{"alt_digits"}{$locale}
Aresult
11
00
70 0 } else { croak "Unknown locale type: $type."; }
71  
72 0 ▶ croak "Value for locale type $type in locale $locale is undefined."
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ret 0 0 0
73 if not defined $ret;
74  
75 0 return $ret;
76 9 }
77  
78 9 1;
79  
80 __END__
↑ Summary P.pm »