File Coverage

blib/lib/BACnet/DataTypes/UnsignedInt.pm
Criterion Covered Total %
statement 28 30 93.3
branch 1 2 50.0
condition n/a
subroutine 7 7 100.0
pod 0 2 0.0
total 36 41 87.8


line stmt bran cond sub pod time code
1             #!/usr/bin/perl
2              
3             package BACnet::DataTypes::UnsignedInt;
4              
5 27     27   161 use warnings;
  27         50  
  27         1599  
6 27     27   140 use strict;
  27         45  
  27         727  
7              
8 27     27   120 use BACnet::DataTypes::Utils;
  27         40  
  27         611  
9              
10 27     27   109 use parent 'BACnet::DataTypes::DataType';
  27         44  
  27         168  
11              
12 27     27   2266 use constant { BYTE_MODULAR => ( 2**8 ) };
  27         51  
  27         9502  
13              
14             sub construct {
15 76     76 0 236153 my ( $class, $input_int, $modified_tag ) = @_;
16              
17 76         284 my $self = {
18             data => '',
19             val => $input_int,
20             };
21              
22             # Context Tag doc. page 378
23              
24 76         313 my ( $len_in_octets, $encoded_int ) =
25             BACnet::DataTypes::Utils::_encode_nonnegative_int($input_int);
26              
27 76         285 $self->{data} .= BACnet::DataTypes::Utils::_construct_head(
28             BACnet::DataTypes::Utils::UNSIGNED_INT_TAG,
29             $modified_tag, $len_in_octets );
30              
31 76         169 $self->{data} .= $encoded_int;
32              
33 76         342 return bless $self, $class;
34             }
35              
36             sub parse {
37 76     76 0 200 my ( $class, $data_in ) = @_;
38              
39 76         302 my $self = bless { data => $data_in, }, $class;
40 76         317 my $head = unpack( 'C', substr( $data_in, 0, 1 ) );
41              
42 76         246 my $headache = BACnet::DataTypes::Utils::_correct_head(
43             data_in => $data_in,
44             expected_tag => BACnet::DataTypes::Utils::UNSIGNED_INT_TAG,
45             );
46              
47 76 50       238 if ( $headache ne "" ) {
48 0         0 $self->{error} = "Unsigned Int: $headache";
49 0         0 return $self;
50             }
51              
52             $self->{val} =
53 76         215 BACnet::DataTypes::Utils::_decode_nonnegative_int(
54             substr( $data_in, BACnet::DataTypes::Utils::_get_head_length($data_in) )
55             );
56              
57 76         423 return $self;
58             }
59              
60             1;