Interact/Transport/Telnet.pm

filter: Statementstmt 62.0% 18 / 29 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 75.0% 6 / 8 Podpod n/a totaltotal 55.8% 24 / 43 CC 4 SCAR 15.9
CC
4
Cov
51%
runtime_options
12.0
_build_app
6.0
BEGIN
1.0
CRAP 4.9
« Interact/Role/Iterator.pm ↑ Summary Interact/Transport/Serial.pm »
1 package Net::CLI::Interact::Transport::Telnet;
2 $Net::CLI::Interact::Transport::Telnet::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::Telnet::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 Int ArrayRef Any);
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 extends 'Net::CLI::Interact::Transport::Options';
18  
19 has 'host' => (
20 is => 'rw',
21 isa => Str,
22 required => 1,
23 );
24  
25 has 'port' => (
26 is => 'rw',
27 isa => Int,
28 default => quote_sub('23'),
29 );
30  
31 has 'opts' => (
32 is => 'rw',
33 isa => ArrayRef[Any],
34 default => sub { [] },
35 );
36 }
37 # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
38  
39 # allow native use of Net::Telnet on Unix
40 if (not Net::CLI::Interact::Transport::Base::is_win32()) {
41 has '+use_net_telnet_connection' => ( default => quote_sub('1') );
42 }
43  
44 has 'connect_options' => (
45 is => 'ro',
46 isa => InstanceOf['Net::CLI::Interact::Transport::Telnet::Options'],
47 coerce => quote_sub(q{ (ref '' eq ref $_[0]) ? $_[0] :
48 Net::CLI::Interact::Transport::Telnet::Options->new(@_) }),
49 required => 1,
50 );
51  
52 sub _build_app {
53 0 ▶ my $self = shift;
Subroutine _build_app: not called CC=2 SCAR=17.9
54 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
55 if $self->is_win32;
56 0 return 'telnet';
57 }
58  
59 sub runtime_options {
60 0 ▶ my $self = shift;
Subroutine runtime_options: not called CC=3 SCAR=24.8
61 0 ▶ if ($self->is_win32) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->is_win32) { } 0 0 0
elsif ($self->can_use_pty) { } 0 0 0
62 return (
63 '-telnet',
64 '-P', $self->connect_options->port,
65 0 @{$self->connect_options->opts},
66 $self->connect_options->host,
67 );
68 }
69 elsif ($self->can_use_pty) {
70 return (
71 Host => $self->connect_options->host,
72 Port => $self->connect_options->port,
73 0 @{$self->connect_options->opts},
74 );
75 }
76 else {
77 return (
78 0 @{$self->connect_options->opts},
79 $self->connect_options->host,
80 $self->connect_options->port,
81 );
82 }
83 }
84  
85 1;
86  
87 =pod
88  
89 =head1 NAME
90  
91 Net::CLI::Interact::Transport::Telnet - TELNET based CLI connection
92  
93 =head1 DESCRIPTION
94  
95 This module provides a wrapped instance of a TELNET client for use by
96 L<Net::CLI::Interact>.
97  
98 =head1 INTERFACE
99  
100 =head2 app
101  
102 On Windows platforms you B<must> download the C<plink.exe> program, and pass its
103 location to the library in this parameter. On other platforms, this defaults to
104 C<telnet>.
105  
106 =head2 runtime_options
107  
108 Based on the C<connect_options> hash provided to Net::CLI::Interact on
109 construction, selects and formats parameters to provide to C<app> on the
110 command line. Supported attributes:
111  
112 =over 4
113  
114 =item host (required)
115  
116 Host name or IP address of the host to which the TELNET application is to
117 connect.
118  
119 =item port
120  
121 Port number on the host which is listening for the TELNET connection.
122 Defaults to 23.
123  
124 =item opts
125  
126 If you want to pass any other options to the Telnet application, then use
127 this option, which should be an array reference.
128  
129 On Windows platforms, each item on the list will be passed to the C<plink.exe>
130 application, separated by a single space character. On Unix platforms, if depends
131 whether you have L<IO::Pty> installed (which in turn depends on a compiler).
132 Typically, the L<Net::Telnet> library is used for TELNET connections, so the
133 list can be any options taken by its C<new()> constructor. Otherwise the local
134 C<telnet> application is used.
135  
136 =item reap
137  
138 Only used on Unix platforms, this installs a signal handler which attempts to
139 reap the C<ssh> child process. Pass a true value to enable this feature only
140 if you notice zombie processes are being left behind after use.
141  
142 =back
143  
144 =head1 COMPOSITION
145  
146 See the following for further interface details:
147  
148 =over 4
149  
150 =item *
151  
152 L<Net::CLI::Interact::Transport::Base>
153  
154 =back
155  
156 =cut
157  
« Interact/Role/Iterator.pm ↑ Summary Interact/Transport/Serial.pm »