| 1 | package WWW::PTV::TimeTable; | ||||||||||||
| 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 | ▶ | use WWW::PTV::TimeTable::Schedule; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | 2 | ▶ | use Carp qw(croak); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | |||||||||||||
| 9 | 2 | our $VERSION = '0.05'; | |||||||||||
| 10 | |||||||||||||
| 11 | 2 | our @ATTR = qw( route_id direction direction_desc name ); | |||||||||||
| 12 | |||||||||||||
| 13 | sub new { | ||||||||||||
| 14 | 0 | ▶ | my($class, $stop_names, $stop_ids, $stop_times) = @_; | ||||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 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} }; | |||||||||||
| 20 | 0 | return $self | |||||||||||
| 21 | } | ||||||||||||
| 22 | |||||||||||||
| 23 | sub stop_ids { | ||||||||||||
| 24 | 0 | ▶ | return @{ $_[0]->{stop_ids} } | ||||||||||
|
Subroutine
stop_ids: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 25 | } | ||||||||||||
| 26 | |||||||||||||
| 27 | sub stop_names { | ||||||||||||
| 28 | 0 | ▶ | return @{ $_[0]->{stop_names} } | ||||||||||
|
Subroutine
stop_names: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 29 | } | ||||||||||||
| 30 | |||||||||||||
| 31 | sub stop_names_and_ids { | ||||||||||||
| 32 | 0 | ▶ | my ($self, $type) = @_; | ||||||||||
|
Subroutine
stop_names_and_ids: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||
| 33 | 0 | ▶ | $type ||= 'array'; | ||||||||||
|
Condition0%0/2
$type ||= "array"
MC/DC0%0/1
$type ||= "array"
$type
Truth table0%0/2
A
A= $type
| |||||||||||||
| 34 | 0 | ▶ | $type = 'array' unless $type =~ /^(array|hash)$/; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 35 | 0 | my @n = @{$self->{stop_names}}; | |||||||||||
| 36 | 0 | my @i = @{$self->{stop_ids}}; | |||||||||||
| 37 | 0 | my $c = 0; | |||||||||||
| 38 | 0 | return map { [ $_, $n[$c++] ] } @i | |||||||||||
| 39 | } | ||||||||||||
| 40 | |||||||||||||
| 41 | sub get_schedule_by_stop_id { | ||||||||||||
| 42 | defined $_[0]->{map}{$_[1]} | ||||||||||||
| 43 | 0 | ▶ | and return WWW::PTV::TimeTable::Schedule->new( $_[0]->{map}{$_[1]} ) | ||||||||||
|
Subroutine
get_schedule_by_stop_id: not called CC=2 SCAR=17.9
Pod
documented
Branch: 1 branch
| |||||||||||||
| 44 | } | ||||||||||||
| 45 | |||||||||||||
| 46 | sub get_schedule_by_stop_name { | ||||||||||||
| 47 | 0 | ▶ | my ($self, $stop) = @_; | ||||||||||
|
Subroutine
get_schedule_by_stop_name: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||
| 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 | map { /$stop/i and return | ||||||||||||
| 52 | WWW::PTV::TimeTable::Schedule->new( | ||||||||||||
| 53 | 0 | ▶ | $self->{map}{ @{ $self->{stop_ids} }[$c]} | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 54 | ); | ||||||||||||
| 55 | 0 | $c++ | |||||||||||
| 56 | 0 | } @{ $self->{stop_names} }; | |||||||||||
| 57 | } | ||||||||||||
| 58 | |||||||||||||
| 59 | sub pretty_print { | ||||||||||||
| 60 | 0 | ▶ | my $self= shift; | ||||||||||
|
Subroutine
pretty_print: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||
| 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} } ) { | |||||||||||
| 71 | 0 | printf( "| %-50s |", @{ $self->{stop_names} }[$c] ); | |||||||||||
| 72 | 0 | map { printf( "%5s|", $_ ) } @{ @{ $self->{stop_times} }[$c] }; | |||||||||||
| 73 | 0 | print "\n+"; | |||||||||||
| 74 | 0 | my $l = ( 54 + ( 7 * scalar @{ @{ $self->{stop_times} }[$c] } ) ) - 2; | |||||||||||
| 75 | 0 | print "-"x$l; | |||||||||||
| 76 | 0 | print "+\n"; | |||||||||||
| 77 | 0 | $c++; | |||||||||||
| 78 | } | ||||||||||||
| 79 | } | ||||||||||||
| 80 | |||||||||||||
| 81 | 2 | 1; | |||||||||||
| 82 | |||||||||||||
| 83 | __END__ | ||||||||||||