From: Colin Newell Date: Sun, 10 Jan 2016 19:38:15 +0000 (+0000) Subject: Made Module::Runtime compat more reliable. X-Git-Tag: v0.003006~6 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=refs%2Fheads%2Fbfwg%2Ferror_message;p=scpubgit%2FObject-Remote.git Made Module::Runtime compat more reliable. Removed Try::Tiny dependency and made Module::Runtime fudge more reliable by walking up the callstack instead of relying on a position. --- diff --git a/Makefile.PL b/Makefile.PL index 6fe8cef..745aaaf 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -10,7 +10,6 @@ WriteMakefile( PREREQ_PM => { Moo => 1.006, 'Module::Runtime' => 0, - 'Try::Tiny' => 0, 'JSON::PP' => 0, 'Future' => 0.29, 'MRO::Compat' => 0, # required to fatpack Moo diff --git a/lib/Object/Remote/ModuleLoader.pm b/lib/Object/Remote/ModuleLoader.pm index 9d4273e..79ae8b1 100644 --- a/lib/Object/Remote/ModuleLoader.pm +++ b/lib/Object/Remote/ModuleLoader.pm @@ -4,14 +4,13 @@ BEGIN { package Object::Remote::ModuleLoader::Hook; use Moo; use Object::Remote::Logging qw( :log :dlog ); - use Try::Tiny; has sender => (is => 'ro', required => 1); # unqualified INC forced into package main sub Object::Remote::ModuleLoader::Hook::INC { my ($self, $module) = @_; log_debug { "Loading $module via " . ref($self) }; - try + my $ret = eval { if (my $code = $self->sender->source_for($module)) { open my $fh, '<', \$code; @@ -20,20 +19,33 @@ BEGIN { } log_trace { "Module sender did not return code for '$module'" }; return; - } - catch + }; + if($@) { - log_trace { "Module sender blew up - $_" }; - if($_ =~ /Can't locate/) + 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/ - my ($package, $file, $line) = caller(9); - s/(in \@INC.)/$1 at $file line $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 $_; + die $@; } + return $ret; } }