HAFAS.pm

filter: Statementstmt 49.1% 194 / 395 Branchbran 29.1% 42 / 144 Conditioncond 28.4% 35 / 123 MC/DCmcdc 2.9% 2 / 68 Subroutinesub 68.8% 31 / 45 Podpod 56.5% 13 / 23 totaltotal 39.7% 317 / 798 CC 130 SCAR 42.8
CC
130
Cov
41%
new
214.2
post_with_cache
90.0
new_p
42.0
CRAP 72.1
« HAFAS/Journey.pm ↑ Summary HAFAS/StopFinder.pm »
1 package Travel::Status::DE::HAFAS;
2  
3 # vim:foldmethod=marker
4  
5 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 5 ▶use 5.014;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 5 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 5 ▶use Carp qw(confess);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 5 ▶use DateTime;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 5 ▶use DateTime::Format::Strptime;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 5 ▶use Digest::MD5 qw(md5_hex);
Subroutine BEGIN: called CC=1 SCAR=0.0
14 5 ▶use Encode qw(decode encode);
Subroutine BEGIN: called CC=1 SCAR=0.0
15 5 ▶use JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 5 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 5 ▶use Travel::Status::DE::HAFAS::Journey;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 5 ▶use Travel::Status::DE::HAFAS::Location;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 5 ▶use Travel::Status::DE::HAFAS::Message;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 5 ▶use Travel::Status::DE::HAFAS::Polyline qw(decode_polyline);
Subroutine BEGIN: called CC=1 SCAR=0.0
21 5 ▶use Travel::Status::DE::HAFAS::Product;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 5 ▶use Travel::Status::DE::HAFAS::Services;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 5 ▶use Travel::Status::DE::HAFAS::StopFinder;
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 5 our $VERSION = '6.15';
26  
27 # {{{ Endpoint Definition
28  
29 # Data sources: <https://github.com/public-transport/transport-apis> and
30 # <https://github.com/public-transport/hafas-client/tree/main/p>. Thanks to
31 # Jannis R / @derhuerst and all contributors for maintaining these.
32 5 my $hafas_instance = Travel::Status::DE::HAFAS::Services::get_service_ref();
33  
34 # }}}
35 # {{{ Constructors
36  
37 5 ▶sub new {
Subroutine new: called CC=43 SCAR=53.7
Pod documented
38 5 my ( $obj, %conf ) = @_;
39 5 my $service = $conf{service};
40  
41 5 my $ua = $conf{user_agent};
42  
43 5 ▶ if ( not $ua ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ua) 5 0 5
44 5 ▶ my %lwp_options = %{ $conf{lwp_options} // { timeout => 10 } };
Condition50%1/2
$conf{"lwp_options"} // {"timeout", 10}
l!l
05
MC/DC0%0/1
$conf{"lwp_options"} // {"timeout", 10}
$conf{"lwp_options"}
Truth table50%1/2
A
A= $conf{"lwp_options"}
Aresult
11
00
45 5 $ua = LWP::UserAgent->new(%lwp_options);
46 5 $ua->env_proxy;
47 }
48  
49 5 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
unless ($conf{"station"} or $conf{"journey"} or $conf{"journeyMatch"} or $conf{"geoSearch"} or $conf{"locationSearch"}) 0 5 5
Condition58%7/12
$conf{"station"} or $conf{"journey"} or $conf{"journeyMatch"} or $conf{"geoSearch"} or $conf{"locationSearch"}
l!l&&r!l&&!r
500
$conf{"station"} or $conf{"journey"} or $conf{"journeyMatch"} or $conf{"geoSearch"}
l!l&&r!l&&!r
500
$conf{"station"} or $conf{"journey"} or $conf{"journeyMatch"}
l!l&&r!l&&!r
410
$conf{"station"} or $conf{"journey"}
l!l&&r!l&&!r
131
MC/DC0%0/5
$conf{"station"} or $conf{"journey"} or $conf{"journeyMatch"} or $conf{"geoSearch"} or $conf{"locationSearch"}
$conf{"station"} $conf{"journey"} $conf{"journeyMatch"} $conf{"geoSearch"} $conf{"locationSearch"}
Truth table50%3/6
A or B or C or D or E
A= $conf{"station"}B= $conf{"journey"}C= $conf{"journeyMatch"}D= $conf{"geoSearch"}E= $conf{"locationSearch"}
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
50 not( $conf{station}
51 or $conf{journey}
52 or $conf{journeyMatch}
53 or $conf{geoSearch}
54 or $conf{locationSearch} )
55 )
56 {
57 0 confess(
58 'station / journey / journeyMatch / geoSearch / locationSearch must be specified'
59 );
60 }
61  
62 5 ▶ if ( not defined $service ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $service) 0 5 5
63 0 $service = $conf{service} = 'DB';
64 }
65  
66 5 ▶ if ( defined $service and not exists $hafas_instance->{$service} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $service and not exists $hafas_instance->{$service}) 0 5 5
Condition33%1/3
defined $service and not exists $hafas_instance->{$service}
!ll&&!rl&&r
050
MC/DC0%0/2
defined $service and not exists $hafas_instance->{$service}
defined $service not exists $hafas_instance->{$service}
Truth table33%1/3
A and not(B)
A= defined $serviceB= not exists $hafas_instance->{$service}
ABresult
0X0
100
111
67 0 confess("The service '$service' is not supported");
68 }
69  
70 my $now = DateTime->now( time_zone => $hafas_instance->{$service}{time_zone}
71 5 ▶ // 'Europe/Berlin' );
Condition50%1/2
$hafas_instance->{$service}{"time_zone"} // "Europe/Berlin"
l!l
50
MC/DC0%0/1
$hafas_instance->{$service}{"time_zone"} // "Europe/Berlin"
$hafas_instance->{$service}{"time_zone"}
Truth table50%1/2
A
A= $hafas_instance->{$service}{"time_zone"}
Aresult
11
00
72 my $self = {
73 active_service => $service,
74 arrivals => $conf{arrivals},
75 cache => $conf{cache},
76 developer_mode => $conf{developer_mode},
77 exclusive_mots => $conf{exclusive_mots},
78 excluded_mots => $conf{excluded_mots},
79 messages => [],
80 results => [],
81 station => $conf{station},
82 5 ua => $ua,
83 now => $now,
84 tz_offset => $now->offset / 60,
85 };
86  
87 5 bless( $self, $obj );
88  
89 5 my $req;
90  
91 5 ▶ if ( $conf{journey} ) {
Branch: 4 branches
BranchTrueFalseTotal
if ($conf{'journey'}) { } 3 2 5
elsif ($conf{'journeyMatch'}) { } 1 1 2
elsif ($conf{'geoSearch'}) { } 0 1 1
elsif ($conf{'locationSearch'}) { } 0 1 1
92 $req = {
93 svcReqL => [
94 {
95 meth => 'JourneyDetails',
96 req => {
97 jid => $conf{journey}{id},
98 name => $conf{journey}{name} // '0',
99 getPolyline => $conf{with_polyline} ? \1 : \0,
100 },
101 }
102 ],
103 3 ▶ %{ $hafas_instance->{$service}{request} }
Branch: 1 branch
BranchTrueFalseTotal
$conf{'with_polyline'} ? : 0 3 3
Condition50%1/2
$conf{"journey"}{"name"} // 0
l!l
03
MC/DC0%0/1
$conf{"journey"}{"name"} // 0
$conf{"journey"}{"name"}
Truth table50%1/2
A
A= $conf{"journey"}{"name"}
Aresult
11
00
104 };
105 }
106 elsif ( $conf{journeyMatch} ) {
107 $req = {
108 svcReqL => [
109 {
110 meth => 'JourneyMatch',
111 req => {
112 date => ( $conf{datetime} // $now )->strftime('%Y%m%d'),
113 input => $conf{journeyMatch},
114 jnyFltrL => [
115 {
116 type => "PROD",
117 mode => "INC",
118 value => $self->mot_mask
119 }
120 ]
121 },
122 }
123 ],
124 1 ▶ %{ $hafas_instance->{$service}{request} }
Condition33%1/3
$conf{"datetime"} // $now
l!l&&r!l&&!r
010
MC/DC0%0/2
$conf{"datetime"} // $now
$conf{"datetime"} $now
Truth table33%1/3
A // B
A= $conf{"datetime"}B= $now
ABresult
1X1
011
000
125 };
126 }
127 elsif ( $conf{geoSearch} ) {
128 $req = {
129 svcReqL => [
130 {
131 cfg => { polyEnc => 'GPA' },
132 meth => 'LocGeoPos',
133 req => {
134 ring => {
135 cCrd => {
136 x => int( $conf{geoSearch}{lon} * 1e6 ),
137 y => int( $conf{geoSearch}{lat} * 1e6 ),
138 },
139 maxDist => -1,
140 minDist => 0,
141 },
142 locFltrL => [
143 {
144 type => "PROD",
145 mode => "INC",
146 value => $self->mot_mask
147 }
148 ],
149 getPOIs => \0,
150 getStops => \1,
151 maxLoc => $conf{results} // 30,
152 }
153 }
154 ],
155 0 ▶ %{ $hafas_instance->{$service}{request} }
Condition0%0/2
$conf{"results"} // 30
l!l
00
MC/DC0%0/1
$conf{"results"} // 30
$conf{"results"}
Truth table0%0/2
A
A= $conf{"results"}
Aresult
11
00
156 };
157 }
158 elsif ( $conf{locationSearch} ) {
159 $req = {
160 svcReqL => [
161 {
162 cfg => { polyEnc => 'GPA' },
163 meth => 'LocMatch',
164 req => {
165 input => {
166 loc => {
167 type => 'S',
168 name => $conf{locationSearch},
169 },
170 maxLoc => $conf{results} // 30,
171 field => 'S',
172 },
173 }
174 }
175 ],
176 0 ▶ %{ $hafas_instance->{$service}{request} }
Condition0%0/2
$conf{"results"} // 30
l!l
00
MC/DC0%0/1
$conf{"results"} // 30
$conf{"results"}
Truth table0%0/2
A
A= $conf{"results"}
Aresult
11
00
177 };
178 }
179 else {
180 1 ▶ my $date = ( $conf{datetime} // $now )->strftime('%Y%m%d');
Condition33%1/3
$conf{"datetime"} // $now
l!l&&r!l&&!r
010
MC/DC0%0/2
$conf{"datetime"} // $now
$conf{"datetime"} $now
Truth table33%1/3
A // B
A= $conf{"datetime"}B= $now
ABresult
1X1
011
000
181 1 ▶ my $time = ( $conf{datetime} // $now )->strftime('%H%M00');
Condition33%1/3
$conf{"datetime"} // $now
l!l&&r!l&&!r
010
MC/DC0%0/2
$conf{"datetime"} // $now
$conf{"datetime"} $now
Truth table33%1/3
A // B
A= $conf{"datetime"}B= $now
ABresult
1X1
011
000
182  
183 1 my $lid;
184 1 ▶ if ( $self->{station} =~ m{ ^ [0-9]+ $ }x ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'station'} =~ / ^ [0-9]+ $ /ux) { } 0 1 1
185 0 $lid = 'A=1@L=' . $self->{station} . '@';
186 }
187 else {
188 1 $lid = 'A=1@O=' . $self->{station} . '@';
189 }
190  
191 1 ▶ my $maxjny = $conf{results} // 30;
Condition50%1/2
$conf{"results"} // 30
l!l
01
MC/DC0%0/1
$conf{"results"} // 30
$conf{"results"}
Truth table50%1/2
A
A= $conf{"results"}
Aresult
11
00
192 1 ▶ my $duration = $conf{lookahead} // -1;
Condition50%1/2
$conf{"lookahead"} // -1
l!l
01
MC/DC0%0/1
$conf{"lookahead"} // -1
$conf{"lookahead"}
Truth table50%1/2
A
A= $conf{"lookahead"}
Aresult
11
00
193  
194 $req = {
195 svcReqL => [
196 {
197 meth => 'StationBoard',
198 req => {
199 type => ( $conf{arrivals} ? 'ARR' : 'DEP' ),
200 stbLoc => { lid => $lid },
201 dirLoc => undef,
202 maxJny => $maxjny,
203 date => $date,
204 time => $time,
205 dur => $duration,
206 jnyFltrL => [
207 {
208 type => "PROD",
209 mode => "INC",
210 value => $self->mot_mask
211 }
212 ]
213 },
214 },
215 ],
216 1 ▶ %{ $hafas_instance->{$service}{request} }
Branch: 1 branch
BranchTrueFalseTotal
$conf{'arrivals'} ? : 0 1 1
217 };
218 }
219  
220 5 ▶ if ( $conf{language} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($conf{"language"}) 0 5 5
221 0 $req->{lang} = $conf{language};
222 }
223  
224 $self->{strptime_obj} //= DateTime::Format::Strptime->new(
225 pattern => '%Y%m%dT%H%M%S',
226 5 ▶ time_zone => $hafas_instance->{$service}{time_zone} // 'Europe/Berlin',
Condition40%2/5
$self->{"strptime_obj"} //= "DateTime::Format::Strptime"->new("pattern", "%Y%m%dT%H%M%S", "time_zone", $hafas_instance->{$service}{"time_zone"} // "Europe/Berlin")
l!l&&r!l&&!r
050
$hafas_instance->{$service}{"time_zone"} // "Europe/Berlin"
l!l
50
MC/DC0%0/2
$self->{"strptime_obj"} //= "DateTime::Format::Strptime"->new("pattern", "%Y%m%dT%H%M%S", "time_zone", $hafas_instance->{$service}{"time_zone"} // "Europe/Berlin")
$self->{"strptime_obj"} "DateTime::Format::Strptime"->new("pattern", "%Y%m%dT%H%M%S", "time_zone", $hafas_instance->{$service}{"time_zone"} // "Europe/Berlin")
MC/DC0%0/1
$hafas_instance->{$service}{"time_zone"} // "Europe/Berlin"
$hafas_instance->{$service}{"time_zone"}
Truth table33%1/3
A //= B
A= $self->{"strptime_obj"}B= "DateTime::Format::Strptime"->new("pattern", "%Y%m%dT%H%M%S", "time_zone", $hafas_instance->{$service}{"time_zone"} // "Europe/Berlin")
ABresult
1X1
011
000
Truth table50%1/2
A
A= $hafas_instance->{$service}{"time_zone"}
Aresult
11
00
227 );
228  
229 5 my $json = $self->{json} = JSON->new->utf8;
230  
231 # The JSON request is the cache key, so if we have a cache we must ensure
232 # that JSON serialization is deterministic.
233 5 ▶ if ( $self->{cache} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"cache"}) 0 5 5
234 0 $json->canonical;
235 }
236  
237 5 $req = $json->encode($req);
238 5 $self->{post} = $req;
239  
240 5 ▶ my $url = $conf{url} // $hafas_instance->{$service}{mgate};
Condition33%1/3
$conf{"url"} // $hafas_instance->{$service}{"mgate"}
l!l&&r!l&&!r
050
MC/DC0%0/2
$conf{"url"} // $hafas_instance->{$service}{"mgate"}
$conf{"url"} $hafas_instance->{$service}{"mgate"}
Truth table33%1/3
A // B
A= $conf{"url"}B= $hafas_instance->{$service}{"mgate"}
ABresult
1X1
011
000
241  
242 5 ▶ if ( my $salt = $hafas_instance->{$service}{salt} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $salt = $hafas_instance->{$service}{"salt"}) 5 0 5
243 5 ▶ if ( $hafas_instance->{$service}{micmac} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hafas_instance->{$service}{'micmac'}) { } 0 5 5
244 0 my $mic = md5_hex( $self->{post} );
245 0 my $mac = md5_hex( $mic . $salt );
246 0 $url .= "?mic=$mic&mac=$mac";
247 }
248 else {
249 5 $url .= '?checksum=' . md5_hex( $self->{post} . $salt );
250 }
251 }
252  
253 5 ▶ if ( $conf{async} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($conf{"async"}) 0 5 5
254 0 $self->{url} = $url;
255 0 return $self;
256 }
257  
258 5 ▶ if ( $conf{json} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($conf{'json'}) { } 5 0 5
259 5 $self->{raw_json} = $conf{json};
260 }
261 else {
262 0 ▶ if ( $self->{developer_mode} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"developer_mode"}) 0 0 0
263 0 say "requesting $req from $url";
264 }
265  
266 0 my ( $content, $error ) = $self->post_with_cache($url);
267  
268 0 ▶ if ($error) {
Branch: 1 branch
BranchTrueFalseTotal
if ($error) 0 0 0
269 0 $self->{errstr} = $error;
270 0 return $self;
271 }
272  
273 0 ▶ if ( $self->{developer_mode} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"developer_mode"}) 0 0 0
274 0 say decode( 'utf-8', $content );
275 }
276  
277 0 $self->{raw_json} = $json->decode($content);
278 }
279  
280 5 $self->check_mgate;
281  
282 5 ▶ if ( $conf{journey} ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($conf{'journey'}) { } 3 2 5
elsif ($conf{'journeyMatch'}) { } 1 1 2
elsif ($conf{'geoSearch'} or $conf{'locationSearch'}) { } 0 1 1
283 3 $self->parse_journey;
284 }
285 elsif ( $conf{journeyMatch} ) {
286 1 $self->parse_journey_match;
287 }
288 ▶ elsif ( $conf{geoSearch} or $conf{locationSearch} ) {
Condition33%1/3
$conf{"geoSearch"} or $conf{"locationSearch"}
l!l&&r!l&&!r
001
MC/DC0%0/2
$conf{"geoSearch"} or $conf{"locationSearch"}
$conf{"geoSearch"} $conf{"locationSearch"}
Truth table33%1/3
A or B
A= $conf{"geoSearch"}B= $conf{"locationSearch"}
ABresult
1X1
011
000
289 0 $self->parse_search;
290 }
291 else {
292 1 $self->parse_board;
293 }
294  
295 5 return $self;
296 }
297  
298 0 ▶sub new_p {
Subroutine new_p: not called CC=6 SCAR=37.4
Pod documented
299 0 my ( $obj, %conf ) = @_;
300 0 my $promise = $conf{promise}->new;
301  
302 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
unless ($conf{"station"} or $conf{"journey"} or $conf{"journeyMatch"} or $conf{"geoSearch"} or $conf{"locationSearch"}) 0 0 0
Condition0%0/12
$conf{"station"} or $conf{"journey"} or $conf{"journeyMatch"} or $conf{"geoSearch"} or $conf{"locationSearch"}
l!l&&r!l&&!r
000
$conf{"station"} or $conf{"journey"} or $conf{"journeyMatch"} or $conf{"geoSearch"}
l!l&&r!l&&!r
000
$conf{"station"} or $conf{"journey"} or $conf{"journeyMatch"}
l!l&&r!l&&!r
000
$conf{"station"} or $conf{"journey"}
l!l&&r!l&&!r
000
MC/DC0%0/5
$conf{"station"} or $conf{"journey"} or $conf{"journeyMatch"} or $conf{"geoSearch"} or $conf{"locationSearch"}
$conf{"station"} $conf{"journey"} $conf{"journeyMatch"} $conf{"geoSearch"} $conf{"locationSearch"}
Truth table0%0/6
A or B or C or D or E
A= $conf{"station"}B= $conf{"journey"}C= $conf{"journeyMatch"}D= $conf{"geoSearch"}E= $conf{"locationSearch"}
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
303 not( $conf{station}
304 or $conf{journey}
305 or $conf{journeyMatch}
306 or $conf{geoSearch}
307 or $conf{locationSearch} )
308 )
309 {
310 0 return $promise->reject(
311 'station / journey / journeyMatch / geoSearch / locationSearch flag must be passed'
312 );
313 }
314  
315 0 my $self = $obj->new( %conf, async => 1 );
316 0 $self->{promise} = $conf{promise};
317  
318 $self->post_with_cache_p( $self->{url} )->then(
319 0 ▶ sub {
Subroutine __ANON__: not called CC=6 SCAR=37.4
320 0 my ($content) = @_;
321 0 $self->{raw_json} = $self->{json}->decode($content);
322 0 $self->check_mgate;
323 0 ▶ if ( $conf{journey} ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($conf{'journey'}) { } 0 0 0
elsif ($conf{'journeyMatch'}) { } 0 0 0
elsif ($conf{'geoSearch'} or $conf{'locationSearch'}) { } 0 0 0
324 0 $self->parse_journey;
325 }
326 elsif ( $conf{journeyMatch} ) {
327 0 $self->parse_journey_match;
328 }
329 ▶ elsif ( $conf{geoSearch} or $conf{locationSearch} ) {
Condition0%0/3
$conf{"geoSearch"} or $conf{"locationSearch"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$conf{"geoSearch"} or $conf{"locationSearch"}
$conf{"geoSearch"} $conf{"locationSearch"}
Truth table0%0/3
A or B
A= $conf{"geoSearch"}B= $conf{"locationSearch"}
ABresult
1X1
011
000
330 0 $self->parse_search;
331 }
332 else {
333 0 $self->parse_board;
334 }
335 0 ▶ if ( $self->errstr ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->errstr) { } 0 0 0
336 0 $promise->reject( $self->errstr, $self );
337 }
338 else {
339 0 $promise->resolve($self);
340 }
341 0 return;
342 }
343 )->catch(
344 0 ▶ sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
345 0 my ($err) = @_;
346 0 $promise->reject($err);
347 0 return;
348 }
349 0 )->wait;
350  
351 0 return $promise;
352 }
353  
354 # }}}
355 # {{{ Internal Helpers
356  
357 2 ▶sub mot_mask {
Subroutine mot_mask: called CC=13 SCAR=37.1
Pod undocumented
358 2 my ($self) = @_;
359  
360 2 my $service = $self->{active_service};
361 2 my $mot_mask = 2**@{ $hafas_instance->{$service}{productbits} } - 1;
362  
363 2 my %mot_pos;
364 2 for my $i ( 0 .. $#{ $hafas_instance->{$service}{productbits} } ) {
365 20 ▶ if ( ref( $hafas_instance->{$service}{productbits}[$i] ) eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $hafas_instance->{$service}{'productbits'}[$i] eq 'ARRAY') { } 20 0 20
366 20 $mot_pos{ $hafas_instance->{$service}{productbits}[$i][0] } = $i;
367 }
368 else {
369 0 $mot_pos{ $hafas_instance->{$service}{productbits}[$i] } = $i;
370 }
371 }
372  
373 2 ▶ if ( my @mots = @{ $self->{exclusive_mots} // [] } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@mots) = @{$self->{"exclusive_mots"} // [];}) 0 2 2
Condition50%1/2
$self->{"exclusive_mots"} // []
l!l
02
MC/DC0%0/1
$self->{"exclusive_mots"} // []
$self->{"exclusive_mots"}
Truth table50%1/2
A
A= $self->{"exclusive_mots"}
Aresult
11
00
374 0 $mot_mask = 0;
375 0 for my $mot (@mots) {
376 0 ▶ if ( exists $mot_pos{$mot} ) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $mot_pos{$mot}) { } 0 0 0
elsif ($mot =~ / ^ \d+ $ /ux) { } 0 0 0
377 0 $mot_mask |= 1 << $mot_pos{$mot};
378 }
379 elsif ( $mot =~ m{ ^ \d+ $ }x ) {
380 0 $mot_mask |= 1 << $mot;
381 }
382 }
383 }
384  
385 2 ▶ if ( my @mots = @{ $self->{excluded_mots} // [] } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@mots) = @{$self->{"excluded_mots"} // [];}) 0 2 2
Condition50%1/2
$self->{"excluded_mots"} // []
l!l
02
MC/DC0%0/1
$self->{"excluded_mots"} // []
$self->{"excluded_mots"}
Truth table50%1/2
A
A= $self->{"excluded_mots"}
Aresult
11
00
386 0 for my $mot (@mots) {
387 0 ▶ if ( exists $mot_pos{$mot} ) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $mot_pos{$mot}) { } 0 0 0
elsif ($mot =~ / ^ \d+ $ /ux) { } 0 0 0
388 0 $mot_mask &= ~( 1 << $mot_pos{$mot} );
389 }
390 elsif ( $mot =~ m{ ^ \d+ $ }x ) {
391 0 $mot_mask &= ~( 1 << $mot );
392 }
393 }
394 }
395  
396 2 return $mot_mask;
397 }
398  
399 0 ▶sub post_with_cache {
Subroutine post_with_cache: not called CC=9 SCAR=45.0
Pod undocumented
400 0 my ( $self, $url ) = @_;
401 0 my $cache = $self->{cache};
402  
403 0 ▶ if ( $self->{developer_mode} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"developer_mode"}) 0 0 0
404 0 say "POST $url $self->{post}";
405 }
406  
407 0 ▶ if ($cache) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cache) 0 0 0
408 0 my $content = $cache->thaw( $self->{post} );
409 0 ▶ if ( $content
Branch: 1 branch
BranchTrueFalseTotal
if ($content and not $content =~ / CGI_NO_SERVER | CGI_READ_FAILED /ux) 0 0 0
Condition0%0/3
$content and not $content =~ / CGI_NO_SERVER | CGI_READ_FAILED /ux
!ll&&!rl&&r
000
MC/DC0%0/2
$content and not $content =~ / CGI_NO_SERVER | CGI_READ_FAILED /ux
$content not $content =~ / CGI_NO_SERVER | CGI_READ_FAILED /ux
Truth table0%0/3
A and not(B)
A= $contentB= not $content =~ / CGI_NO_SERVER | CGI_READ_FAILED /ux
ABresult
0X0
100
111
410 and not $content =~ m{ CGI_NO_SERVER | CGI_READ_FAILED }x )
411 {
412 0 ▶ if ( $self->{developer_mode} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"developer_mode"}) 0 0 0
413 0 say ' cache hit';
414 }
415 0 return ( ${$content}, undef );
416 }
417 }
418  
419 0 ▶ if ( $self->{developer_mode} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"developer_mode"}) 0 0 0
420 0 say ' cache miss';
421 }
422  
423 my $reply = $self->{ua}->post(
424 $url,
425 'Content-Type' => 'application/json',
426 Content => $self->{post}
427 0 );
428  
429 0 ▶ if ( $reply->is_error ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($reply->is_error) 0 0 0
430 0 return ( undef, $reply->status_line );
431 }
432 0 my $content = $reply->content;
433  
434 0 ▶ if ($cache) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cache) 0 0 0
435 0 $cache->freeze( $self->{post}, \$content );
436 }
437  
438 0 return ( $content, undef );
439 }
440  
441 0 ▶sub post_with_cache_p {
Subroutine post_with_cache_p: not called CC=6 SCAR=37.4
Pod undocumented
442 0 my ( $self, $url ) = @_;
443 0 my $cache = $self->{cache};
444  
445 0 ▶ if ( $self->{developer_mode} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"developer_mode"}) 0 0 0
446 0 say "POST $url";
447 }
448  
449 0 my $promise = $self->{promise}->new;
450  
451 0 ▶ if ($cache) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cache) 0 0 0
452 0 my $content = $cache->thaw( $self->{post} );
453 0 ▶ if ($content) {
Branch: 1 branch
BranchTrueFalseTotal
if ($content) 0 0 0
454 0 ▶ if ( $self->{developer_mode} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"developer_mode"}) 0 0 0
455 0 say ' cache hit';
456 }
457 0 return $promise->resolve( ${$content} );
458 }
459 }
460  
461 0 ▶ if ( $self->{developer_mode} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"developer_mode"}) 0 0 0
462 0 say ' cache miss';
463 }
464  
465 $self->{ua}->post_p( $url, $self->{post} )->then(
466 0 ▶ sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
467 0 my ($tx) = @_;
468 0 ▶ if ( my $err = $tx->error ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $err = $tx->error) 0 0 0
469 0 $promise->reject(
470 "POST $url returned HTTP $err->{code} $err->{message}");
471 0 return;
472 }
473 0 my $content = $tx->res->body;
474 0 ▶ if ($cache) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cache) 0 0 0
475 0 $cache->freeze( $self->{post}, \$content );
476 }
477 0 $promise->resolve($content);
478 0 return;
479 }
480 )->catch(
481 0 ▶ sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
482 0 my ($err) = @_;
483 0 $promise->reject($err);
484 0 return;
485 }
486 0 )->wait;
487  
488 0 return $promise;
489 }
490  
491 5 ▶sub check_mgate {
Subroutine check_mgate: called CC=10 SCAR=35.4
Pod undocumented
492 5 my ($self) = @_;
493  
494 5 ▶ if ( $self->{raw_json}{err} and $self->{raw_json}{err} ne 'OK' ) {
Branch: 4 branches
BranchTrueFalseTotal
if ($self->{'raw_json'}{'err'} and $self->{'raw_json'}{'err'} ne 'OK') { } 0 5 5
elsif (defined $self->{'raw_json'}{'cInfo'}{'code'} and $self->{'raw_json'}{'cInfo'}{'code'} ne 'OK' and $self->{'raw_json'}{'cInfo'}{'code'} ne 'VH') { } 0 5 5
elsif (@{$self->{'raw_json'}{'svcResL'} // [];} == 0) { } 0 5 5
elsif ($self->{'raw_json'}{'svcResL'}[0]{'err'} ne 'OK') { } 0 5 5
Condition33%1/3
$self->{"raw_json"}{"err"} and $self->{"raw_json"}{"err"} ne "OK"
!ll&&!rl&&r
500
MC/DC0%0/2
$self->{"raw_json"}{"err"} and $self->{"raw_json"}{"err"} ne "OK"
$self->{"raw_json"}{"err"} $self->{"raw_json"}{"err"} ne "OK"
Truth table33%1/3
A and B
A= $self->{"raw_json"}{"err"}B= $self->{"raw_json"}{"err"} ne "OK"
ABresult
0X0
100
111
495 $self->{errstr} = $self->{raw_json}{errTxt}
496 0 ▶ // 'error code is ' . $self->{raw_json}{err};
Condition0%0/2
$self->{"raw_json"}{"errTxt"} // 'error code is ' . $self->{"raw_json"}{"err"}
l!l
00
MC/DC0%0/1
$self->{"raw_json"}{"errTxt"} // 'error code is ' . $self->{"raw_json"}{"err"}
$self->{"raw_json"}{"errTxt"}
Truth table0%0/2
A
A= $self->{"raw_json"}{"errTxt"}
Aresult
11
00
497 0 $self->{errcode} = $self->{raw_json}{err};
498 }
499 ▶ elsif ( defined $self->{raw_json}{cInfo}{code}
Condition33%2/6
defined $self->{"raw_json"}{"cInfo"}{"code"} and $self->{"raw_json"}{"cInfo"}{"code"} ne "OK" and $self->{"raw_json"}{"cInfo"}{"code"} ne "VH"
!ll&&!rl&&r
500
defined $self->{"raw_json"}{"cInfo"}{"code"} and $self->{"raw_json"}{"cInfo"}{"code"} ne "OK"
!ll&&!rl&&r
050
MC/DC0%0/3
defined $self->{"raw_json"}{"cInfo"}{"code"} and $self->{"raw_json"}{"cInfo"}{"code"} ne "OK" and $self->{"raw_json"}{"cInfo"}{"code"} ne "VH"
defined $self->{"raw_json"}{"cInfo"}{"code"} $self->{"raw_json"}{"cInfo"}{"code"} ne "OK" $self->{"raw_json"}{"cInfo"}{"code"} ne "VH"
Truth table25%1/4
A and B and C
A= defined $self->{"raw_json"}{"cInfo"}{"code"}B= $self->{"raw_json"}{"cInfo"}{"code"} ne "OK"C= $self->{"raw_json"}{"cInfo"}{"code"} ne "VH"
ABCresult
0XX0
10X0
1100
1111
500 and $self->{raw_json}{cInfo}{code} ne 'OK'
501 and $self->{raw_json}{cInfo}{code} ne 'VH' )
502 {
503 0 $self->{errstr} = 'cInfo code is ' . $self->{raw_json}{cInfo}{code};
504 0 $self->{errcode} = $self->{raw_json}{cInfo}{code};
505 }
506 5 ▶ elsif ( @{ $self->{raw_json}{svcResL} // [] } == 0 ) {
Condition50%1/2
$self->{"raw_json"}{"svcResL"} // []
l!l
50
MC/DC0%0/1
$self->{"raw_json"}{"svcResL"} // []
$self->{"raw_json"}{"svcResL"}
Truth table50%1/2
A
A= $self->{"raw_json"}{"svcResL"}
Aresult
11
00
507 0 $self->{errstr} = 'svcResL is empty';
508 }
509 elsif ( $self->{raw_json}{svcResL}[0]{err} ne 'OK' ) {
510 $self->{errstr}
511 0 = 'svcResL[0].err is ' . $self->{raw_json}{svcResL}[0]{err};
512 0 $self->{errcode} = $self->{raw_json}{svcResL}[0]{err};
513 }
514  
515 5 return $self;
516 }
517  
518 32 ▶sub add_message {
Subroutine add_message: called CC=6 SCAR=18.3
Pod undocumented
519 32 my ( $self, $json, $is_him ) = @_;
520  
521 32 my $text = $json->{txtN};
522 32 my $code = $json->{code};
523  
524 32 ▶ if ($is_him) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_him) 0 32 32
525 0 $text = $json->{text};
526 0 $code = $json->{hid};
527 }
528  
529 # Some backends use remL for operator information. We don't want that.
530 32 ▶ if ( $code eq 'OPERATOR' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($code eq "OPERATOR") 0 32 32
531 0 return;
532 }
533  
534 32 for my $message ( @{ $self->{messages} } ) {
535 148 ▶ if ( $code eq $message->{code} and $text eq $message->{text} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($code eq $message->{"code"} and $text eq $message->{"text"}) 1 147 148
Condition100%3/3
$code eq $message->{"code"} and $text eq $message->{"text"}
!ll&&!rl&&r
14251
MC/DC100%2/2
$code eq $message->{"code"} and $text eq $message->{"text"}
$code eq $message->{"code"} $text eq $message->{"text"}
Truth table100%3/3
A and B
A= $code eq $message->{"code"}B= $text eq $message->{"text"}
ABresult
0X0
100
111
536 1 $message->{ref_count}++;
537 1 return $message;
538 }
539 }
540  
541 31 my $message = Travel::Status::DE::HAFAS::Message->new(
542 json => $json,
543 is_him => $is_him,
544 ref_count => 1,
545 );
546 31 push( @{ $self->{messages} }, $message );
547 31 return $message;
548 }
549  
550 5 ▶sub parse_prodL {
Subroutine parse_prodL: called CC=1 SCAR=0.0
Pod undocumented
551 5 my ($self) = @_;
552  
553 5 my $common = $self->{raw_json}{svcResL}[0]{res}{common};
554 return [
555 map {
556 45 Travel::Status::DE::HAFAS::Product->new(
557 common => $common,
558 product => $_
559 )
560 5 } @{ $common->{prodL} }
561 ];
562 }
563  
564 0 ▶sub parse_search {
Subroutine parse_search: not called CC=5 SCAR=34.0
Pod undocumented
565 0 my ($self) = @_;
566  
567 0 $self->{results} = [];
568  
569 0 ▶ if ( $self->{errstr} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"errstr"}) 0 0 0
570 0 return $self;
571 }
572  
573 0 ▶ my @locL = @{ $self->{raw_json}{svcResL}[0]{res}{locL} // [] };
Condition0%0/2
$self->{"raw_json"}{"svcResL"}[0]{"res"}{"locL"} // []
l!l
00
MC/DC0%0/1
$self->{"raw_json"}{"svcResL"}[0]{"res"}{"locL"} // []
$self->{"raw_json"}{"svcResL"}[0]{"res"}{"locL"}
Truth table0%0/2
A
A= $self->{"raw_json"}{"svcResL"}[0]{"res"}{"locL"}
Aresult
11
00
574  
575 0 ▶ if ( $self->{raw_json}{svcResL}[0]{res}{match} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"raw_json"}{"svcResL"}[0]{"res"}{"match"}) 0 0 0
576 0 ▶ @locL = @{ $self->{raw_json}{svcResL}[0]{res}{match}{locL} // [] };
Condition0%0/2
$self->{"raw_json"}{"svcResL"}[0]{"res"}{"match"}{"locL"} // []
l!l
00
MC/DC0%0/1
$self->{"raw_json"}{"svcResL"}[0]{"res"}{"match"}{"locL"} // []
$self->{"raw_json"}{"svcResL"}[0]{"res"}{"match"}{"locL"}
Truth table0%0/2
A
A= $self->{"raw_json"}{"svcResL"}[0]{"res"}{"match"}{"locL"}
Aresult
11
00
577 }
578  
579 0 @{ $self->{results} }
580 0 = map { Travel::Status::DE::HAFAS::Location->new( loc => $_ ) } @locL;
581  
582 0 return $self;
583 }
584  
585 3 ▶sub parse_journey {
Subroutine parse_journey: called CC=9 SCAR=30.4
Pod undocumented
586 3 my ($self) = @_;
587  
588 3 ▶ if ( $self->{errstr} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"errstr"}) 0 3 3
589 0 return $self;
590 }
591  
592 3 my $prodL = $self->parse_prodL;
593  
594 47 my @locL = map { Travel::Status::DE::HAFAS::Location->new( loc => $_ ) }
595 3 ▶ @{ $self->{raw_json}{svcResL}[0]{res}{common}{locL} // [] };
Condition50%1/2
$self->{"raw_json"}{"svcResL"}[0]{"res"}{"common"}{"locL"} // []
l!l
30
MC/DC0%0/1
$self->{"raw_json"}{"svcResL"}[0]{"res"}{"common"}{"locL"} // []
$self->{"raw_json"}{"svcResL"}[0]{"res"}{"common"}{"locL"}
Truth table50%1/2
A
A= $self->{"raw_json"}{"svcResL"}[0]{"res"}{"common"}{"locL"}
Aresult
11
00
596 3 my $journey = $self->{raw_json}{svcResL}[0]{res}{journey};
597 3 my @polyline;
598  
599 3 my $poly = $journey->{poly};
600  
601 # ÖBB
602 0 ▶ if ( $journey->{polyG} and @{ $journey->{polyG}{polyXL} // [] } ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($journey->{"polyG"} and @{$journey->{"polyG"}{"polyXL"} // [];}) 0 3 3
Condition20%1/5
$journey->{"polyG"} and @{$journey->{"polyG"}{"polyXL"} // [];}
!ll&&!rl&&r
300
$journey->{"polyG"}{"polyXL"} // []
l!l
00
MC/DC0%0/2
$journey->{"polyG"} and @{$journey->{"polyG"}{"polyXL"} // [];}
$journey->{"polyG"} @{$journey->{"polyG"}{"polyXL"} // [];}
MC/DC0%0/1
$journey->{"polyG"}{"polyXL"} // []
$journey->{"polyG"}{"polyXL"}
Truth table33%1/3
A and B
A= $journey->{"polyG"}B= @{$journey->{"polyG"}{"polyXL"} // [];}
ABresult
0X0
100
111
Truth table0%0/2
A
A= $journey->{"polyG"}{"polyXL"}
Aresult
11
00
603 $poly = $self->{raw_json}{svcResL}[0]{res}{common}{polyL}
604 0 [ $journey->{polyG}{polyXL}[0] ];
605 }
606  
607 3 ▶ if ($poly) {
Branch: 1 branch
BranchTrueFalseTotal
if ($poly) 0 3 3
608 0 @polyline = decode_polyline( $poly->{crdEncYX} );
609 0 ▶ for my $ref ( @{ $poly->{ppLocRefL} // [] } ) {
Condition0%0/2
$poly->{"ppLocRefL"} // []
l!l
00
MC/DC0%0/1
$poly->{"ppLocRefL"} // []
$poly->{"ppLocRefL"}
Truth table0%0/2
A
A= $poly->{"ppLocRefL"}
Aresult
11
00
610 0 my $poly = $polyline[ $ref->{ppIdx} ];
611 0 my $loc = $locL[ $ref->{locX} ];
612  
613 0 $poly->{name} = $loc->name;
614 0 $poly->{eva} = $loc->eva;
615 }
616 }
617  
618 $self->{result} = Travel::Status::DE::HAFAS::Journey->new(
619 common => $self->{raw_json}{svcResL}[0]{res}{common},
620 3 prodL => $prodL,
621 locL => \@locL,
622 journey => $journey,
623 polyline => \@polyline,
624 hafas => $self,
625 );
626  
627 3 return $self;
628 }
629  
630 1 ▶sub parse_journey_match {
Subroutine parse_journey_match: called CC=5 SCAR=16.5
Pod undocumented
631 1 my ($self) = @_;
632  
633 1 $self->{results} = [];
634  
635 1 ▶ if ( $self->{errstr} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"errstr"}) 0 1 1
636 0 return $self;
637 }
638  
639 1 my $prodL = $self->parse_prodL;
640  
641 2 my @locL = map { Travel::Status::DE::HAFAS::Location->new( loc => $_ ) }
642 1 ▶ @{ $self->{raw_json}{svcResL}[0]{res}{common}{locL} // [] };
Condition50%1/2
$self->{"raw_json"}{"svcResL"}[0]{"res"}{"common"}{"locL"} // []
l!l
10
MC/DC0%0/1
$self->{"raw_json"}{"svcResL"}[0]{"res"}{"common"}{"locL"} // []
$self->{"raw_json"}{"svcResL"}[0]{"res"}{"common"}{"locL"}
Truth table50%1/2
A
A= $self->{"raw_json"}{"svcResL"}[0]{"res"}{"common"}{"locL"}
Aresult
11
00
643  
644 1 ▶ my @jnyL = @{ $self->{raw_json}{svcResL}[0]{res}{jnyL} // [] };
Condition50%1/2
$self->{"raw_json"}{"svcResL"}[0]{"res"}{"jnyL"} // []
l!l
10
MC/DC0%0/1
$self->{"raw_json"}{"svcResL"}[0]{"res"}{"jnyL"} // []
$self->{"raw_json"}{"svcResL"}[0]{"res"}{"jnyL"}
Truth table50%1/2
A
A= $self->{"raw_json"}{"svcResL"}[0]{"res"}{"jnyL"}
Aresult
11
00
645  
646 1 for my $result (@jnyL) {
647 push(
648 1 @{ $self->{results} },
649 Travel::Status::DE::HAFAS::Journey->new(
650 common => $self->{raw_json}{svcResL}[0]{res}{common},
651 1 prodL => $prodL,
652 locL => \@locL,
653 journey => $result,
654 hafas => $self,
655 )
656 );
657 }
658 1 return $self;
659 }
660  
661 1 ▶sub parse_board {
Subroutine parse_board: called CC=7 SCAR=21.5
Pod undocumented
662 1 my ($self) = @_;
663  
664 1 $self->{results} = [];
665  
666 1 ▶ if ( $self->{errstr} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"errstr"}) 0 1 1
667 0 return $self;
668 }
669  
670 1 my $prodL = $self->parse_prodL;
671  
672 135 my @locL = map { Travel::Status::DE::HAFAS::Location->new( loc => $_ ) }
673 1 ▶ @{ $self->{raw_json}{svcResL}[0]{res}{common}{locL} // [] };
Condition50%1/2
$self->{"raw_json"}{"svcResL"}[0]{"res"}{"common"}{"locL"} // []
l!l
10
MC/DC0%0/1
$self->{"raw_json"}{"svcResL"}[0]{"res"}{"common"}{"locL"} // []
$self->{"raw_json"}{"svcResL"}[0]{"res"}{"common"}{"locL"}
Truth table50%1/2
A
A= $self->{"raw_json"}{"svcResL"}[0]{"res"}{"common"}{"locL"}
Aresult
11
00
674 1 ▶ my @jnyL = @{ $self->{raw_json}{svcResL}[0]{res}{jnyL} // [] };
Condition50%1/2
$self->{"raw_json"}{"svcResL"}[0]{"res"}{"jnyL"} // []
l!l
10
MC/DC0%0/1
$self->{"raw_json"}{"svcResL"}[0]{"res"}{"jnyL"} // []
$self->{"raw_json"}{"svcResL"}[0]{"res"}{"jnyL"}
Truth table50%1/2
A
A= $self->{"raw_json"}{"svcResL"}[0]{"res"}{"jnyL"}
Aresult
11
00
675  
676 1 for my $result (@jnyL) {
677 30 eval {
678 push(
679 30 @{ $self->{results} },
680 Travel::Status::DE::HAFAS::Journey->new(
681 common => $self->{raw_json}{svcResL}[0]{res}{common},
682 30 prodL => $prodL,
683 locL => \@locL,
684 journey => $result,
685 hafas => $self,
686 )
687 );
688 };
689 30 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 30 30
690 0 ▶ if ( $@ =~ m{Invalid local time for date in time zone} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@ =~ /Invalid local time for date in time zone/u) { } 0 0 0
691  
692 # Yes, HAFAS does in fact return invalid times during DST change
693 # (as in, it returns 02:XX:XX timestamps when the time jumps from 02:00:00 to 03:00:00)
694 # It's not clear what exactly is going wrong where and whether a 2:30 or a 3:30 journey is the correct one.
695 # For now, silently discard the affected journeys.
696 }
697 else {
698 0 warn("Skipping $result->{jid}: $@");
699 }
700 }
701 }
702 1 return $self;
703 }
704  
705 # }}}
706 # {{{ Public Functions
707  
708 5 ▶sub errcode {
Subroutine errcode: called CC=1 SCAR=0.0
Pod documented
709 5 my ($self) = @_;
710  
711 5 return $self->{errcode};
712 }
713  
714 5 ▶sub errstr {
Subroutine errstr: called CC=1 SCAR=0.0
Pod documented
715 5 my ($self) = @_;
716  
717 5 return $self->{errstr};
718 }
719  
720 0 ▶sub similar_stops {
Subroutine similar_stops: not called CC=4 SCAR=30.0
Pod documented
721 0 my ($self) = @_;
722  
723 0 my $service = $self->{active_service};
724  
725 0 ▶ if ( $service and exists $hafas_instance->{$service}{stopfinder} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($service and exists $hafas_instance->{$service}{"stopfinder"}) 0 0 0
Condition0%0/3
$service and exists $hafas_instance->{$service}{"stopfinder"}
!ll&&!rl&&r
000
MC/DC0%0/2
$service and exists $hafas_instance->{$service}{"stopfinder"}
$service exists $hafas_instance->{$service}{"stopfinder"}
Truth table0%0/3
A and B
A= $serviceB= exists $hafas_instance->{$service}{"stopfinder"}
ABresult
0X0
100
111
726  
727 my $sf = Travel::Status::DE::HAFAS::StopFinder->new(
728 url => $hafas_instance->{$service}{stopfinder},
729 input => $self->{station},
730 ua => $self->{ua},
731 developer_mode => $self->{developer_mode},
732 0 );
733 0 ▶ if ( my $err = $sf->errstr ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $err = $sf->errstr) 0 0 0
734 0 $self->{errstr} = $err;
735 0 return;
736 }
737 0 return $sf->results;
738 }
739 0 return;
740 }
741  
742 0 ▶sub similar_stops_p {
Subroutine similar_stops_p: not called CC=5 SCAR=34.0
Pod documented
743 0 my ( $self, %opt ) = @_;
744  
745 0 my $service = $self->{active_service};
746  
747 0 ▶ if ( $service and exists $hafas_instance->{$service}{stopfinder} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($service and exists $hafas_instance->{$service}{"stopfinder"}) 0 0 0
Condition0%0/3
$service and exists $hafas_instance->{$service}{"stopfinder"}
!ll&&!rl&&r
000
MC/DC0%0/2
$service and exists $hafas_instance->{$service}{"stopfinder"}
$service exists $hafas_instance->{$service}{"stopfinder"}
Truth table0%0/3
A and B
A= $serviceB= exists $hafas_instance->{$service}{"stopfinder"}
ABresult
0X0
100
111
748 0 ▶ $opt{user_agent} //= $self->{ua};
Condition0%0/3
$opt{"user_agent"} //= $self->{"ua"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$opt{"user_agent"} //= $self->{"ua"}
$opt{"user_agent"} $self->{"ua"}
Truth table0%0/3
A //= B
A= $opt{"user_agent"}B= $self->{"ua"}
ABresult
1X1
011
000
749 0 ▶ $opt{promise} //= $self->{promise};
Condition0%0/3
$opt{"promise"} //= $self->{"promise"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$opt{"promise"} //= $self->{"promise"}
$opt{"promise"} $self->{"promise"}
Truth table0%0/3
A //= B
A= $opt{"promise"}B= $self->{"promise"}
ABresult
1X1
011
000
750 return Travel::Status::DE::HAFAS::StopFinder->new_p(
751 url => $hafas_instance->{$service}{stopfinder},
752 input => $self->{station},
753 user_agent => $opt{user_agent},
754 developer_mode => $self->{developer_mode},
755 promise => $opt{promise},
756 0 );
757 }
758 return $opt{promise}
759 0 ->reject("stopfinder not available for backend '$service'");
760 }
761  
762 0 ▶sub station {
Subroutine station: not called CC=4 SCAR=30.0
Pod documented
763 0 my ($self) = @_;
764  
765 0 ▶ if ( $self->{station_info} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"station_info"}) 0 0 0
766 0 return $self->{station_info};
767 }
768  
769 0 my %eva_count;
770 my %name_count;
771 0 my %eva_by_name;
772  
773 0 for my $result ( $self->results ) {
774 0 $eva_count{ $result->station_eva } += 1;
775 0 $name_count{ $result->station } += 1;
776 0 $eva_by_name{ $result->station_eva } = $result->station;
777 }
778  
779 0 my @most_frequent_evas = map { $_->[0] } sort { $b->[1] <=> $a->[1] }
780 0 map { [ $_, $eva_count{$_} ] } keys %eva_count;
781  
782 0 my @most_frequent_names = map { $_->[0] } sort { $b->[1] <=> $a->[1] }
783 0 map { [ $_, $name_count{$_} ] } keys %name_count;
784  
785 0 my @shortest_names = map { $_->[0] } sort { $a->[1] <=> $b->[1] }
786 0 map { [ $_, length($_) ] } keys %name_count;
787  
788 0 ▶ if ( not @shortest_names ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@shortest_names) 0 0 0
789 0 $self->{station_info} = {};
790 0 return $self->{station_info};
791 }
792  
793 # The shortest name is typically the most helpful one, e.g. "Wien Hbf" vs. "Wien Hbf Süd (Sonnwendgasse)"
794 $self->{station_info} = {
795 name => $shortest_names[0],
796 0 eva => $eva_by_name{ $shortest_names[0] },
797 names => \@most_frequent_names,
798 evas => \@most_frequent_evas,
799 };
800  
801 0 return $self->{station_info};
802 }
803  
804 0 ▶sub messages {
Subroutine messages: not called CC=1 SCAR=6.9
Pod documented
805 0 my ($self) = @_;
806 0 return @{ $self->{messages} };
807 }
808  
809 4 ▶sub results {
Subroutine results: called CC=1 SCAR=0.0
Pod documented
810 4 my ($self) = @_;
811 4 return @{ $self->{results} };
812 }
813  
814 3 ▶sub result {
Subroutine result: called CC=1 SCAR=0.0
Pod documented
815 3 my ($self) = @_;
816 3 return $self->{result};
817 }
818  
819 # static
820 0 ▶sub get_services {
Subroutine get_services: not called CC=2 SCAR=17.9
Pod documented
821 0 my @services;
822 0 for my $service ( sort keys %{$hafas_instance} ) {
823 0 my %desc = %{ $hafas_instance->{$service} };
824 0 $desc{shortname} = $service;
825 0 push( @services, \%desc );
826 }
827 0 return @services;
828 }
829  
830 # static
831 0 ▶sub get_service {
Subroutine get_service: not called CC=3 SCAR=24.8
Pod documented
832 0 my ($service) = @_;
833  
834 0 ▶ if ( defined $service and exists $hafas_instance->{$service} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $service and exists $hafas_instance->{$service}) 0 0 0
Condition0%0/3
defined $service and exists $hafas_instance->{$service}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $service and exists $hafas_instance->{$service}
defined $service exists $hafas_instance->{$service}
Truth table0%0/3
A and B
A= defined $serviceB= exists $hafas_instance->{$service}
ABresult
0X0
100
111
835 0 return $hafas_instance->{$service};
836 }
837 0 return;
838 }
839  
840 39 ▶sub get_active_service {
Subroutine get_active_service: called CC=2 SCAR=7.6
Pod documented
841 39 my ($self) = @_;
842  
843 39 ▶ if ( defined $self->{active_service} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"active_service"}) 39 0 39
844 39 return $hafas_instance->{ $self->{active_service} };
845 }
846 0 return;
847 }
848  
849 # }}}
850  
851 5 1;
852  
853 __END__
« HAFAS/Journey.pm ↑ Summary HAFAS/StopFinder.pm »