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 => 'cpanpd', store => \$user },
68 pass => { required => 1, store => \$pass },
71 check( $tmpl, $opts ) or return;
74 my @parts = split /\s+/, $input;
75 my $host = shift @parts || 'localhost';
76 my $port = shift @parts || '1337';
80 my $remote = IO::Socket::INET->new(
85 error( loc( "Cannot connect to port '%1' ".
86 "on host '%2'", $port, $host ) ),
91 connection => $remote,
96 ### store the connection
97 $shell->remote( $con );
99 my($status,$buffer) = $shell->__send_remote_command(
100 "VERSION=$CPANPLUS::Shell::Default::VERSION");
103 print "\n$buffer\n\n";
105 print loc( "Successfully connected to '%1' on port '%2'",
108 print loc( "Note that no output will appear until a command ".
109 "has completed\n-- this may take a while" );
112 ### save the original prompt
113 $Saved_Prompt = $shell->prompt;
115 $shell->prompt( $shell->brand .'@'. $host .':'. $port .'> ' );
118 print "\n$buffer\n\n";
120 print loc( "Failed to connect to '%1' on port '%2'",
124 $shell->remote( undef );
132 print "\n", ( $shell->remote
133 ? loc( "Disconnecting from remote host" )
134 : loc( "Not connected to remote host" )
137 $shell->remote( undef );
138 $shell->prompt( $Saved_Prompt );
143 " /connect [HOST PORT] # Connect to the remote machine,\n" .
144 " # defaults taken from your config\n" .
145 " --user=USER # Optional username\n" .
146 " --pass=PASS # Optional password" );
149 sub disconnect_help {
151 " /disconnect # Disconnect from the remote server" );
160 Please report bugs or other issues to E<lt>bug-cpanplus@rt.cpan.org<gt>.
164 This module by Jos Boumans E<lt>kane@cpan.orgE<gt>.
168 The CPAN++ interface (of which this module is a part of) is copyright (c)
169 2001 - 2007, Jos Boumans E<lt>kane@cpan.orgE<gt>. All rights reserved.
171 This library is free software; you may redistribute and/or modify it
172 under the same terms as Perl itself.
176 L<CPANPLUS::Shell::Default>, L<CPANPLUS::Shell>, L<cpanp>
181 # c-indentation-style: bsd
183 # indent-tabs-mode: nil
185 # vim: expandtab shiftwidth=4: