Carp qw(confess);
use DateTime;
use DateTime::Format::Strptime;
use Encode qw(decode encode);
use JSON;
use LWP::UserAgent;
use Travel::Status::DE::DBRIS::Formation;
use Travel::Status::DE::DBRIS::Jo
/Berlin',
);
my $json = $self->{json} = JSON->new->utf8;
if ( $conf{async} ) {
$self->{req} = $req;
return $self;
}
if ( $conf{json} ) {
$self->{raw_json} = $conf{json};
}
else {
if
}
if ( $self->{developer_mode} ) {
say decode( 'utf-8', $content );
}
$self->{raw_json} = $json->decode($content);
}
if ( $conf{station} ) {
$self->parse_stationboard;
}
elsif ( $co
s;
# vim:readonly
# This module has been automatically generated from share/admin-id-to-operator.json
# by lib/Travel/Status/DE/DBRIS/Operators.pm.PL.
# Do not edit, changes will be lost.
use strict
ings;
use 5.020;
use utf8;
our $VERSION = '0.18';
# Automatically generated, see share/stations.json
my %admin_id_to_operator = (
'OWRE' => ['RE', 'Ostdeutsche Eisenbahn GmbH'],
'8006D2' => ['DB', '
my $json = $opt{json};
my $strpdate = $opt{strpdate_obj};
my $strptime = $opt{strptime_obj};
my $ref = {
id => $opt{id},
day => $strpdate->parse_datetime( $json->{rei
$json->{zugName},
is_cancelled => $json->{cancelled},
raw_route => $json->{halte},
raw_polyline => $json->{polylineGroup}{polylineDescriptions},
strptime_obj => $strptime,
};
if ( $json-
>{halte} and @{ $json->{halte} } ) {
my %admin_id_ml;
my %trip_no_ml;
for my $stop ( @{ $json->{halte} } ) {
if ( defined $stop->{adminID} ) {
$admin_id_ml{ $stop->{adminID} } += 1;
}
= @_;
my $json = $opt{json};
my $ref = {
json => $opt{json},
train_type => $opt{train_type},
platform => $json->{departurePlatform},
platform_sched => $json->{departure
{
my ($self) = @_;
my $platform_length
= $self->{json}{platform}{end} - $self->{json}{platform}{start};
for my $sector ( @{ $self->{json}{platform}{sectors} } ) {
push(
@{ $self->{sector
atus::DE::DBRIS::Formation::Sector->new(
json => $sector,
platform => {
start => $self->{json}{platform}{start},
end => $self->{json}{platform}{end},
}
)
);
}
my @g
ew {
my ( $obj, %opt ) = @_;
my $json = $opt{json};
# station search results include lat/lon keys in JSON; route entries do not
my ( $lon, $lat );
if ( $json->{id} =~ m{ [@]X= (?<lon> -? \d+) [
=> $json->{extId} // $json->{evaNumber},
id => $json->{id},
lat => $json->{lat} // $lat,
lon => $json->{lon} // $lon,
name => $json->{name},
> $json->{products},
type => $json->{type},
is_cancelled => $json->{canceled},
is_additional => $json->{additional},
sched_platform => $json->{gleis},
rt_platform => $json->{
_meters cube_meters cube_percent)
);
sub new {
my ( $obj, %opt ) = @_;
my %section = %{ $opt{json} };
my %platform = %{ $opt{platform} };
my $platform_length = $platform{end} - $platform{start
rm_length,
};
$ref->{length_percent} = $ref->{end_percent} - $ref->{start_percent};
return bless( $ref, $obj );
}
sub TO_JSON {
my ($self) = @_;
my %copy = %{$self};
return {%copy};
}
1;
my %json = %{ $opt{json} };
my $ref = {
carriages => $opt{carriages},
destination => $json{transport}{destination}{name},
train_type => $json{transport}{category},
name => $json{na
me},
line => $json{transport}{numberwline},
train_no => $json{transport}{number},
};
if ( $ref->{name} =~ m{ ^ IC[DE] 0* (\d+) $ }x and exists $ice_name{$1} ) {
$ref->{designation}
no};
$ref->{sectors} = [
uniq grep { defined }
map { $_->{platformPosition}{sector} } @{ $json{vehicles} // [] }
];
if ( @{ $ref->{sectors} } ) {
$ref->{has_sectors} = 1;
}
$ref->{start
=> 'infant_cabin',
);
sub new {
my ( $obj, %opt ) = @_;
my $ref = {};
my %json = %{ $opt{json} };
my $platform = $opt{platform};
$ref->{class_type} = 0;
$ref->{has_bistro}
$ref->{number} = $json{wagonIdentificationNumber};
$ref->{model} = $json{vehicleID};
$ref->{uic_id} = $json{vehicleID};
$ref->{section} = $json{platformPosition}{sector
= $json{type}{constructionType};
$ref->{model} =~ s{^.....(...)....(?:-.)?$}{$1} or $ref->{model} = undef;
my $self = bless( $ref, $obj );
$self->parse_type;
for my $amenity ( @{ $json{amen
$json = $opt{json};
my $strptime = $opt{strptime_obj};
my $ref = {
type => $json->{verkehrmittel}{kurzText},
line => $json->{verkehrmittel}{mittelText},
train => $json
$json->{verkehrmittel}{kurzText},
train_mid => $json->{verkehrmittel}{mittelText},
train_long => $json->{verkehrmittel}{langText},
id => $json->{journeyId},
stop_eva => $json->
hnhofsId},
destination => $json->{terminus},
platform => $json->{gleis},
rt_platform => $json->{ezGleis},
via => $json->{ueber},
via_last => ( $json->{ueber} // [] )->[-1],
};