add sub call code
Matt S Trout [Fri, 18 May 2012 01:27:17 +0000 (01:27 +0000)]
lib/Object/Remote/SubCaller.pm [new file with mode: 0644]

diff --git a/lib/Object/Remote/SubCaller.pm b/lib/Object/Remote/SubCaller.pm
new file mode 100644 (file)
index 0000000..ff5fb40
--- /dev/null
@@ -0,0 +1,18 @@
+package Object::Remote::SubCaller;
+
+use Module::Runtime qw(use_module);
+
+sub new { bless({}, ref($_[0])||$_[0]) }
+
+sub call {
+  my ($self, $name, @args) = @_;
+  my ($pkg, $sub_name) = $name =~ /^(.+)::([^:]+)$/
+    or die "Couldn't split ${name} into package and sub";
+  if (my $sub = use_module($pkg)->can($sub_name)) {
+    return $sub->(@args);
+  } else {
+    die "No subroutine ${sub_name} in package ${pkg}";
+  }
+}
+
+1;