blib/lib/CPANPLUS/Shell/Default/Plugins/Remote.pm untested

filter: Statementstmt 0.0% 0 / 61 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 13 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 11 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 94 CC 3 SCAR 11.7
CC
3
Cov
0%
connect
6.0
disconnect
6.0
plugins
2.0
CRAP 3.2
1 package CPANPLUS::Shell::Default::Plugins::Remote;
2  
3 use strict;
4  
5 use Module::Load;
6 use Params::Check qw[check];
7 use CPANPLUS::Error qw[error msg];
8 use Locale::Maketext::Simple Class => 'CPANPLUS', Style => 'gettext';
9  
10 use vars qw[$VERSION];
11 $VERSION = "0.9914";
12  
13 =head1 NAME
14  
15 CPANPLUS::Shell::Default::Plugins::Remote - connect to a remote CPANPLUS
16  
17 =head1 SYNOPSIS
18  
19 CPAN Terminal> /connect localhost 1337 --user=foo --pass=bar
20 ...
21 CPAN Terminal@localhost> /disconnect
22  
23 =head1 DESCRIPTION
24  
25 This is a C<CPANPLUS::Shell::Default> plugin that allows you to connect
26 to a machine running an instance of C<CPANPLUS::Daemon>, allowing remote
27 usage of the C<CPANPLUS Shell>.
28  
29 A sample session, updating all modules on a remote machine, might look
30 like this:
31  
32 CPAN Terminal> /connect --user=my_user --pass=secret localhost 1337
33  
34 Connection accepted
35  
36 Successfully connected to 'localhost' on port '11337'
37  
38 Note that no output will appear until a command has completed
39 -- this may take a while
40  
41  
42 CPAN Terminal@localhost> o; i *
43  
44 [....]
45  
46 CPAN Terminal@localhost> /disconnect
47  
48 CPAN Terminal>
49  
50 =cut
51  
52 ### store the original prompt here, so we can restore it on disconnect
53 my $Saved_Prompt;
54  
55 sub plugins { ( connect => 'connect', disconnect => 'disconnect' ) }
56  
57 sub connect {
58 my $class = shift;
59 my $shell = shift;
60 my $cb = shift;
61 my $cmd = shift;
62 my $input = shift || '';
63 my $opts = shift || {};
64 my $conf = $cb->configure_object;
65  
66 my $user; my $pass;
67 { local $Params::Check::ALLOW_UNKNOWN = 1;
68  
69 my $tmpl = {
70 user => { default => 'cpanpd', store => \$user },
71 pass => { required => 1, store => \$pass },
72 };
73  
74 check( $tmpl, $opts ) or return;
75 }
76  
77 my @parts = split /\s+/, $input;
78 my $host = shift @parts || 'localhost';
79 my $port = shift @parts || '1337';
80  
81 load IO::Socket;
82  
83 my $remote = IO::Socket::INET->new(
84 Proto => "tcp",
85 PeerAddr => $host,
86 PeerPort => $port,
87 ) or (
88 error( loc( "Cannot connect to port '%1' ".
89 "on host '%2'", $port, $host ) ),
90 return
91 );
92  
93 my $con = {
94 connection => $remote,
95 username => $user,
96 password => $pass,
97 };
98  
99 ### store the connection
100 $shell->remote( $con );
101  
102 my($status,$buffer) = $shell->__send_remote_command(
103 "VERSION=$CPANPLUS::Shell::Default::VERSION");
104  
105 if( $status ) {
106 print "\n$buffer\n\n";
107  
108 print loc( "Successfully connected to '%1' on port '%2'",
109 $host, $port );
110 print "\n\n";
111 print loc( "Note that no output will appear until a command ".
112 "has completed\n-- this may take a while" );
113 print "\n\n";
114  
115 ### save the original prompt
116 $Saved_Prompt = $shell->prompt;
117  
118 $shell->prompt( $shell->brand .'@'. $host .':'. $port .'> ' );
119  
120 } else {
121 print "\n$buffer\n\n";
122  
123 print loc( "Failed to connect to '%1' on port '%2'",
124 $host, $port );
125 print "\n\n";
126  
127 $shell->remote( undef );
128 }
129 }
130  
131 sub disconnect {
132 my $class = shift;
133 my $shell = shift;
134  
135 print "\n", ( $shell->remote
136 ? loc( "Disconnecting from remote host" )
137 : loc( "Not connected to remote host" )
138 ), "\n\n";
139  
140 $shell->remote( undef );
141 $shell->prompt( $Saved_Prompt );
142 }
143  
144 sub connect_help {
145 return loc(
146 " /connect [HOST PORT] # Connect to the remote machine,\n" .
147 " # defaults taken from your config\n" .
148 " --user=USER # Optional username\n" .
149 " --pass=PASS # Optional password" );
150 }
151  
152 sub disconnect_help {
153 return loc(
154 " /disconnect # Disconnect from the remote server" );
155 }
156  
157 1;
158  
159 =pod
160  
161 =head1 BUG REPORTS
162  
163 Please report bugs or other issues to E<lt>bug-cpanplus@rt.cpan.org<gt>.
164  
165 =head1 AUTHOR
166  
167 This module by Jos Boumans E<lt>kane@cpan.orgE<gt>.
168  
169 =head1 COPYRIGHT
170  
171 The CPAN++ interface (of which this module is a part of) is copyright (c)
172 2001 - 2007, Jos Boumans E<lt>kane@cpan.orgE<gt>. All rights reserved.
173  
174 This library is free software; you may redistribute and/or modify it
175 under the same terms as Perl itself.
176  
177 =head1 SEE ALSO
178  
179 L<CPANPLUS::Shell::Default>, L<CPANPLUS::Shell>, L<cpanp>
180  
181 =cut
182  
183 # Local variables:
184 # c-indentation-style: bsd
185 # c-basic-offset: 4
186 # indent-tabs-mode: nil
187 # End:
188 # vim: expandtab shiftwidth=4:
189