File Coverage

blib/lib/Travel/Status/DE/HAFAS/Message.pm
Criterion Covered Total %
statement 23 29 79.3
branch 1 2 50.0
condition n/a
subroutine 5 6 83.3
pod 1 2 50.0
total 30 39 76.9


line stmt bran cond sub pod time code
1             package Travel::Status::DE::HAFAS::Message;
2              
3 5     5   30 use strict;
  5         9  
  5         168  
4 5     5   24 use warnings;
  5         9  
  5         232  
5 5     5   83 use 5.014;
  5         17  
6              
7 5     5   26 use parent 'Class::Accessor';
  5         9  
  5         64  
8              
9             our $VERSION = '6.25';
10              
11             Travel::Status::DE::HAFAS::Message->mk_ro_accessors(
12             qw(short type text code prio is_him ref_count));
13              
14             sub new {
15 31     31 1 122 my ( $obj, %conf ) = @_;
16              
17 31         64 my $json = $conf{json};
18 31         56 my $is_him = $conf{is_him};
19              
20 31         59 my $short = $json->{txtS};
21 31         85 my $text = $json->{txtN};
22 31         74 my $type = $json->{type};
23 31         59 my $code = $json->{code};
24 31         57 my $prio = $json->{prio};
25              
26 31 50       79 if ($is_him) {
27 0         0 $short = $json->{head};
28 0         0 $text = $json->{text};
29 0         0 $code = $json->{hid};
30             }
31              
32             my $ref = {
33             short => $short,
34             text => $text,
35             type => $type,
36             code => $code,
37             prio => $prio,
38             is_him => $is_him,
39             ref_count => $conf{ref_count},
40 31         295 };
41              
42 31         73 bless( $ref, $obj );
43              
44 31         102 return $ref;
45             }
46              
47             sub TO_JSON {
48 0     0 0   my ($self) = @_;
49              
50 0           return { %{$self} };
  0            
51             }
52              
53             1;
54              
55             __END__
56              
57             =head1 NAME
58              
59             Travel::Status::DE::HAFAS::Message - An arrival/departure-related message.
60              
61             =head1 SYNOPSIS
62              
63             if ($message->text) {
64             printf("%s: %s\n", $message->short, $message->text);
65             }
66             else {
67             say $message->short;
68             }
69              
70             =head1 VERSION
71              
72             version 6.25
73              
74             =head1 DESCRIPTION
75              
76             Travel::Status::DE::HAFAS::Message describes a message belonging to an
77             arrival or departure. Messages may refer to planned schedule changes due to
78             construction work, the expected passenger volume, or similar.
79              
80             =head1 METHODS
81              
82             =head2 ACCESSORS
83              
84             =over
85              
86             =item $message->short
87              
88             Message header. May be a concise single-sentence summary or a mostly useless
89             string such as "Information". Does not contain newlines.
90              
91             =item $message->text
92              
93             Detailed message content. Does not contain newlines.
94              
95             =item $message->code
96              
97             Two-digit message code, seems to be only used with messages of type "A".
98             Details unknown.
99              
100             =item $message->type
101              
102             A single character indicating the message type.
103             The following types are known:
104              
105             =over
106              
107             =item A
108              
109             Generic information about a specific trip such as "WiFi available", "air
110             conditioning", "DB tickets are not valid here", or "from here on as [line]
111             towards [destination]".
112              
113             =item C
114              
115             "Current information available", "Journey cancelled", "connection may not be caught", possibly more.
116              
117             =item D
118              
119             Large-scale disruption, e.g. medical emergency on line.
120              
121             =item G
122              
123             Platform change, possibly more.
124              
125             =item H
126              
127             Misc stuff such as "Journey contains trains with mandatory reservation" or
128             "ICE Sprinter".
129              
130             =item L
131              
132             Replacement journey
133              
134             =item M
135              
136             Free-text infos about construction sites, broken elevators, large events and
137             similar occasions.
138              
139             =item P
140              
141             Journey has been cancelled, possibly more.
142              
143             =back
144              
145             =item $message->ref_count
146              
147             Counter indicating how often this message is used by the requested
148             arrivals/departures. ref_count is an integer between 1 and the number of
149             results. If ref_count is 1, it is referenced by a single result only.
150              
151             =item $message->is_him
152              
153             True if it is a HIM message (typically used for service information), false
154             if not (message may be a REM instead, indicating e.g. presence of a bicycle
155             carriage or WiFi).
156              
157             =back
158              
159             =head1 DIAGNOSTICS
160              
161             None.
162              
163             =head1 DEPENDENCIES
164              
165             =over
166              
167             =item Class::Accessor(3pm)
168              
169             =back
170              
171             =head1 BUGS AND LIMITATIONS
172              
173             None known.
174              
175             =head1 SEE ALSO
176              
177             Travel::Status::DE::HAFAS(3pm).
178              
179             =head1 AUTHOR
180              
181             Copyright (C) 2020-2023 by Birte Kristina Friesel E<lt>derf@finalrewind.orgE<gt>
182              
183             =head1 LICENSE
184              
185             This module is licensed under the same terms as Perl itself.