Tweaked error message on failure to import.
[scpubgit/Object-Remote.git] / xt / load_optional.t
1 use strictures 1;
2 use Test::More;
3 use Test::Fatal;
4 use Sys::Hostname qw(hostname);
5
6 $ENV{OBJECT_REMOTE_TEST_LOGGER} = 1;
7
8 use Object::Remote::FromData;
9
10 my $connection = Object::Remote->connect('-');
11
12
13 is exception {
14     my $remote = My::Data::TestClassLoad->new::on($connection);
15     is($remote->counter, 0, 'Counter at 0');
16     is($remote->increment, 1, 'Increment to 1');
17     is($remote->has_missing_module, 0, 'Shouldn\'t have loaded module');
18 }, undef, 'Checking Class::Load load_optional_class works correctly.';
19
20 is exception {
21     my $remote = My::Data::TestModuleRuntime->new::on($connection);
22     is($remote->counter, 0, 'Counter at 0');
23     is($remote->increment, 1, 'Increment to 1');
24     is($remote->has_missing_module, 0, 'Shouldn\'t have loaded module');
25 }, undef, 'Checking Module::Runtime use_package_optimistically works correctly.';
26
27 done_testing;
28
29 __DATA__
30 package My::Data::TestClassLoad;
31
32 use Moo;
33 use Class::Load 'load_optional_class';
34
35 use constant HAS_MISSING_MODULE => load_optional_class('Not::Found');
36
37 has counter => (is => 'rwp', default => sub { 0 });
38
39 sub increment { $_[0]->_set_counter($_[0]->counter + 1); }
40
41 sub has_missing_module { HAS_MISSING_MODULE };
42
43 package My::Data::TestModuleRuntime;
44
45 use Moo;
46 use Module::Runtime 'use_package_optimistically';
47
48 use constant HAS_MISSING_MODULE => use_package_optimistically('Not::Found');
49
50 has counter => (is => 'rwp', default => sub { 0 });
51
52 sub increment { $_[0]->_set_counter($_[0]->counter + 1); }
53
54 sub has_missing_module { HAS_MISSING_MODULE };