File Coverage

blib/lib/BACnet/DataTypes/Int.pm
Criterion Covered Total %
statement 25 27 92.5
branch 1 2 50.0
condition n/a
subroutine 6 6 100.0
pod 0 2 0.0
total 32 37 86.4


line stmt bran cond sub pod time code
1             #!/usr/bin/perl
2              
3             package BACnet::DataTypes::Int;
4              
5 27     27   165 use warnings;
  27         49  
  27         1532  
6 27     27   128 use strict;
  27         45  
  27         662  
7              
8 27     27   106 use BACnet::DataTypes::Utils;
  27         45  
  27         599  
9              
10 27     27   101 use parent 'BACnet::DataTypes::DataType';
  27         52  
  27         128  
11              
12             sub construct {
13 47     47 0 1736481 my ( $class, $input_int, $modified_tag ) = @_;
14              
15 47         157 my $self = {
16             data => '',
17             val => $input_int,
18             };
19              
20             # Context Tag doc. page 378
21              
22 47         232 my ( $len_in_octets, $encoded_int ) =
23             BACnet::DataTypes::Utils::_encode_int($input_int);
24              
25 47         158 $self->{data} .= BACnet::DataTypes::Utils::_construct_head(
26             BACnet::DataTypes::Utils::SIGNED_INT_TAG,
27             $modified_tag, $len_in_octets );
28              
29 47         100 $self->{data} .= $encoded_int;
30              
31 47         268 return bless $self, $class;
32             }
33              
34             sub parse {
35 56     56 0 164 my ( $class, $data_in ) = @_;
36              
37 56         194 my $self = bless { data => $data_in, }, $class;
38 56         132 my $head = unpack( 'C', substr( $data_in, 0, 1 ) );
39              
40 56         216 my $headache = BACnet::DataTypes::Utils::_correct_head(
41             data_in => $data_in,
42             expected_tag => BACnet::DataTypes::Utils::SIGNED_INT_TAG,
43             );
44              
45 56 50       186 if ( $headache ne "" ) {
46 0         0 $self->{error} = "Signed Int: $headache";
47 0         0 return $self;
48             }
49              
50             $self->{val} =
51 56         121 BACnet::DataTypes::Utils::_decode_int(
52             substr( $data_in, BACnet::DataTypes::Utils::_get_head_length($data_in) )
53             );
54              
55 56         236 return $self;
56             }
57              
58             1;