File: | lib/Net/MQTT/Message/JustMessageId.pm |
Coverage: | 93.5% |
line | stmt | bran | cond | sub | pod | time | code |
---|---|---|---|---|---|---|---|
1 | 3 3 3 | 1036 18 202 | use strict; | ||||
2 | 3 3 3 | 38 16 440 | use warnings; | ||||
3 | package Net::MQTT::Message::JustMessageId; | ||||||
4 | |||||||
5 | # ABSTRACT: Perl module for an MQTT message w/message id only payload | ||||||
6 | |||||||
7 - 17 | =head1 SYNOPSIS # abstract class not instantiated directly =head1 DESCRIPTION This module encapsulates a single MQTT message that has only a message id in its payload. This is an abstract class used to implement a number of other MQTT messages such as PubAck, PubComp, etc. =cut | ||||||
18 | |||||||
19 | 3 3 3 | 38 21 658 | use base 'Net::MQTT::Message'; | ||||
20 | 3 3 3 | 42 17 89 | use Net::MQTT::Constants qw/:all/; | ||||
21 | |||||||
22 | sub attributes { | ||||||
23 | 0 | 0 | (shift->SUPER::attributes, qw/message_id/) | ||||
24 | } | ||||||
25 | |||||||
26 | =method C<message_id()> | ||||||
27 | |||||||
28 | Returns the message id field of the MQTT message. | ||||||
29 | |||||||
30 | =cut | ||||||
31 | |||||||
32 | 20 | 843 | sub message_id { shift->{message_id} } | ||||
33 | |||||||
34 | sub _remaining_string { | ||||||
35 | 10 | 88 | my ($self, $prefix) = @_; | ||||
36 | 10 | 142 | $self->message_id.' '.$self->SUPER::_remaining_string($prefix) | ||||
37 | } | ||||||
38 | |||||||
39 | sub _parse_remaining { | ||||||
40 | 5 | 45 | my $self = shift; | ||||
41 | 5 | 34 | my $offset = 0; | ||||
42 | 5 | 160 | $self->{message_id} = decode_short($self->{remaining}, \$offset); | ||||
43 | 5 | 233 | substr $self->{remaining}, 0, $offset, ''; | ||||
44 | } | ||||||
45 | |||||||
46 | sub _remaining_bytes { | ||||||
47 | 10 | 81 | my $self = shift; | ||||
48 | 10 | 107 | encode_short($self->message_id) | ||||
49 | } | ||||||
50 | |||||||
51 | 1; |