File Coverage

blib/lib/BACnet/DataTypes/Enum.pm
Criterion Covered Total %
statement 24 26 92.3
branch 1 2 50.0
condition n/a
subroutine 6 6 100.0
pod 0 2 0.0
total 31 36 86.1


line stmt bran cond sub pod time code
1             #!/usr/bin/perl
2              
3             package BACnet::DataTypes::Enum;
4              
5 27     27   166 use warnings;
  27         54  
  27         1530  
6 27     27   154 use strict;
  27         58  
  27         699  
7              
8 27     27   164 use BACnet::DataTypes::Utils;
  27         58  
  27         787  
9              
10 27     27   124 use parent 'BACnet::DataTypes::DataType';
  27         57  
  27         219  
11              
12             sub construct {
13 27     27 0 731488 my ( $class, $input_enum, $modified_tag ) = @_;
14              
15 27         106 my $self = {
16             data => '',
17             val => $input_enum,
18             };
19              
20             # Context Tag doc. page 378
21              
22 27         119 my ( $len_in_octets, $encoded_body ) =
23             BACnet::DataTypes::Utils::_encode_nonnegative_int($input_enum);
24              
25 27         108 $self->{data} .= BACnet::DataTypes::Utils::_construct_head(
26             BACnet::DataTypes::Utils::ENUMERATED_TAG,
27             $modified_tag, $len_in_octets );
28              
29 27         67 $self->{data} .= $encoded_body;
30              
31 27         174 return bless $self, $class;
32             }
33              
34             sub parse {
35 30     30 0 93 my ( $class, $data_in ) = @_;
36              
37 30         120 my $self = bless { data => $data_in, }, $class;
38              
39 30         119 my $headache = BACnet::DataTypes::Utils::_correct_head(
40             data_in => $data_in,
41             expected_tag => BACnet::DataTypes::Utils::ENUMERATED_TAG,
42             );
43              
44 30 50       95 if ( $headache ne "" ) {
45 0         0 $self->{error} = "Enum: $headache";
46 0         0 return $self;
47             }
48              
49             $self->{val} =
50 30         90 BACnet::DataTypes::Utils::_decode_nonnegative_int(
51             substr( $data_in, BACnet::DataTypes::Utils::_get_head_length($data_in) )
52             );
53              
54 30         173 return $self;
55             }
56              
57             1;