add can::on
[scpubgit/Object-Remote.git] / lib / Object / Remote.pm
index 6cfb9bb..485821d 100644 (file)
@@ -6,8 +6,14 @@ use Module::Runtime qw(use_module);
 
 sub new::on {
   my ($class, $on, @args) = @_;
-  my $conn = use_module('Object::Remote::Connection')->new_from_spec($on);
-  return $conn->new_remote(class => $class, args => \@args);
+  my $conn = __PACKAGE__->connect($on);
+  return $conn->remote_object(class => $class, args => \@args);
+}
+
+sub can::on {
+  my ($class, $on, $name) = @_;
+  my $conn = __PACKAGE__->connect($on);
+  return $conn->remote_sub(join('::', $class, $name));
 }
 
 sub new {
@@ -15,6 +21,11 @@ sub new {
   Object::Remote::Handle->new(@_)->proxy;
 }
 
+sub connect {
+  my ($class, $to) = @_;
+  use_module('Object::Remote::Connection')->new_from_spec($to);
+}
+
 sub current_loop {
   our $Current_Loop ||= Object::Remote::MiniLoop->new
 }