File Coverage

blib/lib/Protocol/Modbus/Exception.pm
Criterion Covered Total %
statement 40 40 100.0
branch n/a
condition 1 3 33.3
subroutine 14 14 100.0
pod 0 4 0.0
total 55 61 90.1


line stmt bran cond sub pod time code
1             package Protocol::Modbus::Exception;
2              
3 5     5   34 use strict;
  5         9  
  5         206  
4 5     5   26 use overload '""' => \&stringify;
  5         17  
  5         35  
5              
6 5     5   417 use constant ILLEGAL_FUNCTION_CODE => 0x01;
  5         10  
  5         367  
7 5     5   24 use constant ILLEGAL_DATA_ADDRESS => 0x02;
  5         8  
  5         233  
8 5     5   30 use constant ILLEGAL_DATA_VALUE => 0x03;
  5         8  
  5         206  
9 5     5   23 use constant SERVER_FAILURE => 0x04;
  5         12  
  5         231  
10 5     5   22 use constant ACKNOWLEDGE => 0x05;
  5         88  
  5         844  
11 5     5   562 use constant SERVER_BUSY => 0x06;
  5         687  
  5         767  
12 5     5   25 use constant GATEWAY_PROBLEM1 => 0x0A;
  5         7  
  5         187  
13 5     5   24 use constant GATEWAY_PROBLEM2 => 0x0B;
  5         8  
  5         1007  
14              
15             sub new {
16 1     1 0 5 my ($obj, %args) = @_;
17 1   33     7 my $class = ref($obj) || $obj;
18 1         4 my $self = {%args};
19 1         7 bless $self, $class;
20             }
21              
22             # Fallback on 'new()'
23             *throw = *new;
24              
25             sub code {
26 3     3 0 174 my $self = $_[0];
27 3         31 return $self->{code};
28             }
29              
30             sub function {
31 2     2 0 4 my $self = $_[0];
32 2         7 return $self->{function};
33             }
34              
35             sub stringify {
36 2     2 0 1140 my $self = $_[0];
37 2         7 return sprintf('Modbus Exception (func=%s, code=%s)', $self->function, $self->code);
38             }
39              
40             1;