summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBirte Kristina Friesel <derf@finalrewind.org>2023-11-11 09:00:59 +0100
committerBirte Kristina Friesel <derf@finalrewind.org>2023-11-11 09:00:59 +0100
commiteaf4de9b5bb6003007cff9c150614fd5fda5376d (patch)
treef5a2a6448ea112ac10b5a83c2051795705750549
parent3d15025266d1fb049c02ff1b726efe350ec6fb39 (diff)
Message: parse JSON in constructor
-rw-r--r--lib/Travel/Status/DE/HAFAS.pm19
-rw-r--r--lib/Travel/Status/DE/HAFAS/Message.pm26
2 files changed, 30 insertions, 15 deletions
diff --git a/lib/Travel/Status/DE/HAFAS.pm b/lib/Travel/Status/DE/HAFAS.pm
index e67eb3b..c24afd9 100644
--- a/lib/Travel/Status/DE/HAFAS.pm
+++ b/lib/Travel/Status/DE/HAFAS.pm
@@ -617,16 +617,12 @@ sub check_mgate {
sub add_message {
my ( $self, $json, $is_him ) = @_;
- my $short = $json->{txtS};
- my $text = $json->{txtN};
- my $type = $json->{type};
- my $code = $json->{code};
- my $prio = $json->{prio};
+ my $text = $json->{txtN};
+ my $code = $json->{code};
if ($is_him) {
- $short = $json->{head};
- $text = $json->{text};
- $code = $json->{hid};
+ $text = $json->{text};
+ $code = $json->{hid};
}
# Some backends use remL for operator information. We don't want that.
@@ -642,12 +638,7 @@ sub add_message {
}
my $message = Travel::Status::DE::HAFAS::Message->new(
- short => $short,
- text => $text,
- type => $type,
- code => $code,
- prio => $prio,
- is_him => $is_him,
+ json => $json,
ref_count => 1,
);
push( @{ $self->{messages} }, $message );
diff --git a/lib/Travel/Status/DE/HAFAS/Message.pm b/lib/Travel/Status/DE/HAFAS/Message.pm
index df49c5a..a9802eb 100644
--- a/lib/Travel/Status/DE/HAFAS/Message.pm
+++ b/lib/Travel/Status/DE/HAFAS/Message.pm
@@ -14,7 +14,31 @@ Travel::Status::DE::HAFAS::Message->mk_ro_accessors(
sub new {
my ( $obj, %conf ) = @_;
- my $ref = \%conf;
+ my $json = $conf{json};
+ my $is_him = $conf{is_him};
+
+ my $short = $json->{txtS};
+ my $text = $json->{txtN};
+ my $type = $json->{type};
+ my $code = $json->{code};
+ my $prio = $json->{prio};
+
+ if ($is_him) {
+ $short = $json->{head};
+ $text = $json->{text};
+ $code = $json->{hid};
+ }
+
+ my $ref = {
+ short => $short,
+ text => $text,
+ type => $type,
+ code => $code,
+ prio => $prio,
+ is_him => $is_him,
+ ref_count => $conf{ref_count},
+ };
+
bless( $ref, $obj );
return $ref;