blob: c4f7df64d826a7c5aff92e24d9ecee3ba375d302 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
package Travel::Status::DE::DBRIS::Journey;
use strict;
use warnings;
use 5.020;
use parent 'Class::Accessor';
use Travel::Status::DE::DBRIS::Location;
our $VERSION = '0.01';
Travel::Status::DE::DBRIS::Journey->mk_ro_accessors(qw(train is_cancelled));
sub new {
my ( $obj, %opt ) = @_;
my $json = $opt{json};
my $strptime = $opt{strptime_obj};
my $ref = {
train => $json->{zugName},
is_cancelled => $json->{cancelled},
raw_route => $json->{halte},
strptime_obj => $strptime,
};
bless( $ref, $obj );
for my $message ( @{ $json->{himMeldungen} // [] } ) {
push( @{ $ref->{messages} }, $message );
}
return $ref;
}
sub route {
my ($self) = @_;
if ( $self->{route} ) {
return @{ $self->{route} };
}
@{ $self->{route} }
= map {
Travel::Status::DE::DBRIS::Location->new(
json => $_,
strptime_obj => $self->{strptime_obj}
)
} ( @{ $self->{raw_route} // [] },
@{ $self->{raw_cancelled_route} // [] } );
return @{ $self->{route} };
}
sub messages {
my ($self) = @_;
return @{ $self->{messages} // [] };
}
sub TO_JSON {
my ($self) = @_;
my $ret = { %{$self} };
return $ret;
}
1;
|