File Coverage

File:lib/Net/MQTT/Message/ConnAck.pm
Coverage:95.1%

linestmtbrancondsubpodtimecode
1
3
3
3
3247
19
221
use strict;
2
3
3
3
38
19
434
use warnings;
3package Net::MQTT::Message::ConnAck;
4
5# ABSTRACT: Perl module to represent an MQTT ConnAck message
6
7 - 17
=head1 SYNOPSIS

  # instantiated by Net::MQTT::Message

=head1 DESCRIPTION

This module encapsulates a single MQTT Connection Acknowledgement
message.  It is a specific subclass used by L<Net::MQTT::Message>
and should not need to be instantiated directly.

=cut
18
19
3
3
3
44
17
580
use base 'Net::MQTT::Message';
20
3
3
3
38
15
106
use Net::MQTT::Constants qw/:all/;
21
22sub message_type {
23
11
296
  2
24}
25
26sub attributes {
27
0
0
  (shift->SUPER::attributes, qw/connack_reserved return_code/)
28}
29
30=method C<connack_reserved()>
31
32Returns the reserved field of the MQTT Connection Acknowledgement
33message.
34
35=cut
36
37
4
174
sub connack_reserved { shift->{connack_reserved} || 0 }
38
39=method C<return_code()>
40
41Returns the return code field of the MQTT Connection Acknowledgement
42message. The module L<Net::MQTT::Constants> provides a function,
43C<connect_return_code_string>, that can be used to convert this value
44to a human readable string.
45
46=cut
47
48
8
311
sub return_code { shift->{return_code} || MQTT_CONNECT_ACCEPTED }
49
50sub _remaining_string {
51
4
113
  my ($self, $prefix) = @_;
52
4
111
  connect_return_code_string($self->return_code).
53    ' '.$self->SUPER::_remaining_string($prefix)
54}
55
56sub _parse_remaining {
57
2
20
  my $self = shift;
58
2
17
  my $offset = 0;
59
2
65
  $self->{connack_reserved} = decode_byte($self->{remaining}, \$offset);
60
2
65
  $self->{return_code} = decode_byte($self->{remaining}, \$offset);
61
2
69
  substr $self->{remaining}, 0, $offset, '';
62}
63
64sub _remaining_bytes {
65
4
34
  my $self = shift;
66
4
46
  my $o = encode_byte($self->connack_reserved);
67
4
45
  $o .= encode_byte($self->return_code);
68}
69
701;