add Class::Load to dev prereqs
[scpubgit/Object-Remote.git] / xt / load_optional.t
CommitLineData
7f5bfc4d 1use strictures 1;
2use Test::More;
3use Test::Fatal;
4use Sys::Hostname qw(hostname);
5
6$ENV{OBJECT_REMOTE_TEST_LOGGER} = 1;
7
8use Object::Remote::FromData;
9
10my $connection = Object::Remote->connect('-');
11
12
13is 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
20is 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
30done_testing;
31
32__DATA__
33package My::Data::TestClassLoad;
34
35use Moo;
36use Class::Load 'load_optional_class';
37
38use constant HAS_MISSING_MODULE => load_optional_class('Not::Found');
39
40has counter => (is => 'rwp', default => sub { 0 });
41
42sub increment { $_[0]->_set_counter($_[0]->counter + 1); }
43
44sub has_missing_module { HAS_MISSING_MODULE };
45
46package My::Data::TestModuleRuntime;
47
48use Moo;
49use Module::Runtime 'use_package_optimistically';
50
51use constant HAS_MISSING_MODULE => use_package_optimistically('Not::Found');
52
53has counter => (is => 'rwp', default => sub { 0 });
54
55sub increment { $_[0]->_set_counter($_[0]->counter + 1); }
56
daa3054c 57sub create_object { use_package_optimistically('Not::Found')->new() };