PIDS.pm

filter: Statementstmt 60.7% 85 / 140 Branchbran 22.2% 4 / 18 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 61.5% 24 / 39 Podpod 100% 1 / 1 totaltotal 57.5% 114 / 198 CC 13 SCAR 15.4
CC
13
Cov
56%
__ANON__
20.0
__validate_parameters
16.4
new
5.2
CRAP 4.7
« PIDS/CoreDataChanges.pm ↑ Summary PIDS/RouteNo.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.02';
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( $_ ) }
38 0 ▶ @{ shift->{diffgram}->{DocumentElement}->{ListOfDestinationsForAllRoutes} }
Subroutine __ANON__: not called CC=1 SCAR=6.9
39 }
40 },
41 GetDestinationsForRoute => {
42 parameters => [ { param => 'routeNo', format => qr/^\d{1,3}$/, type => 'string' } ],
43 result => sub { return WWW::PIDS::RouteDestination->new(
44 0 ▶ %{ shift->{diffgram}->{DocumentElement}->{RouteDestinations} }
Subroutine __ANON__: not called CC=1 SCAR=6.9
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( $_ ) }
52 0 ▶ @{ shift->{diffgram}->{DocumentElement}->{S} }
Subroutine __ANON__: not called CC=1 SCAR=6.9
53 }
54 },
55 GetMainRoutes => {
56 0 result => sub { return map { WWW::PIDS::RouteNo->new( $_ ) }
57 0 ▶ @{ shift->{diffgram}->{DocumentElement}->{ListOfNonSubRoutes} }
Subroutine __ANON__: not called CC=1 SCAR=6.9
58 }
59 },
60 GetMainRoutesForStop => {
61 parameters => [ { param => 'stopNo', format => qr/^\d{4}$/, type => 'short' } ],
62 0 result => sub { return map { WWW::PIDS::RouteNo->new( $_ ) }
63 0 ▶ @{ shift->{diffgram}->{DocumentElement}->{ListOfMainRoutesAtStop} }
Subroutine __ANON__: not called CC=1 SCAR=6.9
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 { return map { WWW::PIDS::ScheduledTime->new( $_ ) }
82 0 ▶ @{ shift->{diffgram}->{DocumentElement}->{ToReturn} }
Subroutine __ANON__: not called CC=1 SCAR=6.9
83 }
84 },
85 GetNewClientGuid => {
86 0 ▶ result => sub { return shift }
Subroutine __ANON__: not called CC=1 SCAR=6.9
87 },
88 'GetPlatformStopsByRouteAndDirection' => {
89 parameters => [ { param => 'routeNo', format => qr/^\d{1,3}[a-z]?$/, type => 'string' },
90 { param => 'isUpDirection',format => qr/^(0|1)$/, type => 'boolean' } ],
91 0 ▶ result => sub { return @_ }
Subroutine __ANON__: not called CC=1 SCAR=6.9
92 #result => sub { return map { WWW::PIDS::RoutesCollection->new( $_ ) } @{ shift->{diffgram}->{DocumentElement}->{ToReturn} } }
93 },
94 GetRouteStopsByRoute => {
95 parameters => [ { param => 'routeNo', format => qr/^\d{1,3}[a-z]?$/, type => 'string' },
96 { param => 'isUpDirection',format => qr/^(0|1)$/, type => 'boolean' } ],
97 0 result => sub { return map { WWW::PIDS::RouteStop->new( $_ ) }
98 0 ▶ @{ shift->{diffgram}->{DocumentElement}->{S} }
Subroutine __ANON__: not called CC=1 SCAR=6.9
99 }
100 },
101 GetRouteSummaries => {
102 0 result => sub { return map { WWW::PIDS::RouteSummary->new( $_ ) }
103 0 ▶ @{ shift->{diffgram}->{DocumentElement}->{RouteSummaries} }
Subroutine __ANON__: not called CC=1 SCAR=6.9
104 }
105 },
106 GetSchedulesCollection => {
107 parameters => [ { param => 'stopNo', format => qr/^\d{4}$/, type => 'short' },
108 { param => 'routeNo', format => qr/^\d{1,3}[a-z]?$/, type => 'string' },
109 { param => 'lowFloor', format => qr/^(0|1)$/, type => 'boolean' },
110 { param => 'clientRequestDateTime', format => qr/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}$/, type => 'dateTime' } ],
111 0 result => sub { return map { WWW::PIDS::PredictedTime->new( $_ ) }
112 0 ▶ @{ shift->{diffgram}->{DocumentElement}->{SchedulesResultsTable} }
Subroutine __ANON__: not called CC=1 SCAR=6.9
113 }
114 },
115 GetSchedulesForTrip => {
116 parameters => [ { param => 'tripID', format => qr/^\d{1,}$/, type => 'int' },
117 { param => 'scheduledDateTime', format => qr/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}$/, type => 'dateTime' } ],
118 0 result => sub { return map { WWW::PIDS::TripSchedule->new( $_ ) }
119 0 ▶ @{ shift->{diffgram}->{DocumentElement}->{Table} }
Subroutine __ANON__: not called CC=1 SCAR=6.9
120 }
121 },
122 GetStopInformation => {
123 parameters => [ { param => 'stopNo', format => qr/^\d{4}$/, type => 'short' } ],
124 0 ▶ result => sub { return WWW::PIDS::StopInformation->new( shift->{diffgram}->{DocumentElement}->{StopInformation} ) }
Subroutine __ANON__: not called CC=1 SCAR=6.9
125 },
126 GetStopsAndRoutesUpdatesSince => {
127 parameters => [ { param => 'dateSince', format => qr/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}$/, type => 'dateTime' } ],
128 0 ▶ result => sub { my $d = shift;
Subroutine __ANON__: not called CC=1 SCAR=6.9
129 0 my @r = map { WWW::PIDS::RouteChange->new( $_ ) }
130 0 @{ $d->{diffgram}->{dsCoreDataChanges}->{dtRoutesChanges} };
131 0 my @s = map { WWW::PIDS::StopChange->new( $_ ) }
132 0 @{ $d->{diffgram}->{dsCoreDataChanges}->{dtStopsChanges} };
133 0 my $t = $d->{diffgram}->{dsCoreDataChanges}->{dtServerTime}->{ServerTime};
134 0 return WWW::PIDS::CoreDataChanges->new( ServerTime => $t, RouteChanges => \@r, StopChanges => \@s )
135 }
136 }
137 9 );
138  
139 9 for my $method ( keys %METHODS ) {
140 {
141 9 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
142  
143 *$method = sub {
144 7 ▶ my ( $self, %parameters ) = @_;
Subroutine __ANON__: called CC=2 SCAR=7.1
145  
146 7 my $valid = __validate_parameters( $method, %parameters );
147 7 ▶ die $valid unless ( $valid eq "1" );
Branch: 1 branch
BranchTrueFalseTotal
unless $valid eq 1 0 7 7
148  
149 7 my @body = __construct_body( $method, %parameters );
150  
151 my $r = SOAP::Lite->endpoint( $ENDPOINT )
152 ->default_ns( $NS )
153 ->proxy( $PROXY )
154 7 ▶ ->on_action( sub { "$NS$method" } )
Subroutine __ANON__: called CC=1 SCAR=0.0
155 ->$method( @body, $self->{pids_header} )
156 7 ->result;
157  
158 0 return $METHODS{ $method }{ 'result' }->($r);
159 135 };
160  
161 }
162 }
163  
164 sub __validate_parameters {
165 7 ▶ my ( $m, %p ) = @_;
Subroutine __validate_parameters: called CC=5 SCAR=28.0
166  
167 7 ▶ return 1 if not defined $METHODS{ $m }{ 'parameters' };
Branch: 1 branch
BranchTrueFalseTotal
unless defined $WWW::PIDS::METHODS{$m}{"parameters"} 7 0 7
168  
169 0 for my $param ( @{ $METHODS{ $m }{ 'parameters' } } ) {
170 defined $p{ $param->{ param } }
171 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
172  
173 ( $p{ $param->{ param } } =~ $param->{ format } )
174 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
175 }
176  
177 0 return 1
178 }
179  
180 sub __construct_body {
181 7 ▶ my ( $m, %p ) = @_;
Subroutine __construct_body: called CC=2 SCAR=7.0
182 7 my @b;
183  
184 7 for my $param ( @{ $METHODS{ $m }{ 'parameters' } } ) {
185 push @b, SOAP::Data->name( $param->{ param } => $p{ $param->{ param } } )
186 ->type( $param->{ type } )
187 0 }
188  
189 return @b
190 7 }
191  
192 sub new {
193 7 ▶ my ( $class, %args ) = @_;
Subroutine new: called CC=4 SCAR=16.4
Pod documented
194 7 my $self = bless {}, $class;
195  
196 7 for my $a ( keys %ATTR ) {
197 defined $args{ $a }
198 ? $self->{ $a } = $args{ $a }
199 28 ▶ : $self->{ $a } = $ATTR{ $a } ;
Branch: 1 branch
BranchTrueFalseTotal
defined $args{$a} ? : 0 28 28
200 }
201  
202 7 ▶ defined $self->{ 'ClientGuid' } or $self->{ 'ClientGuid' } = $self->GetNewClientGuid();
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{"ClientGuid"} or $self->{"ClientGuid"} = $self->GetNewClientGuid 7 0 7
203 0 $ATTR{ 'ClientGuid' } = $self->{ 'ClientGuid' };
204  
205 $self->{pids_header} = SOAP::Header->name( 'PidsClientHeader' )
206 ->attr( { 'xmlns' => $NS } )
207 ->value( \SOAP::Header->value(
208 SOAP::Header->name( 'ClientGuid' => $ATTR{ 'ClientGuid' } ),
209 SOAP::Header->name( 'ClientType' => $ATTR{ 'ClientType' } ),
210 SOAP::Header->name( 'ClientVersion' => $ATTR{ 'ClientVersion' } ),
211 0 SOAP::Header->name( 'ClientWebServiceVersion' => $ATTR{ 'ClientWebServiceVersion' } )
212 ) );
213
214 0 return $self
215 }
216  
217 9 1;
218  
219 __END__
« PIDS/CoreDataChanges.pm ↑ Summary PIDS/RouteNo.pm »