From d6b7c4e95788bc59fe99111066245dd4da75ef78 Mon Sep 17 00:00:00 2001 From: Birte Kristina Friesel Date: Fri, 1 Sep 2023 07:18:49 +0200 Subject: do not use the now-deprecated smartmatch feature Closes #14 --- bin/efa | 39 ++++++++++++++++++++------------ lib/Travel/Routing/DE/EFA.pm | 54 ++++++++++++++++++++++---------------------- lib/Travel/Routing/DE/VRR.pm | 2 -- 3 files changed, 51 insertions(+), 44 deletions(-) diff --git a/bin/efa b/bin/efa index a92cec7..258fc11 100755 --- a/bin/efa +++ b/bin/efa @@ -4,15 +4,13 @@ use warnings; use 5.010; use utf8; -no if $] >= 5.018, warnings => 'experimental::smartmatch'; - use utf8; use Encode qw(decode); use Travel::Routing::DE::EFA; use Exception::Class; use Getopt::Long qw/:config no_ignore_case/; -use List::Util qw(first); +use List::Util qw(first); our $VERSION = '2.21'; my $ignore_info; @@ -49,7 +47,7 @@ sub new_efa_by_url { origin => [ @from, $from_type ], destination => [ @to, $to_type ], - via => ( @via ? [ @via, $via_type ] : undef ), + via => ( @via ? [ @via, $via_type ] : undef ), arrival_time => $opt->{arrive}, departure_time => $opt->{depart}, @@ -340,14 +338,23 @@ if ( $opt->{exclude} ) { @{ $opt->{exclude} } = split( qr{,}, join( q{,}, @{ $opt->{exclude} } ) ); } +my %accessibility_map = ( + s => 'without_solid_stairs', + 'no-stairs' => 'without_solid_stairs', + e => 'without_escalators', + 'no-escalators' => 'without_escalators', + E => 'without_elevators', + 'no-elevators' => 'without_elevators', + l => 'with_low_platform', + nf => 'with_low_platform', + 'low-platform' => 'with_low_platform', + w => 'with_wheelchair', + wheelchair => 'with_wheelchair', +); + for my $field ( @{ $opt->{accessibility} } ) { - given ($field) { - when ( [qw[s no-stairs]] ) { $opt->{without_solid_stairs} = 1 } - when ( [qw[e no-escalators]] ) { $opt->{without_escalators} = 1 } - when ( [qw[E no-elevators]] ) { $opt->{without_elevators} = 1 } - when ( [qw[l nf low-platform]] ) { $opt->{with_low_platform} = 1 } - when ( [qw[w wheelchair]] ) { $opt->{with_wheelchair} = 1 } - when ( [qw[i info]] ) { } # used for ignore_info default + if ( $accessibility_map{$field} ) { + $opt->{ $accessibility_map{$field} } = 1; } } @@ -405,16 +412,18 @@ for my $pair ( [ \@from, \$from_type ], [ \@via, \$via_type ], {$+{target}}x ) { - given ( $+{type} ) { - when ('addr') { ${ $pair->[1] } = 'address' } - default { ${ $pair->[1] } = $+{type} } + if ( $+{type} eq 'addr' ) { + ${ $pair->[1] } = 'address'; + } + else { + ${ $pair->[1] } = $+{type}; } } } if ( $opt->{service} ) { my $service = first { lc( $_->{shortname} ) eq lc( $opt->{service} ) } - Travel::Routing::DE::EFA::get_efa_urls(); + Travel::Routing::DE::EFA::get_efa_urls(); if ( not $service ) { printf STDERR ( "Error: Unknown service '%s'. See 'efa -l' for a " diff --git a/lib/Travel/Routing/DE/EFA.pm b/lib/Travel/Routing/DE/EFA.pm index b13545a..11daa12 100644 --- a/lib/Travel/Routing/DE/EFA.pm +++ b/lib/Travel/Routing/DE/EFA.pm @@ -5,8 +5,6 @@ use warnings; use 5.010; use utf8; -no if $] >= 5.018, warnings => "experimental::smartmatch"; - use Carp qw(cluck); use Encode qw(encode); use Travel::Routing::DE::EFA::Route; @@ -176,17 +174,19 @@ sub number_of_trips { sub select_interchange_by { my ( $self, $prefer ) = @_; - given ($prefer) { - when ('speed') { $self->{post}->{routeType} = 'LEASTTIME' } - when ('waittime') { $self->{post}->{routeType} = 'LEASTINTERCHANGE' } - when ('distance') { $self->{post}->{routeType} = 'LEASTWALKING' } - default { - Travel::Routing::DE::EFA::Exception::Setup->throw( - option => 'select_interchange_by', - have => $prefer, - want => 'speed / waittime / distance', - ); - } + if ( $prefer eq 'speed' ) { $self->{post}->{routeType} = 'LEASTTIME' } + elsif ( $prefer eq 'waittime' ) { + $self->{post}->{routeType} = 'LEASTINTERCHANGE'; + } + elsif ( $prefer eq 'distance' ) { + $self->{post}->{routeType} = 'LEASTWALKING'; + } + else { + Travel::Routing::DE::EFA::Exception::Setup->throw( + option => 'select_interchange_by', + have => $prefer, + want => 'speed / waittime / distance', + ); } return; @@ -195,17 +195,15 @@ sub select_interchange_by { sub train_type { my ( $self, $include ) = @_; - given ($include) { - when ('local') { $self->{post}->{lineRestriction} = 403 } - when ('ic') { $self->{post}->{lineRestriction} = 401 } - when ('ice') { $self->{post}->{lineRestriction} = 400 } - default { - Travel::Routing::DE::EFA::Exception::Setup->throw( - option => 'train_type', - have => $include, - want => 'local / ic / ice', - ); - } + if ( $include eq 'local' ) { $self->{post}->{lineRestriction} = 403 } + elsif ( $include eq 'ic' ) { $self->{post}->{lineRestriction} = 401 } + elsif ( $include eq 'ice' ) { $self->{post}->{lineRestriction} = 400 } + else { + Travel::Routing::DE::EFA::Exception::Setup->throw( + option => 'train_type', + have => $include, + want => 'local / ic / ice', + ); } return; @@ -229,7 +227,7 @@ sub use_near_stops { sub walk_speed { my ( $self, $walk_speed ) = @_; - if ( $walk_speed ~~ [ 'normal', 'fast', 'slow' ] ) { + if ( $walk_speed =~ m{ ^ (?: normal | fast | slow ) $ }x ) { $self->{post}->{changeSpeed} = $walk_speed; } else { @@ -305,7 +303,7 @@ sub place { @{ $self->{post} }{ "place_${which}", "name_${which}" } = ( $place, $stop ); - if ( $type ~~ [qw[address poi stop]] ) { + if ( $type =~ m{ ^ (?: address | poi | stop ) $ }x ) { $self->{post}->{"type_${which}"} = $type; } @@ -728,7 +726,9 @@ sub parse_xml_part { my $name = $ve->getAttribute('name'); my $platform = $ve->getAttribute('platformName'); - if ( $name ~~ [ $hash->{departure_stop}, $hash->{arrival_stop} ] ) { + if ( $name eq $hash->{departure_stop} + or $name eq $hash->{arrival_stop} ) + { next; } diff --git a/lib/Travel/Routing/DE/VRR.pm b/lib/Travel/Routing/DE/VRR.pm index e13522f..1c2f771 100644 --- a/lib/Travel/Routing/DE/VRR.pm +++ b/lib/Travel/Routing/DE/VRR.pm @@ -4,8 +4,6 @@ use strict; use warnings; use 5.010; -no if $] >= 5.018, warnings => "experimental::smartmatch"; - our $VERSION = '2.21'; use parent 'Travel::Routing::DE::EFA'; -- cgit v1.2.3