diff options
author | Derf Null <derf@finalrewind.org> | 2023-04-10 15:12:33 +0200 |
---|---|---|
committer | Derf Null <derf@finalrewind.org> | 2023-04-10 15:12:33 +0200 |
commit | 15753db3b5af50ca441547f46a5a2e8d6fa86eb8 (patch) | |
tree | 66f33a79eaa6fda80ecdc58f8ab57b0ad415c9ee /lib/Travel/Status/DE | |
parent | 8ff409f67697cdb706dc7eaaa1c1bfc029ce1a04 (diff) |
Use separate Stop class for geoSearch stops
Diffstat (limited to 'lib/Travel/Status/DE')
-rw-r--r-- | lib/Travel/Status/DE/HAFAS.pm | 30 | ||||
-rw-r--r-- | lib/Travel/Status/DE/HAFAS/Stop.pm | 128 |
2 files changed, 132 insertions, 26 deletions
diff --git a/lib/Travel/Status/DE/HAFAS.pm b/lib/Travel/Status/DE/HAFAS.pm index 9bf33f1..0ea8859 100644 --- a/lib/Travel/Status/DE/HAFAS.pm +++ b/lib/Travel/Status/DE/HAFAS.pm @@ -20,6 +20,7 @@ use Travel::Status::DE::HAFAS::Message; use Travel::Status::DE::HAFAS::Polyline qw(decode_polyline); use Travel::Status::DE::HAFAS::Journey; use Travel::Status::DE::HAFAS::StopFinder; +use Travel::Status::DE::HAFAS::Stop; our $VERSION = '4.08'; @@ -627,14 +628,7 @@ sub parse_geosearch { for my $loc (@locL) { push( @{ $self->{results} }, - { - eva => 0 + $loc->{extId}, - name => $loc->{name}, - lat => $loc->{crd}{x} * 1e-6, - lon => $loc->{crd}{y} * 1e-6, - weight => $loc->{wt}, - distance_m => $loc->{dist}, - } + Travel::Status::DE::HAFAS::Stop->new( loc => $loc ) ); } @@ -1009,24 +1003,8 @@ describing it. If no error occurred, returns undef. =item $status->results (geoSearch) -Returns a list of stations. Each list element is a hash ref with the following -keys. - -=over - -=item * eva (identifier / EVA code) - -=item * name - -=item * lat (latitude) - -=item * lon (longitude) - -=item * distance_m (distance from requested coordinates, in meters) - -=item * weight (relevance / importance of result, unknown metric) - -=back +Returns a list of stations. Each list element is a +Travel::Status::DE::HAFAS::Stop(3pm) object. If no matching results were found or the parser / http request failed, returns an empty list. diff --git a/lib/Travel/Status/DE/HAFAS/Stop.pm b/lib/Travel/Status/DE/HAFAS/Stop.pm new file mode 100644 index 0000000..441c2a0 --- /dev/null +++ b/lib/Travel/Status/DE/HAFAS/Stop.pm @@ -0,0 +1,128 @@ +package Travel::Status::DE::HAFAS::Stop; + +# vim:foldmethod=marker + +use strict; +use warnings; +use 5.014; + +use parent 'Class::Accessor'; + +our $VERSION = '4.08'; + +Travel::Status::DE::HAFAS::Stop->mk_ro_accessors( + qw(eva name lat lon distance_m weight)); + +# {{{ Constructor + +sub new { + my ( $obj, %opt ) = @_; + + my $loc = $opt{loc}; + my $ref = { + eva => 0 + $loc->{extId}, + name => $loc->{name}, + lat => $loc->{crd}{x} * 1e-6, + lon => $loc->{crd}{y} * 1e-6, + weight => $loc->{wt}, + distance_m => $loc->{dist}, + }; + + bless( $ref, $obj ); + + return $ref; +} + +# }}} + +1; + +__END__ + +=head1 NAME + +Travel::Status::DE::HAFAS::Stop - Information about a HAFAS stop. + +=head1 SYNOPSIS + + # in geoSearch mode + for my $stop ($status->results) { + printf( + "%5.1f km %8d %s\n", + $result->distance_m * 1e-3, + $result->eva, $result->name + ); + } + +=head1 VERSION + +version 4.08 + +=head1 DESCRIPTION + +Travel::Status::DE::HAFAS::Stop describes a HAFAS stop. It may be part of a +journey or part of a geoSearch request. + +geoSearch-specific accessors are annotated with "(geoSearch)" and return +undef for non-geoSearch stops. + +=head1 METHODS + +=head2 ACCESSORS + +=over + +=item $stop->name + +Stop name, e.g. "Essen Hbf" or "Unter den Linden/B75, Tostedt". + +=item $stop->eva + +EVA ID, e.g. 8000080. + +=item $stop->lat + +Stop latitude (WGS-84) + +=item $stop->lon + +Stop longitude (WGS-84) + +=item $stop->distance_m (geoSearch) + +Distance in meters between the requested coordinates and this stop. + +=item $stop->weight + +Weight / Relevance / Importance of this stop using an unknown metric. +Higher values indicate more relevant stops. + +=back + +=head1 DIAGNOSTICS + +None. + +=head1 DEPENDENCIES + +=over + +=item Class::Accessor(3pm) + +=back + +=head1 BUGS AND LIMITATIONS + +None known. + +=head1 SEE ALSO + +Travel::Status::DE::HAFAS(3pm). + +=head1 AUTHOR + +Copyright (C) 2023 by Birthe Friesel E<lt>derf@finalrewind.orgE<gt> + +=head1 LICENSE + +This module is licensed under the same terms as Perl itself. |