Interact/Transport/Serial.pm

filter: Statementstmt 66.6% 18 / 27 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 75.0% 6 / 8 Podpod n/a totaltotal 58.5% 24 / 41 CC 4 SCAR 15.9
CC
4
Cov
55%
runtime_options
12.0
_build_app
6.0
BEGIN
1.0
CRAP 4.9
« Interact/Transport/Telnet.pm ↑ Summary Interact/Role/FindMatch.pm »
1 package Net::CLI::Interact::Transport::Serial;
2 $Net::CLI::Interact::Transport::Serial::VERSION = '2.400001';
3 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Sub::Quote;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use MooX::Types::MooseLike::Base qw(InstanceOf);
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 extends 'Net::CLI::Interact::Transport::Base';
8  
9 {
10 package # hide from pause
11 Net::CLI::Interact::Transport::Serial::Options;
12  
13 1 ▶ use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶ use Sub::Quote;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶ use MooX::Types::MooseLike::Base qw(Str Bool Int ArrayRef Any);
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 extends 'Net::CLI::Interact::Transport::Options';
18  
19 has 'device' => (
20 is => 'rw',
21 isa => Str,
22 required => 1,
23 );
24  
25 has 'parity' => (
26 is => 'rw',
27 isa => quote_sub(
28 q{ die "$_[0] not none/even/odd" unless $_[0] =~ m/^(?:none|even|odd)$/ }),
29 default => quote_sub(q{'none'}),
30 );
31  
32 has 'nostop' => (
33 is => 'rw',
34 isa => Bool,
35 default => quote_sub('0'),
36 );
37  
38 has 'speed' => (
39 is => 'rw',
40 isa => Int,
41 default => quote_sub('9600'),
42 );
43  
44 has 'opts' => (
45 is => 'rw',
46 isa => ArrayRef[Any],
47 default => sub { [] },
48 );
49 }
50 # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
51  
52 has 'connect_options' => (
53 is => 'ro',
54 isa => InstanceOf['Net::CLI::Interact::Transport::Serial::Options'],
55 coerce => quote_sub(q{ (ref '' eq ref $_[0]) ? $_[0] :
56 Net::CLI::Interact::Transport::Serial::Options->new(@_) }),
57 required => 1,
58 );
59  
60 sub _build_app {
61 0 ▶ my $self = shift;
Subroutine _build_app: not called CC=2 SCAR=17.9
62 0 ▶ die "please pass location of plink.exe in 'app' parameter to new()\n"
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_win32 0 0 0
63 if $self->is_win32;
64 0 return 'cu'; # unix
65 }
66  
67 sub runtime_options {
68 0 ▶ my $self = shift;
Subroutine runtime_options: not called CC=3 SCAR=24.8
69  
70 0 ▶ if ($self->is_win32) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->is_win32) { } 0 0 0
71 return (
72 '-serial',
73 0 @{$self->connect_options->opts},
74 $self->connect_options->device,
75 );
76 }
77 else {
78 return (
79 ('--parity=' . $self->connect_options->parity),
80 ('-l', $self->connect_options->device),
81 ('-s', $self->connect_options->speed),
82 ($self->connect_options->nostop ? '--nostop' : ()),
83 0 ▶ @{$self->connect_options->opts},
Branch: 1 branch
BranchTrueFalseTotal
$self->connect_options->nostop ? : 0 0 0
84 );
85 }
86 }
87  
88 1;
89  
90 =pod
91  
92 =head1 NAME
93  
94 Net::CLI::Interact::Transport::Serial - Serial-line based CLI connection
95  
96 =head1 DESCRIPTION
97  
98 This module provides a wrapped instance of a Serial-line client for use by
99 L<Net::CLI::Interact>.
100  
101 =head1 INTERFACE
102  
103 =head2 app
104  
105 On Windows platforms you B<must> download the C<plink.exe> program, and pass its
106 location to the library in this parameter. On other platforms, this defaults to
107 C<cu>, which again you B<must> download and install.
108  
109 =head2 runtime_options
110  
111 Based on the C<connect_options> hash provided to Net::CLI::Interact on
112 construction, selects and formats parameters to provide to C<app> on the
113 command line. Supported attributes:
114  
115 B<FIXME:> on Windows platforms, only the device attribute is supported.
116  
117 =over 4
118  
119 =item device (required)
120  
121 Name of the device providing access to the Serial-line (e.g. C<< /dev/ttyUSB0
122 >> or C<COM5>.
123  
124 =item parity
125  
126 You have a choice of C<even>, C<odd> or C<none> for the parity used in serial
127 communication. The default is C<none>.
128  
129 =item nostop
130  
131 You can control whether to use C<XON/XOFF> handling for the serial
132 communication. The default is to disable this, so to enable it pass any True
133 value.
134  
135 =item speed
136  
137 You can set the speed (or I<baud rate>) of the serial line by passing a value
138 to this named parameter. The default is C<9600>.
139  
140 =item opts
141  
142 If you want to pass any other options to the application, then use
143 this option, which should be an array reference. Each item in the list will be
144 passed to the application, separated by a single space character.
145  
146 =item reap
147  
148 Only used on Unix platforms, this installs a signal handler which attempts to
149 reap the child process. Pass a true value to enable this feature only
150 if you notice zombie processes are being left behind after use.
151  
152 =back
153  
154 =head1 COMPOSITION
155  
156 See the following for further interface details:
157  
158 =over 4
159  
160 =item *
161  
162 L<Net::CLI::Interact::Transport::Base>
163  
164 =back
165  
166 =cut
167  
« Interact/Transport/Telnet.pm ↑ Summary Interact/Role/FindMatch.pm »