Loading bin/hafas-m +7 −7 Original line number Diff line number Diff line Loading @@ -149,14 +149,14 @@ sub display_result { my $d = $line->[6]; my $first_message = 1; for my $msg ( $d->messages ) { if ( $msg->{ref_count} == 1 ) { if ( $msg->ref_count == 1 ) { if ($first_message) { print "\n"; $first_message = 0; } printf( "# %s\n", $msg->{header} ); if ( $msg->{lead} ) { printf( "# %s\n", $msg->{lead} ); printf( "# %s\n", $msg->header ); if ( $msg->lead ) { printf( "# %s\n", $msg->lead ); } } } Loading Loading @@ -184,9 +184,9 @@ if ( my $err = $status->errstr ) { my $message_id = 1; for my $m ( $status->messages ) { if ( $m->{ref_count} > 1 ) { if ( $m->ref_count > 1 ) { $m->{id} = $message_id++; printf( "# (%d) %s\n# %s\n\n", $m->{id}, $m->{header}, $m->{lead} ); printf( "# (%d) %s\n# %s\n\n", $m->{id}, $m->header, $m->lead ); } } Loading @@ -199,7 +199,7 @@ for my $d ( $status->results ) { my $info_line = $d->info // q{}; for my $message ( $d->messages ) { if ( $message->{ref_count} > 1 ) { if ( $message->ref_count > 1 ) { $info_line = sprintf( '(%d) %s', $message->{id}, $info_line ); } } Loading lib/Travel/Status/DE/HAFAS.pm +3 −2 Original line number Diff line number Diff line Loading @@ -13,6 +13,7 @@ use DateTime::Format::Strptime; use List::Util qw(any); use LWP::UserAgent; use POSIX qw(strftime); use Travel::Status::DE::HAFAS::Message; use Travel::Status::DE::HAFAS::Result; use Travel::Status::DE::HAFAS::StopFinder; use XML::LibXML; Loading Loading @@ -299,11 +300,11 @@ sub add_message_node { return $message; } } my $message = { my $message = Travel::Status::DE::HAFAS::Message->new( header => $header, lead => $lead, ref_count => 1, }; ); push( @{ $self->{messages} }, $message ); return $message; } Loading lib/Travel/Status/DE/HAFAS/Message.pm 0 → 100644 +98 −0 Original line number Diff line number Diff line package Travel::Status::DE::HAFAS::Message; use strict; use warnings; use 5.014; use parent 'Class::Accessor'; our $VERSION = '3.01'; Travel::Status::DE::HAFAS::Message->mk_ro_accessors(qw(header lead ref_count)); sub new { my ( $obj, %conf ) = @_; my $ref = \%conf; bless( $ref, $obj ); return $ref; } 1; __END__ =head1 NAME Travel::Status::DE::HAFAS::Message - An arrival/departure-related message. =head1 SYNOPSIS if ($message->lead) { printf("%s: %s\n", $message->header, $message->lead); } else { say $message->header; } =head1 VERSION version 3.01 =head1 DESCRIPTION Travel::Status::DE::HAFAS::Message describes a message belonging to an arrival or departure. Messages may refer to planned schedule changes due to construction work, the expected passenger volume, or similar. =head1 METHODS =head2 ACCESSORS =over =item $message->header Message header. May be a concise single-sentence summary or a mostly useless string such as "Information". Does not contain newlines. =item $message->lead Detailed message content. Does not contain newlines. =item $message->ref_count Counter indicating how often this message is used by the requested arrivals/departures. ref_count is an integer between 1 and the number of results. If ref_count is 1, it is referenced by a single result only. =back =head1 DIAGNOSTICS None. =head1 DEPENDENCIES =over =item Class::Accessor(3pm) =back =head1 BUGS AND LIMITATIONS None known. =head1 SEE ALSO Travel::Status::DE::HAFAS(3pm). =head1 AUTHOR Copyright (C) 2020 by Daniel Friesel E<lt>derf@finalrewind.orgE<gt> =head1 LICENSE This module is licensed under the same terms as Perl itself. Loading
bin/hafas-m +7 −7 Original line number Diff line number Diff line Loading @@ -149,14 +149,14 @@ sub display_result { my $d = $line->[6]; my $first_message = 1; for my $msg ( $d->messages ) { if ( $msg->{ref_count} == 1 ) { if ( $msg->ref_count == 1 ) { if ($first_message) { print "\n"; $first_message = 0; } printf( "# %s\n", $msg->{header} ); if ( $msg->{lead} ) { printf( "# %s\n", $msg->{lead} ); printf( "# %s\n", $msg->header ); if ( $msg->lead ) { printf( "# %s\n", $msg->lead ); } } } Loading Loading @@ -184,9 +184,9 @@ if ( my $err = $status->errstr ) { my $message_id = 1; for my $m ( $status->messages ) { if ( $m->{ref_count} > 1 ) { if ( $m->ref_count > 1 ) { $m->{id} = $message_id++; printf( "# (%d) %s\n# %s\n\n", $m->{id}, $m->{header}, $m->{lead} ); printf( "# (%d) %s\n# %s\n\n", $m->{id}, $m->header, $m->lead ); } } Loading @@ -199,7 +199,7 @@ for my $d ( $status->results ) { my $info_line = $d->info // q{}; for my $message ( $d->messages ) { if ( $message->{ref_count} > 1 ) { if ( $message->ref_count > 1 ) { $info_line = sprintf( '(%d) %s', $message->{id}, $info_line ); } } Loading
lib/Travel/Status/DE/HAFAS.pm +3 −2 Original line number Diff line number Diff line Loading @@ -13,6 +13,7 @@ use DateTime::Format::Strptime; use List::Util qw(any); use LWP::UserAgent; use POSIX qw(strftime); use Travel::Status::DE::HAFAS::Message; use Travel::Status::DE::HAFAS::Result; use Travel::Status::DE::HAFAS::StopFinder; use XML::LibXML; Loading Loading @@ -299,11 +300,11 @@ sub add_message_node { return $message; } } my $message = { my $message = Travel::Status::DE::HAFAS::Message->new( header => $header, lead => $lead, ref_count => 1, }; ); push( @{ $self->{messages} }, $message ); return $message; } Loading
lib/Travel/Status/DE/HAFAS/Message.pm 0 → 100644 +98 −0 Original line number Diff line number Diff line package Travel::Status::DE::HAFAS::Message; use strict; use warnings; use 5.014; use parent 'Class::Accessor'; our $VERSION = '3.01'; Travel::Status::DE::HAFAS::Message->mk_ro_accessors(qw(header lead ref_count)); sub new { my ( $obj, %conf ) = @_; my $ref = \%conf; bless( $ref, $obj ); return $ref; } 1; __END__ =head1 NAME Travel::Status::DE::HAFAS::Message - An arrival/departure-related message. =head1 SYNOPSIS if ($message->lead) { printf("%s: %s\n", $message->header, $message->lead); } else { say $message->header; } =head1 VERSION version 3.01 =head1 DESCRIPTION Travel::Status::DE::HAFAS::Message describes a message belonging to an arrival or departure. Messages may refer to planned schedule changes due to construction work, the expected passenger volume, or similar. =head1 METHODS =head2 ACCESSORS =over =item $message->header Message header. May be a concise single-sentence summary or a mostly useless string such as "Information". Does not contain newlines. =item $message->lead Detailed message content. Does not contain newlines. =item $message->ref_count Counter indicating how often this message is used by the requested arrivals/departures. ref_count is an integer between 1 and the number of results. If ref_count is 1, it is referenced by a single result only. =back =head1 DIAGNOSTICS None. =head1 DEPENDENCIES =over =item Class::Accessor(3pm) =back =head1 BUGS AND LIMITATIONS None known. =head1 SEE ALSO Travel::Status::DE::HAFAS(3pm). =head1 AUTHOR Copyright (C) 2020 by Daniel Friesel E<lt>derf@finalrewind.orgE<gt> =head1 LICENSE This module is licensed under the same terms as Perl itself.