From daa96ebfbec57578e3538fd81eaf2be941a2297f Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Sat, 25 Jul 2015 18:25:38 +0200 Subject: refactor efa object construction --- bin/efa | 100 ++++++++++++++++++++++++---------------------------------------- 1 file changed, 38 insertions(+), 62 deletions(-) (limited to 'bin') diff --git a/bin/efa b/bin/efa index 466ea61..4449970 100755 --- a/bin/efa +++ b/bin/efa @@ -43,6 +43,42 @@ sub show_help { exit $exit_status; } +sub new_efa_by_url { + my ($url) = @_; + my $res = eval { + Travel::Routing::DE::EFA->new( + efa_url => $url, + + origin => [ @from, $from_type ], + destination => [ @to, $to_type ], + via => ( @via ? [ @via, $via_type ] : undef ), + + arrival_time => $opt->{arrive}, + departure_time => $opt->{depart}, + date => $opt->{date}, + exclude => $opt->{exclude}, + train_type => $opt->{include}, + with_bike => $opt->{bike}, + + select_interchange_by => $opt->{prefer}, + use_near_stops => $opt->{proximity}, + walk_speed => $opt->{'walk-speed'}, + max_interchanges => $opt->{'max-change'}, + num_results => $opt->{'num-connections'}, + + without_solid_stairs => $opt->{without_solid_stairs}, + without_escalators => $opt->{without_escalators}, + without_elevators => $opt->{without_elevators}, + with_low_platform => $opt->{with_low_platform}, + with_wheelchair => $opt->{with_wheelchair}, + + developer_mode => $opt->{devmode}, + lwp_options => { timeout => $opt->{timeout} }, + ); + }; + return $res; +} + sub handle_efa_exception { my ($e) = @_; @@ -375,37 +411,7 @@ if ( $opt->{service} ) { if ( $opt->{discover} or $opt->{'auto-url'} ) { for my $service ( Travel::Routing::DE::EFA::get_efa_urls() ) { - $efa = eval { - Travel::Routing::DE::EFA->new( - efa_url => $service->{url}, - - origin => [ @from, $from_type ], - destination => [ @to, $to_type ], - via => ( @via ? [ @via, $via_type ] : undef ), - - arrival_time => $opt->{arrive}, - departure_time => $opt->{depart}, - date => $opt->{date}, - exclude => $opt->{exclude}, - train_type => $opt->{include}, - with_bike => $opt->{bike}, - - select_interchange_by => $opt->{prefer}, - use_near_stops => $opt->{proximity}, - walk_speed => $opt->{'walk-speed'}, - max_interchanges => $opt->{'max-change'}, - num_results => $opt->{'num-connections'}, - - without_solid_stairs => $opt->{without_solid_stairs}, - without_escalators => $opt->{without_escalators}, - without_elevators => $opt->{without_elevators}, - with_low_platform => $opt->{with_low_platform}, - with_wheelchair => $opt->{with_wheelchair}, - - developer_mode => $opt->{devmode}, - lwp_options => { timeout => $opt->{timeout} }, - ); - }; + $efa = new_efa_by_url( $service->{url} ); if ($efa) { if ( $opt->{'auto-url'} ) { last; @@ -422,37 +428,7 @@ if ( $opt->{discover} or $opt->{'auto-url'} ) { } } else { - $efa = eval { - Travel::Routing::DE::EFA->new( - efa_url => $efa_url, - - origin => [ @from, $from_type ], - destination => [ @to, $to_type ], - via => ( @via ? [ @via, $via_type ] : undef ), - - arrival_time => $opt->{arrive}, - departure_time => $opt->{depart}, - date => $opt->{date}, - exclude => $opt->{exclude}, - train_type => $opt->{include}, - with_bike => $opt->{bike}, - - select_interchange_by => $opt->{prefer}, - use_near_stops => $opt->{proximity}, - walk_speed => $opt->{'walk-speed'}, - max_interchanges => $opt->{'max-change'}, - num_results => $opt->{'num-connections'}, - - without_solid_stairs => $opt->{without_solid_stairs}, - without_escalators => $opt->{without_escalators}, - without_elevators => $opt->{without_elevators}, - with_low_platform => $opt->{with_low_platform}, - with_wheelchair => $opt->{with_wheelchair}, - - developer_mode => $opt->{devmode}, - lwp_options => { timeout => $opt->{timeout} }, - ); - }; + $efa = new_efa_by_url($efa_url); } check_for_error($@); -- cgit v1.2.3