1 package Object::Remote;
3 use Object::Remote::MiniLoop;
4 use Object::Remote::Handle;
5 use Module::Runtime qw(use_module);
7 our $VERSION = '0.002003'; # 0.2.3
10 my ($class, $on, @args) = @_;
11 my $conn = __PACKAGE__->connect($on);
12 return $conn->remote_object(class => $class, args => \@args);
16 my ($class, $on, $name) = @_;
17 my $conn = __PACKAGE__->connect($on);
18 return $conn->remote_sub(join('::', $class, $name));
23 Object::Remote::Handle->new(@_)->proxy;
27 my ($class, $to) = @_;
28 use_module('Object::Remote::Connection')->maybe::start::new_from_spec($to);
32 our $Current_Loop ||= Object::Remote::MiniLoop->new
39 Object::Remote - Call methods on objects in other processes or on other hosts
43 Creating a connection:
47 my $conn = Object::Remote->connect('myserver'); # invokes ssh
51 my $capture = IPC::System::Simple->can::on($conn, 'capture');
53 warn $capture->('uptime');
57 my $eval = Eval::WithLexicals->new::on($conn);
59 $eval->eval(q{my $x = `uptime`});
61 warn $eval->eval(q{$x});
63 Importantly: 'myserver' only requires perl 5.8+ - no non-core modules need to
64 be installed on the far side, Object::Remote takes care of it for you!
68 Object::Remote allows you to create an object in another process - usually
69 one running on another machine you can connect to via ssh, although there
70 are other connection mechanisms available.
72 The idea here is that in many cases one wants to be able to run a piece of
73 code on another machine, or perhaps many other machines - but without having
74 to install anything on the far side.
80 The "main" API, which provides the L</connect> method to create a connection
81 to a remote process/host, L</new::on> to create an object on a connection,
82 and L</can::on> to retrieve a subref over a connection.
84 =head2 Object::Remote::Connection
86 The object representing a connection, which provides the
87 L<Object::Remote::Connection/remote_object> and
88 L<Object::Remote::Connection/remote_sub> methods that are used by
89 L</new::on> and L</can::on> to return proxies for objects and subroutines
92 =head2 Object::Remote::Future
94 Code for dealing with asynchronous operations, which provides the
95 L<Object::Remote::Future/start::method> syntax for calling a possibly
96 asynchronous method without blocking, and
97 L<Object::Remote::Future/await_future> and L<Object::Remote::Future/await_all>
98 to block until an asynchronous call completes or fails.
104 my $conn = Object::Remote->connect('-'); # fork()ed connection
106 my $conn = Object::Remote->connect('myserver'); # connection over ssh
108 my $conn = Object::Remote->connect('user@myserver'); # connection over ssh
110 my $conn = Object::Remote->connect('root@'); # connection over sudo
114 my $eval = Eval::WithLexicals->new::on($conn);
116 my $eval = Eval::WithLexicals->new::on('myserver'); # implicit connect
118 my $obj = Some::Class->new::on($conn, %args); # with constructor arguments
122 my $hostname = Sys::Hostname->can::on($conn, 'hostname');
124 my $hostname = Sys::Hostname->can::on('myserver', 'hostname');
128 IRC: #web-simple on irc.perl.org
132 mst - Matt S. Trout (cpan:MSTROUT) <mst@shadowcat.co.uk>
136 phaylon - Robert Sedlacek (cpan:PHAYLON) <r.sedlacek@shadowcat.co.uk>
140 Parts of this code were paid for by
142 Socialflow L<http://www.socialflow.com>
144 Shadowcat Systems L<http://www.shadow.cat>
148 Copyright (c) 2012 the Object::Remote L</AUTHOR>, L</CONTRIBUTORS> and
149 L</SPONSORS> as listed above.
153 This library is free software and may be distributed under the same terms