File Coverage

blib/lib/Net/MQTT/Message/Unsubscribe.pm
Criterion Covered Total %
statement 33 33 100.0
branch n/a
condition n/a
subroutine 12 12 100.0
pod 3 3 100.0
total 48 48 100.0


line stmt bran cond sub pod time code
1 3     3   1623 use strict;
  3         4  
  3         88  
2 3     3   12 use warnings;
  3         2  
  3         112  
3             package Net::MQTT::Message::Unsubscribe;
4             $Net::MQTT::Message::Unsubscribe::VERSION = '1.143260';
5             # ABSTRACT: Perl module to represent an MQTT Unsubscribe message
6              
7              
8 3     3   11 use base 'Net::MQTT::Message';
  3         5  
  3         182  
9 3     3   13 use Net::MQTT::Constants qw/:all/;
  3         3  
  3         12  
10              
11             sub message_type {
12 7     7 1 14 10
13             }
14              
15             sub _default_qos {
16 2     2   7 MQTT_QOS_AT_LEAST_ONCE
17             }
18              
19              
20 4     4 1 11 sub message_id { shift->{message_id} }
21              
22              
23 2     2 1 4 sub topics { shift->{topics} }
24              
25 2     2   2 sub _topics_string { join ',', @{shift->{topics}} }
  2         11  
26              
27             sub _remaining_string {
28 2     2   3 my ($self, $prefix) = @_;
29 2         5 $self->message_id.' '.$self->_topics_string.' '.
30             $self->SUPER::_remaining_string($prefix)
31             }
32              
33             sub _parse_remaining {
34 1     1   2 my $self = shift;
35 1         1 my $offset = 0;
36 1         9 $self->{message_id} = decode_short($self->{remaining}, \$offset);
37 1         5 while ($offset < length $self->{remaining}) {
38 1         1 push @{$self->{topics}}, decode_string($self->{remaining}, \$offset);
  1         6  
39             }
40 1         4 substr $self->{remaining}, 0, $offset, '';
41             }
42              
43             sub _remaining_bytes {
44 2     2   3 my $self = shift;
45 2         4 my $o = encode_short($self->message_id);
46 2         3 foreach my $name (@{$self->topics}) {
  2         5  
47 2         6 $o .= encode_string($name);
48             }
49             $o
50 2         5 }
51              
52             1;
53              
54             __END__