File Coverage

blib/lib/Protocol/Modbus/Transport.pm
Criterion Covered Total %
statement 9 28 32.1
branch 0 4 0.0
condition 0 6 0.0
subroutine 3 10 30.0
pod 4 6 66.6
total 16 54 29.6


line stmt bran cond sub pod time code
1             package Protocol::Modbus::Transport;
2              
3 5     5   24 use strict;
  5         13  
  5         163  
4 5     5   24 use warnings;
  5         22  
  5         119  
5 5     5   27 use Carp ();
  5         8  
  5         1924  
6              
7             sub new {
8 0     0 0   my ($obj, %args) = @_;
9 0   0       my $class = ref($obj) || $obj;
10 0           my $self = {_options => {%args},};
11              
12             # If driver property specified, load "additional" modbus transport class (TCP / Serial)
13 0 0 0       if (exists $args{driver} && $args{driver} ne '') {
14 0           $class = "Protocol::Modbus::Transport::$args{driver}";
15 0           eval "use $class";
16 0 0         if ($@) {
17 0           Carp::croak(
18             "Protocol::Modbus::Transport driver `$args{driver}' failed to load: $@");
19 0           return (undef);
20             }
21             }
22              
23 0           bless $self, $class;
24             }
25              
26             sub options {
27 0     0 0   my $self = $_[0];
28 0           return $self->{_options};
29             }
30              
31             #
32             # Transport virtual methods
33             #
34             sub _virtual {
35 0     0     my ($meth) = @_;
36 0           croak($meth . '() must be implemented by transport layer!');
37 0           return undef;
38             }
39              
40             sub connect {
41 0     0 1   _virtual('connect');
42             }
43              
44             sub disconnect {
45 0     0 1   _virtual('disconnect');
46             }
47              
48             sub send {
49 0     0 1   _virtual('send');
50             }
51              
52             sub receive {
53 0     0 1   _virtual('receive');
54             }
55              
56             1;
57              
58             =head1 NAME
59              
60             Protocol::Modbus::Transport - Modbus protocol transport layer base class
61              
62             =head1 DESCRIPTION
63              
64             Abstract class. No use unless it's derived.
65              
66             =head1 METHODS
67              
68             =over +
69              
70             =item connect
71              
72             =item disconnect
73              
74             =item send
75              
76             =item receive
77              
78             =back
79              
80             =head1 SEE ALSO
81              
82             =over *
83              
84             =item Protocol::Modbus
85              
86             =back
87              
88             =head1 AUTHOR
89              
90             Cosimo Streppone, Ecosimo@cpan.orgE
91              
92             =head1 COPYRIGHT AND LICENSE
93              
94             Copyright (C) 2007 by Cosimo Streppone
95              
96             This library is free software; you can redistribute it and/or modify
97             it under the same terms as Perl itself, either Perl version 5.8.8 or,
98             at your option, any later version of Perl 5 you may have available.
99              
100             =cut