| File: | lib/Net/MQTT/Message/ConnAck.pm |
| Coverage: | 95.1% |
| line | stmt | bran | cond | sub | pod | time | code |
|---|---|---|---|---|---|---|---|
| 1 | 3 3 3 | 3247 19 221 | use strict; | ||||
| 2 | 3 3 3 | 38 19 434 | use warnings; | ||||
| 3 | package 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 | |||||||
| 22 | sub message_type { | ||||||
| 23 | 11 | 296 | 2 | ||||
| 24 | } | ||||||
| 25 | |||||||
| 26 | sub attributes { | ||||||
| 27 | 0 | 0 | (shift->SUPER::attributes, qw/connack_reserved return_code/) | ||||
| 28 | } | ||||||
| 29 | |||||||
| 30 | =method C<connack_reserved()> | ||||||
| 31 | |||||||
| 32 | Returns the reserved field of the MQTT Connection Acknowledgement | ||||||
| 33 | message. | ||||||
| 34 | |||||||
| 35 | =cut | ||||||
| 36 | |||||||
| 37 | 4 | 174 | sub connack_reserved { shift->{connack_reserved} || 0 } | ||||
| 38 | |||||||
| 39 | =method C<return_code()> | ||||||
| 40 | |||||||
| 41 | Returns the return code field of the MQTT Connection Acknowledgement | ||||||
| 42 | message. The module L<Net::MQTT::Constants> provides a function, | ||||||
| 43 | C<connect_return_code_string>, that can be used to convert this value | ||||||
| 44 | to a human readable string. | ||||||
| 45 | |||||||
| 46 | =cut | ||||||
| 47 | |||||||
| 48 | 8 | 311 | sub return_code { shift->{return_code} || MQTT_CONNECT_ACCEPTED } | ||||
| 49 | |||||||
| 50 | sub _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 | |||||||
| 56 | sub _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 | |||||||
| 64 | sub _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 | |||||||
| 70 | 1; | ||||||