PTV/TimeTable.pm

filter: Statementstmt 20.9% 14 / 67 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 36.3% 4 / 11 Podpod 85.7% 6 / 7 totaltotal 25.5% 24 / 94 CC 6 SCAR 16.3
CC
6
Cov
19%
stop_names_and_ids
12.0
get_schedule_by_stop_id
6.0
get_schedule_by_stop_name
6.0
CRAP 5.1
« PTV/Area.pm ↑ Summary PTV/Stop.pm »
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 @ATTR = qw( route_id direction direction_desc name );
10  
11 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
Pod undocumented
12 0 my ( $class, $stop_names, $stop_ids, $stop_times ) = @_;
13  
14 0 my $self = bless {}, $class;
15 0 $self->{stop_names} = $stop_names;
16 0 $self->{stop_ids} = $stop_ids;
17 0 $self->{stop_times} = $stop_times;
18 0 @{ $self->{map} }{ @{ $self->{stop_ids} } } = @{ $self->{stop_times} };
19  
20 0 return $self
21 }
22  
23 0 ▶sub stop_ids {
Subroutine stop_ids: not called CC=1 SCAR=6.9
Pod documented
24 0 return @{ $_[0]->{stop_ids} }
25 }
26  
27 0 ▶sub stop_names {
Subroutine stop_names: not called CC=1 SCAR=6.9
Pod documented
28 0 return @{ $_[0]->{stop_names} }
29 }
30  
31 0 ▶sub stop_names_and_ids {
Subroutine stop_names_and_ids: not called CC=3 SCAR=24.8
Pod documented
32 0 my ( $self, $type ) = @_;
33  
34 0 ▶ $type ||= 'array';
Condition0%0/2
$type ||= "array"
l!l
00
MC/DC0%0/1
$type ||= "array"
$type
Truth table0%0/2
A
A= $type
Aresult
11
00
35 0 ▶ $type = 'array' unless $type =~ /^(array|hash)$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $type =~ /^(array|hash)$/ 0 0 0
36 0 my @n = @{ $self->{stop_names} };
37 0 my @i = @{ $self->{stop_ids} };
38 0 my $c = 0;
39  
40 0 return map { [ $_, $n[$c++] ] } @i
41 }
42  
43 0 ▶sub get_schedule_by_stop_id {
Subroutine get_schedule_by_stop_id: not called CC=2 SCAR=17.9
Pod documented
44 defined $_[0]->{map}{$_[1]}
45 0 ▶ and return WWW::PTV::TimeTable::Schedule->new( $_[0]->{map}{$_[1]} )
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0]{"map"}{$_[1]} and return "WWW::PTV::TimeTable::Schedule"->new($_[0]{"map"}{$_[1]}) 0 0 0
46 }
47  
48 0 ▶sub get_schedule_by_stop_name {
Subroutine get_schedule_by_stop_name: not called CC=2 SCAR=17.9
Pod documented
49 0 my ( $self, $stop ) = @_;
50  
51 0 my $c = 0;
52 # This is really ugly - but we need to use the index of the matching
53 # stop name as a hash key to retrieve the stop times from the map
54 map { /$stop/i and return
55 WWW::PTV::TimeTable::Schedule->new(
56 0 ▶ $self->{map}{ @{ $self->{stop_ids} }[$c]}
Branch: 1 branch
BranchTrueFalseTotal
/$stop/i and return "WWW::PTV::TimeTable::Schedule"->new($self->{"map"}{@{$$self{"stop_ids"};}[$c]}) 0 0 0
57 );
58 0 $c++
59 0 } @{ $self->{stop_names} };
60 }
61  
62 0 ▶sub pretty_print {
Subroutine pretty_print: not called CC=2 SCAR=17.9
Pod documented
63 0 my $self= shift;
64  
65 0 my @t = localtime(time);
66 0 my @d = qw(Sunday Monday Tuesday Wednesday Thursday Friday Saturday
67 Sunday);
68 0 my @m = qw(January February March April May June July August September
69 October November December);
70 0 printf("Current local time and date is: %s %s %s %02d:%02d %s\n",
71 $d[$t[6]], $t[3], $m[$t[4]], $t[2], $t[1], ($t[5]+1900));
72 0 my $c = 0;
73  
74 0 foreach my $s ( @{ $self->{stop_times} } ) {
75 0 printf( "| %-50s |", @{ $self->{stop_names} }[$c] );
76  
77 map {
78 0 printf( "%5s|", $_ )
79 0 } @{ @{ $self->{ stop_times } }[ $c ] };
80  
81 0 print "\n+";
82 0 my $l = ( 54 + ( 7 * scalar @{ @{ $self->{stop_times} }[$c] } ) ) - 2;
83 0 print "-"x$l;
84 0 print "+\n";
85 0 $c++;
86 }
87 }
88  
89 2 1;
90  
91 __END__
« PTV/Area.pm ↑ Summary PTV/Stop.pm »