File Coverage

blib/lib/BACnet/DataTypes/SequenceOfValues.pm
Criterion Covered Total %
statement 46 58 79.3
branch 16 22 72.7
condition n/a
subroutine 6 6 100.0
pod 0 2 0.0
total 68 88 77.2


line stmt bran cond sub pod time code
1             #!/usr/bin/perl
2              
3             package BACnet::DataTypes::SequenceOfValues;
4              
5 27     27   165 use warnings;
  27         50  
  27         1620  
6 27     27   141 use strict;
  27         44  
  27         598  
7              
8 27     27   117 use BACnet::DataTypes::Utils;
  27         74  
  27         676  
9              
10 27     27   101 use parent 'BACnet::DataTypes::DataType';
  27         588  
  27         398  
11              
12             require BACnet::DataTypes::BitString;
13             require BACnet::DataTypes::Bool;
14             require BACnet::DataTypes::Date;
15             require BACnet::DataTypes::Double;
16             require BACnet::DataTypes::Enum;
17             require BACnet::DataTypes::Int;
18             require BACnet::DataTypes::Null;
19             require BACnet::DataTypes::ObjectIdentifier;
20             require BACnet::DataTypes::OctetString;
21             require BACnet::DataTypes::Real;
22             require BACnet::DataTypes::SequenceValue;
23             require BACnet::DataTypes::SequenceOfValues;
24             require BACnet::DataTypes::Time;
25             require BACnet::DataTypes::UnsignedInt;
26             require BACnet::DataTypes::CharString;
27              
28             sub construct {
29 10     10 0 4747 my ( $class, $values, $modified_tag ) = @_;
30              
31 10         31 my $self = {
32             data => '',
33             val => $values,
34             };
35              
36 10 100       30 if ( defined $modified_tag ) {
37 8         29 $self->{data} .= BACnet::DataTypes::Utils::_make_head( $modified_tag, 1,
38             BACnet::DataTypes::Utils::OPENING_LVT, 1 );
39             }
40              
41 10         20 for my $val ( @{$values} ) {
  10         21  
42 24         67 $self->{data} .= $val->data();
43             }
44              
45 10 100       29 if ( defined $modified_tag ) {
46 8         32 $self->{data} .= BACnet::DataTypes::Utils::_make_head( $modified_tag, 1,
47             BACnet::DataTypes::Utils::CLOSING_LVT, 1 );
48             }
49              
50 10         36 return bless $self, $class;
51             }
52              
53             sub parse {
54 10     10 0 25 my ( $class, $data_in, $skeleton ) = @_;
55              
56 10         35 my $self = bless { data => $data_in, val => [] }, $class;
57              
58 10 100       30 if ( ( length $data_in ) == 0 ) {
59 1         2 return $self;
60             }
61              
62 9         13 my $head_index = 0;
63 9         18 my $context_tag = undef;
64              
65 9 100       30 if ( BACnet::DataTypes::Utils::_is_context_sequence($data_in) ) {
66 8         32 $context_tag = BACnet::DataTypes::Utils::_get_head_tag($data_in);
67              
68 8 50       20 if ( $context_tag == -1 ) {
69             $self->{error} =
70 0         0 "SequenceOfValues: opening context lvt tag parse error";
71 0         0 return $self;
72             }
73 8         25 $head_index += BACnet::DataTypes::Utils::_get_head_length($data_in);
74             }
75              
76 9         27 while ( length($data_in) > $head_index ) {
77 32 100       91 if (
78             BACnet::DataTypes::Utils::_is_end_of_context_sequence(
79             substr( $data_in, $head_index )
80             )
81             )
82             {
83 8 50       28 if (
84             $context_tag != BACnet::DataTypes::Utils::_get_head_tag(
85             substr( $data_in, $head_index )
86             )
87             )
88             {
89             $self->{error} =
90 0         0 "SequenceOfValues: sudden closing context lvt tag parse error";
91 0         0 return $self;
92             }
93             else {
94 8         38 $self->{data} = substr( $data_in, 0,
95             $head_index +
96             BACnet::DataTypes::Utils::_get_head_length($data_in) );
97 8         35 return $self;
98             }
99             }
100              
101 24         84 my $new_dt = BACnet::DataTypes::Utils::_parse_context_dt(
102             substr( $data_in, $head_index ),
103             $skeleton->[0] );
104              
105 24 50       87 if ( !defined $new_dt ) {
106 0         0 $self->{error} = "SequenceOfValues: unexpected parse error";
107 0         0 return $self;
108             }
109              
110 24 50       107 if ( defined $new_dt->error() ) {
111 0         0 my $error = $new_dt->error();
112 0         0 $self->{error} = "SequenceOfValues: propagated error from($error)";
113 0         0 return $self;
114             }
115              
116 24 50       64 if ( length( $new_dt->{data} ) == 0 ) {
117 0         0 $self->{error} = "SequenceOfValues: unparsable elements";
118 0         0 return $self;
119             }
120              
121 24         32 push( @{ $self->{val} }, $new_dt );
  24         59  
122 24         50 $head_index += length( $new_dt->data() );
123             }
124              
125 1 50       4 if ( defined $context_tag ) {
126             $self->{error} =
127 0         0 "SequenceOfValues: closing context lvt tag parse error";
128             }
129              
130 1         3 return $self;
131              
132             }
133              
134             1;