| File: | lib/Net/MQTT/Message/Unsubscribe.pm |
| Coverage: | 95.7% |
| line | stmt | bran | cond | sub | pod | time | code |
|---|---|---|---|---|---|---|---|
| 1 | 3 3 3 | 3317 21 233 | use strict; | ||||
| 2 | 3 3 3 | 55 17 402 | use warnings; | ||||
| 3 | package Net::MQTT::Message::Unsubscribe; | ||||||
| 4 | |||||||
| 5 | # ABSTRACT: Perl module to represent an MQTT Unsubscribe message | ||||||
| 6 | |||||||
| 7 - 17 | =head1 SYNOPSIS # instantiated by Net::MQTT::Message =head1 DESCRIPTION This module encapsulates a single MQTT Unsubscribe 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 | 76 57 701 | use base 'Net::MQTT::Message'; | ||||
| 20 | 3 3 3 | 44 15 94 | use Net::MQTT::Constants qw/:all/; | ||||
| 21 | |||||||
| 22 | sub message_type { | ||||||
| 23 | 7 | 220 | 10 | ||||
| 24 | } | ||||||
| 25 | |||||||
| 26 | sub attributes { | ||||||
| 27 | 0 | 0 | (shift->SUPER::attributes, qw/message_id topics/) | ||||
| 28 | } | ||||||
| 29 | |||||||
| 30 | sub _default_qos { | ||||||
| 31 | 2 | 66 | MQTT_QOS_AT_LEAST_ONCE | ||||
| 32 | } | ||||||
| 33 | |||||||
| 34 | =method C<message_id()> | ||||||
| 35 | |||||||
| 36 | Returns the message id field of the MQTT Unsubscribe message. | ||||||
| 37 | |||||||
| 38 | =cut | ||||||
| 39 | |||||||
| 40 | 4 | 95 | sub message_id { shift->{message_id} } | ||||
| 41 | |||||||
| 42 | =method C<topics()> | ||||||
| 43 | |||||||
| 44 | Returns the list of topics of the MQTT Subscribe message. | ||||||
| 45 | |||||||
| 46 | =cut | ||||||
| 47 | |||||||
| 48 | 2 | 25 | sub topics { shift->{topics} } | ||||
| 49 | |||||||
| 50 | 2 2 | 15 173 | sub _topics_string { join ',', @{shift->{topics}} } | ||||
| 51 | |||||||
| 52 | sub _remaining_string { | ||||||
| 53 | 2 | 22 | my ($self, $prefix) = @_; | ||||
| 54 | 2 | 24 | $self->message_id.' '.$self->_topics_string.' '. | ||||
| 55 | $self->SUPER::_remaining_string($prefix) | ||||||
| 56 | } | ||||||
| 57 | |||||||
| 58 | sub _parse_remaining { | ||||||
| 59 | 1 | 12 | my $self = shift; | ||||
| 60 | 1 | 10 | my $offset = 0; | ||||
| 61 | 1 | 36 | $self->{message_id} = decode_short($self->{remaining}, \$offset); | ||||
| 62 | 1 | 20 | while ($offset < length $self->{remaining}) { | ||||
| 63 | 1 1 | 8 40 | push @{$self->{topics}}, decode_string($self->{remaining}, \$offset); | ||||
| 64 | } | ||||||
| 65 | 1 | 36 | substr $self->{remaining}, 0, $offset, ''; | ||||
| 66 | } | ||||||
| 67 | |||||||
| 68 | sub _remaining_bytes { | ||||||
| 69 | 2 | 18 | my $self = shift; | ||||
| 70 | 2 | 35 | my $o = encode_short($self->message_id); | ||||
| 71 | 2 2 | 18 20 | foreach my $name (@{$self->topics}) { | ||||
| 72 | 2 | 58 | $o .= encode_string($name); | ||||
| 73 | } | ||||||
| 74 | $o | ||||||
| 75 | 2 | 60 | } | ||||
| 76 | |||||||
| 77 | 1; | ||||||