PTV/TimeTable/Schedule.pm

filter: Statementstmt 16.3% 8 / 49 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 13 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 25.0% 2 / 8 Podpod 83.3% 5 / 6 totaltotal 15.7% 15 / 95 CC 13 SCAR 47.8
CC
13
Cov
11%
next
182.0
new
2.0
as_list
2.0
CRAP 118.9
« PTV/Route.pm ↑ Summary PTV.pm »
1 package WWW::PTV::TimeTable::Schedule;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 our $VERSION = '0.06';
7  
8 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
Pod undocumented
9 0 my ($class, $schedule) = @_;
10 0 my $self = bless {}, $class;
11 0 $self->{schedule} = $schedule;
12 0 return $self
13 }
14  
15 0 ▶sub as_list {
Subroutine as_list: not called CC=1 SCAR=6.9
Pod documented
16 0 return @{ $_[0]->{schedule} };
17 }
18  
19 0 ▶sub next {
Subroutine next: not called CC=13 SCAR=52.0
Pod documented
20 0 my ($self, $n, $i) = @_;
21 0 ▶ $n ||= 1;
Condition0%0/2
$n ||= 1
l!l
00
MC/DC0%0/1
$n ||= 1
$n
Truth table0%0/2
A
A= $n
Aresult
11
00
22 0 ▶ $i ||= 0;
Condition0%0/2
$i ||= 0
l!l
00
MC/DC0%0/1
$i ||= 0
$i
Truth table0%0/2
A
A= $i
Aresult
11
00
23 0 my(@res,$c,$l);
24 0 my($h,$m) = (localtime(time))[2,1];
25  
26 0 foreach my $t ( @{ $self->{schedule} } ) {
27 0 $l++;
28 0 my($nh,$nm) = split /:/, $t;
29 0 ▶ $nm and $nh ne '-' or next;
Branch: 1 branch
BranchTrueFalseTotal
$nm and $nh ne "-" or next 0 0 0
Condition0%0/3
$nm and $nh ne "-"
!ll&&!rl&&r
000
MC/DC0%0/2
$nm and $nh ne "-"
$nm $nh ne "-"
Truth table0%0/3
A and B
A= $nmB= $nh ne "-"
ABresult
0X0
100
111
30  
31 0 ▶ if( ($nh > $h) ||
Branch: 1 branch
BranchTrueFalseTotal
if ($nh > $h or $nh >= $h and $nm >= $m) 0 0 0
Condition0%0/6
$nh > $h or $nh >= $h and $nm >= $m
l!l&&r!l&&!r
000
$nh >= $h and $nm >= $m
!ll&&!rl&&r
000
MC/DC0%0/3
$nh > $h or $nh >= $h and $nm >= $m
$nh > $h $nh >= $h $nm >= $m
Truth table0%0/4
A or B and C
A= $nh > $hB= $nh >= $hC= $nm >= $m
ABCresult
1XX1
0111
00X0
0100
32 ($nh >= $h && $nm >= $m) ) {
33 0 push @res, [$nh,$nm];
34  
35 0 ▶ if( $i == 7 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i == 7) 0 0 0
36 0 return $l-1
37 }
38 0 ▶ if( ++$c == $n ) {
Branch: 1 branch
BranchTrueFalseTotal
if (++$c == $n) 0 0 0
39 0 ▶ return ( ~~@res == 1
Branch: 1 branch
BranchTrueFalseTotal
~~@res == 1 ? : 0 0 0
40 ? $res[0]
41 : \@res )
42 }
43 }
44 }
45  
46 0 ▶ return ( @res ? \@res : 0 )
Branch: 1 branch
BranchTrueFalseTotal
@res ? : 0 0 0
47 }
48  
49 0 ▶sub index_of_next {
Subroutine index_of_next: not called CC=1 SCAR=6.9
Pod documented
50 0 return $_[0]->next(1,7)
51 }
52  
53 0 ▶sub next_five {
Subroutine next_five: not called CC=1 SCAR=6.9
Pod documented
54 0 return $_[0]->next(5)
55 }
56  
57 0 ▶sub pretty_print {
Subroutine pretty_print: not called CC=1 SCAR=6.9
Pod documented
58 0 my $self= shift;
59 0 my @t = localtime(time);
60 0 my $i = $self->index_of_next;
61 0 my @s = $self->as_list;
62 0 my $n = $s[$i];
63 0 my @d = qw(Sunday Monday Tuesday Wednesday Thursday Friday Saturday
64 Sunday);
65 0 my @m = qw(January February March April May June July August September
66 October November December);
67 0 printf("Current local time and date is: %s %s %s %02d:%02d %s\n",
68 $d[$t[6]], $t[3], $m[$t[4]], $t[2], $t[1], ($t[5]+1900));
69 0 @s = map { sprintf("| %-6s |\n", $_ ) } @s;
70 0 $s[$i] = "===== Next service =====\n"
71 . " $n\n"
72 . "========================\n";
73 0 @s = grep { /:/ } @s;
74 0 push @s, ""; unshift @s, "";
75 0 print join "+--------+\n", @s;
76 }
77  
78 2 1;
79  
80 __END__
« PTV/Route.pm ↑ Summary PTV.pm »