IRIS/Result.pm

filter: Statementstmt 78.5% 318 / 405 Branchbran 68.8% 73 / 106 Conditioncond 52.7% 67 / 127 MC/DCmcdc 18.9% 14 / 74 Subroutinesub 82.4% 47 / 57 Podpod 58.1% 25 / 43 totaltotal 67.0% 544 / 812 CC 113 SCAR 26.3
CC
113
Cov
72%
is_additional
56.0
TO_JSON
56.0
sorted_sublist
20.0
CRAP 13.9
« IRIS.pm ↑ Summary IRIS/Stations.pm »
1 package Travel::Status::DE::IRIS::Result;
2  
3 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 7 ▶use 5.014;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 7 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 7 ▶use parent 'Class::Accessor';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 7 ▶use Carp qw(cluck);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 7 ▶use DateTime;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 7 ▶use DateTime::Format::Strptime;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 7 ▶use List::Compare;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 7 ▶use List::Util qw(any);
Subroutine BEGIN: called CC=1 SCAR=0.0
14 7 ▶use List::MoreUtils qw(uniq lastval);
Subroutine BEGIN: called CC=1 SCAR=0.0
15 7 ▶use Scalar::Util qw(weaken);
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 7 our $VERSION = '2.05';
18  
19 7 Travel::Status::DE::IRIS::Result->mk_ro_accessors(
20 qw(arrival arrival_delay arrival_has_realtime arrival_is_additional arrival_is_cancelled arrival_hidden
21 date datetime delay
22 departure departure_delay departure_has_realtime departure_is_additional departure_is_cancelled departure_hidden
23 ds100 has_realtime is_transfer is_unscheduled is_wing
24 line_no old_train_id old_train_no operator platform raw_id
25 realtime_xml route_start route_end
26 sched_arrival sched_departure sched_platform sched_route_start
27 sched_route_end start
28 station station_eva station_uic
29 stop_no time train_id train_no transfer type
30 unknown_t unknown_o wing_id wing_of)
31 );
32  
33 # {{{ Data (message codes, station fixups)
34  
35 7 my %translation = (
36 1 => 'Nähere Informationen in Kürze',
37 2 => 'Polizeieinsatz',
38 3 => 'Feuerwehreinsatz auf der Strecke',
39 4 => 'Kurzfristiger Personalausfall', # xlsx: missing
40 5 => 'Ärztliche Versorgung eines Fahrgastes',
41 6 => 'Betätigen der Notbremse', # xlsx: "Unbefugtes Ziehen der Notbremse"
42 7 => 'Unbefugte Personen auf der Strecke',
43 8 => 'Notarzteinsatz auf der Strecke',
44 9 => 'Streikauswirkungen',
45 10 => 'Tiere auf der Strecke',
46 11 => 'Unwetter',
47 12 => 'Warten auf ein verspätetes Schiff',
48 13 => 'Pass- und Zollkontrolle',
49 14 => 'Defekt am Bahnhof', # xlsx: "Technischer Defekt am Bahnhof"
50 15 => 'Beeinträchtigung durch Vandalismus',
51 16 => 'Entschärfung einer Fliegerbombe',
52 17 => 'Beschädigung einer Brücke',
53 18 => 'Umgestürzter Baum auf der Strecke',
54 19 => 'Unfall an einem Bahnübergang',
55 20 => 'Tiere im Gleis', # xlsx: missing
56 21 => 'Warten auf Anschlussreisende',
57 22 => 'Witterungsbedingte Beeinträchtigungen',
58 23 => 'Betriebsstabilisierung', # deleted as of 2025-12-14
59 24 => 'Verspätung im Ausland',
60 25 => 'Bereitstellung weiterer Wagen',
61 26 => 'Abhängen von Wagen',
62 27 => 'Technische Störung am Bus',
63 28 => 'Gegenstände auf der Strecke',
64 29 => 'Ersatzverkehr mit Bus ist eingerichtet',
65 30 => 'Personalausfall im Stellwerk',
66 31 => 'Bauarbeiten',
67 32 => 'Längere Haltezeit am Bahnhof',
68 33 => 'Defekt an der Oberleitung', # xlsx: "Reparatur an der Oberleitung"
69 34 => 'Defekt an einem Signal', # xlsx: "Reparatur an einem Signal"
70 35 => 'Streckensperrung',
71 36 => 'Technische Störung am Zug',
72 37 => 'Kurzfristiger Fahrzeugausfall',
73 38 => 'Defekt an der Strecke', # xlsx: "Reparatur an der Strecke"
74 39 => 'Stau / Hohes Verkehrsaufkommen',
75 40 => 'Defektes Stellwerk',
76 41 => 'Defekt an einem Bahnübergang'
77 , # xlsx: "Technischer Defekt an einem Bahnüburgang"
78 42 => 'Außerplanmäßige Geschwindigkeitsbeschränkung'
79 , # xlsx: "Vorübergehend verminderte Geschwindigkeit auf der Strecke"
80 43 => 'Verspätung eines vorausfahrenden Zuges',
81 44 => 'Warten auf einen entgegenkommenden Zug',
82 45 => 'Vorfahrt eines anderen Zuges',
83 46 => 'Vorfahrt eines anderen Zuges', # xlsx: missing
84 47 => 'Verspätete Bereitstellung',
85 48 => 'Verspätung aus vorheriger Fahrt',
86 49 => 'Kurzfristiger Personalausfall',
87 50 => 'Kurzfristige Erkrankung von Personal',
88 51 => 'Verspätetes Personal aus vorheriger Fahrt',
89 52 => 'Streik',
90 53 => 'Unwetterauswirkungen',
91 54 => 'Verfügbarkeit der Gleise derzeit eingeschränkt',
92 55 => 'Technischer Defekt an einem anderen Zug',
93 56 => 'Laden der Antriebsbatterie',
94 57 => 'Zusätzlicher Halt', # xslx: "Zusätzlicher Halt zum Ein- und Ausstieg"
95 58 => 'Umleitung', # xlsx: "Umleitung des Zuges"
96 59 => 'Schnee und Eis',
97 60 => 'Witterungsbedingt verminderte Geschwindigkeit',
98 61 => 'Defekte Tür',
99 62 => 'Behobener Defekt am Zug',
100 63 => 'Technische Untersuchung am Zug',
101 64 => 'Defekt an einer Weiche',
102 65 => 'Erdrutsch',
103 66 => 'Hochwasser',
104 67 => 'Behördliche Maßnahme',
105 68 => 'Hohes Fahrgastaufkommen'
106 , # xlsx: "Hohes Fahrgastaufkommen verlängert Ein- und Ausstieg"
107 69 => 'Zug verkehrt mit verminderter Geschwindigeit',
108 70 => 'WLAN nicht verfügbar',
109 71 => 'Eingeschränktes WLAN',
110 72 => 'Info/Entertainment nicht verfügbar',
111 73 => 'Heute: Mehrzweckabteil vorne',
112 74 => 'Heute: Mehrzweckabteil hinten',
113 75 => 'Heute: 1. Klasse vorne',
114 76 => 'Heute: 1. Klasse hinten',
115 77 => '1. Klasse fehlt',
116 78 => 'Ersatzverkehr mit Bus ist eingerichtet',
117 79 => 'Mehrzweckabteil fehlt',
118 80 => 'Abweichende Wagenreihung',
119 81 => 'Fahrzeugtausch', # deleted as of 2025-12-14
120 82 => 'Mehrere Wagen fehlen',
121 83 => 'Heute ohne fahrzeuggebundene Einstiegshilfe',
122 84 => 'Zug verkehrt richtig gereiht',
123 85 => 'Ein Wagen fehlt',
124 86 => 'Gesamter Zug ohne Reservierung',
125 87 => 'Einzelne Wagen ohne Reservierung',
126 88 => 'Keine Qualitätsmängel',
127 89 => 'Reservierungen sind wieder vorhanden',
128 90 => 'Kein gastronomisches Angebot',
129 91 => 'Fahrradmitnahme nicht möglich',
130 92 => 'Fahrradmitnahme kann nicht garantiert werden',
131 93 => 'Behindertengerechte Einrichtung fehlt',
132 94 => 'Ersatzbewirtschaftung',
133 95 => 'Universaltoilette fehlt',
134 96 => 'Zustieg kann nicht garantiert werden',
135 97 => 'Hohe Auslastung',
136 98 => 'Sonstige Qualitätsmängel',
137 99 => 'Verzögerungen im Betriebsablauf',
138  
139 # Occasionally, there's a message with ID 900. In all cases observed so far,
140 # it was used for "Anschlussbus wartet". However, as we don't know which bus
141 # it refers to, we don't show it to users.
142 );
143  
144 # IRIS may return "Betriebsstelle nicht bekannt" for some recently added
145 # stations. Fix those manually.
146 7 my %fixup = (
147 8002795 => 'Herten(Westf)',
148 8003983 => 'Merklingen - Schwäbische Alb',
149 8005493 => 'Schwetzingen-Hirschacker',
150 8070678 => 'Metzingen-Neuhausen',
151 );
152  
153 # }}}
154 # {{{ Constructor
155  
156 1140 ▶sub new {
Subroutine new: called CC=14 SCAR=26.7
Pod documented
157 1140 my ( $obj, %opt ) = @_;
158  
159 1140 my $ref = \%opt;
160  
161 1140 my ( $train_id, $start_ts, $stop_no ) = split( /.\K-/, $opt{raw_id} );
162  
163 1140 bless( $ref, $obj );
164  
165 1140 ▶ $ref->{strptime_obj} //= DateTime::Format::Strptime->new(
Condition33%1/3
$ref->{"strptime_obj"} //= "DateTime::Format::Strptime"->new("pattern", "%y%m%d%H%M", "time_zone", "Europe/Berlin")
l!l&&r!l&&!r
114000
MC/DC0%0/2
$ref->{"strptime_obj"} //= "DateTime::Format::Strptime"->new("pattern", "%y%m%d%H%M", "time_zone", "Europe/Berlin")
$ref->{"strptime_obj"} "DateTime::Format::Strptime"->new("pattern", "%y%m%d%H%M", "time_zone", "Europe/Berlin")
Truth table33%1/3
A //= B
A= $ref->{"strptime_obj"}B= "DateTime::Format::Strptime"->new("pattern", "%y%m%d%H%M", "time_zone", "Europe/Berlin")
ABresult
1X1
011
000
166 pattern => '%y%m%d%H%M',
167 time_zone => 'Europe/Berlin',
168 );
169  
170 1140 $ref->{wing_id} = "${train_id}-${start_ts}";
171 1140 $ref->{is_wing} = 0;
172 1140 $train_id =~ s{^-}{};
173  
174 1140 $ref->{start} = $ref->parse_ts($start_ts);
175  
176 1140 $ref->{train_id} = $train_id;
177 1140 $ref->{stop_no} = $stop_no;
178  
179 1140 ▶ if ( $opt{transfer} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt{"transfer"}) 24 1116 1140
180 24 my ($transfer) = split( /.\K-/, $opt{transfer} );
181 24 $transfer =~ s{^-}{};
182 24 $ref->{transfer} = $transfer;
183 }
184  
185 my $ar = $ref->{arrival} = $ref->{sched_arrival}
186 1140 = $ref->parse_ts( $opt{arrival_ts} );
187 my $dp = $ref->{departure} = $ref->{sched_departure}
188 1140 = $ref->parse_ts( $opt{departure_ts} );
189  
190 1140 ▶ if ( not( defined $ar or defined $dp ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $ar or defined $dp) 0 1140 1140
Condition66%2/3
defined $ar or defined $dp
l!l&&r!l&&!r
9851550
MC/DC0%0/2
defined $ar or defined $dp
defined $ar defined $dp
Truth table66%2/3
A or B
A= defined $arB= defined $dp
ABresult
1X1
011
000
191 cluck(
192 sprintf(
193 "Neither arrival '%s' nor departure '%s' are valid "
194 . "timestamps - can't handle this train",
195 $opt{arrival_ts}, $opt{departure_ts}
196 )
197 0 );
198 }
199  
200 1140 ▶ my $dt = $ref->{datetime} = $dp // $ar;
Condition66%2/3
$dp // $ar
l!l&&r!l&&!r
9392010
MC/DC0%0/2
$dp // $ar
$dp $ar
Truth table66%2/3
A // B
A= $dpB= $ar
ABresult
1X1
011
000
201  
202 1140 $ref->{date} = $dt->strftime('%d.%m.%Y');
203 1140 $ref->{time} = $dt->strftime('%H:%M');
204 1140 $ref->{epoch} = $dt->epoch;
205  
206 $ref->{route_pre} = $ref->{sched_route_pre}
207 1140 ▶ = [ split( qr{[|]}, $ref->{route_pre} // q{} ) ];
Condition100%2/2
$ref->{"route_pre"} // ""
l!l
985155
MC/DC100%1/1
$ref->{"route_pre"} // ""
$ref->{"route_pre"}
Truth table100%2/2
A
A= $ref->{"route_pre"}
Aresult
11
00
208 $ref->{route_post} = $ref->{sched_route_post}
209 1140 ▶ = [ split( qr{[|]}, $ref->{route_post} // q{} ) ];
Condition100%2/2
$ref->{"route_post"} // ""
l!l
939201
MC/DC100%1/1
$ref->{"route_post"} // ""
$ref->{"route_post"}
Truth table100%2/2
A
A= $ref->{"route_post"}
Aresult
11
00
210  
211 1140 $ref->fixup_route( $ref->{route_pre} );
212 1140 $ref->fixup_route( $ref->{route_post} );
213  
214 1140 ▶ $ref->{route_pre_incomplete} = $ref->{route_end} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$ref->{'route_end'} ? : 38 1102 1140
215 1140 ▶ $ref->{route_post_incomplete} = $ref->{route_post} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$ref->{'route_post'} ? : 1140 0 1140
216  
217 1140 $ref->{sched_platform} = $ref->{platform};
218 $ref->{route_end}
219 = $ref->{sched_route_end}
220 = $ref->{route_end}
221 || $ref->{route_post}[-1]
222 1140 ▶ || $ref->{station};
Condition83%5/6
$ref->{'route_end'} || $ref->{'route_post'}[-1] || $ref->{'station'}
l!l&&r!l&&!r
9392010
$ref->{"route_end"} or $ref->{"route_post"}[-1]
l!l&&r!l&&!r
38901201
MC/DC0%0/3
$ref->{'route_end'} || $ref->{'route_post'}[-1] || $ref->{'station'}
$ref->{"route_end"} $ref->{"route_post"}[-1] $ref->{'station'}
Truth table75%3/4
A or B || C
A= $ref->{"route_end"}B= $ref->{"route_post"}[-1]C= $ref->{'station'}
ABCresult
1XX1
01X1
0011
0000
223 $ref->{route_start}
224 = $ref->{sched_route_start}
225 = $ref->{route_start}
226 || $ref->{route_pre}[0]
227 1140 ▶ || $ref->{station};
Condition83%5/6
$ref->{'route_start'} || $ref->{'route_pre'}[0] || $ref->{'station'}
l!l&&r!l&&!r
9851550
$ref->{"route_start"} or $ref->{"route_pre"}[0]
l!l&&r!l&&!r
48937155
MC/DC0%0/3
$ref->{'route_start'} || $ref->{'route_pre'}[0] || $ref->{'station'}
$ref->{"route_start"} $ref->{"route_pre"}[0] $ref->{'station'}
Truth table75%3/4
A or B || C
A= $ref->{"route_start"}B= $ref->{"route_pre"}[0]C= $ref->{'station'}
ABCresult
1XX1
01X1
0011
0000
228  
229 1140 return $ref;
230 }
231  
232 # }}}
233 # {{{ Internal Helpers
234  
235 3012 ▶sub fixup_route {
Subroutine fixup_route: called CC=4 SCAR=17.9
Pod undocumented
236 3012 my ( $self, $route ) = @_;
237 3012 for my $stop ( @{$route} ) {
238 27180 ▶ if ( $stop =~ m{^Betriebsstelle nicht bekannt (\d+)$} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($stop =~ /^Betriebsstelle nicht bekannt (\d+)$/u) 0 27180 27180
239 0 ▶ if ( $fixup{$1} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fixup{$1}) 0 0 0
240 0 $stop = $fixup{$1};
241 }
242 }
243 }
244 }
245  
246 5011 ▶sub parse_ts {
Subroutine parse_ts: called CC=2 SCAR=6.9
Pod undocumented
247 5011 my ( $self, $string ) = @_;
248  
249 5011 ▶ if ( defined $string ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $string) 4655 356 5011
250 4655 return $self->{strptime_obj}->parse_datetime($string);
251 }
252 356 return;
253 }
254  
255 # List::Compare does not keep the order of its arguments (even with unsorted).
256 # So we need to re-sort all stops to maintain their original order.
257 0 ▶sub sorted_sublist {
Subroutine sorted_sublist: not called CC=4 SCAR=30.0
Pod undocumented
258 0 my ( $self, $list, $sublist ) = @_;
259 0 my %pos;
260  
261 0 ▶ if ( not $sublist or not @{$sublist} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($sublist and @{$sublist;}) 0 0 0
Condition0%0/3
$sublist and @{$sublist;}
!ll&&!rl&&r
000
MC/DC0%0/2
$sublist and @{$sublist;}
$sublist @{$sublist;}
Truth table0%0/3
A and B
A= $sublistB= @{$sublist;}
ABresult
0X0
100
111
262 0 return;
263 }
264  
265 0 for my $i ( 0 .. $#{$list} ) {
266 0 $pos{ $list->[$i] } = $i;
267 }
268  
269 0 my @sorted = sort { $pos{$a} <=> $pos{$b} } @{$sublist};
270  
271 0 return @sorted;
272 }
273  
274 3 ▶sub superseded_messages {
Subroutine superseded_messages: called CC=2 SCAR=7.0
Pod undocumented
275 3 my ( $self, $msg ) = @_;
276 3 my %superseded = (
277 73 => [74],
278 74 => [73],
279 75 => [76],
280 76 => [75],
281 84 => [ 73, 74, 75, 76, 80 ],
282 88 => [
283 70, 71, 72, 77, 78, 79, 82, 83, 85, 90,
284 91, 92, 93, 94, 95, 96, 97, 98
285 ],
286 89 => [ 86, 87 ],
287 );
288  
289 3 ▶ return @{ $superseded{$msg} // [] };
Condition50%1/2
$superseded{$msg} // []
l!l
03
MC/DC0%0/1
$superseded{$msg} // []
$superseded{$msg}
Truth table50%1/2
A
A= $superseded{$msg}
Aresult
11
00
290 }
291  
292 # }}}
293 # {{{ Internal Setters for IRIS.pm
294  
295 760 ▶sub set_ar {
Subroutine set_ar: called CC=17 SCAR=28.7
Pod undocumented
296 760 my ( $self, %attrib ) = @_;
297  
298 760 ▶ if ( $attrib{status} and $attrib{status} eq 'c' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($attrib{'status'} and $attrib{'status'} eq 'c') { } 54 706 760
elsif ($attrib{'status'} and $attrib{'status'} eq 'a') { } 0 706 706
Condition100%3/3
$attrib{"status"} and $attrib{"status"} eq "c"
!ll&&!rl&&r
6753154
MC/DC100%2/2
$attrib{"status"} and $attrib{"status"} eq "c"
$attrib{"status"} $attrib{"status"} eq "c"
Truth table100%3/3
A and B
A= $attrib{"status"}B= $attrib{"status"} eq "c"
ABresult
0X0
100
111
299 54 $self->{has_realtime} = $self->{arrival_has_realtime} = 1;
300 54 $self->{arrival_is_cancelled} = 1;
301 }
302 ▶ elsif ( $attrib{status} and $attrib{status} eq 'a' ) {
Condition66%2/3
$attrib{"status"} and $attrib{"status"} eq "a"
!ll&&!rl&&r
675310
MC/DC0%0/2
$attrib{"status"} and $attrib{"status"} eq "a"
$attrib{"status"} $attrib{"status"} eq "a"
Truth table66%2/3
A and B
A= $attrib{"status"}B= $attrib{"status"} eq "a"
ABresult
0X0
100
111
303 0 $self->{arrival_is_additional} = 1;
304 }
305 else {
306 706 $self->{arrival_is_additional} = 0;
307 706 $self->{arrival_is_cancelled} = 0;
308 }
309  
310 760 ▶ if ( $attrib{arrival_hidden} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attrib{"arrival_hidden"}) 0 760 760
311 0 $self->{arrival_hidden} = $attrib{arrival_hidden};
312 }
313  
314 # unscheduled arrivals may not appear in the plan, but we do need to
315 # know their planned arrival time
316 760 ▶ if ( $attrib{plan_arrival_ts} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attrib{"plan_arrival_ts"}) 184 576 760
317 $self->{sched_arrival}
318 184 = $self->parse_ts( $attrib{plan_arrival_ts} );
319 }
320  
321 760 ▶ if ( $attrib{arrival_ts} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attrib{'arrival_ts'}) { } 648 112 760
322 648 $self->{has_realtime} = $self->{arrival_has_realtime} = 1;
323 648 $self->{arrival} = $self->parse_ts( $attrib{arrival_ts} );
324 648 ▶ if ( not $self->{arrival_is_cancelled} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"arrival_is_cancelled"}) 640 8 648
325 $self->{delay} = $self->{arrival_delay}
326 640 = $self->arrival->subtract_datetime( $self->sched_arrival )
327 ->in_units('minutes');
328 }
329 }
330 else {
331 112 $self->{arrival} = $self->{sched_arrival};
332 112 ▶ $self->{arrival_delay} //= 0;
Condition50%1/2
$self->{"arrival_delay"} //= 0
l!l
0112
MC/DC0%0/1
$self->{"arrival_delay"} //= 0
$self->{"arrival_delay"}
Truth table50%1/2
A
A= $self->{"arrival_delay"}
Aresult
11
00
333 112 ▶ $self->{delay} //= 0;
Condition50%1/2
$self->{"delay"} //= 0
l!l
0112
MC/DC0%0/1
$self->{"delay"} //= 0
$self->{"delay"}
Truth table50%1/2
A
A= $self->{"delay"}
Aresult
11
00
334 }
335  
336 760 ▶ if ( $attrib{platform} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attrib{'platform'}) { } 14 746 760
337 14 $self->{platform} = $attrib{platform};
338 }
339 else {
340 746 $self->{platform} = $self->{sched_platform};
341 }
342  
343 760 ▶ if ( defined $attrib{route_pre} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $attrib{'route_pre'}) { } 190 570 760
344 190 ▶ $self->{route_pre} = [ split( qr{[|]}, $attrib{route_pre} // q{} ) ];
Condition50%1/2
$attrib{"route_pre"} // ""
l!l
1900
MC/DC0%0/1
$attrib{"route_pre"} // ""
$attrib{"route_pre"}
Truth table50%1/2
A
A= $attrib{"route_pre"}
Aresult
11
00
345 190 $self->fixup_route( $self->{route_pre} );
346 190 ▶ if ( @{ $self->{route_pre} } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->{"route_pre"};}) 144 46 190
347 144 $self->{route_start} = $self->{route_pre}[0];
348 }
349 }
350 else {
351 570 $self->{route_pre} = $self->{sched_route_pre};
352 570 $self->{route_start} = $self->{sched_route_start};
353 }
354  
355 # also only for unscheduled arrivals
356 760 ▶ if ( $attrib{sched_route_pre} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attrib{"sched_route_pre"}) 184 576 760
357 $self->{sched_route_pre}
358 184 ▶ = [ split( qr{[|]}, $attrib{sched_route_pre} // q{} ) ];
Condition50%1/2
$attrib{"sched_route_pre"} // ""
l!l
1840
MC/DC0%0/1
$attrib{"sched_route_pre"} // ""
$attrib{"sched_route_pre"}
Truth table50%1/2
A
A= $attrib{"sched_route_pre"}
Aresult
11
00
359 184 $self->fixup_route( $self->{sched_route_pre} );
360 184 $self->{sched_route_start} = $self->{sched_route_pre}[0];
361 }
362  
363 760 return $self;
364 }
365  
366 686 ▶sub set_dp {
Subroutine set_dp: called CC=17 SCAR=28.6
Pod undocumented
367 686 my ( $self, %attrib ) = @_;
368  
369 686 ▶ if ( $attrib{status} and $attrib{status} eq 'c' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($attrib{'status'} and $attrib{'status'} eq 'c') { } 53 633 686
elsif ($attrib{'status'} and $attrib{'status'} eq 'a') { } 0 633 633
Condition100%3/3
$attrib{"status"} and $attrib{"status"} eq "c"
!ll&&!rl&&r
6023153
MC/DC100%2/2
$attrib{"status"} and $attrib{"status"} eq "c"
$attrib{"status"} $attrib{"status"} eq "c"
Truth table100%3/3
A and B
A= $attrib{"status"}B= $attrib{"status"} eq "c"
ABresult
0X0
100
111
370 53 $self->{has_realtime} = $self->{arrival_has_realtime} = 1;
371 53 $self->{departure_is_cancelled} = 1;
372 }
373 ▶ elsif ( $attrib{status} and $attrib{status} eq 'a' ) {
Condition66%2/3
$attrib{"status"} and $attrib{"status"} eq "a"
!ll&&!rl&&r
602310
MC/DC0%0/2
$attrib{"status"} and $attrib{"status"} eq "a"
$attrib{"status"} $attrib{"status"} eq "a"
Truth table66%2/3
A and B
A= $attrib{"status"}B= $attrib{"status"} eq "a"
ABresult
0X0
100
111
374 0 $self->{departure_is_additional} = 1;
375 }
376 else {
377 633 $self->{departure_is_additional} = 0;
378 633 $self->{departure_is_cancelled} = 0;
379 }
380  
381 686 ▶ if ( $attrib{departure_hidden} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attrib{"departure_hidden"}) 0 686 686
382 0 $self->{departure_hidden} = $attrib{departure_hidden};
383 }
384  
385 # unscheduled arrivals may not appear in the plan, but we do need to
386 # know their planned arrival time
387 686 ▶ if ( $attrib{plan_departure_ts} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attrib{"plan_departure_ts"}) 176 510 686
388 $self->{sched_departure}
389 176 = $self->parse_ts( $attrib{plan_departure_ts} );
390 }
391  
392 686 ▶ if ( $attrib{departure_ts} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attrib{'departure_ts'}) { } 572 114 686
393 572 $self->{has_realtime} = $self->{departure_has_realtime} = 1;
394 572 $self->{departure} = $self->parse_ts( $attrib{departure_ts} );
395 572 ▶ if ( not $self->{departure_is_cancelled} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"departure_is_cancelled"}) 564 8 572
396 $self->{delay} = $self->{departure_delay}
397 564 = $self->departure->subtract_datetime( $self->sched_departure )
398 ->in_units('minutes');
399 }
400 }
401 else {
402 114 $self->{departure} = $self->{sched_departure};
403 114 ▶ $self->{delay} //= 0;
Condition100%2/2
$self->{"delay"} //= 0
l!l
10212
MC/DC100%1/1
$self->{"delay"} //= 0
$self->{"delay"}
Truth table100%2/2
A
A= $self->{"delay"}
Aresult
11
00
404 114 ▶ $self->{departure_delay} //= 0;
Condition50%1/2
$self->{"departure_delay"} //= 0
l!l
0114
MC/DC0%0/1
$self->{"departure_delay"} //= 0
$self->{"departure_delay"}
Truth table50%1/2
A
A= $self->{"departure_delay"}
Aresult
11
00
405 }
406  
407 686 ▶ if ( $attrib{platform} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attrib{'platform'}) { } 7 679 686
408 7 $self->{platform} = $attrib{platform};
409 }
410 else {
411 679 $self->{platform} = $self->{sched_platform};
412 }
413  
414 686 ▶ if ( defined $attrib{route_post} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $attrib{'route_post'}) { } 182 504 686
415 182 ▶ $self->{route_post} = [ split( qr{[|]}, $attrib{route_post} // q{} ) ];
Condition50%1/2
$attrib{"route_post"} // ""
l!l
1820
MC/DC0%0/1
$attrib{"route_post"} // ""
$attrib{"route_post"}
Truth table50%1/2
A
A= $attrib{"route_post"}
Aresult
11
00
416 182 $self->fixup_route( $self->{route_post} );
417 182 ▶ if ( @{ $self->{route_post} } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->{"route_post"};}) 137 45 182
418 137 $self->{route_end} = $self->{route_post}[-1];
419 }
420 }
421 else {
422 504 $self->{route_post} = $self->{sched_route_post};
423 504 $self->{route_end} = $self->{sched_route_end};
424 }
425  
426 # also only for unscheduled departures
427 686 ▶ if ( $attrib{sched_route_post} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attrib{"sched_route_post"}) 176 510 686
428 $self->{sched_route_post}
429 176 ▶ = [ split( qr{[|]}, $attrib{sched_route_post} // q{} ) ];
Condition50%1/2
$attrib{"sched_route_post"} // ""
l!l
1760
MC/DC0%0/1
$attrib{"sched_route_post"} // ""
$attrib{"sched_route_post"}
Truth table50%1/2
A
A= $attrib{"sched_route_post"}
Aresult
11
00
430 176 $self->fixup_route( $self->{sched_route_post} );
431 176 $self->{sched_route_end} = $self->{sched_route_post}[-1];
432 }
433  
434 686 return $self;
435 }
436  
437 827 ▶sub set_messages {
Subroutine set_messages: called CC=1 SCAR=0.0
Pod undocumented
438 827 my ( $self, %messages ) = @_;
439  
440 827 $self->{messages} = \%messages;
441  
442 827 return $self;
443 }
444  
445 827 ▶sub set_realtime {
Subroutine set_realtime: called CC=1 SCAR=0.0
Pod undocumented
446 827 my ( $self, $xmlobj ) = @_;
447  
448 827 $self->{realtime_xml} = $xmlobj;
449  
450 827 return $self;
451 }
452  
453 1 ▶sub add_raw_ref {
Subroutine add_raw_ref: called CC=1 SCAR=0.0
Pod undocumented
454 1 my ( $self, %attrib ) = @_;
455  
456 1 push( @{ $self->{refs} }, \%attrib );
457  
458 1 return $self;
459 }
460  
461 121 ▶sub set_unscheduled {
Subroutine set_unscheduled: called CC=1 SCAR=0.0
Pod undocumented
462 121 my ( $self, $unscheduled ) = @_;
463  
464 121 $self->{is_unscheduled} = $unscheduled;
465  
466 121 return $self;
467 }
468  
469 14 ▶sub add_arrival_wingref {
Subroutine add_arrival_wingref: called CC=1 SCAR=0.0
Pod undocumented
470 14 my ( $self, $ref ) = @_;
471  
472 14 my $backref = $self;
473  
474 14 weaken($ref);
475 14 weaken($backref);
476 14 $ref->{is_wing} = 1;
477 14 $ref->{wing_of} = $backref;
478 14 push( @{ $self->{arrival_wings} }, $ref );
479 14 return $self;
480 }
481  
482 8 ▶sub add_departure_wingref {
Subroutine add_departure_wingref: called CC=1 SCAR=0.0
Pod undocumented
483 8 my ( $self, $ref ) = @_;
484  
485 8 my $backref = $self;
486  
487 8 weaken($ref);
488 8 weaken($backref);
489 8 $ref->{is_wing} = 1;
490 8 $ref->{wing_of} = $backref;
491 8 push( @{ $self->{departure_wings} }, $ref );
492 8 return $self;
493 }
494  
495 0 ▶sub add_reference {
Subroutine add_reference: not called CC=1 SCAR=6.9
Pod undocumented
496 0 my ( $self, $ref ) = @_;
497  
498 0 $ref->add_inverse_reference($self);
499 0 weaken($ref);
500 0 push( @{ $self->{replacement_for} }, $ref );
501 0 return $self;
502 }
503  
504 10 ▶sub merge_with_departure {
Subroutine merge_with_departure: called CC=2 SCAR=6.9
Pod undocumented
505 10 my ( $self, $result ) = @_;
506  
507 # result must be departure-only
508  
509 10 $self->{is_transfer} = 1;
510  
511 10 $self->{old_train_id} = $self->{train_id};
512 10 $self->{old_train_no} = $self->{train_no};
513  
514 # departure is preferred over arrival, so overwrite default values
515 10 $self->{date} = $result->{date};
516 10 $self->{time} = $result->{time};
517 10 $self->{epoch} = $result->{epoch};
518 10 $self->{datetime} = $result->{datetime};
519 10 $self->{train_id} = $result->{train_id};
520 10 $self->{train_no} = $result->{train_no};
521  
522 10 $self->{departure} = $result->{departure};
523 10 $self->{departure_wings} = $result->{departure_wings};
524 10 $self->{route_end} = $result->{route_end};
525 10 $self->{route_post} = $result->{route_post};
526 10 $self->{sched_departure} = $result->{sched_departure};
527 10 $self->{sched_route_post} = $result->{sched_route_post};
528  
529 # update realtime info only if applicable
530 10 ▶ $self->{is_cancelled} ||= $result->{is_cancelled};
Condition33%1/3
$self->{"is_cancelled"} ||= $result->{"is_cancelled"}
l!l&&r!l&&!r
0010
MC/DC0%0/2
$self->{"is_cancelled"} ||= $result->{"is_cancelled"}
$self->{"is_cancelled"} $result->{"is_cancelled"}
Truth table33%1/3
A ||= B
A= $self->{"is_cancelled"}B= $result->{"is_cancelled"}
ABresult
1X1
011
000
531  
532 10 return $self;
533 }
534  
535 0 ▶sub add_inverse_reference {
Subroutine add_inverse_reference: not called CC=1 SCAR=6.9
Pod undocumented
536 0 my ( $self, $ref ) = @_;
537  
538 0 weaken($ref);
539 0 push( @{ $self->{replaced_by} }, $ref );
540 0 return $self;
541 }
542  
543 # }}}
544 # {{{ Public Accessors
545  
546 0 ▶sub is_additional {
Subroutine is_additional: not called CC=7 SCAR=40.3
Pod documented
547 0 my ($self) = @_;
548  
549 0 ▶ if ( $self->{arrival_is_additional} and $self->{departure_is_additional} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"arrival_is_additional"} and $self->{"departure_is_additional"}) 0 0 0
Condition0%0/3
$self->{"arrival_is_additional"} and $self->{"departure_is_additional"}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"arrival_is_additional"} and $self->{"departure_is_additional"}
$self->{"arrival_is_additional"} $self->{"departure_is_additional"}
Truth table0%0/3
A and B
A= $self->{"arrival_is_additional"}B= $self->{"departure_is_additional"}
ABresult
0X0
100
111
550 0 return 1;
551 }
552 0 ▶ if ( $self->{arrival_is_additional}
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"arrival_is_additional"} and not defined $self->{"departure_is_additional"}) 0 0 0
Condition0%0/3
$self->{"arrival_is_additional"} and not defined $self->{"departure_is_additional"}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"arrival_is_additional"} and not defined $self->{"departure_is_additional"}
$self->{"arrival_is_additional"} not defined $self->{"departure_is_additional"}
Truth table0%0/3
A and not(B)
A= $self->{"arrival_is_additional"}B= not defined $self->{"departure_is_additional"}
ABresult
0X0
100
111
553 and not defined $self->{departure_is_additional} )
554 {
555 0 return 1;
556 }
557 0 ▶ if ( not defined $self->{arrival_is_additional}
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $self->{"arrival_is_additional"} and $self->{"departure_is_additional"}) 0 0 0
Condition0%0/3
not defined $self->{"arrival_is_additional"} and $self->{"departure_is_additional"}
!ll&&!rl&&r
000
MC/DC0%0/2
not defined $self->{"arrival_is_additional"} and $self->{"departure_is_additional"}
not defined $self->{"arrival_is_additional"} $self->{"departure_is_additional"}
Truth table0%0/3
not(A) and B
A= not defined $self->{"arrival_is_additional"}B= $self->{"departure_is_additional"}
ABresult
0X0
100
111
558 and $self->{departure_is_additional} )
559 {
560 0 return 1;
561 }
562 0 return 0;
563 }
564  
565 2 ▶sub is_cancelled {
Subroutine is_cancelled: called CC=7 SCAR=23.0
Pod documented
566 2 my ($self) = @_;
567  
568 2 ▶ if ( $self->{arrival_is_cancelled} and $self->{departure_is_cancelled} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"arrival_is_cancelled"} and $self->{"departure_is_cancelled"}) 1 1 2
Condition66%2/3
$self->{"arrival_is_cancelled"} and $self->{"departure_is_cancelled"}
!ll&&!rl&&r
101
MC/DC50%1/2
$self->{"arrival_is_cancelled"} and $self->{"departure_is_cancelled"}
$self->{"arrival_is_cancelled"} $self->{"departure_is_cancelled"}
Truth table66%2/3
A and B
A= $self->{"arrival_is_cancelled"}B= $self->{"departure_is_cancelled"}
ABresult
0X0
100
111
569 1 return 1;
570 }
571 1 ▶ if ( $self->{arrival_is_cancelled}
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"arrival_is_cancelled"} and not defined $self->{"departure_is_cancelled"}) 0 1 1
Condition33%1/3
$self->{"arrival_is_cancelled"} and not defined $self->{"departure_is_cancelled"}
!ll&&!rl&&r
100
MC/DC0%0/2
$self->{"arrival_is_cancelled"} and not defined $self->{"departure_is_cancelled"}
$self->{"arrival_is_cancelled"} not defined $self->{"departure_is_cancelled"}
Truth table33%1/3
A and not(B)
A= $self->{"arrival_is_cancelled"}B= not defined $self->{"departure_is_cancelled"}
ABresult
0X0
100
111
572 and not defined $self->{departure_is_cancelled} )
573 {
574 0 return 1;
575 }
576 1 ▶ if ( not defined $self->{arrival_is_cancelled}
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $self->{"arrival_is_cancelled"} and $self->{"departure_is_cancelled"}) 0 1 1
Condition33%1/3
not defined $self->{"arrival_is_cancelled"} and $self->{"departure_is_cancelled"}
!ll&&!rl&&r
100
MC/DC0%0/2
not defined $self->{"arrival_is_cancelled"} and $self->{"departure_is_cancelled"}
not defined $self->{"arrival_is_cancelled"} $self->{"departure_is_cancelled"}
Truth table33%1/3
not(A) and B
A= not defined $self->{"arrival_is_cancelled"}B= $self->{"departure_is_cancelled"}
ABresult
0X0
100
111
577 and $self->{departure_is_cancelled} )
578 {
579 0 return 1;
580 }
581 1 return 0;
582 }
583  
584 0 ▶sub additional_stops {
Subroutine additional_stops: not called CC=2 SCAR=17.9
Pod documented
585 0 my ($self) = @_;
586  
587 $self->{comparator} //= List::Compare->new(
588 {
589 0 ▶ lists => [ $self->{sched_route_post}, $self->{route_post} ],
Condition0%0/3
$self->{"comparator"} //= "List::Compare"->new({"lists", [$self->{"sched_route_post"}, $self->{"route_post"}], "unsorted", 1})
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"comparator"} //= "List::Compare"->new({"lists", [$self->{"sched_route_post"}, $self->{"route_post"}], "unsorted", 1})
$self->{"comparator"} "List::Compare"->new({"lists", [$self->{"sched_route_post"}, $self->{"route_post"}], "unsorted", 1})
Truth table0%0/3
A //= B
A= $self->{"comparator"}B= "List::Compare"->new({"lists", [$self->{"sched_route_post"}, $self->{"route_post"}], "unsorted", 1})
ABresult
1X1
011
000
590 unsorted => 1,
591 }
592 );
593  
594 return $self->sorted_sublist( $self->{route_post},
595 0 [ $self->{comparator}->get_complement ] );
596 }
597  
598 0 ▶sub canceled_stops {
Subroutine canceled_stops: not called CC=2 SCAR=17.9
Pod documented
599 0 my ($self) = @_;
600  
601 $self->{comparator} //= List::Compare->new(
602 {
603 0 ▶ lists => [ $self->{sched_route_post}, $self->{route_post} ],
Condition0%0/3
$self->{"comparator"} //= "List::Compare"->new({"lists", [$self->{"sched_route_post"}, $self->{"route_post"}], "unsorted", 1})
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"comparator"} //= "List::Compare"->new({"lists", [$self->{"sched_route_post"}, $self->{"route_post"}], "unsorted", 1})
$self->{"comparator"} "List::Compare"->new({"lists", [$self->{"sched_route_post"}, $self->{"route_post"}], "unsorted", 1})
Truth table0%0/3
A //= B
A= $self->{"comparator"}B= "List::Compare"->new({"lists", [$self->{"sched_route_post"}, $self->{"route_post"}], "unsorted", 1})
ABresult
1X1
011
000
604 unsorted => 1,
605 }
606 );
607  
608 return $self->sorted_sublist( $self->{sched_route_post},
609 0 [ $self->{comparator}->get_unique ] );
610 }
611  
612 1 ▶sub classes {
Subroutine classes: called CC=2 SCAR=7.1
Pod documented
613 1 my ($self) = @_;
614  
615 1 ▶ my @classes = split( //, $self->{classes} // q{} );
Condition50%1/2
$self->{"classes"} // ""
l!l
10
MC/DC0%0/1
$self->{"classes"} // ""
$self->{"classes"}
Truth table50%1/2
A
A= $self->{"classes"}
Aresult
11
00
616  
617 1 return @classes;
618 }
619  
620 134 ▶sub origin {
Subroutine origin: called CC=1 SCAR=0.0
Pod documented
621 134 my ($self) = @_;
622  
623 134 return $self->route_start;
624 }
625  
626 134 ▶sub destination {
Subroutine destination: called CC=1 SCAR=0.0
Pod documented
627 134 my ($self) = @_;
628  
629 134 return $self->route_end;
630 }
631  
632 1 ▶sub delay_messages {
Subroutine delay_messages: called CC=3 SCAR=11.0
Pod documented
633 1 my ($self) = @_;
634  
635 1 my @keys = sort keys %{ $self->{messages} };
636 1 my @msgs = grep { $_->[1] eq 'd' } map { $self->{messages}{$_} } @keys;
637 1 my @msgids = uniq( map { $_->[2] } @msgs );
638 1 my @ret;
639  
640 1 for my $id (@msgids) {
641 2 for my $superseded ( $self->superseded_messages($id) ) {
642 0 @ret = grep { not( $_->[2] == $superseded ) } @ret;
643 }
644 2 ▶ my $msg = lastval { $_->[2] == $id } @msgs;
Subroutine __ANON__: called CC=1 SCAR=0.0
645 2 push( @ret, $msg );
646 }
647  
648 @ret = reverse
649 1 map { [ $self->parse_ts( $_->[0] ), $self->translate_msg( $_->[2] ) ] }
650 @ret;
651  
652 1 return @ret;
653 }
654  
655 4 ▶sub arrival_wings {
Subroutine arrival_wings: called CC=2 SCAR=6.9
Pod documented
656 4 my ($self) = @_;
657  
658 4 ▶ if ( $self->{arrival_wings} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"arrival_wings"}) 2 2 4
659 2 return @{ $self->{arrival_wings} };
660 }
661 2 return;
662 }
663  
664 6 ▶sub departure_wings {
Subroutine departure_wings: called CC=2 SCAR=6.9
Pod documented
665 6 my ($self) = @_;
666  
667 6 ▶ if ( $self->{departure_wings} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"departure_wings"}) 4 2 6
668 4 return @{ $self->{departure_wings} };
669 }
670 2 return;
671 }
672  
673 0 ▶sub replaced_by {
Subroutine replaced_by: not called CC=2 SCAR=17.9
Pod documented
674 0 my ($self) = @_;
675  
676 0 ▶ if ( $self->{replaced_by} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"replaced_by"}) 0 0 0
677 0 return @{ $self->{replaced_by} };
678 }
679 0 return;
680 }
681  
682 0 ▶sub replacement_for {
Subroutine replacement_for: not called CC=2 SCAR=17.9
Pod documented
683 0 my ($self) = @_;
684  
685 0 ▶ if ( $self->{replacement_for} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"replacement_for"}) 0 0 0
686 0 return @{ $self->{replacement_for} };
687 }
688 0 return;
689 }
690  
691 1 ▶sub qos_messages {
Subroutine qos_messages: called CC=6 SCAR=19.5
Pod documented
692 1 my ($self) = @_;
693  
694 1 my @keys = sort keys %{ $self->{messages} };
695 my @msgs
696 1 = grep { $_->[1] =~ m{^[fq]$} } map { $self->{messages}{$_} } @keys;
697 1 my @ret;
698  
699 1 for my $msg (@msgs) {
700 1 for my $superseded ( $self->superseded_messages( $msg->[2] ) ) {
701 0 @ret = grep { not( $_->[2] == $superseded ) } @ret;
702 }
703 0 @ret = grep { $_->[2] != $msg->[2] } @ret;
704  
705 # 88 is "no qos shortcomings" and only required to cancel previous qos
706 # messages. Same for 84 ("correct wagon order") and 89 ("reservations
707 # display is working again").
708 1 ▶ if ( $msg->[2] != 84 and $msg->[2] != 88 and $msg->[2] != 89 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($msg->[2] != 84 and $msg->[2] != 88 and $msg->[2] != 89) 1 0 1
Condition33%2/6
$msg->[2] != 84 and $msg->[2] != 88 and $msg->[2] != 89
!ll&&!rl&&r
001
$msg->[2] != 84 and $msg->[2] != 88
!ll&&!rl&&r
001
MC/DC0%0/3
$msg->[2] != 84 and $msg->[2] != 88 and $msg->[2] != 89
$msg->[2] != 84 $msg->[2] != 88 $msg->[2] != 89
Truth table25%1/4
A and B and C
A= $msg->[2] != 84B= $msg->[2] != 88C= $msg->[2] != 89
ABCresult
0XX0
10X0
1100
1111
709 1 push( @ret, $msg );
710 }
711 }
712  
713 @ret
714 1 = map { [ $self->parse_ts( $_->[0] ), $self->translate_msg( $_->[2] ) ] }
715 reverse @ret;
716  
717 1 return @ret;
718 }
719  
720 0 ▶sub raw_messages {
Subroutine raw_messages: not called CC=1 SCAR=6.9
Pod undocumented
721 0 my ($self) = @_;
722  
723 0 my @messages = reverse sort keys %{ $self->{messages} };
724 my @ret = map {
725 0 [
726 $self->parse_ts( $self->{messages}->{$_}->[0] ),
727 0 $self->{messages}->{$_}->[2]
728 ]
729 } @messages;
730  
731 0 return @ret;
732 }
733  
734 1 ▶sub messages {
Subroutine messages: called CC=3 SCAR=11.2
Pod documented
735 1 my ($self) = @_;
736  
737 1 my @messages = reverse sort keys %{ $self->{messages} };
738 my @ret = map {
739 1 [
740 $self->parse_ts( $self->{messages}{$_}[0] ),
741 $self->translate_msg(
742 $self->{messages}{$_}[2],
743 $self->{messages}{$_}[1]
744 ),
745 $_,
746 $self->{messages}{$_}[3]
747 ? $self->parse_ts( $self->{messages}{$_}[3] )
748 : undef,
749 $self->{messages}{$_}[4]
750 8 ▶ ? $self->parse_ts( $self->{messages}{$_}[4] )
Branch: 2 branches
BranchTrueFalseTotal
$self->{'messages'}{$_}[3] ? : 0 8 8
$self->{'messages'}{$_}[4] ? : 0 8 8
751 : undef,
752 ]
753 } @messages;
754  
755 1 return @ret;
756 }
757  
758 1 ▶sub info {
Subroutine info: called CC=1 SCAR=0.0
Pod documented
759 1 my ($self) = @_;
760  
761 1 my @messages = sort keys %{ $self->{messages} };
762 1 my @ids = uniq( map { $self->{messages}{$_}->[2] } @messages );
763  
764 1 my @info = map { $self->translate_msg($_) } @ids;
765  
766 1 return @info;
767 }
768  
769 268 ▶sub line {
Subroutine line: called CC=4 SCAR=16.9
Pod documented
770 268 my ($self) = @_;
771  
772 return sprintf( '%s %s',
773 $self->{type} // 'Zug',
774 268 ▶ $self->{line_no} // $self->{train_no} // '-' );
Condition42%3/7
$self->{"type"} // "Zug"
l!l
2680
($self->{"line_no"} // $self->{"train_no"}) // "-"
l!l
2680
$self->{"line_no"} // $self->{"train_no"}
l!l&&r!l&&!r
02680
MC/DC0%0/1
$self->{"type"} // "Zug"
$self->{"type"}
MC/DC0%0/2
($self->{"line_no"} // $self->{"train_no"}) // "-"
$self->{"line_no"} $self->{"train_no"}
Truth table50%1/2
A
A= $self->{"type"}
Aresult
11
00
Truth table33%1/3
A // B
A= $self->{"line_no"}B= $self->{"train_no"}
ABresult
1X1
011
000
775 }
776  
777 4 ▶sub route_pre {
Subroutine route_pre: called CC=1 SCAR=0.0
Pod documented
778 4 my ($self) = @_;
779  
780 4 return @{ $self->{route_pre} };
781 }
782  
783 8 ▶sub route_post {
Subroutine route_post: called CC=1 SCAR=0.0
Pod documented
784 8 my ($self) = @_;
785  
786 8 return @{ $self->{route_post} };
787 }
788  
789 2 ▶sub route {
Subroutine route: called CC=1 SCAR=0.0
Pod documented
790 2 my ($self) = @_;
791  
792 2 return ( $self->route_pre, $self->{station}, $self->route_post );
793 }
794  
795 134 ▶sub train {
Subroutine train: called CC=1 SCAR=0.0
Pod documented
796 134 my ($self) = @_;
797  
798 134 return $self->line;
799 }
800  
801 4 ▶sub route_interesting {
Subroutine route_interesting: called CC=19 SCAR=29.9
Pod documented
802 4 my ( $self, $max_parts ) = @_;
803  
804 4 my @via = $self->route_post;
805 4 my ( @via_main, @via_show, $last_stop );
806 4 ▶ $max_parts //= 3;
Condition50%1/2
$max_parts //= 3
l!l
04
MC/DC0%0/1
$max_parts //= 3
$max_parts
Truth table50%1/2
A
A= $max_parts
Aresult
11
00
807  
808 # Centraal: dutch main station (Hbf in .nl)
809 # HB: swiss main station (Hbf in .ch)
810 # hl.n.: czech main station (Hbf in .cz)
811 4 for my $stop (@via) {
812 16 ▶ if ( $stop =~ m{ HB $ | hl\.n\. $ | Hbf | Centraal | Flughafen }x ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($stop =~ / HB $ | hl\.n\. $ | Hbf | Centraal | Flughafen /ux) 9 7 16
813 9 push( @via_main, $stop );
814 }
815 }
816 $last_stop
817 4 ▶ = $self->{route_post_incomplete} ? $self->{route_end} : pop(@via);
Branch: 1 branch
BranchTrueFalseTotal
$self->{'route_post_incomplete'} ? : 4 0 4
818  
819 4 ▶ if ( @via_main and $via_main[-1] eq $last_stop ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@via_main and $via_main[-1] eq $last_stop) 2 2 4
Condition100%3/3
@via_main and $via_main[-1] eq $last_stop
!ll&&!rl&&r
112
MC/DC100%2/2
@via_main and $via_main[-1] eq $last_stop
@via_main $via_main[-1] eq $last_stop
Truth table100%3/3
A and B
A= @via_mainB= $via_main[-1] eq $last_stop
ABresult
0X0
100
111
820 2 pop(@via_main);
821 }
822 4 ▶ if ( @via and $via[-1] eq $last_stop ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@via and $via[-1] eq $last_stop) 3 1 4
Condition66%2/3
@via and $via[-1] eq $last_stop
!ll&&!rl&&r
103
MC/DC50%1/2
@via and $via[-1] eq $last_stop
@via $via[-1] eq $last_stop
Truth table66%2/3
A and B
A= @viaB= $via[-1] eq $last_stop
ABresult
0X0
100
111
823 3 pop(@via);
824 }
825  
826 4 ▶ if ( @via_main and @via and $via[0] eq $via_main[0] ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@via_main and @via and $via[0] eq $via_main[0]) 1 3 4
Condition83%5/6
@via_main and @via and $via[0] eq $via_main[0]
!ll&&!rl&&r
211
@via_main and @via
!ll&&!rl&&r
202
MC/DC66%2/3
@via_main and @via and $via[0] eq $via_main[0]
@via_main @via $via[0] eq $via_main[0]
Truth table75%3/4
A and B and C
A= @via_mainB= @viaC= $via[0] eq $via_main[0]
ABCresult
0XX0
10X0
1100
1111
827 1 shift(@via_main);
828 }
829  
830 4 ▶ if ( @via < $max_parts ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@via < $max_parts) { } 2 2 4
831 2 @via_show = @via;
832 }
833 else {
834 2 ▶ if ( @via_main >= $max_parts ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@via_main >= $max_parts) { } 1 1 2
835 1 @via_show = ( $via[0] );
836 }
837 else {
838 1 @via_show = splice( @via, 0, $max_parts - @via_main );
839 }
840  
841 2 ▶ while ( @via_show < $max_parts and @via_main ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@via_show < $max_parts and @via_main) 4 2 6
Condition66%2/3
@via_show < $max_parts and @via_main
!ll&&!rl&&r
204
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
842 4 my $stop = shift(@via_main);
843 4 ▶ if ( any { $stop eq $_ } @via_show or $stop eq $last_stop ) {
Subroutine __ANON__: called CC=1 SCAR=0.8
Branch: 1 branch
BranchTrueFalseTotal
if (&any(sub { $stop eq $_; } , @via_show) or $stop eq $last_stop) 0 4 4
Condition33%1/3
&any(sub { $stop eq $_; } , @via_show) or $stop eq $last_stop
l!l&&r!l&&!r
004
MC/DC0%0/2
&any(sub { $stop eq $_; } , @via_show) or $stop eq $last_stop
&any(sub { $stop eq $_; } , @via_show) $stop eq $last_stop
Truth table33%1/3
A or B
A= &any(sub { $stop eq $_; } , @via_show)B= $stop eq $last_stop
ABresult
1X1
011
000
844 0 next;
845 }
846 4 push( @via_show, $stop );
847 }
848 }
849  
850 4 for (@via_show) {
851 6 s{ \s? Hbf .* }{}x;
852 }
853  
854 4 return @via_show;
855  
856 }
857  
858 2 ▶sub sched_route_pre {
Subroutine sched_route_pre: called CC=1 SCAR=0.0
Pod documented
859 2 my ($self) = @_;
860  
861 2 return @{ $self->{sched_route_pre} };
862 }
863  
864 2 ▶sub sched_route_post {
Subroutine sched_route_post: called CC=1 SCAR=0.0
Pod documented
865 2 my ($self) = @_;
866  
867 2 return @{ $self->{sched_route_post} };
868 }
869  
870 1 ▶sub sched_route {
Subroutine sched_route: called CC=1 SCAR=0.0
Pod documented
871 1 my ($self) = @_;
872  
873 return ( $self->sched_route_pre, $self->{station},
874 1 $self->sched_route_post );
875 }
876  
877 14 ▶sub translate_msg {
Subroutine translate_msg: called CC=4 SCAR=15.6
Pod undocumented
878 14 my ( $self, $msg, $type ) = @_;
879  
880 14 ▶ if ( $type and $type eq 'h' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type and $type eq "h") 0 14 14
Condition66%2/3
$type and $type eq "h"
!ll&&!rl&&r
680
MC/DC0%0/2
$type and $type eq "h"
$type $type eq "h"
Truth table66%2/3
A and B
A= $typeB= $type eq "h"
ABresult
0X0
100
111
881 0 return $msg;
882 }
883 14 ▶ return $translation{$msg} // "?($msg)";
Condition50%1/2
$translation{$msg} // "?($msg)"
l!l
140
MC/DC0%0/1
$translation{$msg} // "?($msg)"
$translation{$msg}
Truth table50%1/2
A
A= $translation{$msg}
Aresult
11
00
884 }
885  
886 0 ▶sub TO_JSON {
Subroutine TO_JSON: not called CC=7 SCAR=40.3
Pod undocumented
887 0 my ($self) = @_;
888  
889 0 my %copy = %{$self};
890 0 delete $copy{realtime_xml};
891 0 delete $copy{strptime_obj};
892  
893 0 for my $ref_key (
894 qw(arrival_wings departure_wings replaced_by replacement_for))
895 {
896 0 delete $copy{$ref_key};
897 0 ▶ for my $train_ref ( @{ $self->{$ref_key} // [] } ) {
Condition0%0/2
$self->{$ref_key} // []
l!l
00
MC/DC0%0/1
$self->{$ref_key} // []
$self->{$ref_key}
Truth table0%0/2
A
A= $self->{$ref_key}
Aresult
11
00
898 push(
899 0 @{ $copy{$ref_key} },
900 {
901 raw_id => $train_ref->raw_id,
902 train => $train_ref->train,
903 train_no => $train_ref->train_no,
904 type => $train_ref->type,
905 }
906 );
907 }
908 }
909  
910 0 delete $copy{wing_of};
911 0 ▶ if ( my $train_ref = $self->wing_of ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $train_ref = $self->wing_of) 0 0 0
912 $copy{wing_of} = {
913 0 raw_id => $train_ref->raw_id,
914 train => $train_ref->train,
915 train_no => $train_ref->train_no,
916 type => $train_ref->type,
917 };
918 }
919  
920 0 for my $datetime_key (
921 qw(arrival departure sched_arrival sched_departure start datetime))
922 {
923 0 ▶ if ( defined $copy{$datetime_key} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $copy{$datetime_key}) 0 0 0
924 0 $copy{$datetime_key} = $copy{$datetime_key}->epoch;
925 }
926 }
927  
928 0 return {%copy};
929 }
930  
931 # }}}
932  
933 7 1;
934  
935 __END__
« IRIS.pm ↑ Summary IRIS/Stations.pm »