HAFAS/Journey.pm

filter: Statementstmt 71.0% 140 / 197 Branchbran 56.1% 46 / 82 Conditioncond 39.2% 42 / 107 MC/DCmcdc 16.6% 11 / 66 Subroutinesub 72.2% 13 / 18 Podpod 80.0% 8 / 10 totaltotal 54.1% 260 / 480 CC 87 SCAR 45.2
CC
87
Cov
59%
new
173.4
operators
42.0
product_at
30.0
CRAP 91.6
« HAFAS.pm ↑ Summary HAFAS/StopFinder.pm »
1 package Travel::Status::DE::HAFAS::Journey;
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  
9 5 ▶use parent 'Class::Accessor';
Subroutine BEGIN: called CC=1 SCAR=0.0
10 5 ▶use DateTime::Format::Strptime;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 5 ▶use List::Util qw(any uniq);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 5 ▶use Travel::Status::DE::HAFAS::Stop;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 5 our $VERSION = '6.25';
15  
16 5 Travel::Status::DE::HAFAS::Journey->mk_ro_accessors(
17 qw(datetime sched_datetime rt_datetime tz_offset
18 is_additional is_cancelled is_partially_cancelled
19 station station_eva platform sched_platform rt_platform operator
20 product
21 id name type type_long class number line line_no load delay
22 route_end route_start origin destination direction)
23 );
24  
25 # {{{ Constructor
26  
27 34 ▶sub new {
Subroutine new: called CC=50 SCAR=51.6
Pod documented
28 34 my ( $obj, %opt ) = @_;
29  
30 34 ▶ my @icoL = @{ $opt{common}{icoL} // [] };
Condition50%1/2
$opt{"common"}{"icoL"} // []
l!l
340
MC/DC0%0/1
$opt{"common"}{"icoL"} // []
$opt{"common"}{"icoL"}
Truth table50%1/2
A
A= $opt{"common"}{"icoL"}
Aresult
11
00
31 34 ▶ my @tcocL = @{ $opt{common}{tcocL} // [] };
Condition100%2/2
$opt{"common"}{"tcocL"} // []
l!l
331
MC/DC100%1/1
$opt{"common"}{"tcocL"} // []
$opt{"common"}{"tcocL"}
Truth table100%2/2
A
A= $opt{"common"}{"tcocL"}
Aresult
11
00
32 34 ▶ my @remL = @{ $opt{common}{remL} // [] };
Condition50%1/2
$opt{"common"}{"remL"} // []
l!l
340
MC/DC0%0/1
$opt{"common"}{"remL"} // []
$opt{"common"}{"remL"}
Truth table50%1/2
A
A= $opt{"common"}{"remL"}
Aresult
11
00
33 34 ▶ my @himL = @{ $opt{common}{himL} // [] };
Condition50%1/2
$opt{"common"}{"himL"} // []
l!l
034
MC/DC0%0/1
$opt{"common"}{"himL"} // []
$opt{"common"}{"himL"}
Truth table50%1/2
A
A= $opt{"common"}{"himL"}
Aresult
11
00
34  
35 34 my $prodL = $opt{prodL};
36 34 my $locL = $opt{locL};
37 34 my $hafas = $opt{hafas};
38 34 my $journey = $opt{journey};
39  
40 34 ▶ my $date = $opt{date} // $journey->{date};
Condition33%1/3
$opt{"date"} // $journey->{"date"}
l!l&&r!l&&!r
0340
MC/DC0%0/2
$opt{"date"} // $journey->{"date"}
$opt{"date"} $journey->{"date"}
Truth table33%1/3
A // B
A= $opt{"date"}B= $journey->{"date"}
ABresult
1X1
011
000
41  
42 34 my $direction = $journey->{dirTxt};
43 34 my $jid = $journey->{jid};
44  
45 34 my $is_cancelled = $journey->{isCncl};
46 34 my $partially_cancelled = $journey->{isPartCncl};
47  
48 34 my $product = $prodL->[ $journey->{prodX} ];
49  
50 34 my @messages;
51 34 ▶ for my $msg ( @{ $journey->{msgL} // [] } ) {
Condition100%2/2
$journey->{"msgL"} // []
l!l
430
MC/DC100%1/1
$journey->{"msgL"} // []
$journey->{"msgL"}
Truth table100%2/2
A
A= $journey->{"msgL"}
Aresult
11
00
52 25 ▶ if ( $msg->{type} eq 'REM' and defined $msg->{remX} ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($msg->{'type'} eq 'REM' and defined $msg->{'remX'}) { } 25 0 25
elsif ($msg->{'type'} eq 'HIM' and defined $msg->{'himX'}) { } 0 0 0
Condition33%1/3
$msg->{"type"} eq "REM" and defined $msg->{"remX"}
!ll&&!rl&&r
0025
MC/DC0%0/2
$msg->{"type"} eq "REM" and defined $msg->{"remX"}
$msg->{"type"} eq "REM" defined $msg->{"remX"}
Truth table33%1/3
A and B
A= $msg->{"type"} eq "REM"B= defined $msg->{"remX"}
ABresult
0X0
100
111
53 25 push( @messages, $hafas->add_message( $remL[ $msg->{remX} ] ) );
54 }
55 ▶ elsif ( $msg->{type} eq 'HIM' and defined $msg->{himX} ) {
Condition0%0/3
$msg->{"type"} eq "HIM" and defined $msg->{"himX"}
!ll&&!rl&&r
000
MC/DC0%0/2
$msg->{"type"} eq "HIM" and defined $msg->{"himX"}
$msg->{"type"} eq "HIM" defined $msg->{"himX"}
Truth table0%0/3
A and B
A= $msg->{"type"} eq "HIM"B= defined $msg->{"himX"}
ABresult
0X0
100
111
56 0 push( @messages, $hafas->add_message( $himL[ $msg->{himX} ], 1 ) );
57 }
58 else {
59 0 say "Unknown message type $msg->{type}";
60 }
61 }
62  
63 34 my $datetime_ref;
64  
65 34 ▶ if ( @{ $journey->{stopL} // [] } or $journey->{stbStop} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$journey->{"stopL"} // [];} or $journey->{"stbStop"}) 34 0 34
Condition40%2/5
@{$journey->{"stopL"} // [];} or $journey->{"stbStop"}
l!l&&r!l&&!r
3400
$journey->{"stopL"} // []
l!l
340
MC/DC0%0/2
@{$journey->{"stopL"} // [];} or $journey->{"stbStop"}
@{$journey->{"stopL"} // [];} $journey->{"stbStop"}
MC/DC0%0/1
$journey->{"stopL"} // []
$journey->{"stopL"}
Truth table33%1/3
A or B
A= @{$journey->{"stopL"} // [];}B= $journey->{"stbStop"}
ABresult
1X1
011
000
Truth table50%1/2
A
A= $journey->{"stopL"}
Aresult
11
00
66 34 my ( $date_ref, $parse_fmt );
67 34 ▶ if ( $jid =~ /#/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($jid =~ /#/u) { } 0 34 34
68  
69 # modern trip ID, used e.g. by DB and ÖBB
70 0 $date_ref = ( split( /#/, $jid ) )[12];
71 0 $parse_fmt = '%d%m%y';
72 0 ▶ if ( length($date_ref) < 5 ) {
Branch: 2 branches
BranchTrueFalseTotal
if (length $date_ref < 5) { } 0 0 0
elsif (length $date_ref == 5) { } 0 0 0
73 0 warn(
74 "HAFAS, not even once -- midnight crossing may be bogus -- date_ref $date_ref"
75 );
76 }
77 elsif ( length($date_ref) == 5 ) {
78 0 $date_ref = "0${date_ref}";
79 }
80 }
81 else {
82 # old (legacy?) trip ID
83 34 $date_ref = ( split( qr{[|]}, $jid ) )[4];
84 34 $parse_fmt = '%d%m%Y';
85 34 ▶ if ( length($date_ref) < 7 ) {
Branch: 2 branches
BranchTrueFalseTotal
if (length $date_ref < 7) { } 0 34 34
elsif (length $date_ref == 7) { } 30 4 34
86 0 warn(
87 "HAFAS, not even once -- midnight crossing may be bogus -- date_ref $date_ref"
88 );
89 }
90 elsif ( length($date_ref) == 7 ) {
91 30 $date_ref = "0${date_ref}";
92 }
93 }
94 $datetime_ref = DateTime::Format::Strptime->new(
95 pattern => $parse_fmt,
96 time_zone => $hafas->get_active_service->{time_zone}
97 34 ▶ // 'Europe/Berlin'
Condition50%1/2
$hafas->get_active_service->{"time_zone"} // "Europe/Berlin"
l!l
340
MC/DC0%0/1
$hafas->get_active_service->{"time_zone"} // "Europe/Berlin"
$hafas->get_active_service->{"time_zone"}
Truth table50%1/2
A
A= $hafas->get_active_service->{"time_zone"}
Aresult
11
00
98 )->parse_datetime($date_ref);
99 }
100  
101 34 my @stops;
102 my $route_end;
103 34 ▶ for my $stop ( @{ $journey->{stopL} // [] } ) {
Condition50%1/2
$journey->{"stopL"} // []
l!l
340
MC/DC0%0/1
$journey->{"stopL"} // []
$journey->{"stopL"}
Truth table50%1/2
A
A= $journey->{"stopL"}
Aresult
11
00
104 438 my $loc = $locL->[ $stop->{locX} ];
105  
106 my $stopref = {
107 loc => $loc,
108 stop => $stop,
109 common => $opt{common},
110 438 prodL => $prodL,
111 hafas => $hafas,
112 date => $date,
113 datetime_ref => $datetime_ref,
114 };
115  
116 438 push( @stops, $stopref );
117  
118 438 $route_end = $loc->name;
119 }
120  
121 34 ▶ if ( $journey->{stbStop} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($journey->{"stbStop"}) 30 4 34
122 30 ▶ if ( $hafas->{arrivals} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hafas->{'arrivals'}) { } 0 30 30
123 0 $route_end = $stops[0]->{name};
124 0 pop(@stops);
125 }
126 else {
127 30 shift(@stops);
128 }
129 }
130  
131 34 ▶ my $ref = {
Condition33%1/3
$route_end // $direction
l!l&&r!l&&!r
3400
MC/DC0%0/2
$route_end // $direction
$route_end $direction
Truth table33%1/3
A // B
A= $route_endB= $direction
ABresult
1X1
011
000
132 id => $jid,
133 product => $product,
134 name => $product->name,
135 number => $product->number,
136 line => $product->name,
137 line_no => $product->line_no,
138 type => $product->type,
139 type_long => $product->type_long,
140 class => $product->class,
141 operator => $product->operator,
142 direction => $direction,
143 is_cancelled => $is_cancelled,
144 is_partially_cancelled => $partially_cancelled,
145 route_end => $route_end // $direction,
146 messages => \@messages,
147 route => \@stops,
148 };
149  
150 34 ▶ if ( $journey->{stbStop} ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($journey->{'stbStop'}) { } 30 4 34
elsif ($stops[0] and $stops[0]{'loc'}) { } 4 0 4
151 30 ▶ if ( $hafas->{arrivals} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hafas->{'arrivals'}) { } 0 30 30
152 0 $ref->{origin} = $ref->{route_end};
153 0 ▶ $ref->{is_cancelled} ||= $journey->{stbStop}{aCncl};
Condition0%0/3
$ref->{"is_cancelled"} ||= $journey->{"stbStop"}{"aCncl"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$ref->{"is_cancelled"} ||= $journey->{"stbStop"}{"aCncl"}
$ref->{"is_cancelled"} $journey->{"stbStop"}{"aCncl"}
Truth table0%0/3
A ||= B
A= $ref->{"is_cancelled"}B= $journey->{"stbStop"}{"aCncl"}
ABresult
1X1
011
000
154 }
155 else {
156 30 $ref->{destination} = $ref->{route_end};
157 30 ▶ $ref->{is_cancelled} ||= $journey->{stbStop}{dCncl};
Condition66%2/3
$ref->{"is_cancelled"} ||= $journey->{"stbStop"}{"dCncl"}
l!l&&r!l&&!r
1029
MC/DC50%1/2
$ref->{"is_cancelled"} ||= $journey->{"stbStop"}{"dCncl"}
$ref->{"is_cancelled"} $journey->{"stbStop"}{"dCncl"}
Truth table66%2/3
A ||= B
A= $ref->{"is_cancelled"}B= $journey->{"stbStop"}{"dCncl"}
ABresult
1X1
011
000
158 }
159 30 $ref->{is_additional} = $journey->{stbStop}{isAdd};
160 }
161 ▶ elsif ( $stops[0] and $stops[0]{loc} ) {
Condition33%1/3
$stops[0] and $stops[0]{"loc"}
!ll&&!rl&&r
004
MC/DC0%0/2
$stops[0] and $stops[0]{"loc"}
$stops[0] $stops[0]{"loc"}
Truth table33%1/3
A and B
A= $stops[0]B= $stops[0]{"loc"}
ABresult
0X0
100
111
162 4 $ref->{route_start} = $stops[0]{loc}->name;
163 }
164  
165 34 bless( $ref, $obj );
166  
167 34 ▶ if ( $journey->{stbStop} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($journey->{"stbStop"}) 30 4 34
168 30 $ref->{station} = $locL->[ $journey->{stbStop}{locX} ]->name;
169 30 $ref->{station_eva} = 0 + $locL->[ $journey->{stbStop}{locX} ]->eva;
170 $ref->{sched_platform} = $journey->{stbStop}{dPlatfS}
171 30 ▶ // $journey->{stbStop}{dPltfS}{txt};
Condition66%2/3
$journey->{"stbStop"}{"dPlatfS"} // $journey->{"stbStop"}{"dPltfS"}{"txt"}
l!l&&r!l&&!r
14016
MC/DC50%1/2
$journey->{"stbStop"}{"dPlatfS"} // $journey->{"stbStop"}{"dPltfS"}{"txt"}
$journey->{"stbStop"}{"dPlatfS"} $journey->{"stbStop"}{"dPltfS"}{"txt"}
Truth table66%2/3
A // B
A= $journey->{"stbStop"}{"dPlatfS"}B= $journey->{"stbStop"}{"dPltfS"}{"txt"}
ABresult
1X1
011
000
172 $ref->{rt_platform} = $journey->{stbStop}{dPlatfR}
173 30 ▶ // $journey->{stbStop}{dPltfR}{txt};
Condition33%1/3
$journey->{"stbStop"}{"dPlatfR"} // $journey->{"stbStop"}{"dPltfR"}{"txt"}
l!l&&r!l&&!r
0030
MC/DC0%0/2
$journey->{"stbStop"}{"dPlatfR"} // $journey->{"stbStop"}{"dPltfR"}{"txt"}
$journey->{"stbStop"}{"dPlatfR"} $journey->{"stbStop"}{"dPltfR"}{"txt"}
Truth table33%1/3
A // B
A= $journey->{"stbStop"}{"dPlatfR"}B= $journey->{"stbStop"}{"dPltfR"}{"txt"}
ABresult
1X1
011
000
174 30 ▶ $ref->{platform} = $ref->{rt_platform} // $ref->{sched_platform};
Condition66%2/3
$ref->{"rt_platform"} // $ref->{"sched_platform"}
l!l&&r!l&&!r
01416
MC/DC50%1/2
$ref->{"rt_platform"} // $ref->{"sched_platform"}
$ref->{"rt_platform"} $ref->{"sched_platform"}
Truth table66%2/3
A // B
A= $ref->{"rt_platform"}B= $ref->{"sched_platform"}
ABresult
1X1
011
000
175  
176 my $datetime_s = Travel::Status::DE::HAFAS::Stop::handle_day_change(
177 $ref,
178 input =>
179 $journey->{stbStop}{ $hafas->{arrivals} ? 'aTimeS' : 'dTimeS' },
180 offset => $journey->{stbStop}{
181 $hafas->{arrivals}
182 ? 'aTZOffset'
183 : 'dTZOffset'
184 },
185 date => $date,
186 strp_obj => $hafas->{strptime_obj},
187 30 ▶ ref => $datetime_ref,
Branch: 2 branches
BranchTrueFalseTotal
$hafas->{'arrivals'} ? : 0 30 30
$hafas->{'arrivals'} ? : 0 30 30
188 );
189  
190 my $datetime_r = Travel::Status::DE::HAFAS::Stop::handle_day_change(
191 $ref,
192 input =>
193 $journey->{stbStop}{ $hafas->{arrivals} ? 'aTimeR' : 'dTimeR' },
194 offset => $journey->{stbStop}{
195 $hafas->{arrivals}
196 ? 'aTZOffset'
197 : 'dTZOffset'
198 },
199 date => $date,
200 strp_obj => $hafas->{strptime_obj},
201 30 ▶ ref => $datetime_ref,
Branch: 2 branches
BranchTrueFalseTotal
$hafas->{'arrivals'} ? : 0 30 30
$hafas->{'arrivals'} ? : 0 30 30
202 );
203  
204 30 ▶ my $delay
Branch: 1 branch
BranchTrueFalseTotal
$datetime_r ? : 29 1 30
205 = $datetime_r
206 ? ( $datetime_r->epoch - $datetime_s->epoch ) / 60
207 : undef;
208  
209 30 $ref->{sched_datetime} = $datetime_s;
210 30 $ref->{rt_datetime} = $datetime_r;
211 30 ▶ $ref->{datetime} = $datetime_r // $datetime_s;
Condition66%2/3
$datetime_r // $datetime_s
l!l&&r!l&&!r
2910
MC/DC0%0/2
$datetime_r // $datetime_s
$datetime_r $datetime_s
Truth table66%2/3
A // B
A= $datetime_rB= $datetime_s
ABresult
1X1
011
000
212 30 $ref->{delay} = $delay;
213  
214 30 ▶ if ( $ref->{delay} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ref->{'delay'}) { } 2 28 30
215 2 $ref->{datetime} = $ref->{rt_datetime};
216 }
217 else {
218 28 $ref->{datetime} = $ref->{sched_datetime};
219 }
220  
221 30 my %tco;
222 30 ▶ for my $tco_id ( @{ $journey->{stbStop}{dTrnCmpSX}{tcocX} // [] } ) {
Condition50%1/2
$journey->{"stbStop"}{"dTrnCmpSX"}{"tcocX"} // []
l!l
030
MC/DC0%0/1
$journey->{"stbStop"}{"dTrnCmpSX"}{"tcocX"} // []
$journey->{"stbStop"}{"dTrnCmpSX"}{"tcocX"}
Truth table50%1/2
A
A= $journey->{"stbStop"}{"dTrnCmpSX"}{"tcocX"}
Aresult
11
00
223 0 my $tco_kv = $tcocL[$tco_id];
224  
225 # BVG has rRT (real-time?) and r (prognosed?); others only have r
226 0 ▶ my $load = $tco_kv->{rRT} // $tco_kv->{r};
Condition0%0/3
$tco_kv->{"rRT"} // $tco_kv->{"r"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$tco_kv->{"rRT"} // $tco_kv->{"r"}
$tco_kv->{"rRT"} $tco_kv->{"r"}
Truth table0%0/3
A // B
A= $tco_kv->{"rRT"}B= $tco_kv->{"r"}
ABresult
1X1
011
000
227  
228 # BVG uses 11 .. 13 rather than 1 .. 4
229 0 ▶ if ( defined $load and $load > 10 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $load and $load > 10) 0 0 0
Condition0%0/3
defined $load and $load > 10
!ll&&!rl&&r
000
MC/DC0%0/2
defined $load and $load > 10
defined $load $load > 10
Truth table0%0/3
A and B
A= defined $loadB= $load > 10
ABresult
0X0
100
111
230 0 $load -= 10;
231 }
232  
233 0 $tco{ $tco_kv->{c} } = $load;
234 }
235 30 ▶ if (%tco) {
Branch: 1 branch
BranchTrueFalseTotal
if (%tco) 0 30 30
236 0 $ref->{load} = \%tco;
237 }
238 }
239 34 ▶ if ( $opt{polyline} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt{"polyline"}) 3 31 34
240 3 $ref->{polyline} = $opt{polyline};
241 }
242  
243 34 return $ref;
244 }
245  
246 # }}}
247  
248 # {{{ Accessors
249  
250 # Legacy
251 0 ▶sub station_uic {
Subroutine station_uic: not called CC=1 SCAR=6.9
Pod undocumented
252 0 my ($self) = @_;
253 0 return $self->{station_eva};
254 }
255  
256 5 ▶sub is_changed_platform {
Subroutine is_changed_platform: called CC=5 SCAR=23.1
Pod documented
257 5 my ($self) = @_;
258  
259 5 ▶ if ( defined $self->{rt_platform} and defined $self->{sched_platform} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"rt_platform"} and defined $self->{"sched_platform"}) 0 5 5
Condition33%1/3
defined $self->{"rt_platform"} and defined $self->{"sched_platform"}
!ll&&!rl&&r
500
MC/DC0%0/2
defined $self->{"rt_platform"} and defined $self->{"sched_platform"}
defined $self->{"rt_platform"} defined $self->{"sched_platform"}
Truth table33%1/3
A and B
A= defined $self->{"rt_platform"}B= defined $self->{"sched_platform"}
ABresult
0X0
100
111
260 0 ▶ if ( $self->{rt_platform} ne $self->{sched_platform} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"rt_platform"} ne $self->{"sched_platform"}) 0 0 0
261 0 return 1;
262 }
263 0 return 0;
264 }
265 5 ▶ if ( defined $self->{rt_platform} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"rt_platform"}) 0 5 5
266 0 return 1;
267 }
268  
269 5 return 0;
270 }
271  
272 2 ▶sub messages {
Subroutine messages: called CC=2 SCAR=7.4
Pod documented
273 2 my ($self) = @_;
274  
275 2 ▶ if ( $self->{messages} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"messages"}) 2 0 2
276 2 return @{ $self->{messages} };
277 }
278 0 return;
279 }
280  
281 0 ▶sub operators {
Subroutine operators: not called CC=6 SCAR=37.4
Pod documented
282 0 my ($self) = @_;
283  
284 0 ▶ if ( $self->{operators} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"operators"}) 0 0 0
285 0 return @{ $self->{operators} };
286 }
287  
288 $self->{operators} = [
289 0 ▶ uniq map { ( $_->prod_arr // $_->prod_dep )->operator } grep {
Condition0%0/3
$_->prod_arr // $_->prod_dep
l!l&&r!l&&!r
000
MC/DC0%0/2
$_->prod_arr // $_->prod_dep
$_->prod_arr $_->prod_dep
Truth table0%0/3
A // B
A= $_->prod_arrB= $_->prod_dep
ABresult
1X1
011
000
290 0 ▶ ( $_->prod_arr or $_->prod_dep )
Condition0%0/9
($_->prod_arr || $_->prod_dep) && ($_->prod_arr // $_->prod_dep)->operator
!ll&&!rl&&r
000
$_->prod_arr or $_->prod_dep
l!l&&r!l&&!r
000
$_->prod_arr // $_->prod_dep
l!l&&r!l&&!r
000
MC/DC0%0/3
($_->prod_arr || $_->prod_dep) && ($_->prod_arr // $_->prod_dep)->operator
$_->prod_arr $_->prod_dep ($_->prod_arr // $_->prod_dep)->operator
MC/DC0%0/2
$_->prod_arr // $_->prod_dep
$_->prod_arr $_->prod_dep
Truth table0%0/5
A or B && C
A= $_->prod_arrB= $_->prod_depC= ($_->prod_arr // $_->prod_dep)->operator
ABCresult
00X0
1X00
0100
1X11
0111
Truth table0%0/3
A // B
A= $_->prod_arrB= $_->prod_dep
ABresult
1X1
011
000
291 and ( $_->prod_arr // $_->prod_dep )->operator
292 } $self->route
293 ];
294  
295 0 return @{ $self->{operators} };
296 }
297  
298 0 ▶sub polyline {
Subroutine polyline: not called CC=2 SCAR=17.9
Pod documented
299 0 my ($self) = @_;
300  
301 0 ▶ if ( $self->{polyline} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"polyline"}) 0 0 0
302 0 return @{ $self->{polyline} };
303 }
304 0 return;
305 }
306  
307 215 ▶sub route {
Subroutine route: called CC=5 SCAR=16.7
Pod documented
308 215 my ($self) = @_;
309  
310 215 ▶ if ( $self->{route} and @{ $self->{route} } ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"route"} and @{$self->{"route"};}) 215 0 215
Condition33%1/3
$self->{"route"} and @{$self->{"route"};}
!ll&&!rl&&r
00215
MC/DC0%0/2
$self->{"route"} and @{$self->{"route"};}
$self->{"route"} @{$self->{"route"};}
Truth table33%1/3
A and B
A= $self->{"route"}B= @{$self->{"route"};}
ABresult
0X0
100
111
311 215 ▶ if ( $self->{route}[0] and $self->{route}[0]{stop} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"route"}[0] and $self->{"route"}[0]{"stop"}) 7 208 215
Condition66%2/3
$self->{"route"}[0] and $self->{"route"}[0]{"stop"}
!ll&&!rl&&r
02087
MC/DC50%1/2
$self->{"route"}[0] and $self->{"route"}[0]{"stop"}
$self->{"route"}[0] $self->{"route"}[0]{"stop"}
Truth table66%2/3
A and B
A= $self->{"route"}[0]B= $self->{"route"}[0]{"stop"}
ABresult
0X0
100
111
312 $self->{route}
313 85 = [ map { Travel::Status::DE::HAFAS::Stop->new( %{$_} ) }
314 7 @{ $self->{route} } ];
315 }
316 215 return @{ $self->{route} };
317 }
318 0 return;
319 }
320  
321 18 ▶sub route_interesting {
Subroutine route_interesting: called CC=17 SCAR=29.2
Pod documented
322 18 my ( $self, $max_parts ) = @_;
323  
324 18 my @via = $self->route;
325 18 my ( @via_main, @via_show, $last_stop );
326 18 ▶ $max_parts //= 3;
Condition50%1/2
$max_parts //= 3
l!l
018
MC/DC0%0/1
$max_parts //= 3
$max_parts
Truth table50%1/2
A
A= $max_parts
Aresult
11
00
327  
328 # Centraal: dutch main station (Hbf in .nl)
329 # HB: swiss main station (Hbf in .ch)
330 # hl.n.: czech main station (Hbf in .cz)
331 18 for my $stop (@via) {
332 232 ▶ if ( $stop->loc->name
Branch: 1 branch
BranchTrueFalseTotal
if ($stop->loc->name =~ / HB $ | hl\.n\. $ | Hbf | Hauptbahnhof | Bf | Bahnhof | Centraal | Flughafen /ux) 84 148 232
333 =~ m{ HB $ | hl\.n\. $ | Hbf | Hauptbahnhof | Bf | Bahnhof | Centraal | Flughafen }x
334 )
335 {
336 84 push( @via_main, $stop );
337 }
338 }
339 18 $last_stop = pop(@via);
340  
341 18 ▶ if ( @via_main and $via_main[-1]->loc->name eq $last_stop->loc->name ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@via_main and $via_main[-1]->loc->name eq $last_stop->loc->name) 6 12 18
Condition100%3/3
@via_main and $via_main[-1]->loc->name eq $last_stop->loc->name
!ll&&!rl&&r
846
MC/DC100%2/2
@via_main and $via_main[-1]->loc->name eq $last_stop->loc->name
@via_main $via_main[-1]->loc->name eq $last_stop->loc->name
Truth table100%3/3
A and B
A= @via_mainB= $via_main[-1]->loc->name eq $last_stop->loc->name
ABresult
0X0
100
111
342 6 pop(@via_main);
343 }
344 18 ▶ if ( @via and $via[-1]->loc->name eq $last_stop->loc->name ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@via and $via[-1]->loc->name eq $last_stop->loc->name) 0 18 18
Condition33%1/3
@via and $via[-1]->loc->name eq $last_stop->loc->name
!ll&&!rl&&r
0180
MC/DC0%0/2
@via and $via[-1]->loc->name eq $last_stop->loc->name
@via $via[-1]->loc->name eq $last_stop->loc->name
Truth table33%1/3
A and B
A= @viaB= $via[-1]->loc->name eq $last_stop->loc->name
ABresult
0X0
100
111
345 0 pop(@via);
346 }
347  
348 18 ▶ if ( @via_main and @via and $via[0]->loc->name eq $via_main[0]->loc->name )
Branch: 1 branch
BranchTrueFalseTotal
if (@via_main and @via and $via[0]->loc->name eq $via_main[0]->loc->name) 6 12 18
Condition83%5/6
@via_main and @via and $via[0]->loc->name eq $via_main[0]->loc->name
!ll&&!rl&&r
846
@via_main and @via
!ll&&!rl&&r
8010
MC/DC66%2/3
@via_main and @via and $via[0]->loc->name eq $via_main[0]->loc->name
@via_main @via $via[0]->loc->name eq $via_main[0]->loc->name
Truth table75%3/4
A and B and C
A= @via_mainB= @viaC= $via[0]->loc->name eq $via_main[0]->loc->name
ABCresult
0XX0
10X0
1100
1111
349 {
350 6 shift(@via_main);
351 }
352  
353 18 ▶ if ( @via < $max_parts ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@via < $max_parts) { } 2 16 18
354 2 @via_show = @via;
355 }
356 else {
357 16 ▶ if ( @via_main >= $max_parts ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@via_main >= $max_parts) { } 4 12 16
358 4 @via_show = ( $via[0] );
359 }
360 else {
361 12 @via_show = splice( @via, 0, $max_parts - @via_main );
362 }
363  
364 16 ▶ while ( @via_show < $max_parts and @via_main ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@via_show < $max_parts and @via_main) 12 16 28
Condition66%2/3
@via_show < $max_parts and @via_main
!ll&&!rl&&r
16012
MC/DC50%1/2
@via_show < $max_parts and @via_main
@via_show < $max_parts @via_main
Truth table66%2/3
A and B
A= @via_show < $max_partsB= @via_main
ABresult
0X0
100
111
365 12 my $stop = shift(@via_main);
366 12 ▶ if ( any { $_->loc->name eq $stop->loc->name } @via_show
Subroutine __ANON__: called CC=1 SCAR=0.8
Branch: 1 branch
BranchTrueFalseTotal
if (&any(sub { $_->loc->name eq $stop->loc->name; } , @via_show) or $stop->loc->name eq $last_stop->loc->name) 0 12 12
Condition33%1/3
&any(sub { $_->loc->name eq $stop->loc->name; } , @via_show) or $stop->loc->name eq $last_stop->loc->name
l!l&&r!l&&!r
0012
MC/DC0%0/2
&any(sub { $_->loc->name eq $stop->loc->name; } , @via_show) or $stop->loc->name eq $last_stop->loc->name
&any(sub { $_->loc->name eq $stop->loc->name; } , @via_show) $stop->loc->name eq $last_stop->loc->name
Truth table33%1/3
A or B
A= &any(sub { $_->loc->name eq $stop->loc->name; } , @via_show)B= $stop->loc->name eq $last_stop->loc->name
ABresult
1X1
011
000
367 or $stop->loc->name eq $last_stop->loc->name )
368 {
369 0 next;
370 }
371 12 push( @via_show, $stop );
372 }
373 }
374  
375 18 return @via_show;
376  
377 }
378  
379 0 ▶sub product_at {
Subroutine product_at: not called CC=5 SCAR=34.0
Pod documented
380 0 my ( $self, $req_stop ) = @_;
381 0 for my $stop ( $self->route ) {
382 0 ▶ if ( $stop->loc->name eq $req_stop or $stop->loc->eva eq $req_stop ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($stop->loc->name eq $req_stop or $stop->loc->eva eq $req_stop) 0 0 0
Condition0%0/3
$stop->loc->name eq $req_stop or $stop->loc->eva eq $req_stop
l!l&&r!l&&!r
000
MC/DC0%0/2
$stop->loc->name eq $req_stop or $stop->loc->eva eq $req_stop
$stop->loc->name eq $req_stop $stop->loc->eva eq $req_stop
Truth table0%0/3
A or B
A= $stop->loc->name eq $req_stopB= $stop->loc->eva eq $req_stop
ABresult
1X1
011
000
383 0 ▶ return $stop->prod_dep // $stop->prod_arr;
Condition0%0/3
$stop->prod_dep // $stop->prod_arr
l!l&&r!l&&!r
000
MC/DC0%0/2
$stop->prod_dep // $stop->prod_arr
$stop->prod_dep $stop->prod_arr
Truth table0%0/3
A // B
A= $stop->prod_depB= $stop->prod_arr
ABresult
1X1
011
000
384 }
385 }
386 0 return;
387 }
388  
389 0 ▶sub TO_JSON {
Subroutine TO_JSON: not called CC=3 SCAR=24.8
Pod undocumented
390 0 my ($self) = @_;
391  
392 0 my $ret = { %{$self} };
393  
394 0 for my $k ( keys %{$ret} ) {
395 0 ▶ if ( ref( $ret->{$k} ) eq 'DateTime' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $ret->{$k} eq "DateTime") 0 0 0
396 0 $ret->{$k} = $ret->{$k}->epoch;
397 }
398 }
399 0 $ret->{route} = [ map { $_->TO_JSON } $self->route ];
400  
401 0 return $ret;
402 }
403  
404 # }}}
405  
406 5 1;
407  
408 __END__
« HAFAS.pm ↑ Summary HAFAS/StopFinder.pm »