summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorBirte Kristina Friesel <derf@finalrewind.org>2025-12-21 10:28:34 +0100
committerBirte Kristina Friesel <derf@finalrewind.org>2025-12-21 10:28:34 +0100
commitd6417395491a4025ab3346a4318d8a67a2ad5db4 (patch)
treea98050c000d23d4d09c6f232e7ef49af46aacaa7 /lib
parent959dd718de340bff4fbdd70f2d0e008ea0cc91df (diff)
Carriage: pos / length accessors: fix uninitialized value warnings
Diffstat (limited to 'lib')
-rw-r--r--lib/Travel/Status/DE/DBRIS/Formation/Carriage.pm29
1 files changed, 21 insertions, 8 deletions
diff --git a/lib/Travel/Status/DE/DBRIS/Formation/Carriage.pm b/lib/Travel/Status/DE/DBRIS/Formation/Carriage.pm
index 1024aab..f4f602d 100644
--- a/lib/Travel/Status/DE/DBRIS/Formation/Carriage.pm
+++ b/lib/Travel/Status/DE/DBRIS/Formation/Carriage.pm
@@ -95,22 +95,35 @@ sub new {
$ref->{start_meters} = $pos->{start};
$ref->{end_meters} = $pos->{end};
- $ref->{start_percent}
- = ( $pos->{start} - $platform->{start} ) * 100 / $platform_length;
- $ref->{end_percent}
- = ( $pos->{end} - $platform->{start} ) * 100 / $platform_length;
- if ( defined $pos->{start} and defined $pos->{end} ) {
- $ref->{length_meters} = $pos->{start} - $pos->{end};
+ if ( defined $pos->{start}
+ and defined $platform->{start}
+ and $platform_length )
+ {
+ $ref->{start_percent}
+ = ( $pos->{start} - $platform->{start} ) * 100 / $platform_length;
+ }
+ if ( defined $pos->{end}
+ and defined $platform->{start}
+ and $platform_length )
+ {
+ $ref->{end_percent}
+ = ( $pos->{end} - $platform->{start} ) * 100 / $platform_length;
}
- $ref->{length_percent} = $ref->{end_percent} - $ref->{start_percent};
- if ( $pos->{start} eq ''
+ if ( not defined $pos->{start}
+ or not defined $pos->{end}
+ or $pos->{start} eq ''
or $pos->{end} eq '' )
{
$ref->{position}{valid} = 0;
}
else {
$ref->{position}{valid} = 1;
+ $ref->{length_meters} = $pos->{start} - $pos->{end};
+ }
+
+ if ( defined $ref->{start_percent} and defined $ref->{end_percent} ) {
+ $ref->{length_percent} = $ref->{end_percent} - $ref->{start_percent};
}
return $self;