blib/lib/Langertha/Holmgang/Sim/Linux/Calendar.pm

filter: Statementstmt 100% 193 / 193 Branchbran 90.9% 140 / 154 Conditioncond 74.8% 92 / 123 MC/DCmcdc 56.5% 39 / 69 Subroutinesub 100% 15 / 15 Podpod 100% 5 / 5 totaltotal 86.5% 484 / 559 CC 125 SCAR 32.0
CC
125
Cov
90%
parse
42.4
_field
29.3
next_elapse
20.0
CRAP 24.4
« blib/lib/Langertha/Holmgang/Target.pm ↑ Summary blib/lib/Langertha/Holmgang/Haystack.pm »
1 package Langertha::Holmgang::Sim::Linux::Calendar;
2 # ABSTRACT: systemd calendar expressions (OnCalendar) for the Linux simulator — check, normalise, next elapse
3  
4 82 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 82 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 82 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 82 ▶use Time::Local ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 82 our $VERSION = '0.001';
11  
12  
13 82 my @WD = qw( Mon Tue Wed Thu Fri Sat Sun );
14 82 my %WD;
15 82 for my $i ( 0 .. 6 ) {
16 574 $WD{ lc $WD[$i] } = $i;
17 574 $WD{ (qw( monday tuesday wednesday thursday friday saturday sunday ))[$i] } = $i;
18 }
19  
20 82 my %SHORT = (
21 minutely => '*-*-* *:*:00',
22 hourly => '*-*-* *:00:00',
23 daily => '*-*-* 00:00:00',
24 weekly => 'Mon *-*-* 00:00:00',
25 monthly => '*-*-01 00:00:00',
26 quarterly => '*-01,04,07,10-01 00:00:00',
27 semiannually => '*-01,07-01 00:00:00',
28 yearly => '*-01-01 00:00:00',
29 annually => '*-01-01 00:00:00',
30 );
31  
32 # Zeitzone -> [ Normalzeit-Versatz in s, Regel (eu|us|undef), Abkuerzung normal, Sommer ]
33 our %ZONE = (
34 # Abkuerzungen der Ortszeit nimmt systemd an (fester Versatz)
35 CET => [ 3600, undef, 'CET' ], CEST => [ 7200, undef, 'CEST' ],
36 UTC => [ 0, undef, 'UTC' ], GMT => [ 0, undef, 'GMT' ], 'Etc/UTC' => [ 0, undef, 'UTC' ], 'Etc/GMT' => [ 0, undef, 'GMT' ],
37 1230 ( map { ( "Europe/$_" => [ 3600, 'eu', 'CET', 'CEST' ] ) }
38 qw( Berlin Vienna Zurich Paris Amsterdam Brussels Luxembourg Rome Madrid Copenhagen Oslo Stockholm Warsaw Prague Budapest ) ),
39 246 ▶ ( map { ( "Europe/$_" => [ 0, 'eu', $_ eq 'Lisbon' ? 'WET' : $_ eq 'Dublin' ? 'GMT' : 'GMT', $_ eq 'Lisbon' ? 'WEST' : $_ eq 'Dublin' ? 'IST' : 'BST' ] ) }
Branch: 4 branches
BranchTrueFalseTotal
$_ eq 'Lisbon' ? : 82 164 246
$_ eq 'Dublin' ? : 82 82 164
$_ eq 'Lisbon' ? : 82 164 246
$_ eq 'Dublin' ? : 82 82 164
40 qw( London Dublin Lisbon ) ),
41 82 ( map { ( "Europe/$_" => [ 7200, 'eu', 'EET', 'EEST' ] ) } qw( Helsinki Athens Bucharest Sofia Riga Tallinn Vilnius ) ),
42 'America/New_York' => [ -18000, 'us', 'EST', 'EDT' ],
43 'America/Chicago' => [ -21600, 'us', 'CST', 'CDT' ],
44 'America/Denver' => [ -25200, 'us', 'MST', 'MDT' ],
45 'America/Los_Angeles' => [ -28800, 'us', 'PST', 'PDT' ],
46 'Asia/Tokyo' => [ 32400, undef, 'JST' ],
47 'Asia/Singapore' => [ 28800, undef, '+08' ],
48 'Asia/Kolkata' => [ 19800, undef, 'IST' ],
49 );
50  
51 82 our $LOCAL = 'Europe/Berlin';
52  
53 # Ein Feld -> ( [ Werte ] oder undef fuer *, Text der Normalform ); () = ungueltig
54 818 ▶sub _field {
Subroutine _field: called CC=25 SCAR=33.8
55 818 my ( $s, $min, $max, $width, $frac ) = @_;
56 818 ▶ return ( undef, '*' ) if $s eq '*';
Branch: 1 branch
BranchTrueFalseTotal
if $s eq "*" 398 420 818
57 420 ▶ if ( $frac && $s =~ /\A(\d+)\.(\d{1,6})\z/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($frac and $s =~ /\A(\d+)\.(\d{1,6})\z/) 1 419 420
Condition100%3/3
$frac and $s =~ /\A(\d+)\.(\d{1,6})\z/
!ll&&!rl&&r
2881311
MC/DC100%2/2
$frac and $s =~ /\A(\d+)\.(\d{1,6})\z/
$frac $s =~ /\A(\d+)\.(\d{1,6})\z/
Truth table100%3/3
A and B
A= $fracB= $s =~ /\A(\d+)\.(\d{1,6})\z/
ABresult
0X0
100
111
58 1 ▶ return () if $1 > $max;
Branch: 1 branch
BranchTrueFalseTotal
if $1 > $max 0 1 1
59 1 return ( [ 0 + $1 ], sprintf( "%0${width}d.%06d", $1, substr( $2 . '000000', 0, 6 ) ) );
60 }
61 419 my ( @v, @txt );
62 419 for my $part ( split /,/, $s, -1 ) {
63 426 ▶ my ( $a, $b, $step ) = $part =~ /\A(\*|\d+)(?:\.\.(\d+))?(?:\/(\d+))?\z/ or return ();
Branch: 1 branch
BranchTrueFalseTotal
() = $part =~ m[\A(\*|\d+)(?:\.\.(\d+))?(?:/(\d+))?\z] or return () 426 0 426
64 426 ▶ return () if $a eq '*' && ( defined $b || !defined $step );
Branch: 1 branch
BranchTrueFalseTotal
if $a eq "*" and defined $b || !defined($step) 0 426 426
Condition16%1/6
$a eq "*" and defined $b || !defined($step)
!ll&&!rl&&r
42600
defined $b or not defined $step
l!l&&r!l&&!r
000
MC/DC0%0/3
$a eq "*" and defined $b || !defined($step)
$a eq "*" defined $b not defined $step
Truth table25%1/4
A and B or not(C)
A= $a eq "*"B= defined $bC= not defined $step
ABCresult
0XX0
1000
11X1
1011
65 426 ▶ my $lo = $a eq '*' ? $min : $a;
Branch: 1 branch
BranchTrueFalseTotal
$a eq '*' ? : 0 426 426
66 426 ▶ my $hi = defined $b ? $b : defined $step ? $max : $lo;
Branch: 2 branches
BranchTrueFalseTotal
defined $b ? : 5 421 426
defined $step ? : 10 411 421
67 426 ▶ return () if $lo < $min || $hi > $max || $lo > $hi || ( defined $step && $step == 0 );
Branch: 1 branch
BranchTrueFalseTotal
if $lo < $min or $hi > $max or $lo > $hi or defined $step and $step == 0 5 421 426
Condition66%8/12
$lo < $min or $hi > $max or $lo > $hi or defined $step and $step == 0
l!l&&r!l&&!r
50421
$lo < $min or $hi > $max or $lo > $hi
l!l&&r!l&&!r
50421
$lo < $min or $hi > $max
l!l&&r!l&&!r
05421
defined $step and $step == 0
!ll&&!rl&&r
410110
MC/DC20%1/5
$lo < $min or $hi > $max or $lo > $hi or defined $step and $step == 0
$lo < $min $hi > $max $lo > $hi defined $step $step == 0
Truth table50%3/6
A or B or C or D and E
A= $lo < $minB= $hi > $maxC= $lo > $hiD= defined $stepE= $step == 0
ABCDEresult
1XXXX1
01XXX1
001XX1
000111
0000X0
000100
68 421 ▶ undef $step if defined $b && defined $step && $step == 1;
Branch: 1 branch
BranchTrueFalseTotal
if defined $b and defined $step and $step == 1 1 420 421
Condition83%5/6
defined $b and defined $step and $step == 1
!ll&&!rl&&r
42001
defined $b and defined $step
!ll&&!rl&&r
41641
MC/DC66%2/3
defined $b and defined $step and $step == 1
defined $b defined $step $step == 1
Truth table75%3/4
A and B and C
A= defined $bB= defined $stepC= $step == 1
ABCresult
0XX0
10X0
1100
1111
69 421 ▶ for ( my $i = $lo; $i <= $hi; $i += $step // 1 ) { push @v, 0 + $i }
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $hi) 543 421 964
Condition100%2/2
$step // 1
l!l
96447
MC/DC100%1/1
$step // 1
$step
Truth table100%2/2
A
A= $step
Aresult
11
00
70 421 ▶ my $f = sub { $_[0] eq '*' ? '*' : sprintf( "%0${width}d", $_[0] ) };
Subroutine __ANON__: called CC=2 SCAR=7.2
Branch: 1 branch
BranchTrueFalseTotal
$_[0] eq '*' ? : 0 426 426
71 421 ▶ push @txt, $f->($a) . ( defined $b ? '..' . $f->($b) : '' ) . ( defined $step ? '/' . $step : '' );
Branch: 2 branches
BranchTrueFalseTotal
defined $b ? : 5 416 421
defined $step ? : 10 411 421
72 }
73 414 my %u = map { $_ => 1 } @v;
74 414 return ( [ sort { $a <=> $b } keys %u ], join( ',', @txt ) );
75 }
76  
77 # Wochentage "Mon-Wed,Fri" -> ( [ 0..6 ] oder undef fuer alle, Normalform )
78 60 ▶sub _weekdays {
Subroutine _weekdays: called CC=15 SCAR=27.1
79 60 my ($s) = @_;
80 60 my %on;
81 60 for my $part ( split /,/, $s, -1 ) {
82 85 ▶ my ( $a, $b ) = $part =~ /\A([A-Za-z]+)(?:(?:\.\.|-)([A-Za-z]+))?\z/ or return ();
Branch: 1 branch
BranchTrueFalseTotal
() = $part =~ /\A([A-Za-z]+)(?:(?:\.\.|-)([A-Za-z]+))?\z/ or return () 84 1 85
83 84 ▶ return () unless exists $WD{ lc $a } && ( !defined $b || exists $WD{ lc $b } );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $WD{lc $a} and !defined($b) || exists $WD{lc $b} 12 72 84
Condition66%4/6
exists $WD{lc $a} and !defined($b) || exists $WD{lc $b}
!ll&&!rl&&r
12072
not defined $b or exists $WD{lc $b}
l!l&&r!l&&!r
49230
MC/DC33%1/3
exists $WD{lc $a} and !defined($b) || exists $WD{lc $b}
exists $WD{lc $a} not defined $b exists $WD{lc $b}
Truth table75%3/4
A and not(B) or C
A= exists $WD{lc $a}B= not defined $bC= exists $WD{lc $b}
ABCresult
0XX0
1000
11X1
1011
84 72 ▶ my ( $x, $y ) = ( $WD{ lc $a }, defined $b ? $WD{ lc $b } : $WD{ lc $a } );
Branch: 1 branch
BranchTrueFalseTotal
defined $b ? : 23 49 72
85 72 ▶ return () if $y < $x;
Branch: 1 branch
BranchTrueFalseTotal
if $y < $x 3 69 72
86 69 $on{$_} = 1 for $x .. $y;
87 }
88 44 my @d = sort { $a <=> $b } keys %on;
89 44 ▶ return ( undef, undef ) if @d == 7;
Branch: 1 branch
BranchTrueFalseTotal
if @d == 7 3 41 44
90 41 my @txt;
91 41 my $i = 0;
92 41 ▶ while ( $i < @d ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @d) 46 41 87
93 46 my $j = $i;
94 46 ▶ $j++ while $j + 1 < @d && $d[ $j + 1 ] == $d[$j] + 1;
Branch: 1 branch
BranchTrueFalseTotal
$j + 1 < @d and $d[$j + 1] == $d[$j] + 1 and do { ++$j } 66 46 112
Condition100%3/3
$j + 1 < @d and $d[$j + 1] == $d[$j] + 1
!ll&&!rl&&r
41566
MC/DC100%2/2
$j + 1 < @d and $d[$j + 1] == $d[$j] + 1
$j + 1 < @d $d[$j + 1] == $d[$j] + 1
Truth table100%3/3
A and B
A= $j + 1 < @dB= $d[$j + 1] == $d[$j] + 1
ABresult
0X0
100
111
95 46 ▶ if ( $j - $i >= 2 ) { push @txt, "$WD[$d[$i]]..$WD[$d[$j]]" }
Branch: 2 branches
BranchTrueFalseTotal
if ($j - $i >= 2) { } 17 29 46
elsif ($j == $i) { } 22 7 29
96 22 elsif ( $j == $i ) { push @txt, $WD[ $d[$i] ] }
97 7 else { push @txt, $WD[ $d[$i] ], $WD[ $d[$j] ] }
98 46 $i = $j + 1;
99 }
100 41 return ( \@d, join( ',', @txt ) );
101 }
102  
103  
104 171 ▶sub parse {
Subroutine parse: called CC=42 SCAR=37.5
Pod documented
105 171 my ($expr) = @_;
106 171 ▶ return undef unless defined $expr && $expr =~ /\A\S/;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $expr and $expr =~ /\A\S/ 2 169 171
Condition66%2/3
defined $expr and $expr =~ /\A\S/
!ll&&!rl&&r
02169
MC/DC50%1/2
defined $expr and $expr =~ /\A\S/
defined $expr $expr =~ /\A\S/
Truth table66%2/3
A and B
A= defined $exprB= $expr =~ /\A\S/
ABresult
0X0
100
111
107 169 ( my $s = $expr ) =~ s/\s+\z//;
108 169 my @w = split /\s+/, $s;
109 169 my $tz;
110 169 ▶ if ( @w > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@w > 1) 121 48 169
111 121 ▶ my $z = lc( $w[-1] ) eq 'utc' ? 'UTC' : $w[-1];
Branch: 1 branch
BranchTrueFalseTotal
lc $w[-1] eq 'utc' ? : 8 113 121
112 121 ▶ if ( $ZONE{$z} ) { $tz = $z; pop @w }
Branch: 1 branch
BranchTrueFalseTotal
if ($Langertha::Holmgang::Sim::Linux::Calendar::ZONE{$z}) 14 107 121
113 }
114 169 ▶ if ( @w == 1 && exists $SHORT{ lc $w[0] } ) { @w = split / /, $SHORT{ lc $w[0] } }
Branch: 1 branch
BranchTrueFalseTotal
if (@w == 1 and exists $SHORT{lc $w[0]}) 20 149 169
Condition100%3/3
@w == 1 and exists $SHORT{lc $w[0]}
!ll&&!rl&&r
1103920
MC/DC100%2/2
@w == 1 and exists $SHORT{lc $w[0]}
@w == 1 exists $SHORT{lc $w[0]}
Truth table100%3/3
A and B
A= @w == 1B= exists $SHORT{lc $w[0]}
ABresult
0X0
100
111
115 169 ▶ my %c = ( tz => $tz, utc => defined $tz && !$ZONE{$tz}[0] && !$ZONE{$tz}[1] ? 1 : 0 );
Branch: 1 branch
BranchTrueFalseTotal
defined $tz && !$Langertha::Holmgang::Sim::Linux::Calendar::ZONE{$tz}[0] && !$Langertha::Holmgang::Sim::Linux::Calendar::ZONE{$tz}[1] ? : 10 159 169
Condition83%5/6
defined $tz and not $Langertha::Holmgang::Sim::Linux::Calendar::ZONE{$tz}[0] and not $Langertha::Holmgang::Sim::Linux::Calendar::ZONE{$tz}[1]
!ll&&!rl&&r
159010
defined $tz and not $Langertha::Holmgang::Sim::Linux::Calendar::ZONE{$tz}[0]
!ll&&!rl&&r
155410
MC/DC66%2/3
defined $tz and not $Langertha::Holmgang::Sim::Linux::Calendar::ZONE{$tz}[0] and not $Langertha::Holmgang::Sim::Linux::Calendar::ZONE{$tz}[1]
defined $tz not $Langertha::Holmgang::Sim::Linux::Calendar::ZONE{$tz}[0] not $Langertha::Holmgang::Sim::Linux::Calendar::ZONE{$tz}[1]
Truth table75%3/4
A and not(B) and not(C)
A= defined $tzB= not $Langertha::Holmgang::Sim::Linux::Calendar::ZONE{$tz}[0]C= not $Langertha::Holmgang::Sim::Linux::Calendar::ZONE{$tz}[1]
ABCresult
0XX0
10X0
1100
1111
116 169 my @norm;
117 169 ▶ if ( @w && $w[0] =~ /\A[A-Za-z]/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@w and $w[0] =~ /\A[A-Za-z]/) 60 109 169
Condition66%2/3
@w and $w[0] =~ /\A[A-Za-z]/
!ll&&!rl&&r
010960
MC/DC50%1/2
@w and $w[0] =~ /\A[A-Za-z]/
@w $w[0] =~ /\A[A-Za-z]/
Truth table66%2/3
A and B
A= @wB= $w[0] =~ /\A[A-Za-z]/
ABresult
0X0
100
111
118 60 ▶ my ( $d, $t ) = _weekdays( shift @w ) or return undef;
Branch: 1 branch
BranchTrueFalseTotal
() = _weekdays(shift @w) or return undef 44 16 60
119 44 $c{wd} = $d;
120 44 ▶ push @norm, $t if defined $t;
Branch: 1 branch
BranchTrueFalseTotal
if defined $t 41 3 44
121 }
122 153 my ( $date, $time );
123 153 for my $x (@w) {
124 232 ▶ if ( !defined $date && !defined $time && $x !~ /:/ && $x =~ /[-~]/ ) { $date = $x }
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $date || defined $time || $x =~ /:/ and $x =~ /[-~]/) { } 79 153 232
elsif (not defined $time and $x =~ /:/) { } 140 13 153
Condition100%9/9
not defined $date || defined $time || $x =~ /:/ and $x =~ /[-~]/
!ll&&!rl&&r
147679
defined $date || defined $time || $x =~ /:/
l!l&&r!l&&!r
816685
defined $date or defined $time
l!l&&r!l&&!r
765151
MC/DC100%4/4
not defined $date || defined $time || $x =~ /:/ and $x =~ /[-~]/
defined $date defined $time $x =~ /:/ $x =~ /[-~]/
Truth table100%5/5
not(A or B || C) and D
A= defined $dateB= defined $timeC= $x =~ /:/D= $x =~ /[-~]/
ABCDresult
1XXX0
01XX0
001X0
00000
00011
125 140 ▶ elsif ( !defined $time && $x =~ /:/ ) { $time = $x }
Condition100%3/3
not defined $time and $x =~ /:/
!ll&&!rl&&r
67140
MC/DC100%2/2
not defined $time and $x =~ /:/
not defined $time $x =~ /:/
Truth table100%3/3
not(A) and B
A= not defined $timeB= $x =~ /:/
ABresult
0X0
100
111
126 13 else { return undef }
127 }
128 140 ▶ return undef if !defined $date && !defined $time && !exists $c{wd};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $date or defined $time or exists $c{"wd"} 0 140 140
Condition83%5/6
defined $date or defined $time or exists $c{"wd"}
l!l&&r!l&&!r
13820
defined $date or defined $time
l!l&&r!l&&!r
77612
MC/DC0%0/3
defined $date or defined $time or exists $c{"wd"}
defined $date defined $time exists $c{"wd"}
Truth table75%3/4
A or B or C
A= defined $dateB= defined $timeC= exists $c{"wd"}
ABCresult
1XX1
01X1
0011
0000
129 140 ▶ $date //= '*-*-*';
Condition100%2/2
$date //= "*-*-*"
l!l
7763
MC/DC100%1/1
$date //= "*-*-*"
$date
Truth table100%2/2
A
A= $date
Aresult
11
00
130 140 ▶ $time //= '00:00:00';
Condition100%2/2
$time //= "00:00:00"
l!l
1346
MC/DC100%1/1
$time //= "00:00:00"
$time
Truth table100%2/2
A
A= $time
Aresult
11
00
131 140 ▶ my ( $ym, $sep, $day ) = $date =~ /\A(.*)([-~])([^-~]*)\z/ or return undef;
Branch: 1 branch
BranchTrueFalseTotal
() = $date =~ /\A(.*)([-~])([^-~]*)\z/ or return undef 140 0 140
132 140 ▶ $c{last} = $sep eq '~' ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$sep eq '~' ? : 5 135 140
133 140 my @ymv = split /-/, $ym, -1;
134 140 ▶ unshift @ymv, '*' if @ymv == 1;
Branch: 1 branch
BranchTrueFalseTotal
if @ymv == 1 0 140 140
135 140 ▶ return undef unless @ymv == 2;
Branch: 1 branch
BranchTrueFalseTotal
unless @ymv == 2 2 138 140
136 138 ▶ $ymv[0] = $ymv[0] + ( $ymv[0] < 70 ? 2000 : 1900 ) if $ymv[0] =~ /\A\d{2}\z/;
Branch: 2 branches
BranchTrueFalseTotal
if $ymv[0] =~ /\A\d{2}\z/ 1 137 138
$ymv[0] < 70 ? : 1 0 1
137 138 my @t = split /:/, $time, -1;
138 138 ▶ push @t, '00' if @t == 2;
Branch: 1 branch
BranchTrueFalseTotal
if @t == 2 79 59 138
139 138 ▶ return undef unless @t == 3;
Branch: 1 branch
BranchTrueFalseTotal
unless @t == 3 0 138 138
140 138 my @f = ( @ymv, $day, @t );
141 138 my @lim = ( [ 1970, 2199, 4 ], [ 1, 12, 2 ], [ 1, 31, 2 ], [ 0, 23, 2 ], [ 0, 59, 2 ], [ 0, 59, 2, 1 ] );
142 138 my @txt;
143 138 for my $i ( 0 .. 5 ) {
144 818 ▶ my ( $v, $tx ) = _field( $f[$i], @{ $lim[$i] } ) or return undef;
Branch: 1 branch
BranchTrueFalseTotal
() = _field($f[$i], @{$lim[$i];}) or return undef 813 5 818
145 813 $c{ (qw( year mon day hour min sec ))[$i] } = $v;
146 813 push @txt, $tx;
147 }
148 # ~T/n zaehlt vom Monatsende aus weiter zum Ende hin: ~07/1 = die letzten sieben Tage
149 133 ▶ if ( $c{last} && $f[2] =~ /\A(\d+)\/(\d+)\z/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c{"last"} and $f[2] =~ m[\A(\d+)/(\d+)\z]) 1 132 133
Condition100%3/3
$c{"last"} and $f[2] =~ m[\A(\d+)/(\d+)\z]
!ll&&!rl&&r
13021
MC/DC100%2/2
$c{"last"} and $f[2] =~ m[\A(\d+)/(\d+)\z]
$c{"last"} $f[2] =~ m[\A(\d+)/(\d+)\z]
Truth table100%3/3
A and B
A= $c{"last"}B= $f[2] =~ m[\A(\d+)/(\d+)\z]
ABresult
0X0
100
111
150 1 my @d;
151 1 ▶ for ( my $i = $1; $i >= 1; $i -= $2 ) { push @d, 0 + $i }
Branch: 1 branch
BranchTrueFalseTotal
if ($i >= 1) 7 1 8
152 1 $c{day} = [ sort { $a <=> $b } @d ];
153 }
154 133 ▶ push @norm, "$txt[0]-$txt[1]" . ( $c{last} ? '~' : '-' ) . $txt[2], join( ':', @txt[ 3 .. 5 ] );
Branch: 1 branch
BranchTrueFalseTotal
$c{'last'} ? : 3 130 133
155 133 ▶ push @norm, $tz if defined $tz;
Branch: 1 branch
BranchTrueFalseTotal
if defined $tz 14 119 133
156 133 $c{normalized} = join ' ', @norm;
157 133 return \%c;
158 }
159  
160 218104 ▶sub _last_sunday {
Subroutine _last_sunday: called CC=1 SCAR=0.0
161 218104 my ( $y, $m ) = @_; # $m 0-basiert; Mitternacht UTC des letzten Sonntags
162 218104 my $t = Time::Local::timegm( 0, 0, 0, _dim( $y, $m ), $m, $y );
163 218104 return $t - ( gmtime $t )[6] * 86400;
164 }
165  
166 10 ▶sub _nth_sunday {
Subroutine _nth_sunday: called CC=1 SCAR=0.0
167 10 my ( $y, $m, $n ) = @_;
168 10 my $t = Time::Local::timegm( 0, 0, 0, 1, $m, $y );
169 10 my $wd = ( gmtime $t )[6];
170 10 return $t + ( ( 7 - $wd ) % 7 ) * 86400 + ( $n - 1 ) * 7 * 86400;
171 }
172  
173 218150 ▶sub _dim {
Subroutine _dim: called CC=4 SCAR=20.1
174 218150 my ( $y, $m ) = @_;
175 218150 ▶ return ( 31, ( $y % 4 == 0 && ( $y % 100 != 0 || $y % 400 == 0 ) ) ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 )[$m];
Branch: 1 branch
BranchTrueFalseTotal
$y % 4 == 0 && ($y % 100 != 0 || $y % 400 == 0) ? : 0 218150 218150
Condition16%1/6
$y % 4 == 0 and $y % 100 != 0 || $y % 400 == 0
!ll&&!rl&&r
21815000
$y % 100 != 0 or $y % 400 == 0
l!l&&r!l&&!r
000
MC/DC0%0/3
$y % 4 == 0 and $y % 100 != 0 || $y % 400 == 0
$y % 4 == 0 $y % 100 != 0 $y % 400 == 0
Truth table25%1/4
A and B or C
A= $y % 4 == 0B= $y % 100 != 0C= $y % 400 == 0
ABCresult
0XX0
1000
11X1
1011
176 }
177  
178  
179 109168 ▶sub offset {
Subroutine offset: called CC=9 SCAR=22.7
Pod documented
180 109168 my ( $t, $tz ) = @_;
181 109168 ▶ my ( $std, $rule ) = @{ $ZONE{ $tz // $LOCAL } || $ZONE{$LOCAL} };
Condition50%3/6
$Langertha::Holmgang::Sim::Linux::Calendar::ZONE{$tz // $Langertha::Holmgang::Sim::Linux::Calendar::LOCAL} || $Langertha::Holmgang::Sim::Linux::Calendar::ZONE{$Langertha::Holmgang::Sim::Linux::Calendar::LOCAL}
l!l&&r!l&&!r
10916800
$tz // $Langertha::Holmgang::Sim::Linux::Calendar::LOCAL
l!l&&r!l&&!r
3111088570
MC/DC0%0/2
$Langertha::Holmgang::Sim::Linux::Calendar::ZONE{$tz // $Langertha::Holmgang::Sim::Linux::Calendar::LOCAL} || $Langertha::Holmgang::Sim::Linux::Calendar::ZONE{$Langertha::Holmgang::Sim::Linux::Calendar::LOCAL}
$Langertha::Holmgang::Sim::Linux::Calendar::ZONE{$tz // $Langertha::Holmgang::Sim::Linux::Calendar::LOCAL} $Langertha::Holmgang::Sim::Linux::Calendar::ZONE{$Langertha::Holmgang::Sim::Linux::Calendar::LOCAL}
MC/DC0%0/2
$tz // $Langertha::Holmgang::Sim::Linux::Calendar::LOCAL
$tz $Langertha::Holmgang::Sim::Linux::Calendar::LOCAL
Truth table33%1/3
A || B
A= $Langertha::Holmgang::Sim::Linux::Calendar::ZONE{$tz // $Langertha::Holmgang::Sim::Linux::Calendar::LOCAL}B= $Langertha::Holmgang::Sim::Linux::Calendar::ZONE{$Langertha::Holmgang::Sim::Linux::Calendar::LOCAL}
ABresult
1X1
011
000
Truth table66%2/3
A // B
A= $tzB= $Langertha::Holmgang::Sim::Linux::Calendar::LOCAL
ABresult
1X1
011
000
182 109168 ▶ return $std unless $rule;
Branch: 1 branch
BranchTrueFalseTotal
unless $rule 107 109061 109168
183 109061 my $y = ( gmtime $t )[5] + 1900;
184 109061 ▶ if ( $rule eq 'eu' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rule eq "eu") 109056 5 109061
185 109056 ▶ return $t >= _last_sunday( $y, 2 ) + 3600 && $t < _last_sunday( $y, 9 ) + 3600 ? $std + 3600 : $std;
Branch: 1 branch
BranchTrueFalseTotal
$t >= _last_sunday($y, 2) + 3600 && $t < _last_sunday($y, 9) + 3600 ? : 108929 127 109056
Condition100%3/3
$t >= _last_sunday($y, 2) + 3600 and $t < _last_sunday($y, 9) + 3600
!ll&&!rl&&r
8119108929
MC/DC100%2/2
$t >= _last_sunday($y, 2) + 3600 and $t < _last_sunday($y, 9) + 3600
$t >= _last_sunday($y, 2) + 3600 $t < _last_sunday($y, 9) + 3600
Truth table100%3/3
A and B
A= $t >= _last_sunday($y, 2) + 3600B= $t < _last_sunday($y, 9) + 3600
ABresult
0X0
100
111
186 }
187 5 my $from = _nth_sunday( $y, 2, 2 ) + 7200 - $std;
188 5 my $to = _nth_sunday( $y, 10, 1 ) + 7200 - ( $std + 3600 );
189 5 ▶ return $t >= $from && $t < $to ? $std + 3600 : $std;
Branch: 1 branch
BranchTrueFalseTotal
$t >= $from && $t < $to ? : 5 0 5
Condition33%1/3
$t >= $from and $t < $to
!ll&&!rl&&r
005
MC/DC0%0/2
$t >= $from and $t < $to
$t >= $from $t < $to
Truth table33%1/3
A and B
A= $t >= $fromB= $t < $to
ABresult
0X0
100
111
190 }
191  
192  
193 110 ▶sub next_elapse {
Subroutine next_elapse: called CC=20 SCAR=30.0
Pod documented
194 110 my ( $c, $after ) = @_;
195 110 my $tz = $c->{tz};
196 110 my ( undef, undef, undef, $d0, $m0, $y0 ) = gmtime( $after + offset( $after, $tz ) );
197 110 my $day = Time::Local::timegm( 0, 0, 0, $d0, $m0, $y0 );
198 110 ▶ my %in = map { my $k = $_; ( $k => $c->{$k} ? { map { $_ => 1 } @{ $c->{$k} } } : undef ) } qw( year mon day );
Branch: 1 branch
BranchTrueFalseTotal
$$c{$k} ? : 27 303 330
199 110 ▶ my $wd = $c->{wd} ? { map { $_ => 1 } @{ $c->{wd} } } : undef;
Branch: 1 branch
BranchTrueFalseTotal
$$c{'wd'} ? : 37 73 110
200 110 ▶ my @hours = $c->{hour} ? @{ $c->{hour} } : 0 .. 23;
Branch: 1 branch
BranchTrueFalseTotal
$$c{'hour'} ? : 100 10 110
201 110 ▶ my @mins = $c->{min} ? @{ $c->{min} } : 0 .. 59;
Branch: 1 branch
BranchTrueFalseTotal
$$c{'min'} ? : 106 4 110
202 110 ▶ my @secs = $c->{sec} ? @{ $c->{sec} } : 0 .. 59;
Branch: 1 branch
BranchTrueFalseTotal
$$c{'sec'} ? : 109 1 110
203 110 for my $n ( 0 .. 366 * 5 ) {
204 2745 my $d = $day + $n * 86400;
205 2745 my ( undef, undef, undef, $dd, $mm, $yy, $w ) = gmtime $d;
206 2745 ▶ next if $in{year} && !$in{year}{ $yy + 1900 };
Branch: 1 branch
BranchTrueFalseTotal
if $in{"year"} and not $in{"year"}{$yy + 1900} 1758 987 2745
Condition100%3/3
$in{"year"} and not $in{"year"}{$yy + 1900}
!ll&&!rl&&r
8351521758
MC/DC100%2/2
$in{"year"} and not $in{"year"}{$yy + 1900}
$in{"year"} not $in{"year"}{$yy + 1900}
Truth table100%3/3
A and not(B)
A= $in{"year"}B= not $in{"year"}{$yy + 1900}
ABresult
0X0
100
111
207 987 ▶ next if $in{mon} && !$in{mon}{ $mm + 1 };
Branch: 1 branch
BranchTrueFalseTotal
if $in{"mon"} and not $in{"mon"}{$mm + 1} 560 427 987
Condition100%3/3
$in{"mon"} and not $in{"mon"}{$mm + 1}
!ll&&!rl&&r
33394560
MC/DC100%2/2
$in{"mon"} and not $in{"mon"}{$mm + 1}
$in{"mon"} not $in{"mon"}{$mm + 1}
Truth table100%3/3
A and not(B)
A= $in{"mon"}B= not $in{"mon"}{$mm + 1}
ABresult
0X0
100
111
208 427 ▶ next if $in{day} && !$in{day}{ $c->{last} ? _dim( $yy + 1900, $mm ) - $dd + 1 : $dd };
Branch: 2 branches
BranchTrueFalseTotal
if $in{"day"} and not $in{"day"}{$$c{"last"} ? _dim($yy + 1900, $mm) - $dd + 1 : $dd} 149 278 427
$$c{'last'} ? : 46 119 165
Condition100%3/3
$in{"day"} and not $in{"day"}{$$c{"last"} ? _dim($yy + 1900, $mm) - $dd + 1 : $dd}
!ll&&!rl&&r
26216149
MC/DC100%2/2
$in{"day"} and not $in{"day"}{$$c{"last"} ? _dim($yy + 1900, $mm) - $dd + 1 : $dd}
$in{"day"} not $in{"day"}{$$c{"last"} ? _dim($yy + 1900, $mm) - $dd + 1 : $dd}
Truth table100%3/3
A and not(B)
A= $in{"day"}B= not $in{"day"}{$$c{"last"} ? _dim($yy + 1900, $mm) - $dd + 1 : $dd}
ABresult
0X0
100
111
209 278 ▶ next if $wd && !$wd->{ ( $w + 6 ) % 7 };
Branch: 1 branch
BranchTrueFalseTotal
if $wd and not $$wd{($w + 6) % 7} 108 170 278
Condition100%3/3
$wd and not $$wd{($w + 6) % 7}
!ll&&!rl&&r
11555108
MC/DC100%2/2
$wd and not $$wd{($w + 6) % 7}
$wd not $$wd{($w + 6) % 7}
Truth table100%3/3
A and not(B)
A= $wdB= not $$wd{($w + 6) % 7}
ABresult
0X0
100
111
210 170 for my $h (@hours) {
211 338 for my $mi (@mins) {
212 3820 for my $s (@secs) {
213 54222 my $lt = $d + $h * 3600 + $mi * 60 + $s;
214 54222 my $t = $lt - offset( $lt - offset( $lt, $tz ), $tz );
215 54222 ▶ return $t if $t > $after;
Branch: 1 branch
BranchTrueFalseTotal
if $t > $after 109 54113 54222
216 }
217 }
218 }
219 }
220 1 return undef;
221 }
222  
223  
224 162 ▶sub format_local {
Subroutine format_local: called CC=8 SCAR=21.4
Pod documented
225 162 my ( $t, $zone ) = @_;
226 162 ▶ $zone = !defined $zone || $zone eq '0' || $zone eq '' ? $LOCAL : $zone eq '1' ? 'UTC' : $zone;
Branch: 2 branches
BranchTrueFalseTotal
!defined($zone) || $zone eq '0' || $zone eq '' ? : 149 13 162
$zone eq '1' ? : 9 4 13
Condition66%4/6
not defined $zone or $zone eq 0 or $zone eq ""
l!l&&r!l&&!r
149013
not defined $zone or $zone eq 0
l!l&&r!l&&!r
149013
MC/DC33%1/3
not defined $zone or $zone eq 0 or $zone eq ""
not defined $zone $zone eq 0 $zone eq ""
Truth table50%2/4
not(A) or B or C
A= not defined $zoneB= $zone eq 0C= $zone eq ""
ABCresult
1XX1
01X1
0011
0000
227 162 ▶ my $z = $ZONE{$zone} || $ZONE{$LOCAL};
Condition33%1/3
$Langertha::Holmgang::Sim::Linux::Calendar::ZONE{$zone} || $Langertha::Holmgang::Sim::Linux::Calendar::ZONE{$Langertha::Holmgang::Sim::Linux::Calendar::LOCAL}
l!l&&r!l&&!r
16200
MC/DC0%0/2
$Langertha::Holmgang::Sim::Linux::Calendar::ZONE{$zone} || $Langertha::Holmgang::Sim::Linux::Calendar::ZONE{$Langertha::Holmgang::Sim::Linux::Calendar::LOCAL}
$Langertha::Holmgang::Sim::Linux::Calendar::ZONE{$zone} $Langertha::Holmgang::Sim::Linux::Calendar::ZONE{$Langertha::Holmgang::Sim::Linux::Calendar::LOCAL}
Truth table33%1/3
A || B
A= $Langertha::Holmgang::Sim::Linux::Calendar::ZONE{$zone}B= $Langertha::Holmgang::Sim::Linux::Calendar::ZONE{$Langertha::Holmgang::Sim::Linux::Calendar::LOCAL}
ABresult
1X1
011
000
228 162 my $off = offset( $t, $zone );
229 162 my @g = gmtime( $t + $off );
230 162 ▶ my $abbr = $off != $z->[0] && defined $z->[3] ? $z->[3] : $z->[2];
Branch: 1 branch
BranchTrueFalseTotal
$off != $$z[0] && defined $$z[3] ? : 117 45 162
Condition66%2/3
$off != $$z[0] and defined $$z[3]
!ll&&!rl&&r
450117
MC/DC50%1/2
$off != $$z[0] and defined $$z[3]
$off != $$z[0] defined $$z[3]
Truth table66%2/3
A and B
A= $off != $$z[0]B= defined $$z[3]
ABresult
0X0
100
111
231 162 return sprintf '%s %04d-%02d-%02d %02d:%02d:%02d %s', $WD[ ( $g[6] + 6 ) % 7 ], $g[5] + 1900, $g[4] + 1, $g[3], $g[2], $g[1], $g[0], $abbr;
232 }
233  
234  
235 17 ▶sub left {
Subroutine left: called CC=8 SCAR=20.8
Pod documented
236 17 my ($s) = @_;
237 17 ▶ return '0s' if $s <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if $s <= 0 0 17 17
238 17 my @p;
239 17 my $d = int( $s / 86400 ); $s -= $d * 86400;
240 17 my $h = int( $s / 3600 ); $s -= $h * 3600;
241 17 my $m = int( $s / 60 );
242 17 ▶ push @p, $d == 1 ? '1 day' : "$d days" if $d;
Branch: 2 branches
BranchTrueFalseTotal
if $d 1 16 17
$d == 1 ? : 0 1 1
243 17 ▶ push @p, "${h}h" if $h;
Branch: 1 branch
BranchTrueFalseTotal
if $h 16 1 17
244 17 ▶ push @p, "${m}min" if $m && !$d;
Branch: 1 branch
BranchTrueFalseTotal
if $m and not $d 9 8 17
Condition100%3/3
$m and not $d
!ll&&!rl&&r
719
MC/DC100%2/2
$m and not $d
$m not $d
Truth table100%3/3
A and not(B)
A= $mB= not $d
ABresult
0X0
100
111
245 17 ▶ return @p ? join( ' ', @p ) : int($s) . 's';
Branch: 1 branch
BranchTrueFalseTotal
@p ? : 16 1 17
246 }
247  
248 82 1;
249  
250 __END__
« blib/lib/Langertha/Holmgang/Target.pm ↑ Summary blib/lib/Langertha/Holmgang/Haystack.pm »