summaryrefslogtreecommitdiff
path: root/lib
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 /lib
parent1a400b9d4894a0d403d2613f3d5e36d97a2e7851 (diff)
perltidy
Diffstat (limited to 'lib')
-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
6 files changed, 187 insertions, 155 deletions
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;
}