Unverified Commit eaf4de9b authored by Birte Kristina Friesel's avatar Birte Kristina Friesel
Browse files

Message: parse JSON in constructor

parent 3d150252
Loading
Loading
Loading
Loading
+5 −14
Original line number Diff line number Diff line
@@ -617,14 +617,10 @@ 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};

	if ($is_him) {
		$short = $json->{head};
		$text = $json->{text};
		$code = $json->{hid};
	}
@@ -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 );
+25 −1
Original line number Diff line number Diff line
@@ -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;