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