Commit | Line | Data |
7f5bfc4d |
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'); |
daa3054c |
24 | like exception { |
25 | my $o = $remote->create_object; |
26 | }, qr/Can't locate Not\/Found.pm in \@INC/, 'Should fail to load Not::Found'; |
27 | |
7f5bfc4d |
28 | }, undef, 'Checking Module::Runtime use_package_optimistically works correctly.'; |
29 | |
30 | done_testing; |
31 | |
32 | __DATA__ |
33 | package My::Data::TestClassLoad; |
34 | |
35 | use Moo; |
36 | use Class::Load 'load_optional_class'; |
37 | |
38 | use constant HAS_MISSING_MODULE => load_optional_class('Not::Found'); |
39 | |
40 | has counter => (is => 'rwp', default => sub { 0 }); |
41 | |
42 | sub increment { $_[0]->_set_counter($_[0]->counter + 1); } |
43 | |
44 | sub has_missing_module { HAS_MISSING_MODULE }; |
45 | |
46 | package My::Data::TestModuleRuntime; |
47 | |
48 | use Moo; |
49 | use Module::Runtime 'use_package_optimistically'; |
50 | |
51 | use constant HAS_MISSING_MODULE => use_package_optimistically('Not::Found'); |
52 | |
53 | has counter => (is => 'rwp', default => sub { 0 }); |
54 | |
55 | sub increment { $_[0]->_set_counter($_[0]->counter + 1); } |
56 | |
daa3054c |
57 | sub create_object { use_package_optimistically('Not::Found')->new() }; |