Travel-Status-MOTIS
view release on metacpan or search on metacpan
lib/Travel/Status/MOTIS.pm view on Meta::CPAN
}
sub results {
my ($self) = @_;
return @{ $self->{results} };
}
sub result {
my ($self) = @_;
return $self->{result};
}
# static
sub get_services {
my @services;
for my $service ( sort keys %{$motis_instance} ) {
my %desc = %{ $motis_instance->{$service} };
$desc{shortname} = $service;
push( @services, \%desc );
}
return @services;
}
# static
sub get_service {
my ($service) = @_;
if ( defined $service and exists $motis_instance->{$service} ) {
return $motis_instance->{$service};
}
return;
}
# }}}
1;
__END__
=head1 NAME
Travel::Status::MOTIS - An interface to the MOTIS routing service
=head1 SYNOPSIS
Blocking variant:
use Travel::Status::MOTIS;
my $status = Travel::Status::MOTIS->new(
service => 'RNV',
stop_id => 'rnv_241721',
);
for my $result ($status->results) {
printf(
"%s +%-3d %10s -> %s\n",
$result->stopover->departure->strftime('%H:%M'),
$result->stopover->delay,
$result->route_name,
$result->headsign,
);
}
Non-blocking variant;
use Mojo::Promise;
use Mojo::UserAgent;
use Travel::Status::MOTIS;
Travel::Status::MOTIS->new_p(
service => 'RNV',
stop_id => 'rnv_241721',
promise => 'Mojo::Promise',
user_agent => Mojo::UserAgent->new
)->then(sub {
my ($status) = @_;
for my $result ($status->results) {
printf(
"%s +%-3d %10s -> %s\n",
$result->stopover->departure->strftime('%H:%M'),
$result->stopover->delay,
$result->route_name,
$result->headsign,
);
}
})->wait;
=head1 VERSION
version 0.03
=head1 DESCRIPTION
Travel::Status::MOTIS is an interface to the departures and trips
provided by MOTIS routing services
=head1 METHODS
=over
=item my $status = Travel::Status::MOTIS->new(I<%opt>)
Requests item(s) as specified by I<opt> and returns a new
Travel::Status::MOTIS element with the results. Dies if the wrong
I<opt> were passed.
I<opt> must contain exactly one of the following keys:
=over
=item B<stop_id> => I<$stop_id>
Request stop board (departures) for the stop specified by I<$stop_id>.
Use B<stops_by_coordinate> or B<stops_by_query> to obtain a stop id.
Results are available via C<< $status->results >>.
=item B<stops_by_coordinate> => B<{> B<lat> => I<latitude>, B<lon> => I<longitude> B<}>
Search for stops near I<latitude>, I<longitude>.
Results are available via C<< $status->results >>.
=item B<stops_by_query> => I<$query>
Search for stops whose name is equal or similar to I<query>. Results are
available via C<< $status->results >> and include the stop id needed for
stop board requests.
=item B<trip_id> => I<$trip_id>
Request trip details for I<$trip_id>.
The result is available via C<< $status->result >>.
=back
The following optional keys may be set.
Values in brackets indicate keys that are only relevant in certain request
modes, e.g. stops_by_coordinate or stop_id.
=over
=item B<cache> => I<$obj>
A Cache::File(3pm) object used to cache realtime data requests. It should be
( run in 1.535 second using v1.01-cache-2.11-cpan-6de40a662fe )