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/
+ # the callstack range is a bit of a guess, we want
+ # to make a reasonable effort, but not spend forever.
+ for(my $i = 4; $i < 20; $i++)
+ {
+ 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;
}
}