-
Birte Kristina Friesel authoredBirte Kristina Friesel authored
efa 9.14 KiB
#!/usr/bin/env perl
## Copyright © 2009,2010 by Daniel Friesel <derf@finalrewind.org>
## License: WTFPL <http://sam.zoy.org/wtfpl>
## 0. You just DO WHAT THE FUCK YOU WANT TO.
use strict;
use warnings;
use 5.010;
no if $] >= 5.018, warnings => "experimental::smartmatch";
use utf8;
use Encode qw(decode);
use Travel::Routing::DE::VRR;
use Exception::Class;
use Getopt::Long qw/:config no_ignore_case/;
our $VERSION = '2.03';
my $ignore_info = 'Fahrradmitnahme';
my $efa;
my ( @from, @to, @via, $from_type, $to_type, $via_type );
my $opt = {
'help' => sub { show_help(0) },
'ignore-info' => \$ignore_info,
'from' => \@from,
'to' => \@to,
'version' => sub { say "efa version $VERSION"; exit 0 },
'via' => \@via,
};
binmode( STDOUT, ':encoding(utf-8)' );
binmode( STDERR, ':encoding(utf-8)' );
sub show_help {
my ($exit_status) = @_;
say 'Usage: efa [options] <from-city> <from-stop> <to-city> <to-stop>';
say 'See also: man efa';
exit $exit_status;
}
sub handle_efa_exception {
my ($e) = @_;
if ( $e->isa('Travel::Routing::DE::VRR::Exception::Setup') ) {
if ( $e->message ) {
printf STDERR (
"Error: %s (option '%s'): %s\n",
$e->description, $e->option, $e->message
);
}
else {
printf STDERR (
"Error: %s (option '%s', got '%s', want '%s')\n",
$e->description, $e->option, $e->have, $e->want
);
}
exit 1;
}
if ( $e->isa('Travel::Routing::DE::VRR::Exception::Net') ) {
printf STDERR ( "Error: %s: %s\n", $e->description,
$e->http_response->as_string );
exit 2;
}
if ( $e->isa('Travel::Routing::DE::VRR::Exception::NoData') ) {
printf STDERR ( 'Error: %s', $e->description );
exit 3;
}