summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBirte Kristina Friesel <derf@finalrewind.org>2025-04-20 10:56:03 +0200
committerBirte Kristina Friesel <derf@finalrewind.org>2025-04-20 10:56:03 +0200
commit48c70c47cd2134f33d317a7921c55173ae303d38 (patch)
tree1e5d937168a013096994e47156fa12995090e19e
parent1a400b9d4894a0d403d2613f3d5e36d97a2e7851 (diff)
perltidy
-rwxr-xr-xbin/motis75
-rw-r--r--lib/Travel/Status/MOTIS.pm46
-rw-r--r--lib/Travel/Status/MOTIS/Services.pm.PL23
-rw-r--r--lib/Travel/Status/MOTIS/Stop.pm32
-rw-r--r--lib/Travel/Status/MOTIS/Stopover.pm82
-rw-r--r--lib/Travel/Status/MOTIS/Trip.pm104
-rw-r--r--lib/Travel/Status/MOTIS/TripAtStopover.pm55
7 files changed, 235 insertions, 182 deletions
diff --git a/bin/motis b/bin/motis
index f6d0ab1..8e8794a 100755
--- a/bin/motis
+++ b/bin/motis
@@ -25,8 +25,11 @@ my $cache;
my ( $list_services, $service );
my ( $json_output, $raw_json_output, $with_polyline );
-my %known_mode_of_transit = map { $_ => 1 }
- (qw(TRANSIT TRAM SUBWAY FERRY AIRPLANE BUS COACH RAIL METRO HIGHSPEED_RAIL LONG_DISTANCE NIGHT_RAIL REGIONAL_FAST_RAIL REGIONAL_RAIL));
+my %known_mode_of_transit
+ = map { $_ => 1 }
+ (
+ qw(TRANSIT TRAM SUBWAY FERRY AIRPLANE BUS COACH RAIL METRO HIGHSPEED_RAIL LONG_DISTANCE NIGHT_RAIL REGIONAL_FAST_RAIL REGIONAL_RAIL)
+ );
binmode( STDOUT, ':encoding(utf-8)' );
for my $arg (@ARGV) {
@@ -47,13 +50,13 @@ GetOptions(
'i|show-trip-ids' => \$show_trip_ids,
'm|modes-of-transit=s' => \$modes_of_transit,
't|time=s' => \$time,
- 's|service=s' => \$service,
+ 's|service=s' => \$service,
'V|version' => \&show_version,
'cache!' => \$use_cache,
'devmode' => \$developer_mode,
'json' => \$json_output,
'raw-json' => \$raw_json_output,
- 'list' => \$list_services,
+ 'list' => \$list_services,
) or show_help(1);
if ($list_services) {
@@ -65,8 +68,7 @@ if ($list_services) {
for my $service ( Travel::Status::MOTIS::get_services() ) {
printf(
"%-40s %-14s %-15s\n",
- $service->{name},
- $service->{shortname},
+ $service->{name}, $service->{shortname},
join( q{ }, @{ $service->{languages} // [] } ),
);
}
@@ -77,9 +79,10 @@ if ($list_services) {
$service //= 'transitous';
if ($use_cache) {
- my $cache_path = ( $ENV{XDG_CACHE_HOME} // "$ENV{HOME}/.cache" ) . '/Travel-Status-MOTIS';
+ my $cache_path = ( $ENV{XDG_CACHE_HOME} // "$ENV{HOME}/.cache" )
+ . '/Travel-Status-MOTIS';
- eval {
+ eval {
require Cache::File;
$cache = Cache::File->new(
@@ -94,7 +97,7 @@ if ($use_cache) {
}
}
-my ( $input ) = @ARGV;
+my ($input) = @ARGV;
if ( not $input ) {
show_help(1);
@@ -102,7 +105,7 @@ if ( not $input ) {
my %opt = (
cache => $cache,
- service => $service,
+ service => $service,
developer_mode => $developer_mode,
);
@@ -112,20 +115,23 @@ if ( $input =~ m{ ^ (?<lat> [0-9.]+ ) : (?<lon> [0-9].+ ) $ }x ) {
lon => $+{lon},
};
}
+
# Format: yyyymmdd_hh:mm_feed_id
elsif ( $input =~ m{^[0-9]{8}_[0-9]{2}:[0-9]{2}_} ) {
$opt{trip_id} = $input;
}
+
# Format: feed_id
elsif ( $input =~ m{_} ) {
$opt{stop_id} = $input;
}
else {
- $opt{stops_by_query} = $input;
+ $opt{stops_by_query} = $input;
my $status = Travel::Status::MOTIS->new(%opt);
if ( my $err = $status->errstr ) {
- say STDERR "Request error while looking up '$opt{stops_by_query}': ${err}";
+ say STDERR
+ "Request error while looking up '$opt{stops_by_query}': ${err}";
exit 2;
}
@@ -190,7 +196,8 @@ if ( $date or $time ) {
if ( $modes_of_transit and $modes_of_transit eq 'help' ) {
say "Supported modes of transmit (-m / --modes-of-transit):";
for my $mot (
- qw(TRANSIT TRAM SUBWAY FERRY AIRPLANE BUS COACH RAIL METRO HIGHSPEED_RAIL LONG_DISTANCE NIGHT_RAIL REGIONAL_FAST_RAIL REGIONAL_RAIL))
+ qw(TRANSIT TRAM SUBWAY FERRY AIRPLANE BUS COACH RAIL METRO HIGHSPEED_RAIL LONG_DISTANCE NIGHT_RAIL REGIONAL_FAST_RAIL REGIONAL_RAIL)
+ )
{
say $mot;
}
@@ -199,6 +206,7 @@ if ( $modes_of_transit and $modes_of_transit eq 'help' ) {
}
if ($modes_of_transit) {
+
# Passing unknown MOTs to the backend results in HTTP 422 Unprocessable Entity
my @mots = split( qr{, *}, $modes_of_transit );
@@ -274,31 +282,39 @@ if ($json_output) {
if ( $opt{stop_id} ) {
my $max_route_name = max map { length( $_->route_name ) } $status->results;
- my $max_headsign = max map { length( $_->headsign // q{} ) } $status->results;
- my $max_delay = max map { length( $_->stopover->departure_delay // q{} ) } $status->results;
- my $max_track = max map { length( $_->stopover->track // $_->stopover->scheduled_track // q{} ) } $status->results;
+ my $max_headsign
+ = max map { length( $_->headsign // q{} ) } $status->results;
+ my $max_delay = max map { length( $_->stopover->departure_delay // q{} ) }
+ $status->results;
+ my $max_track = max map {
+ length( $_->stopover->track // $_->stopover->scheduled_track // q{} )
+ } $status->results;
$max_delay += 1;
my @results = map { $_->[1] }
sort { $a->[0] <=> $b->[0] }
- map { [ ( $_->stopover->departure // $_->stopover->arrival )->epoch, $_ ] } $status->results;
+ map {
+ [ ( $_->stopover->departure // $_->stopover->arrival )->epoch, $_ ]
+ } $status->results;
- printf("%s\n\n", $results[0]->stopover->stop->name);
+ printf( "%s\n\n", $results[0]->stopover->stop->name );
for my $result (@results) {
printf(
"%s %s %${max_route_name}s %${max_headsign}s %${max_track}s\n",
- $result->is_cancelled ? '--:--' : $result->stopover->departure->strftime('%H:%M'),
- $result->stopover->departure_delay
- ? sprintf( "(%+${max_delay}d)", $result->stopover->departure_delay )
+ $result->is_cancelled ? '--:--'
+ : $result->stopover->departure->strftime('%H:%M'),
+ $result->stopover->departure_delay ? sprintf(
+ "(%+${max_delay}d)", $result->stopover->departure_delay
+ )
: q{ } x ( $max_delay + 2 ),
$result->route_name,
$result->headsign // q{???},
$result->stopover->track // q{}
);
- if ( $show_trip_ids ) {
+ if ($show_trip_ids) {
say $result->id;
}
}
@@ -308,7 +324,8 @@ elsif ( $opt{trip_id} ) {
my $max_name = max map { length( $_->stop->name ) } $trip->stopovers;
my $max_track = max map { length( $_->track // q{} ) } $trip->stopovers;
- my $max_delay = max map { $_->delay ? length( $_->delay ) + 3 : 0 } $trip->stopovers;
+ my $max_delay
+ = max map { $_->delay ? length( $_->delay ) + 3 : 0 } $trip->stopovers;
my $mark_stop = 0;
my $now = DateTime->now;
@@ -320,12 +337,14 @@ elsif ( $opt{trip_id} ) {
not $stop->is_cancelled
and ( $stop->departure and $now <= $stop->departure
or $stop->arrival and $now <= $stop->arrival )
- ) {
+ )
+ {
$mark_stop = $stop;
}
}
- printf( "%s am %s\n\n", $trip->route_name, $trip->scheduled_arrival->strftime('%d.%m.%Y') );
+ printf( "%s am %s\n\n",
+ $trip->route_name, $trip->scheduled_arrival->strftime('%d.%m.%Y') );
for my $stop ( $trip->stopovers ) {
if ( $stop == $mark_stop ) {
@@ -351,8 +370,10 @@ elsif ( $opt{trip_id} ) {
print(' ');
}
- printf( " %${max_delay}s", format_delay( $stop->delay, $max_delay - 3 ) );
- printf( " %-${max_name}s %${max_track}s\n", $stop->stop->name, $stop->track // q{} );
+ printf( " %${max_delay}s",
+ format_delay( $stop->delay, $max_delay - 3 ) );
+ printf( " %-${max_name}s %${max_track}s\n",
+ $stop->stop->name, $stop->track // q{} );
if ( $stop == $mark_stop ) {
print($output_reset);
diff --git a/lib/Travel/Status/MOTIS.pm b/lib/Travel/Status/MOTIS.pm
index 23cc55e..b2a8be2 100644
--- a/lib/Travel/Status/MOTIS.pm
+++ b/lib/Travel/Status/MOTIS.pm
@@ -48,9 +48,8 @@ sub new {
my $user_agent = $conf{user_agent};
if ( not $user_agent ) {
- $user_agent = LWP::UserAgent->new(%{
- $conf{lwp_options} // { timeout => 10 }
- });
+ $user_agent
+ = LWP::UserAgent->new( %{ $conf{lwp_options} // { timeout => 10 } } );
}
my $self = {
@@ -68,7 +67,7 @@ sub new {
if ( my $stop_id = $conf{stop_id} ) {
my $timestamp = $conf{timestamp} // DateTime->now;
- my @modes_of_transit = ( qw(TRANSIT) );
+ my @modes_of_transit = (qw(TRANSIT));
if ( $conf{modes_of_transit} ) {
@modes_of_transit = @{ $conf{modes_of_transit} // [] };
@@ -76,7 +75,7 @@ sub new {
$request_url->path('api/v1/stoptimes');
$request_url->query_form(
- time => DateTime::Format::ISO8601->format_datetime( $timestamp ),
+ time => DateTime::Format::ISO8601->format_datetime($timestamp),
stopId => $stop_id,
n => $conf{results} // 10,
mode => join( ',', @modes_of_transit ),
@@ -105,12 +104,15 @@ sub new {
);
}
else {
- confess('stop_id / trip_id / stops_by_coordinate / stops_by_query must be specified');
+ confess(
+'stop_id / trip_id / stops_by_coordinate / stops_by_query must be specified'
+ );
}
my $json = $self->{json} = JSON->new->utf8;
- $request_url = $request_url->abs( $motis_instance->{$service}{endpoint} )->as_string;
+ $request_url
+ = $request_url->abs( $motis_instance->{$service}{endpoint} )->as_string;
if ( $conf{async} ) {
$self->{request_url} = $request_url;
@@ -157,13 +159,15 @@ sub new_p {
my $promise = $conf{promise}->new;
- if (not($conf{stop_id}
- or $conf{trip_id}
- or $conf{stops_by_coordinate}
- or $conf{stops_by_query}
- )) {
+ if (
+ not( $conf{stop_id}
+ or $conf{trip_id}
+ or $conf{stops_by_coordinate}
+ or $conf{stops_by_query} )
+ )
+ {
return $promise->reject(
- 'stop_id / trip_id / stops_by_coordinate / stops_by_query flag must be passed'
+'stop_id / trip_id / stops_by_coordinate / stops_by_query flag must be passed'
);
}
@@ -277,7 +281,8 @@ sub get_with_cache_p {
sub {
my ($tx) = @_;
if ( my $err = $tx->error ) {
- $promise->reject("GET $url returned HTTP $err->{code} $err->{message}");
+ $promise->reject(
+ "GET $url returned HTTP $err->{code} $err->{message}");
return;
}
@@ -305,14 +310,17 @@ sub get_with_cache_p {
sub parse_trip {
my ( $self, %opt ) = @_;
- $self->{result} = Travel::Status::MOTIS::Trip->new( json => $self->{raw_json} );
+ $self->{result}
+ = Travel::Status::MOTIS::Trip->new( json => $self->{raw_json} );
}
sub parse_stops_by {
my ($self) = @_;
@{ $self->{results} } = map {
- $_->{type} eq 'STOP' ? Travel::Status::MOTIS::Stop->from_match( json => $_ ) : ()
+ $_->{type} eq 'STOP'
+ ? Travel::Status::MOTIS::Stop->from_match( json => $_ )
+ : ()
} @{ $self->{raw_json} // [] };
return $self;
@@ -321,9 +329,9 @@ sub parse_stops_by {
sub parse_trips_at_stopover {
my ($self) = @_;
- @{ $self->{results} } = map {
- Travel::Status::MOTIS::TripAtStopover->new( json => $_ )
- } @{ $self->{raw_json}{stopTimes} // [] };
+ @{ $self->{results} }
+ = map { Travel::Status::MOTIS::TripAtStopover->new( json => $_ ) }
+ @{ $self->{raw_json}{stopTimes} // [] };
return $self;
}
diff --git a/lib/Travel/Status/MOTIS/Services.pm.PL b/lib/Travel/Status/MOTIS/Services.pm.PL
index dc86963..8331b6c 100644
--- a/lib/Travel/Status/MOTIS/Services.pm.PL
+++ b/lib/Travel/Status/MOTIS/Services.pm.PL
@@ -14,14 +14,15 @@ my $json = JSON->new->utf8;
sub load_instance {
my ( $path, %opt ) = @_;
- my $data = $json->decode( scalar read_file("ext/transport-apis/data/${path}.json") );
+ my $data = $json->decode(
+ scalar read_file("ext/transport-apis/data/${path}.json") );
my %ret = (
- name => $data->{name} =~ s{ *[(][^)]+[)]}{}r,
- license => $data->{attribution}{license},
- homepage => $data->{attribution}{homepage},
- languages => $data->{supportedLanguages},
- endpoint => $data->{options}{endpoint},
- coverage => {
+ name => $data->{name} =~ s{ *[(][^)]+[)]}{}r,
+ license => $data->{attribution}{license},
+ homepage => $data->{attribution}{homepage},
+ languages => $data->{supportedLanguages},
+ endpoint => $data->{options}{endpoint},
+ coverage => {
area => $data->{coverage}{realtimeCoverage}{area},
regions => $data->{coverage}{realtimeCoverage}{region} // []
},
@@ -80,12 +81,8 @@ sub load_instance {
}
my %motis_instance = (
- RNV => {
- load_instance('de/rnv-motis')
- },
- transitous => {
- load_instance('un/transitous')
- },
+ RNV => { load_instance('de/rnv-motis') },
+ transitous => { load_instance('un/transitous') },
);
my $perlobj = Data::Dumper->new( [ \%motis_instance ], ['motis_instance'] );
diff --git a/lib/Travel/Status/MOTIS/Stop.pm b/lib/Travel/Status/MOTIS/Stop.pm
index 85348bf..9a11544 100644
--- a/lib/Travel/Status/MOTIS/Stop.pm
+++ b/lib/Travel/Status/MOTIS/Stop.pm
@@ -8,13 +8,15 @@ use parent 'Class::Accessor';
our $VERSION = '0.01';
-Travel::Status::MOTIS::Stop->mk_ro_accessors(qw(
- id
- name
- type
- lat
- lon
-));
+Travel::Status::MOTIS::Stop->mk_ro_accessors(
+ qw(
+ id
+ name
+ type
+ lat
+ lon
+ )
+);
sub from_match {
my ( $obj, %opt ) = @_;
@@ -22,10 +24,10 @@ sub from_match {
my $json = $opt{json};
my $ref = {
- id => $json->{id},
- name => $json->{name},
- lat => $json->{lat},
- lon => $json->{lon},
+ id => $json->{id},
+ name => $json->{name},
+ lat => $json->{lat},
+ lon => $json->{lon},
};
bless( $ref, $obj );
@@ -39,10 +41,10 @@ sub from_stopover {
my $json = $opt{json};
my $ref = {
- id => $json->{stopId},
- name => $json->{name},
- lat => $json->{lat},
- lon => $json->{lon},
+ id => $json->{stopId},
+ name => $json->{name},
+ lat => $json->{lat},
+ lon => $json->{lon},
};
bless( $ref, $obj );
diff --git a/lib/Travel/Status/MOTIS/Stopover.pm b/lib/Travel/Status/MOTIS/Stopover.pm
index e0b03df..2c0c978 100644
--- a/lib/Travel/Status/MOTIS/Stopover.pm
+++ b/lib/Travel/Status/MOTIS/Stopover.pm
@@ -10,73 +10,79 @@ use DateTime::Format::ISO8601;
our $VERSION = '0.01';
-Travel::Status::MOTIS::Stopover->mk_ro_accessors(qw(
- stop
+Travel::Status::MOTIS::Stopover->mk_ro_accessors(
+ qw(
+ stop
- is_cancelled
- is_realtime
+ is_cancelled
+ is_realtime
- arrival
- scheduled_arrival
- realtime_arrival
+ arrival
+ scheduled_arrival
+ realtime_arrival
- departure
- scheduled_departure
- realtime_departure
+ departure
+ scheduled_departure
+ realtime_departure
- delay
- arrival_delay
- departure_delay
+ delay
+ arrival_delay
+ departure_delay
- track
- scheduled_track
- realtime_track
-));
+ track
+ scheduled_track
+ realtime_track
+ )
+);
sub new {
my ( $obj, %opt ) = @_;
- my $json = $opt{json};
- my $realtime = $opt{realtime} // 0;
- my $cancelled = $opt{cancelled};
+ my $json = $opt{json};
+ my $realtime = $opt{realtime} // 0;
+ my $cancelled = $opt{cancelled};
my $ref = {
- stop => Travel::Status::MOTIS::Stop->from_stopover( json => $json ),
+ stop => Travel::Status::MOTIS::Stop->from_stopover( json => $json ),
is_realtime => $realtime,
is_cancelled => $json->{cancelled} // $cancelled,
};
if ( $json->{scheduledArrival} ) {
- $ref->{scheduled_arrival} = DateTime::Format::ISO8601->parse_datetime( $json->{scheduledArrival} );
+ $ref->{scheduled_arrival} = DateTime::Format::ISO8601->parse_datetime(
+ $json->{scheduledArrival} );
$ref->{scheduled_arrival}->set_time_zone('local');
}
if ( $json->{arrival} and $realtime ) {
- $ref->{realtime_arrival} = DateTime::Format::ISO8601->parse_datetime( $json->{arrival} );
+ $ref->{realtime_arrival}
+ = DateTime::Format::ISO8601->parse_datetime( $json->{arrival} );
$ref->{realtime_arrival}->set_time_zone('local');
}
if ( $json->{scheduledDeparture} ) {
- $ref->{scheduled_departure} = DateTime::Format::ISO8601->parse_datetime( $json->{scheduledDeparture} );
+ $ref->{scheduled_departure} = DateTime::Format::ISO8601->parse_datetime(
+ $json->{scheduledDeparture} );
$ref->{scheduled_departure}->set_time_zone('local');
}
if ( $json->{departure} and $realtime ) {
- $ref->{realtime_departure} = DateTime::Format::ISO8601->parse_datetime( $json->{departure} );
+ $ref->{realtime_departure}
+ = DateTime::Format::ISO8601->parse_datetime( $json->{departure} );
$ref->{realtime_departure}->set_time_zone('local');
}
if ( $ref->{scheduled_arrival} and $ref->{realtime_arrival} ) {
$ref->{arrival_delay} = $ref->{realtime_arrival}
- ->subtract_datetime( $ref->{scheduled_arrival} )
- ->in_units('minutes');
+ ->subtract_datetime( $ref->{scheduled_arrival} )->in_units('minutes');
}
if ( $ref->{scheduled_departure} and $ref->{realtime_departure} ) {
- $ref->{departure_delay} = $ref->{realtime_departure}
- ->subtract_datetime( $ref->{scheduled_departure} )
- ->in_units('minutes');
+ $ref->{departure_delay}
+ = $ref->{realtime_departure}
+ ->subtract_datetime( $ref->{scheduled_departure} )
+ ->in_units('minutes');
}
if ( $json->{scheduledTrack} ) {
@@ -87,11 +93,12 @@ sub new {
$ref->{realtime_track} = $json->{track};
}
- $ref->{delay} = $ref->{arrival_delay} // $ref->{departure_delay};
+ $ref->{delay} = $ref->{arrival_delay} // $ref->{departure_delay};
- $ref->{arrival} = $ref->{realtime_arrival} // $ref->{scheduled_arrival};
- $ref->{departure} = $ref->{realtime_departure} // $ref->{scheduled_departure};
- $ref->{track} = $ref->{realtime_track} // $ref->{scheduled_track};
+ $ref->{arrival} = $ref->{realtime_arrival} // $ref->{scheduled_arrival};
+ $ref->{departure} = $ref->{realtime_departure}
+ // $ref->{scheduled_departure};
+ $ref->{track} = $ref->{realtime_track} // $ref->{scheduled_track};
bless( $ref, $obj );
@@ -103,7 +110,8 @@ sub TO_JSON {
my $ret = { %{$self} };
- for my $timestamp_key (qw(
+ for my $timestamp_key (
+ qw(
arrival
scheduled_arrival
realtime_arrival
@@ -111,7 +119,9 @@ sub TO_JSON {
departure
scheduled_departure
realtime_departure
- )) {
+ )
+ )
+ {
if ( $ret->{$timestamp_key} ) {
$ret->{$timestamp_key} = $ret->{$timestamp_key}->epoch;
}
diff --git a/lib/Travel/Status/MOTIS/Trip.pm b/lib/Travel/Status/MOTIS/Trip.pm
index c879bee..161b4f7 100644
--- a/lib/Travel/Status/MOTIS/Trip.pm
+++ b/lib/Travel/Status/MOTIS/Trip.pm
@@ -13,25 +13,27 @@ use Travel::Status::MOTIS::Polyline qw(decode_polyline);
our $VERSION = '0.01';
-Travel::Status::MOTIS::Trip->mk_ro_accessors(qw(
- id
- mode
- agency
- route_name
- route_color
- headsign
-
- is_realtime
- is_cancelled
-
- arrival
- scheduled_arrival
- realtime_arrival
-
- departure
- scheduled_departure
- realtime_departure
-));
+Travel::Status::MOTIS::Trip->mk_ro_accessors(
+ qw(
+ id
+ mode
+ agency
+ route_name
+ route_color
+ headsign
+
+ is_realtime
+ is_cancelled
+
+ arrival
+ scheduled_arrival
+ realtime_arrival
+
+ departure
+ scheduled_departure
+ realtime_departure
+ )
+);
sub new {
my ( $obj, %opt ) = @_;
@@ -39,35 +41,41 @@ sub new {
my $json = $opt{json}{legs}[0];
my $ref = {
- id => $json->{tripId},
- mode => $json->{mode},
- agency => $json->{agencyName},
- route_name => $json->{routeShortName},
- route_color => $json->{routeColor},
- headsign => $json->{headsign},
-
- is_cancelled => $json->{cancelled},
- is_realtime => $json->{realTime},
-
- raw_stopovers => [ $json->{from}, @{ $json->{intermediateStops} }, $json->{to} ],
- raw_polyline => $json->{legGeometry}->{points},
+ id => $json->{tripId},
+ mode => $json->{mode},
+ agency => $json->{agencyName},
+ route_name => $json->{routeShortName},
+ route_color => $json->{routeColor},
+ headsign => $json->{headsign},
+
+ is_cancelled => $json->{cancelled},
+ is_realtime => $json->{realTime},
+
+ raw_stopovers =>
+ [ $json->{from}, @{ $json->{intermediateStops} }, $json->{to} ],
+ raw_polyline => $json->{legGeometry}->{points},
};
- $ref->{scheduled_departure} = DateTime::Format::ISO8601->parse_datetime( $json->{scheduledStartTime} );
+ $ref->{scheduled_departure} = DateTime::Format::ISO8601->parse_datetime(
+ $json->{scheduledStartTime} );
$ref->{scheduled_departure}->set_time_zone('local');
if ( $json->{realTime} ) {
- $ref->{realtime_departure} = DateTime::Format::ISO8601->parse_datetime( $json->{startTime} );
+ $ref->{realtime_departure}
+ = DateTime::Format::ISO8601->parse_datetime( $json->{startTime} );
$ref->{realtime_departure}->set_time_zone('local');
}
- $ref->{departure} = $ref->{realtime_departure} // $ref->{scheduled_departure};
+ $ref->{departure} = $ref->{realtime_departure}
+ // $ref->{scheduled_departure};
- $ref->{scheduled_arrival} = DateTime::Format::ISO8601->parse_datetime( $json->{scheduledEndTime} );
+ $ref->{scheduled_arrival}
+ = DateTime::Format::ISO8601->parse_datetime( $json->{scheduledEndTime} );
$ref->{scheduled_arrival}->set_time_zone('local');
if ( $json->{realTime} ) {
- $ref->{realtime_arrival} = DateTime::Format::ISO8601->parse_datetime( $json->{endTime} );
+ $ref->{realtime_arrival}
+ = DateTime::Format::ISO8601->parse_datetime( $json->{endTime} );
$ref->{realtime_arrival}->set_time_zone('local');
}
@@ -106,16 +114,14 @@ sub polyline {
for my $polyline_index ( 0 .. $#{$polyline} ) {
my $coordinate = $polyline->[$polyline_index];
- my $distance = $gis_distance->distance_metal(
- $stop->{lat},
- $stop->{lon},
- $coordinate->{lat},
- $coordinate->{lon},
+ my $distance = $gis_distance->distance_metal(
+ $stop->{lat}, $stop->{lon},
+ $coordinate->{lat}, $coordinate->{lon},
);
if ( not $minimum_distances{ $stop->id }
- or $minimum_distances{ $stop->id }{distance} > $distance
- ) {
+ or $minimum_distances{ $stop->id }{distance} > $distance )
+ {
$minimum_distances{ $stop->id } = {
distance => $distance,
index => $polyline_index,
@@ -128,7 +134,8 @@ sub polyline {
my $stop = $stopover->stop;
if ( $minimum_distances{ $stop->id } ) {
- $polyline->[ $minimum_distances{ $stop->id }{index} ]{stop} = $stop;
+ $polyline->[ $minimum_distances{ $stop->id }{index} ]{stop}
+ = $stop;
}
}
}
@@ -147,7 +154,7 @@ sub stopovers {
@{ $self->{stopovers} } = map {
Travel::Status::MOTIS::Stopover->new(
- json => $_,
+ json => $_,
realtime => $self->{is_realtime}
)
} ( @{ $self->{raw_stopovers} // [] } );
@@ -166,7 +173,8 @@ sub TO_JSON {
my $ret = { %{$self} };
- for my $timestamp_key (qw(
+ for my $timestamp_key (
+ qw(
arrival
scheduled_arrival
realtime_arrival
@@ -174,7 +182,9 @@ sub TO_JSON {
departure
scheduled_departure
realtime_departure
- )) {
+ )
+ )
+ {
if ( $ret->{$timestamp_key} ) {
$ret->{$timestamp_key} = $ret->{$timestamp_key}->epoch;
}
diff --git a/lib/Travel/Status/MOTIS/TripAtStopover.pm b/lib/Travel/Status/MOTIS/TripAtStopover.pm
index 3d8d390..2d58f98 100644
--- a/lib/Travel/Status/MOTIS/TripAtStopover.pm
+++ b/lib/Travel/Status/MOTIS/TripAtStopover.pm
@@ -10,19 +10,21 @@ use parent 'Class::Accessor';
our $VERSION = '0.01';
-Travel::Status::MOTIS::TripAtStopover->mk_ro_accessors(qw(
- id
- mode
- agency
- route_name
- route_color
- headsign
-
- is_cancelled
- is_realtime
-
- stopover
-));
+Travel::Status::MOTIS::TripAtStopover->mk_ro_accessors(
+ qw(
+ id
+ mode
+ agency
+ route_name
+ route_color
+ headsign
+
+ is_cancelled
+ is_realtime
+
+ stopover
+ )
+);
sub new {
my ( $obj, %opt ) = @_;
@@ -30,21 +32,21 @@ sub new {
my $json = $opt{json};
my $ref = {
- id => $json->{tripId},
- mode => $json->{mode},
- agency => $json->{agencyName},
- route_name => $json->{routeShortName},
- route_color => $json->{routeColor},
- headsign => $json->{headsign},
+ id => $json->{tripId},
+ mode => $json->{mode},
+ agency => $json->{agencyName},
+ route_name => $json->{routeShortName},
+ route_color => $json->{routeColor},
+ headsign => $json->{headsign},
is_cancelled => $json->{cancelled},
is_realtime => $json->{realTime},
- stopover => Travel::Status::MOTIS::Stopover->new(
- json => $json->{place},
+ stopover => Travel::Status::MOTIS::Stopover->new(
+ json => $json->{place},
- # NOTE: $json->{place}->{cancelled} isn't set, we just override this here.
- cancelled => $json->{cancelled},
+ # NOTE: $json->{place}->{cancelled} isn't set, we just override this here.
+ cancelled => $json->{cancelled},
realtime => $json->{realTime},
),
};
@@ -59,14 +61,17 @@ sub TO_JSON {
my $ret = { %{$self} };
- for my $timestamp_key (qw(
+ for my $timestamp_key (
+ qw(
scheduled_departure
realtime_departure
departure
scheduled_arrival
realtime_arrival
arrival
- )) {
+ )
+ )
+ {
if ( $ret->{$timestamp_key} ) {
$ret->{$timestamp_key} = $ret->{$timestamp_key}->epoch;
}