line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WWW::PTV::TimeTable::Schedule; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
42
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1326
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.05'; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub new { |
9
|
0
|
|
|
0
|
0
|
|
my ($class, $schedule) = @_; |
10
|
0
|
|
|
|
|
|
my $self = bless {}, $class; |
11
|
0
|
|
|
|
|
|
$self->{schedule} = $schedule; |
12
|
0
|
|
|
|
|
|
return $self |
13
|
|
|
|
|
|
|
} |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub as_list { |
16
|
0
|
|
|
0
|
1
|
|
return @{ $_[0]->{schedule} }; |
|
0
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub next { |
20
|
0
|
|
|
0
|
1
|
|
my ($self, $n, $i) = @_; |
21
|
0
|
|
0
|
|
|
|
$n ||= 1; |
22
|
0
|
|
0
|
|
|
|
$i ||= 0; |
23
|
0
|
|
|
|
|
|
my(@res,$c,$l); |
24
|
0
|
|
|
|
|
|
my($h,$m) = (localtime(time))[2,1]; |
25
|
|
|
|
|
|
|
|
26
|
0
|
|
|
|
|
|
foreach my $t ( @{ $self->{schedule} } ) { |
|
0
|
|
|
|
|
|
|
27
|
0
|
|
|
|
|
|
$l++; |
28
|
0
|
|
|
|
|
|
my($nh,$nm) = split /:/, $t; |
29
|
0
|
0
|
0
|
|
|
|
$nm and $nh ne '-' or next; |
30
|
|
|
|
|
|
|
|
31
|
0
|
0
|
0
|
|
|
|
if( ($nh > $h) || |
|
|
|
0
|
|
|
|
|
32
|
|
|
|
|
|
|
($nh >= $h && $nm >= $m) ) { |
33
|
0
|
|
|
|
|
|
push @res, [$nh,$nm]; |
34
|
|
|
|
|
|
|
|
35
|
0
|
0
|
|
|
|
|
if( $i == 7 ) { |
36
|
0
|
|
|
|
|
|
return $l-1 |
37
|
|
|
|
|
|
|
} |
38
|
0
|
0
|
|
|
|
|
if( ++$c == $n ) { |
39
|
0
|
0
|
|
|
|
|
return ( ~~@res == 1 |
40
|
|
|
|
|
|
|
? $res[0] |
41
|
|
|
|
|
|
|
: \@res ) |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
0
|
0
|
|
|
|
|
return ( @res ? \@res : 0 ) |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub index_of_next { |
50
|
0
|
|
|
0
|
1
|
|
return $_[0]->next(1,7) |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub next_five { |
54
|
0
|
|
|
0
|
1
|
|
return $_[0]->next(5) |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub pretty_print { |
58
|
0
|
|
|
0
|
1
|
|
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; |
|
0
|
|
|
|
|
|
|
70
|
0
|
|
|
|
|
|
$s[$i] = "===== Next service =====\n" |
71
|
|
|
|
|
|
|
. " $n\n" |
72
|
|
|
|
|
|
|
. "========================\n"; |
73
|
0
|
|
|
|
|
|
@s = grep { /:/ } @s; |
|
0
|
|
|
|
|
|
|
74
|
0
|
|
|
|
|
|
push @s, ""; unshift @s, ""; |
|
0
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
|
print join "+--------+\n", @s; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
1; |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
__END__ |