| 1 | package Net::CLI::Interact::Transport::Telnet; | ||
| 2 | { | ||
| 3 | $Net::CLI::Interact::Transport::Telnet::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::Telnet::Options; | ||
| 15 | |||
| 16 | use Moo; | ||
| 17 | use Sub::Quote; | ||
| 18 | use MooX::Types::MooseLike::Base qw(Str Int ArrayRef Any); | ||
| 19 | |||
| 20 | extends 'Net::CLI::Interact::Transport::Options'; | ||
| 21 | |||
| 22 | has 'host' => ( | ||
| 23 | is => 'rw', | ||
| 24 | isa => Str, | ||
| 25 | required => 1, | ||
| 26 | ); | ||
| 27 | |||
| 28 | has 'port' => ( | ||
| 29 | is => 'rw', | ||
| 30 | isa => Int, | ||
| 31 | default => quote_sub('23'), | ||
| 32 | ); | ||
| 33 | |||
| 34 | has 'opts' => ( | ||
| 35 | is => 'rw', | ||
| 36 | isa => ArrayRef[Any], | ||
| 37 | default => sub { [] }, | ||
| 38 | ); | ||
| 39 | } | ||
| 40 | # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| 41 | |||
| 42 | # allow native use of Net::Telnet on Unix | ||
| 43 | if (not Net::CLI::Interact::Transport::Base::is_win32()) { | ||
| 44 | has '+use_net_telnet_connection' => ( default => quote_sub('1') ); | ||
| 45 | } | ||
| 46 | |||
| 47 | has 'connect_options' => ( | ||
| 48 | is => 'ro', | ||
| 49 | isa => InstanceOf['Net::CLI::Interact::Transport::Telnet::Options'], | ||
| 50 | coerce => quote_sub(q{ (ref '' eq ref $_[0]) ? $_[0] : | ||
| 51 | Net::CLI::Interact::Transport::Telnet::Options->new(@_) }), | ||
| 52 | required => 1, | ||
| 53 | ); | ||
| 54 | |||
| 55 | sub _build_app { | ||
| 56 | my $self = shift; | ||
| 57 | die "please pass location of plink.exe in 'app' parameter to new()\n" | ||
| 58 | if $self->is_win32; | ||
| 59 | return 'telnet'; | ||
| 60 | } | ||
| 61 | |||
| 62 | sub runtime_options { | ||
| 63 | my $self = shift; | ||
| 64 | if ($self->is_win32) { | ||
| 65 | return ( | ||
| 66 | '-telnet', | ||
| 67 | '-P', $self->connect_options->port, | ||
| 68 | @{$self->connect_options->opts}, | ||
| 69 | $self->connect_options->host, | ||
| 70 | ); | ||
| 71 | } | ||
| 72 | elsif ($self->can_use_pty) { | ||
| 73 | return ( | ||
| 74 | Host => $self->connect_options->host, | ||
| 75 | Port => $self->connect_options->port, | ||
| 76 | @{$self->connect_options->opts}, | ||
| 77 | ); | ||
| 78 | } | ||
| 79 | else { | ||
| 80 | return ( | ||
| 81 | @{$self->connect_options->opts}, | ||
| 82 | $self->connect_options->host, | ||
| 83 | $self->connect_options->port, | ||
| 84 | ); | ||
| 85 | } | ||
| 86 | } | ||
| 87 | |||
| 88 | 1; | ||
| 89 | |||
| 90 | # ABSTRACT: TELNET based CLI connection | ||
| 91 | |||
| 92 | |||
| 93 | __END__ | ||
| 94 | =pod | ||
| 95 | |||
| 96 | =head1 NAME | ||
| 97 | |||
| 98 | Net::CLI::Interact::Transport::Telnet - TELNET based CLI connection | ||
| 99 | |||
| 100 | =head1 VERSION | ||
| 101 | |||
| 102 | version 2.143070 | ||
| 103 | |||
| 104 | =head1 DESCRIPTION | ||
| 105 | |||
| 106 | This module provides a wrapped instance of a TELNET client for use by | ||
| 107 | L<Net::CLI::Interact>. | ||
| 108 | |||
| 109 | =head1 INTERFACE | ||
| 110 | |||
| 111 | =head2 app | ||
| 112 | |||
| 113 | On Windows platforms you B<must> download the C<plink.exe> program, and pass its | ||
| 114 | location to the library in this parameter. On other platforms, this defaults to | ||
| 115 | C<telnet>. | ||
| 116 | |||
| 117 | =head2 runtime_options | ||
| 118 | |||
| 119 | Based on the C<connect_options> hash provided to Net::CLI::Interact on | ||
| 120 | construction, selects and formats parameters to provide to C<app> on the | ||
| 121 | command line. Supported attributes: | ||
| 122 | |||
| 123 | =over 4 | ||
| 124 | |||
| 125 | =item host (required) | ||
| 126 | |||
| 127 | Host name or IP address of the host to which the TELNET application is to | ||
| 128 | connect. | ||
| 129 | |||
| 130 | =item port | ||
| 131 | |||
| 132 | Port number on the host which is listening for the TELNET connection. | ||
| 133 | Defaults to 23. | ||
| 134 | |||
| 135 | =item opts | ||
| 136 | |||
| 137 | If you want to pass any other options to the Telnet application, then use | ||
| 138 | this option, which should be an array reference. | ||
| 139 | |||
| 140 | On Windows platforms, each item on the list will be passed to the C<plink.exe> | ||
| 141 | application, separated by a single space character. On Unix platforms, if depends | ||
| 142 | whether you have L<IO::Pty> installed (which in turn depends on a compiler). | ||
| 143 | Typically, the L<Net::Telnet> library is used for TELNET connections, so the | ||
| 144 | list can be any options taken by its C<new()> constructor. Otherwise the local | ||
| 145 | C<telnet> application is used. | ||
| 146 | |||
| 147 | =item reap | ||
| 148 | |||
| 149 | Only used on Unix platforms, this installs a signal handler which attempts to | ||
| 150 | reap the C<ssh> child process. Pass a true value to enable this feature only | ||
| 151 | if you notice zombie processes are being left behind after use. | ||
| 152 | |||
| 153 | =back | ||
| 154 | |||
| 155 | =head1 COMPOSITION | ||
| 156 | |||
| 157 | See the following for further interface details: | ||
| 158 | |||
| 159 | =over 4 | ||
| 160 | |||
| 161 | =item * | ||
| 162 | |||
| 163 | L<Net::CLI::Interact::Transport::Base> | ||
| 164 | |||
| 165 | =back | ||
| 166 | |||
| 167 | =head1 AUTHOR | ||
| 168 | |||
| 169 | Oliver Gorwits <oliver@cpan.org> | ||
| 170 | |||
| 171 | =head1 COPYRIGHT AND LICENSE | ||
| 172 | |||
| 173 | This software is copyright (c) 2014 by Oliver Gorwits. | ||
| 174 | |||
| 175 | This is free software; you can redistribute it and/or modify it under | ||
| 176 | the same terms as the Perl 5 programming language system itself. | ||
| 177 | |||
| 178 | =cut | ||
| 179 |