From c5c197f16c7d77ef4e1592ceb19116c71f319791 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Fri, 28 Jan 2022 20:27:03 +0100 Subject: IRIS: refactor ahead of promises support --- lib/Travel/Status/DE/IRIS.pm | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) (limited to 'lib') diff --git a/lib/Travel/Status/DE/IRIS.pm b/lib/Travel/Status/DE/IRIS.pm index 9aef5a2..f46cb2b 100644 --- a/lib/Travel/Status/DE/IRIS.pm +++ b/lib/Travel/Status/DE/IRIS.pm @@ -65,6 +65,15 @@ sub new { bless( $self, $class ); + my $lookahead_steps = int( $self->{lookahead} / 60 ); + if ( ( 60 - $self->{datetime}->minute ) < ( $self->{lookahead} % 60 ) ) { + $lookahead_steps++; + } + my $lookbehind_steps = int( $self->{lookbehind} / 60 ); + if ( $self->{datetime}->minute < ( $self->{lookbehind} % 60 ) ) { + $lookbehind_steps++; + } + if ( not $self->{user_agent} ) { my %lwp_options = %{ $opt{lwp_options} // { timeout => 10 } }; $self->{user_agent} = LWP::UserAgent->new(%lwp_options); @@ -110,15 +119,6 @@ sub new { return $self; } - my $lookahead_steps = int( $self->{lookahead} / 60 ); - if ( ( 60 - $self->{datetime}->minute ) < ( $self->{lookahead} % 60 ) ) { - $lookahead_steps++; - } - my $lookbehind_steps = int( $self->{lookbehind} / 60 ); - if ( $self->{datetime}->minute < ( $self->{lookbehind} % 60 ) ) { - $lookbehind_steps++; - } - my $dt_req = $self->{datetime}->clone; $self->get_timetable( $self->{station}{uic}, $dt_req ); for ( 1 .. $lookahead_steps ) { @@ -133,6 +133,13 @@ sub new { $self->get_realtime; + $self->postprocess_results; + + return $self; +} + +sub postprocess_results { + my ($self) = @_; if ( not $self->{keep_transfers} ) { # tra (transfer?) indicates a train changing its ID, so there are two @@ -173,8 +180,6 @@ sub new { # same goes for replacement refs (the tag in the fchg document) $self->create_replacement_refs; - - return $self; } sub get_with_cache { -- cgit v1.2.3