Skip to content

Commit

Permalink
do not use the now-deprecated smartmatch feature
Browse files Browse the repository at this point in the history
Closes #14
  • Loading branch information
derf committed Sep 1, 2023
1 parent 5da08b1 commit d6b7c4e
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 44 deletions.
39 changes: 24 additions & 15 deletions bin/efa
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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},
Expand Down Expand Up @@ -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;
}
}

Expand Down Expand Up @@ -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 "
Expand Down
54 changes: 27 additions & 27 deletions lib/Travel/Routing/DE/EFA.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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 {
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down
2 changes: 0 additions & 2 deletions lib/Travel/Routing/DE/VRR.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down

0 comments on commit d6b7c4e

Please sign in to comment.