From eaf4de9b5bb6003007cff9c150614fd5fda5376d Mon Sep 17 00:00:00 2001 From: Birte Kristina Friesel Date: Sat, 11 Nov 2023 09:00:59 +0100 Subject: Message: parse JSON in constructor --- lib/Travel/Status/DE/HAFAS/Message.pm | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'lib/Travel/Status/DE/HAFAS/Message.pm') 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; -- cgit v1.2.3