From: Colin Newell Date: Fri, 8 Jan 2016 20:35:42 +0000 (+0000) Subject: Tweaked error message on failure to import. X-Git-Tag: v0.003006~8 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=7f5bfc4dfef392ba306ec6967482987afde767b4;p=scpubgit%2FObject-Remote.git Tweaked error message on failure to import. This was primarily to make it work with the regex in Class::Load load_optional_class. --- diff --git a/lib/Object/Remote.pm b/lib/Object/Remote.pm index 7b75851..0ecbc2d 100644 --- a/lib/Object/Remote.pm +++ b/lib/Object/Remote.pm @@ -239,6 +239,8 @@ phaylon - Robert Sedlacek (cpan:PHAYLON) triddle - Tyler Riddle (cpan:TRIDDLE) +bfwg - Colin Newell (cpan:NEWELLC) + =head1 SPONSORS Parts of this code were paid for by diff --git a/lib/Object/Remote/ModuleSender.pm b/lib/Object/Remote/ModuleSender.pm index 6624d6b..681ef96 100644 --- a/lib/Object/Remote/ModuleSender.pm +++ b/lib/Object/Remote/ModuleSender.pm @@ -28,7 +28,7 @@ sub source_for { my ($found) = first { -f $_ } map File::Spec->catfile($_, $module), @{$self->dir_list}; - die "Couldn't find ${module} in remote \@INC. dir_list contains:\n" + die "Can't locate ${module} in \@INC. (on remote host) dir_list contains:\n" .join("\n", @{$self->dir_list}) unless $found; log_debug { "found '$module' at '$found'" }; diff --git a/t/not_found.t b/t/not_found.t new file mode 100644 index 0000000..62b099a --- /dev/null +++ b/t/not_found.t @@ -0,0 +1,24 @@ +use strictures 1; +use Test::More; +use Test::Fatal; +use Sys::Hostname qw(hostname); + +$ENV{OBJECT_REMOTE_TEST_LOGGER} = 1; + +use Object::Remote::FromData; + +my $connection = Object::Remote->connect('-'); + + +like exception { + my $remote = My::Data::TestClass->new::on($connection); +}, qr/Can't locate Not\/Found.pm in \@INC/, 'Should fail to load Not::Found'; + +done_testing; + +__DATA__ +package My::Data::TestClass; + +use Moo; +use Not::Found; + diff --git a/xt/load_optional.t b/xt/load_optional.t new file mode 100644 index 0000000..2e7f510 --- /dev/null +++ b/xt/load_optional.t @@ -0,0 +1,54 @@ +use strictures 1; +use Test::More; +use Test::Fatal; +use Sys::Hostname qw(hostname); + +$ENV{OBJECT_REMOTE_TEST_LOGGER} = 1; + +use Object::Remote::FromData; + +my $connection = Object::Remote->connect('-'); + + +is exception { + my $remote = My::Data::TestClassLoad->new::on($connection); + is($remote->counter, 0, 'Counter at 0'); + is($remote->increment, 1, 'Increment to 1'); + is($remote->has_missing_module, 0, 'Shouldn\'t have loaded module'); +}, undef, 'Checking Class::Load load_optional_class works correctly.'; + +is exception { + my $remote = My::Data::TestModuleRuntime->new::on($connection); + is($remote->counter, 0, 'Counter at 0'); + is($remote->increment, 1, 'Increment to 1'); + is($remote->has_missing_module, 0, 'Shouldn\'t have loaded module'); +}, undef, 'Checking Module::Runtime use_package_optimistically works correctly.'; + +done_testing; + +__DATA__ +package My::Data::TestClassLoad; + +use Moo; +use Class::Load 'load_optional_class'; + +use constant HAS_MISSING_MODULE => load_optional_class('Not::Found'); + +has counter => (is => 'rwp', default => sub { 0 }); + +sub increment { $_[0]->_set_counter($_[0]->counter + 1); } + +sub has_missing_module { HAS_MISSING_MODULE }; + +package My::Data::TestModuleRuntime; + +use Moo; +use Module::Runtime 'use_package_optimistically'; + +use constant HAS_MISSING_MODULE => use_package_optimistically('Not::Found'); + +has counter => (is => 'rwp', default => sub { 0 }); + +sub increment { $_[0]->_set_counter($_[0]->counter + 1); } + +sub has_missing_module { HAS_MISSING_MODULE };