diff options
| author | Birte Kristina Friesel <derf@finalrewind.org> | 2026-01-04 19:23:47 +0100 |
|---|---|---|
| committer | Birte Kristina Friesel <derf@finalrewind.org> | 2026-01-04 19:23:47 +0100 |
| commit | c2bf7522f26718f8977c6810ccea74de4eb4f37f (patch) | |
| tree | 88d5c0c1dd8f35f654d7b8697b0c1add7187720c | |
| parent | b9e67e40e07be9f1bcfa1e30e36f07cb9f9f85ca (diff) | |
Carriage: handle undefined values
| -rw-r--r-- | lib/Travel/Status/DE/DBRIS/Formation/Carriage.pm | 29 |
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 3308efa..ab35906 100644 --- a/lib/Travel/Status/DE/DBRIS/Formation/Carriage.pm +++ b/lib/Travel/Status/DE/DBRIS/Formation/Carriage.pm @@ -83,14 +83,16 @@ sub new { $ref->{has_first_class} = $json{type}{hasFirstClass}; $ref->{has_second_class} = $json{type}{hasEconomyClass}; - if ( $ref->{type} =~ m{AB} ) { - $ref->{class_type} = 12; - } - elsif ( $ref->{type} =~ m{A} ) { - $ref->{class_type} = 1; - } - elsif ( $ref->{type} =~ m{B|WR} ) { - $ref->{class_type} = 2; + if ( $ref->{type} ) { + if ( $ref->{type} =~ m{AB} ) { + $ref->{class_type} = 12; + } + elsif ( $ref->{type} =~ m{A} ) { + $ref->{class_type} = 1; + } + elsif ( $ref->{type} =~ m{B|WR} ) { + $ref->{class_type} = 2; + } } my $pos = $json{platformPosition}; @@ -147,6 +149,11 @@ sub parse_type { my $type = $self->{type}; my @desc; + if ( not $type ) { + $self->{attributes} = []; + return; + } + if ( $type =~ m{^D} ) { $self->{is_dosto} = 1; push( @desc, 'Doppelstock' ); @@ -201,6 +208,9 @@ sub parse_type { sub is_first_class { my ($self) = @_; + if ( not defined $self->{type} ) { + return; + } if ( $self->{type} =~ m{^D?A} ) { return 1; } @@ -210,6 +220,9 @@ sub is_first_class { sub is_second_class { my ($self) = @_; + if ( not defined $self->{type} ) { + return; + } if ( $self->{type} =~ m{^D?A?B} ) { return 1; } |
