From 1b2bd0dc355d3e5f265a112380d076b9db7c3e81 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Wed, 11 Dec 2013 00:13:48 +0100 Subject: initial commit --- .gitignore | 10 ++ Build.PL | 29 ++++ COPYING | 4 + bin/aseag-m | 172 ++++++++++++++++++++++++ lib/Travel/Status/DE/ASEAG.pm | 249 +++++++++++++++++++++++++++++++++++ lib/Travel/Status/DE/ASEAG/Result.pm | 141 ++++++++++++++++++++ 6 files changed, 605 insertions(+) create mode 100644 .gitignore create mode 100644 Build.PL create mode 100644 COPYING create mode 100755 bin/aseag-m create mode 100644 lib/Travel/Status/DE/ASEAG.pm create mode 100644 lib/Travel/Status/DE/ASEAG/Result.pm diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..189304f --- /dev/null +++ b/.gitignore @@ -0,0 +1,10 @@ +/_build +/Build +/blib +/cover_db +/MANIFEST +/MANIFEST.bak +/MANIFEST.SKIP +/MANIFEST.SKIP.bak +/MYMETA.yml +/MYMETA.json diff --git a/Build.PL b/Build.PL new file mode 100644 index 0000000..19e5e59 --- /dev/null +++ b/Build.PL @@ -0,0 +1,29 @@ +#!/usr/bin/env perl + +use strict; +use warnings; +use Module::Build; + +Module::Build->new( + + build_requires => { + 'File::Slurp' => 0, + 'Test::More' => 0, + 'Test::Pod' => 0, + }, + configure_requires => { + 'Module::Build' => 0.40, + }, + module_name => 'Travel::Status::DE::ASEAG', + license => 'perl', + requires => { + 'perl' => '5.10.1', + 'Carp' => 0, + 'Class::Accessor' => 0, + 'Getopt::Long' => 0, + 'List::Util' => 0, + 'LWP::UserAgent' => 0, + }, + sign => 1, + +)->create_build_script(); diff --git a/COPYING b/COPYING new file mode 100644 index 0000000..15afa80 --- /dev/null +++ b/COPYING @@ -0,0 +1,4 @@ +Copyright (C) 2013 Daniel Friesel + +All files in this distribution are licensed under the same terms as Perl +itself. diff --git a/bin/aseag-m b/bin/aseag-m new file mode 100755 index 0000000..70eaeb9 --- /dev/null +++ b/bin/aseag-m @@ -0,0 +1,172 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use 5.010; + +no if $] >= 5.018, warnings => "experimental::smartmatch"; + +our $VERSION = '0.00'; + +binmode( STDOUT, ':encoding(utf-8)' ); + +use Getopt::Long qw(:config no_ignore_case); +use List::Util qw(max); +use Travel::Status::DE::ASEAG; + +my ( @grep_lines ); + +GetOptions( + 'h|help' => sub { show_help(0) }, + 'l|line=s@' => \@grep_lines, + 'V|version' => \&show_version, + +) or show_help(1); + +if ( @ARGV != 1 ) { + show_help(1); +} + +# --line=foo,bar support +@grep_lines = split( qr{,}, join( q{,}, @grep_lines ) ); + +my ( $stop_name ) = @ARGV; + +my $status = Travel::Status::DE::ASEAG->new( + name => $stop_name, +); + +sub show_help { + my ($code) = @_; + + print "Usage: aseag-m \n" + . "See also: man aseag-m\n"; + + exit $code; +} + +sub show_version { + say "aseag-m version ${VERSION}"; + + exit 0; +} + +sub display_result { + my (@lines) = @_; + + my @line_length; + + if ( not @lines ) { + die("Nothing to show\n"); + } + + for my $i ( 0 .. 2 ) { + $line_length[$i] = max map { length( $_->[$i] ) } @lines; + } + + for my $line (@lines) { + + printf( + join( q{ }, ( map { "%-${_}s" } @line_length ) ) . "\n", + @{$line}[ 0 .. 2 ] + ); + } + + return; +} + +sub show_results { + my @output; + + for my $d ( $status->results ) { + + my $dtime = $d->time; + + if ( + ( @grep_lines and not( $d->line ~~ \@grep_lines ) ) + ) + { + next; + } + + push( @output, + [ $dtime, $d->line, $d->destination ] ); + } + + display_result(@output); + + return; +} + +if ( my $err = $status->errstr ) { + say STDERR "Request error: ${err}"; + exit 2; +} + +show_results(); + +__END__ + +=head1 NAME + +efa-m - Unofficial interface to the efa.vrr.de departure monitor + +=head1 SYNOPSIS + +B [B<-d> I] [B<-t> I