1 package CPANPLUS::Shell::Default::Plugins::Remote;
6 use Params::Check qw[check];
7 use CPANPLUS::Error qw[error msg];
8 use Locale::Maketext::Simple Class => 'CPANPLUS', Style => 'gettext';
12 CPANPLUS::Shell::Default::Plugins::Remote
16 CPAN Terminal> /connect localhost 1337 --user=foo --pass=bar
18 CPAN Terminal@localhost> /disconnect
22 This is a C<CPANPLUS::Shell::Default> plugin that allows you to connect
23 to a machine running an instance of C<CPANPLUS::Daemon>, allowing remote
24 usage of the C<CPANPLUS Shell>.
26 A sample session, updating all modules on a remote machine, might look
29 CPAN Terminal> /connect --user=my_user --pass=secret localhost 1337
33 Successfully connected to 'localhost' on port '11337'
35 Note that no output will appear until a command has completed
36 -- this may take a while
39 CPAN Terminal@localhost> o; i *
43 CPAN Terminal@localhost> /disconnect
49 ### store the original prompt here, so we can restore it on disconnect
52 sub plugins { ( connect => 'connect', disconnect => 'disconnect' ) }
59 my $input = shift || '';
60 my $opts = shift || {};
61 my $conf = $cb->configure_object;
64 { local $Params::Check::ALLOW_UNKNOWN = 1;
67 user => { default => $conf->_get_daemon('username'),
69 pass => { default => $conf->_get_daemon('password'),
73 check( $tmpl, $opts ) or return;
76 my @parts = split /\s+/, $input;
77 my $host = shift @parts || 'localhost';
78 my $port = shift @parts || $conf->_get_daemon('port');
82 my $remote = IO::Socket::INET->new(
87 error( loc( "Cannot connect to port '%1' ".
88 "on host '%2'", $port, $host ) ),
93 connection => $remote,
98 ### store the connection
99 $shell->remote( $con );
101 my($status,$buffer) = $shell->__send_remote_command(
102 "VERSION=$CPANPLUS::Shell::Default::VERSION");
105 print "\n$buffer\n\n";
107 print loc( "Successfully connected to '%1' on port '%2'",
110 print loc( "Note that no output will appear until a command ".
111 "has completed\n-- this may take a while" );
114 ### save the original prompt
115 $Saved_Prompt = $shell->prompt;
117 $shell->prompt( $shell->brand .'@'. $host .'> ' );
120 print "\n$buffer\n\n";
122 print loc( "Failed to connect to '%1' on port '%2'",
126 $shell->remote( undef );
134 print "\n", ( $shell->remote
135 ? loc( "Disconnecting from remote host" )
136 : loc( "Not connected to remote host" )
139 $shell->remote( undef );
140 $shell->prompt( $Saved_Prompt );
145 " /connect [HOST PORT] # Connect to the remote machine,\n" .
146 " # defaults taken from your config\n" .
147 " --user=USER # Optional username\n" .
148 " --pass=PASS # Optional password" );
151 sub disconnect_help {
153 " /disconnect # Disconnect from the remote server" );
162 Please report bugs or other issues to E<lt>bug-cpanplus@rt.cpan.org<gt>.
166 This module by Jos Boumans E<lt>kane@cpan.orgE<gt>.
170 The CPAN++ interface (of which this module is a part of) is copyright (c)
171 2001 - 2007, Jos Boumans E<lt>kane@cpan.orgE<gt>. All rights reserved.
173 This library is free software; you may redistribute and/or modify it
174 under the same terms as Perl itself.
178 L<CPANPLUS::Shell::Default>, L<CPANPLUS::Shell>, L<cpanp>
183 # c-indentation-style: bsd
185 # indent-tabs-mode: nil
187 # vim: expandtab shiftwidth=4: