line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WWW::PTV::TimeTable; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
37
|
|
4
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
23
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
1036
|
use WWW::PTV::TimeTable::Schedule; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
323
|
|
7
|
1
|
|
|
1
|
|
10
|
use Carp qw(croak); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1229
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = '0.05'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our @ATTR = qw( route_id direction direction_desc name ); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub new { |
14
|
0
|
|
|
0
|
0
|
|
my($class, $stop_names, $stop_ids, $stop_times) = @_; |
15
|
0
|
|
|
|
|
|
my $self = bless {}, $class; |
16
|
0
|
|
|
|
|
|
$self->{stop_names} = $stop_names; |
17
|
0
|
|
|
|
|
|
$self->{stop_ids} = $stop_ids; |
18
|
0
|
|
|
|
|
|
$self->{stop_times} = $stop_times; |
19
|
0
|
|
|
|
|
|
@{ $self->{map} }{ @{ $self->{stop_ids} } } = @{ $self->{stop_times} }; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
20
|
0
|
|
|
|
|
|
return $self |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub stop_ids { |
24
|
0
|
|
|
0
|
1
|
|
return @{ $_[0]->{stop_ids} } |
|
0
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub stop_names { |
28
|
0
|
|
|
0
|
1
|
|
return @{ $_[0]->{stop_names} } |
|
0
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub stop_names_and_ids { |
32
|
0
|
|
|
0
|
1
|
|
my ($self, $type) = @_; |
33
|
0
|
|
0
|
|
|
|
$type ||= 'array'; |
34
|
0
|
0
|
|
|
|
|
$type = 'array' unless $type =~ /^(array|hash)$/; |
35
|
0
|
|
|
|
|
|
my @n = @{$self->{stop_names}}; |
|
0
|
|
|
|
|
|
|
36
|
0
|
|
|
|
|
|
my @i = @{$self->{stop_ids}}; |
|
0
|
|
|
|
|
|
|
37
|
0
|
|
|
|
|
|
my $c = 0; |
38
|
0
|
|
|
|
|
|
return map { [ $_, $n[$c++] ] } @i |
|
0
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub get_schedule_by_stop_id { |
42
|
0
|
0
|
|
0
|
1
|
|
defined $_[0]->{map}{$_[1]} |
43
|
|
|
|
|
|
|
and return WWW::PTV::TimeTable::Schedule->new( $_[0]->{map}{$_[1]} ) |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub get_schedule_by_stop_name { |
47
|
0
|
|
|
0
|
1
|
|
my ($self, $stop) = @_; |
48
|
0
|
|
|
|
|
|
my $c = 0; |
49
|
|
|
|
|
|
|
# This is really ugly - but we need to use the index of the matching |
50
|
|
|
|
|
|
|
# stop name as a hash key to retrieve the stop times from the map |
51
|
0
|
|
|
|
|
|
map { /$stop/i and return |
|
0
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
WWW::PTV::TimeTable::Schedule->new( |
53
|
0
|
0
|
|
|
|
|
$self->{map}{ @{ $self->{stop_ids} }[$c]} |
54
|
|
|
|
|
|
|
); |
55
|
0
|
|
|
|
|
|
$c++ |
56
|
0
|
|
|
|
|
|
} @{ $self->{stop_names} }; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub pretty_print { |
60
|
0
|
|
|
0
|
1
|
|
my $self= shift; |
61
|
0
|
|
|
|
|
|
my @t = localtime(time); |
62
|
0
|
|
|
|
|
|
my @d = qw(Sunday Monday Tuesday Wednesday Thursday Friday Saturday |
63
|
|
|
|
|
|
|
Sunday); |
64
|
0
|
|
|
|
|
|
my @m = qw(January February March April May June July August September |
65
|
|
|
|
|
|
|
October November December); |
66
|
0
|
|
|
|
|
|
printf("Current local time and date is: %s %s %s %02d:%02d %s\n", |
67
|
|
|
|
|
|
|
$d[$t[6]], $t[3], $m[$t[4]], $t[2], $t[1], ($t[5]+1900)); |
68
|
0
|
|
|
|
|
|
my $c = 0; |
69
|
|
|
|
|
|
|
|
70
|
0
|
|
|
|
|
|
foreach my $s ( @{ $self->{stop_times} } ) { |
|
0
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
printf( "| %-50s |", @{ $self->{stop_names} }[$c] ); |
|
0
|
|
|
|
|
|
|
72
|
0
|
|
|
|
|
|
map { printf( "%5s|", $_ ) } @{ @{ $self->{stop_times} }[$c] }; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
73
|
0
|
|
|
|
|
|
print "\n+"; |
74
|
0
|
|
|
|
|
|
my $l = ( 54 + ( 7 * scalar @{ @{ $self->{stop_times} }[$c] } ) ) - 2; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
|
print "-"x$l; |
76
|
0
|
|
|
|
|
|
print "+\n"; |
77
|
0
|
|
|
|
|
|
$c++; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
1; |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
__END__ |