1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
|
package Net::CLI::Interact::Transport::Serial;
{
$Net::CLI::Interact::Transport::Serial::VERSION = '1.121640';
}
use Moose;
extends 'Net::CLI::Interact::Transport';
{
package # hide from pause
Net::CLI::Interact::Transport::Serial::Options;
use Moose;
use Moose::Util::TypeConstraints qw(enum);
extends 'Net::CLI::Interact::Transport::Options';
has 'device' => (
is => 'rw',
isa => 'Str',
required => 1,
);
has 'parity' => (
is => 'rw',
isa => enum([qw/none even odd/]);
default => 'none',
required => 0,
);
has 'nostop' => (
is => 'rw',
isa => 'Bool',
default => 0,
required => 0,
);
has 'speed' => (
is => 'rw',
isa => 'Int',
default => 9600,
required => 0,
);
use Moose::Util::TypeConstraints;
coerce 'Net::CLI::Interact::Transport::Serial::Options'
=> from 'HashRef[Any]'
=> via { Net::CLI::Interact::Transport::Serial::Options->new($_) };
}
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
has 'connect_options' => (
is => 'ro',
isa => 'Net::CLI::Interact::Transport::Serial::Options',
coerce => 1,
required => 1,
);
sub _build_app {
my $self = shift;
confess "please pass location of plink.exe in 'app' parameter to new()\n"
if $self->is_win32;
return 'cu'; # unix
}
sub runtime_options {
my $self = shift;
if ($self->is_win32) {
return ('-serial',);
}
else {
return (
('--parity=' . $self->connect_options->parity),
('-l ' . $self->connect_options->device),
('-s ' . $self->connect_options->speed),
($self->connect_options->nostop ? '--nostop' : ()),
);
}
}
1;
# ABSTRACT: Serial-line based CLI connection
__END__
=pod
=head1 NAME
Net::CLI::Interact::Transport::Serial - Serial-line based CLI connection
=head1 VERSION
version 1.121640
=head1 DECRIPTION
This module provides a wrapped instance of a Serial-line client for use by
L<Net::CLI::Interact>.
=head1 INTERFACE
=head2 app
On Windows platforms you B<must> download the C<plink.exe> program, and pass its
location to the library in this parameter. On other platforms, this defaults to
C<cu>, which again you B<must> download and install.
=head2 runtime_options
Based on the C<connect_options> hash provided to Net::CLI::Interact on
construction, selects and formats parameters to provide to C<app> on the
command line. Supported attributes:
B<FIXME:> on Windows platforms, only the device attribute is supported.
=over 4
=item device (required)
Name of the device providing access to the Serial-line (e.g. C<< /dev/ttyUSB0
>> or C<COM5>.
=item parity
You have a choice of C<even>, C<odd> or C<none> for the parity used in serial
communication. The default is C<none>.
=item nostop
You can control whether to use C<XON/XOFF> handling for the serial
communication. The default is to disable this, so to enable it pass any True
value.
=item speed
You can set the speed (or I<baud rate>) of the serial line by passing a value
to this named parameter. The default is C<9600>.
=item reap
Only used on Unix platforms, this installs a signal handler which attempts to
reap the C<ssh> child process. Pass a true value to enable this feature only
if you notice zombie processes are being left behind after use.
=back
=head1 COMPOSITION
See the following for further interface details:
=over 4
=item *
L<Net::CLI::Interact::Transport>
=back
=head1 AUTHOR
Oliver Gorwits <oliver@cpan.org>
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2012 by Oliver Gorwits.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=cut
|