blib/lib/App/dateseq/idn.pm

filter: Statementstmt 58.3% 28 / 48 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 10 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 77.7% 7 / 9 Podpod n/a totaltotal 43.7% 35 / 80 CC 8 SCAR 36.0
CC
8
Cov
42%
__ANON__
72.0
__ANON__
2.0
BEGIN
1.0
CRAP 36.6
↑ Summary
1 package App::dateseq::idn;
2  
3 1 our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
4 1 our $DATE = '2021-03-09'; # DATE
5 1 our $DIST = 'App-dateseq-idn'; # DIST
6 1 our $VERSION = '0.004'; # VERSION
7  
8 1 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Log::ger;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 1 ▶use App::dateseq ();
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use Perinci::Sub::Util qw(gen_modified_sub);
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 gen_modified_sub(
17 base_name => 'App::dateseq::dateseq',
18 output_name => 'dateseq_idn',
19 add_args => {
20 holiday => {
21 summary => 'Only list holidays (or non-holidays)',
22 schema => 'bool*',
23 tags => ['category:filtering'],
24 },
25 include_joint_leave => {
26 summary => 'Whether to assume joint leave days as holidays',
27 schema => 'bool*',
28 tags => ['category:filtering'],
29 cmdline_aliases => {j=>{}},
30 },
31 },
32 1 ▶ modify_meta => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
33 1 my $meta = shift;
34 1 $meta->{summary} = 'Like dateseq, but with built-in support for Indonesian holidays';
35 1 $meta->{description} = <<'_';
36 This utility is a wrapper for <prog:dateseq>, with builtin support for
37 Indonesian holidays (data from <pm:Calendar::Indonesia::Holiday>). It offers
38 additional --holiday (and --noholiday, as well as -j) options to let you filter
39 dates based on whether they are Indonesian holidays.
40 _
41  
42 $meta->{examples} = [
43 {
44 1 summary => 'List Indonesian holidays between 2020-01-01 to 2021-12-31',
45 src => '[[prog]] 2020-01-01 2021-12-13 --holiday',
46 src_plang => 'bash',
47 test => 0,
48 'x.doc.show_result' => 0,
49 },
50 {
51 summary => 'List the last non-holiday business day of each month in 2021',
52 src => '[[prog]] 2021-12-31 2021-01-01 -r --noholiday -j --business --limit-monthly 1',
53 src_plang => 'bash',
54 test => 0,
55 'x.doc.show_result' => 0,
56 },
57 ];
58  
59 $meta->{links} = [
60 1 {url=>'prog:dateseq'},
61 ];
62 },
63 0 ▶ output_code => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
64 0 require Calendar::Indonesia::Holiday;
65  
66 0 my %args = @_;
67  
68 0 my $holiday = delete $args{holiday};
69 0 my $inc_jv = delete $args{include_joint_leave};
70 0 ▶ $args{_filter} = sub {
Subroutine __ANON__: not called CC=8 SCAR=42.8
71 0 my $dt = shift;
72  
73 0 ▶ if (defined $holiday) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $holiday) 0 0 0
74 0 my $date = $dt->ymd;
75 0 my $res = Calendar::Indonesia::Holiday::is_idn_holiday(date=>$date, detail=>1);
76 0 ▶ unless ($res->[0] == 200) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($res->[0] == 200) 0 0 0
77 0 log_error "Cannot determine if %s is a holiday: %s", $date, $res;
78 0 return 0;
79 }
80 0 my $is_holiday = $res->[2];
81 0 ▶ unless (defined $is_holiday) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $is_holiday) 0 0 0
82 0 log_error "Cannot determine if %s is a holiday (2): %s", $date, $res->[3]{'cmdline.result'};
83 0 return 0;
84 }
85 0 ▶ $is_holiday = 0 if $is_holiday && $is_holiday->{is_joint_leave} && !$inc_jv;
Branch: 1 branch
BranchTrueFalseTotal
if $is_holiday and $is_holiday->{"is_joint_leave"} and not $inc_jv 0 0 0
Condition0%0/6
$is_holiday and $is_holiday->{"is_joint_leave"} and not $inc_jv
!ll&&!rl&&r
000
$is_holiday and $is_holiday->{"is_joint_leave"}
!ll&&!rl&&r
000
MC/DC0%0/3
$is_holiday and $is_holiday->{"is_joint_leave"} and not $inc_jv
$is_holiday $is_holiday->{"is_joint_leave"} not $inc_jv
Truth table0%0/4
A and B and not(C)
A= $is_holidayB= $is_holiday->{"is_joint_leave"}C= not $inc_jv
ABCresult
0XX0
10X0
1100
1111
86 0 ▶ return !($is_holiday xor $holiday);
Condition0%0/4
$is_holiday ^^ $holiday
l&&rl&&!r!l&&r!l&&!r
0000
MC/DC0%0/2
$is_holiday ^^ $holiday
$is_holiday $holiday
Truth table0%0/4
A ^^ B
A= $is_holidayB= $holiday
ABresult
110
101
011
000
87 }
88  
89 0 1;
90 0 };
91  
92 0 App::dateseq::dateseq(%args);
93 },
94 1 );
95  
96 1 1;
97 # ABSTRACT: Like dateseq, but with built-in support for Indonesian holidays
98  
99 __END__
↑ Summary