From: Matt S Trout Date: Fri, 18 May 2012 01:27:17 +0000 (+0000) Subject: add sub call code X-Git-Tag: v0.001001~53 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=92237e220c2a5af3d535319c94bb3f9c1faeceb9;p=scpubgit%2FObject-Remote.git add sub call code --- diff --git a/lib/Object/Remote/SubCaller.pm b/lib/Object/Remote/SubCaller.pm new file mode 100644 index 0000000..ff5fb40 --- /dev/null +++ b/lib/Object/Remote/SubCaller.pm @@ -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;