X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=scpubgit%2FObject-Remote.git;a=blobdiff_plain;f=lib%2FObject%2FRemote%2FModuleLoader.pm;h=43a3a38f9f38276fbbc6f806288932e9407c372b;hp=6ef459be0657221ffb1c29d5415381aa21b5c73a;hb=bef36e73e4257b2ba8e59eb55661ffc51d8a620a;hpb=624072a8803b6bb08260ff6f2b7fcb0dc05dd190 diff --git a/lib/Object/Remote/ModuleLoader.pm b/lib/Object/Remote/ModuleLoader.pm index 6ef459b..43a3a38 100644 --- a/lib/Object/Remote/ModuleLoader.pm +++ b/lib/Object/Remote/ModuleLoader.pm @@ -10,13 +10,39 @@ BEGIN { sub Object::Remote::ModuleLoader::Hook::INC { my ($self, $module) = @_; log_debug { "Loading $module via " . ref($self) }; - if (my $code = $self->sender->source_for($module)) { - open my $fh, '<', \$code; - Dlog_trace { "Module sender successfully sent code for '$module': $code" } $code; - return $fh; + my $ret = eval { + if (my $code = $self->sender->source_for($module)) { + open my $fh, '<', \$code; + Dlog_trace { "Module sender successfully sent code for '$module': $code" } $code; + return $fh; + } + log_trace { "Module sender did not return code for '$module'" }; + return; + }; + if ($@) { + log_trace { "Module sender blew up - $@" }; + if ($@ =~ /Can't locate/) { + # Fudge the error messge to make it work with + # Module::Runtime use_package_optimistically + # Module::Runtime wants - /\ACan't locate \Q$fn\E .+ at \Q@{[__FILE__]}\E line/ + # We could probably measure and hard-code this but that could easily + # be a forwards compatibility disaster, so do a quick search of caller + # with a reasonable range; we're already into a woefully inefficient + # situation here so a little defensiveness won't make things much worse + foreach my $i (4..20) { + my ($package, $file, $line) = caller($i); + last unless $package; + if ($package eq 'Module::Runtime') { + # we want to fill in the error message with the + # module runtime module call info. + $@ =~ s/(in \@INC.)/$1 at $file line $line/; + last; + } + } + } + die $@; } - log_trace { "Module sender did not return code for '$module'" }; - return; + return $ret; } } @@ -33,7 +59,7 @@ sub _build_inc_hook { log_debug { "Constructing module builder hook" }; my $hook = Object::Remote::ModuleLoader::Hook->new(sender => $self->module_sender); log_trace { "Done constructing module builder hook" }; - return $hook; + return $hook; } sub BUILD { shift->enable }