summaryrefslogtreecommitdiff
path: root/lib/Travel/Status
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Travel/Status')
-rw-r--r--lib/Travel/Status/DE/DBWagenreihung.pm70
-rw-r--r--lib/Travel/Status/DE/DBWagenreihung/Section.pm2
-rw-r--r--lib/Travel/Status/DE/DBWagenreihung/Wagon.pm39
3 files changed, 60 insertions, 51 deletions
diff --git a/lib/Travel/Status/DE/DBWagenreihung.pm b/lib/Travel/Status/DE/DBWagenreihung.pm
index 608702a..c879d14 100644
--- a/lib/Travel/Status/DE/DBWagenreihung.pm
+++ b/lib/Travel/Status/DE/DBWagenreihung.pm
@@ -24,15 +24,15 @@ sub new {
}
my $self = {
- api_base => $opt{api_base}
+ api_base => $opt{api_base}
// 'https://www.apps-bahn.de/wr/wagenreihung/1.0',
developer_mode => $opt{developer_mode},
- cache => $opt{cache},
- departure => $opt{departure},
- json => JSON->new,
- serializable => $opt{serializable},
- train_number => $opt{train_number},
- user_agent => $opt{user_agent},
+ cache => $opt{cache},
+ departure => $opt{departure},
+ json => JSON->new,
+ serializable => $opt{serializable},
+ train_number => $opt{train_number},
+ user_agent => $opt{user_agent},
};
bless( $self, $class );
@@ -51,17 +51,19 @@ sub new {
sub get_wagonorder {
my ($self) = @_;
- my $api_base = $self->{api_base};
- my $cache = $self->{cache};
+ my $api_base = $self->{api_base};
+ my $cache = $self->{cache};
my $train_number = $self->{train_number};
my $datetime = $self->{departure};
- if (ref($datetime) eq 'DateTime') {
+ if ( ref($datetime) eq 'DateTime' ) {
$datetime = $datetime->strftime('%Y%m%d%H%M');
}
- my ($content, $err) = $self->get_with_cache($cache, "${api_base}/${train_number}/${datetime}");
+ my ( $content, $err )
+ = $self->get_with_cache( $cache,
+ "${api_base}/${train_number}/${datetime}" );
if ($err) {
$self->{errstr} = "Failed to fetch station data: $err";
@@ -69,7 +71,7 @@ sub get_wagonorder {
}
my $json = $self->{json}->decode($content);
- if (exists $json->{error}) {
+ if ( exists $json->{error} ) {
$self->{errstr} = 'Backend error: ' . $json->{error}{msg};
return;
}
@@ -87,38 +89,46 @@ sub error {
sub sections {
my ($self) = @_;
- if (exists $self->{sections}) {
- return @{$self->{sections}};
+ if ( exists $self->{sections} ) {
+ return @{ $self->{sections} };
}
- for my $section (@{$self->{data}{istformation}{halt}{allSektor}}) {
+ for my $section ( @{ $self->{data}{istformation}{halt}{allSektor} } ) {
my $pos = $section->{positionamgleis};
- push(@{$self->{sections}}, Travel::Status::DE::DBWagenreihung::Section->new(
- name => $section->{sektorbezeichnung},
- start_percent => $pos->{startprozent},
- end_percent => $pos->{endeprozent},
- start_meters => $pos->{startmeter},
- end_meters => $pos->{endemeter},
- ));
+ push(
+ @{ $self->{sections} },
+ Travel::Status::DE::DBWagenreihung::Section->new(
+ name => $section->{sektorbezeichnung},
+ start_percent => $pos->{startprozent},
+ end_percent => $pos->{endeprozent},
+ start_meters => $pos->{startmeter},
+ end_meters => $pos->{endemeter},
+ )
+ );
}
- return @{$self->{sections} // []};
+ return @{ $self->{sections} // [] };
}
sub wagons {
my ($self) = @_;
- if (exists $self->{wagons}) {
- return @{$self->{wagons}};
+ if ( exists $self->{wagons} ) {
+ return @{ $self->{wagons} };
}
- for my $group (@{$self->{data}{istformation}{allFahrzeuggruppe}}) {
- for my $wagon (@{$group->{allFahrzeug}}) {
- push(@{$self->{wagons}}, Travel::Status::DE::DBWagenreihung::Wagon->new(%{$wagon}));
+ for my $group ( @{ $self->{data}{istformation}{allFahrzeuggruppe} } ) {
+ for my $wagon ( @{ $group->{allFahrzeug} } ) {
+ push(
+ @{ $self->{wagons} },
+ Travel::Status::DE::DBWagenreihung::Wagon->new( %{$wagon} )
+ );
}
}
- @{$self->{wagons}} = sort { $a->{position}->{start_percent} <=> $b->{position}->{start_percent} } @{$self->{wagons}};
- return @{$self->{wagons} // []};
+ @{ $self->{wagons} } = sort {
+ $a->{position}->{start_percent} <=> $b->{position}->{start_percent}
+ } @{ $self->{wagons} };
+ return @{ $self->{wagons} // [] };
}
sub get_with_cache {
diff --git a/lib/Travel/Status/DE/DBWagenreihung/Section.pm b/lib/Travel/Status/DE/DBWagenreihung/Section.pm
index 780031c..1c3bdf8 100644
--- a/lib/Travel/Status/DE/DBWagenreihung/Section.pm
+++ b/lib/Travel/Status/DE/DBWagenreihung/Section.pm
@@ -17,7 +17,7 @@ sub new {
my ( $obj, %opt ) = @_;
my $ref = \%opt;
- $ref->{length_meters} = $ref->{end_meters} - $ref->{start_meters};
+ $ref->{length_meters} = $ref->{end_meters} - $ref->{start_meters};
$ref->{length_percent} = $ref->{end_percent} - $ref->{start_percent};
return bless( $ref, $obj );
diff --git a/lib/Travel/Status/DE/DBWagenreihung/Wagon.pm b/lib/Travel/Status/DE/DBWagenreihung/Wagon.pm
index ed1b87a..850bc84 100644
--- a/lib/Travel/Status/DE/DBWagenreihung/Wagon.pm
+++ b/lib/Travel/Status/DE/DBWagenreihung/Wagon.pm
@@ -11,47 +11,46 @@ use Carp qw(cluck);
our $VERSION = '0.00';
Travel::Status::DE::DBWagenreihung::Wagon->mk_ro_accessors(
- qw(class_type has_bistro is_locomotive is_powercar number section)
-);
+ qw(class_type has_bistro is_locomotive is_powercar number section));
sub new {
my ( $obj, %opt ) = @_;
my $ref = {};
- $ref->{class_type} = 0;
- $ref->{has_bistro} = 0;
+ $ref->{class_type} = 0;
+ $ref->{has_bistro} = 0;
$ref->{is_locomotive} = 0;
- $ref->{is_powercar} = 0;
- $ref->{number} = $opt{wagenordnungsnummer};
- $ref->{section} = $opt{fahrzeugsektor};
- $ref->{type} = $opt{fahrzeugtyp};
+ $ref->{is_powercar} = 0;
+ $ref->{number} = $opt{wagenordnungsnummer};
+ $ref->{section} = $opt{fahrzeugsektor};
+ $ref->{type} = $opt{fahrzeugtyp};
- if ($opt{kategorie} =~ m{SPEISEWAGEN}) {
+ if ( $opt{kategorie} =~ m{SPEISEWAGEN} ) {
$ref->{has_bistro} = 1;
}
- elsif ($opt{kategorie} eq 'LOK') {
+ elsif ( $opt{kategorie} eq 'LOK' ) {
$ref->{is_locomotive} = 1;
}
- elsif ($opt{kategorie} eq 'TRIEBKOPF') {
+ elsif ( $opt{kategorie} eq 'TRIEBKOPF' ) {
$ref->{is_powercar} = 1;
}
- if ($opt{fahrzeugtyp} =~ m{AB}) {
+ if ( $opt{fahrzeugtyp} =~ m{AB} ) {
$ref->{class_type} = 12;
}
- elsif ($opt{fahrzeugtyp} =~ m{A}) {
+ elsif ( $opt{fahrzeugtyp} =~ m{A} ) {
$ref->{class_type} = 1;
}
- elsif ($opt{fahrzeugtyp} =~ m{B|WR}) {
+ elsif ( $opt{fahrzeugtyp} =~ m{B|WR} ) {
$ref->{class_type} = 2;
}
my $pos = $opt{positionamhalt};
$ref->{position}{start_percent} = $pos->{startprozent};
- $ref->{position}{end_percent} = $pos->{endeprozent};
- $ref->{position}{start_meters} = $pos->{startmeter};
- $ref->{position}{end_meters} = $pos->{endemeter};
+ $ref->{position}{end_percent} = $pos->{endeprozent};
+ $ref->{position}{start_meters} = $pos->{startmeter};
+ $ref->{position}{end_meters} = $pos->{endemeter};
return bless( $ref, $obj );
}
@@ -59,7 +58,7 @@ sub new {
sub is_first_class {
my ($self) = @_;
- if ($self->{type} =~ m{^A}) {
+ if ( $self->{type} =~ m{^A} ) {
return 1;
}
return 0;
@@ -68,7 +67,7 @@ sub is_first_class {
sub is_second_class {
my ($self) = @_;
- if ($self->{type} =~ m{^A?B}) {
+ if ( $self->{type} =~ m{^A?B} ) {
return 1;
}
return 0;
@@ -77,7 +76,7 @@ sub is_second_class {
sub sections {
my ($self) = @_;
- return @{$self->{sections}};
+ return @{ $self->{sections} };
}
sub TO_JSON {