PIDS.pm

filter: Statementstmt 60.2% 85 / 141 Branchbran 20.0% 4 / 20 Conditioncond 0.0% 0 / 24 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 61.5% 24 / 39 Podpod 100% 1 / 1 totaltotal 48.7% 114 / 234 CC 22 SCAR 31.0
CC
22
Cov
48%
__ANON__
110.0
__ANON__
20.0
__validate_parameters
16.4
CRAP 22.3
↑ Summary PIDS/ListedStop.pm »
1 package WWW::PIDS;
2  
3 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 9 ▶use SOAP::Lite;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 9 ▶use WWW::PIDS::CoreDataChanges;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 9 ▶use WWW::PIDS::Destination;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 9 ▶use WWW::PIDS::ListedStop;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 9 ▶use WWW::PIDS::NextPredictedStopDetail;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 9 ▶use WWW::PIDS::PredictedTime;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 9 ▶use WWW::PIDS::PredictedArrivalTimeData;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 9 ▶use WWW::PIDS::RouteChange;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 9 ▶use WWW::PIDS::RouteDestination;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 9 ▶use WWW::PIDS::RouteNo;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 9 ▶use WWW::PIDS::RouteStop;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 9 ▶use WWW::PIDS::RouteSummary;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 9 ▶use WWW::PIDS::ScheduledTime;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 9 ▶use WWW::PIDS::StopChange;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 9 ▶use WWW::PIDS::StopInformation;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 9 ▶use WWW::PIDS::TripSchedule;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 9 our $VERSION = '0.03';
24 9 our %ATTR = (
25 ClientGuid => undef,
26 ClientType => 'WEBPID',
27 ClientVersion => $VERSION,
28 ClientWebServiceVersion => '6.4.0.0',
29 );
30  
31 9 our $ENDPOINT = 'http://ws.tramtracker.com.au/pidsservice/pids.asmx';
32 9 our $NS = 'http://www.yarratrams.com.au/pidsservice/';
33 9 our $PROXY = 'http://ws.tramtracker.com.au/pidsservice/pids.asmx';
34  
35 our %METHODS = (
36 GetDestinationsForAllRoutes => {
37 0 ▶ result => sub { return map { WWW::PIDS::Destination->new( $_ ) }
Subroutine __ANON__: not called CC=1 SCAR=6.9
38 0 @{ shift->{diffgram}->{DocumentElement}->{ListOfDestinationsForAllRoutes} }
39 }
40 },
41 GetDestinationsForRoute => {
42 parameters => [ { param => 'routeNo', format => qr/^\d{1,3}$/, type => 'string' } ],
43 0 ▶ result => sub { return WWW::PIDS::RouteDestination->new(
Subroutine __ANON__: not called CC=1 SCAR=6.9
44 0 %{ shift->{diffgram}->{DocumentElement}->{RouteDestinations} }
45 )
46 }
47 },
48 GetListOfStopsByRouteNoAndDirection => {
49 parameters => [ { param => 'routeNo', format => qr/^\d{1,3}\w{0,2}$/, type => 'string' },
50 { param => 'isUpDirection',format => qr/^(0|1)$/, type => 'boolean' } ],
51 0 ▶ result => sub { return map { WWW::PIDS::ListedStop->new( $_ ) }
Subroutine __ANON__: not called CC=1 SCAR=6.9
52 0 @{ shift->{diffgram}->{DocumentElement}->{S} }
53 }
54 },
55 GetMainRoutes => {
56 0 ▶ result => sub { return map { WWW::PIDS::RouteNo->new( $_ ) }
Subroutine __ANON__: not called CC=1 SCAR=6.9
57 0 @{ shift->{diffgram}->{DocumentElement}->{ListOfNonSubRoutes} }
58 }
59 },
60 GetMainRoutesForStop => {
61 parameters => [ { param => 'stopNo', format => qr/^\d{4}$/, type => 'short' } ],
62 0 ▶ result => sub { return map { WWW::PIDS::RouteNo->new( $_ ) }
Subroutine __ANON__: not called CC=1 SCAR=6.9
63 0 @{ shift->{diffgram}->{DocumentElement}->{ListOfMainRoutesAtStop} }
64 }
65 },
66 GetNextPredictedArrivalTimeAtStopsForTramNo => {
67 parameters => [ { param => 'tramNo', format => qr/^\d{1,4}$/, type => 'short' } ],
68 0 ▶ result => sub { my $n = shift;
Subroutine __ANON__: not called CC=4 SCAR=30.0
69 0 ▶ return unless exists $n->{diffgram};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $n->{"diffgram"} 0 0 0
70 0 ▶ return unless defined $n->{diffgram}->{NewDataSet};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $n->{"diffgram"}{"NewDataSet"} 0 0 0
71 return ( defined $n->{diffgram}->{NewDataSet}
72 ? WWW::PIDS::PredictedArrivalTimeData->new( $n->{diffgram}->{NewDataSet} )
73 0 ▶ : undef
Branch: 1 branch
BranchTrueFalseTotal
defined $n->{'diffgram'}{'NewDataSet'} ? : 0 0 0
74 )
75 }
76 },
77 GetNextPredictedRoutesCollection => {
78 parameters => [ { param => 'stopNo', format => qr/^\d{4}$/, type => 'short' },
79 { param => 'routeNo', format => qr/^\d{1,3}[a-z]?$/, type => 'string' },
80 { param => 'lowFloor', format => qr/^(0|1)$/, type => 'boolean' } ],
81 0 ▶ result => sub { my $n = shift;
Subroutine __ANON__: not called CC=10 SCAR=47.0
82 # Ugh...
83 return ( exists $n->{diffgram} &&
84 defined $n->{diffgram} &&
85 $n->{diffgram} ne '' &&
86 exists $n->{diffgram}->{DocumentElement} &&
87 defined $n->{diffgram}->{DocumentElement} &&
88 $n->{diffgram}->{DocumentElement} ne '' &&
89 exists $n->{diffgram}->{DocumentElement}->{ToReturn} &&
90 defined $n->{diffgram}->{DocumentElement}->{ToReturn} &&
91 $n->{diffgram}->{DocumentElement}->{ToReturn}ne '' )
92 0 ? map { WWW::PIDS::ScheduledTime->new( $_ ) }
93 0 ▶ @{ $n->{diffgram}->{DocumentElement}->{ToReturn} }
Branch: 1 branch
BranchTrueFalseTotal
exists $n->{'diffgram'} && defined $n->{'diffgram'} && $n->{'diffgram'} ne '' && exists $n->{'diffgram'}{'DocumentElement'} && defined $n->{'diffgram'}{'DocumentElement'} && $n->{'diffgram'}{'DocumentElement'} ne '' && exists $n->{'diffgram'}{'DocumentElement'}{'ToReturn'} && defined $n->{'diffgram'}{'DocumentElement'}{'ToReturn'} && $n->{'diffgram'}{'DocumentElement'}{'ToReturn'} ne '' ? : 0 0 0
Condition0%0/24
exists $n->{"diffgram"} and defined $n->{"diffgram"} and $n->{"diffgram"} ne "" and exists $n->{"diffgram"}{"DocumentElement"} and defined $n->{"diffgram"}{"DocumentElement"} and $n->{"diffgram"}{"DocumentElement"} ne "" and exists $n->{"diffgram"}{"DocumentElement"}{"ToReturn"} and defined $n->{"diffgram"}{"DocumentElement"}{"ToReturn"} and $n->{"diffgram"}{"DocumentElement"}{"ToReturn"} ne ""
!ll&&!rl&&r
000
exists $n->{"diffgram"} and defined $n->{"diffgram"} and $n->{"diffgram"} ne "" and exists $n->{"diffgram"}{"DocumentElement"} and defined $n->{"diffgram"}{"DocumentElement"} and $n->{"diffgram"}{"DocumentElement"} ne "" and exists $n->{"diffgram"}{"DocumentElement"}{"ToReturn"} and defined $n->{"diffgram"}{"DocumentElement"}{"ToReturn"}
!ll&&!rl&&r
000
exists $n->{"diffgram"} and defined $n->{"diffgram"} and $n->{"diffgram"} ne "" and exists $n->{"diffgram"}{"DocumentElement"} and defined $n->{"diffgram"}{"DocumentElement"} and $n->{"diffgram"}{"DocumentElement"} ne "" and exists $n->{"diffgram"}{"DocumentElement"}{"ToReturn"}
!ll&&!rl&&r
000
exists $n->{"diffgram"} and defined $n->{"diffgram"} and $n->{"diffgram"} ne "" and exists $n->{"diffgram"}{"DocumentElement"} and defined $n->{"diffgram"}{"DocumentElement"} and $n->{"diffgram"}{"DocumentElement"} ne ""
!ll&&!rl&&r
000
exists $n->{"diffgram"} and defined $n->{"diffgram"} and $n->{"diffgram"} ne "" and exists $n->{"diffgram"}{"DocumentElement"} and defined $n->{"diffgram"}{"DocumentElement"}
!ll&&!rl&&r
000
exists $n->{"diffgram"} and defined $n->{"diffgram"} and $n->{"diffgram"} ne "" and exists $n->{"diffgram"}{"DocumentElement"}
!ll&&!rl&&r
000
exists $n->{"diffgram"} and defined $n->{"diffgram"} and $n->{"diffgram"} ne ""
!ll&&!rl&&r
000
exists $n->{"diffgram"} and defined $n->{"diffgram"}
!ll&&!rl&&r
000
MC/DC0%0/9
exists $n->{"diffgram"} and defined $n->{"diffgram"} and $n->{"diffgram"} ne "" and exists $n->{"diffgram"}{"DocumentElement"} and defined $n->{"diffgram"}{"DocumentElement"} and $n->{"diffgram"}{"DocumentElement"} ne "" and exists $n->{"diffgram"}{"DocumentElement"}{"ToReturn"} and defined $n->{"diffgram"}{"DocumentElement"}{"ToReturn"} and $n->{"diffgram"}{"DocumentElement"}{"ToReturn"} ne ""
exists $n->{"diffgram"} defined $n->{"diffgram"} $n->{"diffgram"} ne "" exists $n->{"diffgram"}{"DocumentElement"} defined $n->{"diffgram"}{"DocumentElement"} $n->{"diffgram"}{"DocumentElement"} ne "" exists $n->{"diffgram"}{"DocumentElement"}{"ToReturn"} defined $n->{"diffgram"}{"DocumentElement"}{"ToReturn"} $n->{"diffgram"}{"DocumentElement"}{"ToReturn"} ne ""
Truth table0%0/10
A and B and C and D and E and F and G and H and I
A= exists $n->{"diffgram"}B= defined $n->{"diffgram"}C= $n->{"diffgram"} ne ""D= exists $n->{"diffgram"}{"DocumentElement"}E= defined $n->{"diffgram"}{"DocumentElement"}F= $n->{"diffgram"}{"DocumentElement"} ne ""G= exists $n->{"diffgram"}{"DocumentElement"}{"ToReturn"}H= defined $n->{"diffgram"}{"DocumentElement"}{"ToReturn"}I= $n->{"diffgram"}{"DocumentElement"}{"ToReturn"} ne ""
ABCDEFGHIresult
0XXXXXXXX0
10XXXXXXX0
110XXXXXX0
1110XXXXX0
11110XXXX0
111110XXX0
1111110XX0
11111110X0
1111111100
1111111111
94 : ()
95 }
96 },
97 GetNewClientGuid => {
98 0 ▶ result => sub { return shift }
Subroutine __ANON__: not called CC=1 SCAR=6.9
99 },
100 'GetPlatformStopsByRouteAndDirection' => {
101 parameters => [ { param => 'routeNo', format => qr/^\d{1,3}[a-z]?$/, type => 'string' },
102 { param => 'isUpDirection',format => qr/^(0|1)$/, type => 'boolean' } ],
103 0 ▶ result => sub { return @_ }
Subroutine __ANON__: not called CC=1 SCAR=6.9
104 #result => sub { return map { WWW::PIDS::RoutesCollection->new( $_ ) } @{ shift->{diffgram}->{DocumentElement}->{ToReturn} } }
105 },
106 GetRouteStopsByRoute => {
107 parameters => [ { param => 'routeNo', format => qr/^\d{1,3}[a-z]?$/, type => 'string' },
108 { param => 'isUpDirection',format => qr/^(0|1)$/, type => 'boolean' } ],
109 0 ▶ result => sub { return map { WWW::PIDS::RouteStop->new( $_ ) }
Subroutine __ANON__: not called CC=1 SCAR=6.9
110 0 @{ shift->{diffgram}->{DocumentElement}->{S} }
111 }
112 },
113 GetRouteSummaries => {
114 0 ▶ result => sub { return map { WWW::PIDS::RouteSummary->new( $_ ) }
Subroutine __ANON__: not called CC=1 SCAR=6.9
115 0 @{ shift->{diffgram}->{DocumentElement}->{RouteSummaries} }
116 }
117 },
118 GetSchedulesCollection => {
119 parameters => [ { param => 'stopNo', format => qr/^\d{4}$/, type => 'short' },
120 { param => 'routeNo', format => qr/^\d{1,3}[a-z]?$/, type => 'string' },
121 { param => 'lowFloor', format => qr/^(0|1)$/, type => 'boolean' },
122 { param => 'clientRequestDateTime', format => qr/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}$/, type => 'dateTime' } ],
123 0 ▶ result => sub { return map { WWW::PIDS::PredictedTime->new( $_ ) }
Subroutine __ANON__: not called CC=1 SCAR=6.9
124 0 @{ shift->{diffgram}->{DocumentElement}->{SchedulesResultsTable} }
125 }
126 },
127 GetSchedulesForTrip => {
128 parameters => [ { param => 'tripID', format => qr/^\d{1,}$/, type => 'int' },
129 { param => 'scheduledDateTime', format => qr/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}$/, type => 'dateTime' } ],
130 0 ▶ result => sub { return map { WWW::PIDS::TripSchedule->new( $_ ) }
Subroutine __ANON__: not called CC=1 SCAR=6.9
131 0 @{ shift->{diffgram}->{DocumentElement}->{Table} }
132 }
133 },
134 GetStopInformation => {
135 parameters => [ { param => 'stopNo', format => qr/^\d{4}$/, type => 'short' } ],
136 0 ▶ result => sub { return WWW::PIDS::StopInformation->new( shift->{diffgram}->{DocumentElement}->{StopInformation} ) }
Subroutine __ANON__: not called CC=1 SCAR=6.9
137 },
138 GetStopsAndRoutesUpdatesSince => {
139 parameters => [ { param => 'dateSince', format => qr/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}$/, type => 'dateTime' } ],
140 0 ▶ result => sub { my $d = shift;
Subroutine __ANON__: not called CC=1 SCAR=6.9
141 0 my @r = map { WWW::PIDS::RouteChange->new( $_ ) }
142 0 @{ $d->{diffgram}->{dsCoreDataChanges}->{dtRoutesChanges} };
143 0 my @s = map { WWW::PIDS::StopChange->new( $_ ) }
144 0 @{ $d->{diffgram}->{dsCoreDataChanges}->{dtStopsChanges} };
145 0 my $t = $d->{diffgram}->{dsCoreDataChanges}->{dtServerTime}->{ServerTime};
146 0 return WWW::PIDS::CoreDataChanges->new( ServerTime => $t, RouteChanges => \@r, StopChanges => \@s )
147 }
148 }
149 9 );
150  
151 9 for my $method ( keys %METHODS ) {
152 {
153 9 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
154  
155 7 ▶ *$method = sub {
Subroutine __ANON__: called CC=2 SCAR=7.1
156 7 my ( $self, %parameters ) = @_;
157  
158 7 my $valid = __validate_parameters( $method, %parameters );
159 7 ▶ die $valid unless ( $valid eq "1" );
Branch: 1 branch
BranchTrueFalseTotal
unless $valid eq 1 0 7 7
160  
161 7 my @body = __construct_body( $method, %parameters );
162  
163 my $r = SOAP::Lite->endpoint( $ENDPOINT )
164 ->default_ns( $NS )
165 ->proxy( $PROXY )
166 7 ▶ ->on_action( sub { "$NS$method" } )
Subroutine __ANON__: called CC=1 SCAR=0.0
167 ->$method( @body, $self->{pids_header} )
168 7 ->result;
169  
170 0 return $METHODS{ $method }{ 'result' }->($r);
171 135 };
172  
173 }
174 }
175  
176 7 ▶sub __validate_parameters {
Subroutine __validate_parameters: called CC=5 SCAR=28.0
177 7 my ( $m, %p ) = @_;
178  
179 7 ▶ return 1 if not defined $METHODS{ $m }{ 'parameters' };
Branch: 1 branch
BranchTrueFalseTotal
unless defined $WWW::PIDS::METHODS{$m}{"parameters"} 7 0 7
180  
181 0 for my $param ( @{ $METHODS{ $m }{ 'parameters' } } ) {
182 defined $p{ $param->{ param } }
183 0 ▶ or return "Mandatory parameter $param->{ param } missing";
Branch: 1 branch
BranchTrueFalseTotal
defined $p{$param->{"param"}} or return qq[Mandatory parameter $param->{"param"} missing] 0 0 0
184  
185 ( $p{ $param->{ param } } =~ $param->{ format } )
186 0 ▶ or return "Value of parameter $param->{ param } does not conform to expected format";
Branch: 1 branch
BranchTrueFalseTotal
$p{$param->{"param"}} =~ /$param->{"format"}/ or return qq[Value of parameter $param->{"param"} does not conform to expected format] 0 0 0
187 }
188  
189 0 return 1
190 }
191  
192 7 ▶sub __construct_body {
Subroutine __construct_body: called CC=2 SCAR=7.0
193 7 my ( $m, %p ) = @_;
194 7 my @b;
195  
196 7 for my $param ( @{ $METHODS{ $m }{ 'parameters' } } ) {
197 push @b, SOAP::Data->name( $param->{ param } => $p{ $param->{ param } } )
198 ->type( $param->{ type } )
199 0 }
200  
201 return @b
202 7 }
203  
204 7 ▶sub new {
Subroutine new: called CC=4 SCAR=16.4
Pod documented
205 7 my ( $class, %args ) = @_;
206 7 my $self = bless {}, $class;
207  
208 7 for my $a ( keys %ATTR ) {
209 defined $args{ $a }
210 ? $self->{ $a } = $args{ $a }
211 28 ▶ : $self->{ $a } = $ATTR{ $a } ;
Branch: 1 branch
BranchTrueFalseTotal
defined $args{$a} ? : 0 28 28
212 }
213  
214 7 ▶ defined $self->{ 'ClientGuid' } or $self->{ 'ClientGuid' } = $self->GetNewClientGuid();
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{"ClientGuid"} or $self->{"ClientGuid"} = $self->GetNewClientGuid 0 7 7
215 0 $ATTR{ 'ClientGuid' } = $self->{ 'ClientGuid' };
216  
217 $self->{pids_header} = SOAP::Header->name( 'PidsClientHeader' )
218 ->attr( { 'xmlns' => $NS } )
219 ->value( \SOAP::Header->value(
220 SOAP::Header->name( 'ClientGuid' => $ATTR{ 'ClientGuid' } ),
221 SOAP::Header->name( 'ClientType' => $ATTR{ 'ClientType' } ),
222 SOAP::Header->name( 'ClientVersion' => $ATTR{ 'ClientVersion' } ),
223 0 SOAP::Header->name( 'ClientWebServiceVersion' => $ATTR{ 'ClientWebServiceVersion' } )
224 ) );
225
226 0 return $self
227 }
228  
229 9 1;
230  
231 __END__
↑ Summary PIDS/ListedStop.pm »