summaryrefslogtreecommitdiff
path: root/lib/Travel/Status/DE/IRIS.pm
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2015-11-05 17:04:43 +0100
committerDaniel Friesel <derf@finalrewind.org>2015-11-05 17:04:43 +0100
commit8d6c6d5aa8000fe753810085d56a34e156be503b (patch)
treec052946c5111493bbd173056f790ec1ed11f9db1 /lib/Travel/Status/DE/IRIS.pm
parent7a24a7d8168639e8e6a6c0f17429681dbdc2aed7 (diff)
move get_station into separate method to prepare for recurvise fetching
Diffstat (limited to 'lib/Travel/Status/DE/IRIS.pm')
-rw-r--r--lib/Travel/Status/DE/IRIS.pm62
1 files changed, 41 insertions, 21 deletions
diff --git a/lib/Travel/Status/DE/IRIS.pm b/lib/Travel/Status/DE/IRIS.pm
index f9300f0..c8c3c8b 100644
--- a/lib/Travel/Status/DE/IRIS.pm
+++ b/lib/Travel/Status/DE/IRIS.pm
@@ -43,31 +43,16 @@ sub new {
$ua->env_proxy;
- my $res_st = $ua->get( $self->{iris_base} . '/station/' . $opt{station} );
-
- if ( $res_st->is_error ) {
- $self->{errstr}
- = 'Failed to fetch station data: ' . $res_st->status_line;
- return $self;
- }
-
- my $xml_st = XML::LibXML->load_xml( string => $res_st->decoded_content );
-
- my $station_node = ( $xml_st->findnodes('//station') )[0];
-
- # TODO parse 'meta' and maybe 'p' flags
- # They're optional pointers to related platforms. For instance
- # Berlin Hbf/BL -> Berlin HBf (tief), Berlin Hbf (S), ...
+ my ($station_code, $station_name, @related) = $self->get_station(
+ name => $opt{station},
+ );
- if ( not $station_node ) {
- $self->{errstr}
- = "The station '$opt{station}' has no associated timetable";
+ if ($self->{errstr}) {
return $self;
}
- $self->{station} = $opt{station};
- $self->{station_code} = $station_node->getAttribute('eva');
- $self->{station_name} = $station_node->getAttribute('name');
+ $self->{station_code} = $station_code;
+ $self->{station_name} = $station_name;
my $dt_req = $self->{datetime}->clone;
for ( 1 .. 3 ) {
@@ -116,6 +101,35 @@ sub new {
return $self;
}
+sub get_station {
+ my ($self, %opt) = @_;
+
+ my $ua = $self->{user_agent};
+ my $res_st = $ua->get( $self->{iris_base} . '/station/' . $opt{name} );
+
+ if ( $res_st->is_error ) {
+ $self->{errstr}
+ = 'Failed to fetch station data: ' . $res_st->status_line;
+ return $self;
+ }
+
+ my $xml_st = XML::LibXML->load_xml( string => $res_st->decoded_content );
+
+ my $station_node = ( $xml_st->findnodes('//station') )[0];
+
+ # TODO parse 'meta' and maybe 'p' flags
+ # They're optional pointers to related platforms. For instance
+ # Berlin Hbf/BL -> Berlin HBf (tief), Berlin Hbf (S), ...
+
+ if ( not $station_node ) {
+ $self->{errstr}
+ = "The station '$opt{name}' has no associated timetable";
+ return;
+ }
+
+ return ($station_node->getAttribute('eva'), $station_node->getAttribute('name'));
+}
+
sub add_result {
my ( $self, $station, $s ) = @_;
@@ -367,6 +381,12 @@ sub create_replacement_refs {
}
}
+sub station_code {
+ my ($self) = @_;
+
+ return $self->{station_code};
+}
+
sub errstr {
my ($self) = @_;