4 use Sys::Hostname qw(hostname);
6 $ENV{OBJECT_REMOTE_TEST_LOGGER} = 1;
8 use Object::Remote::FromData;
10 my $connection = Object::Remote->connect('-');
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.';
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');
25 my $o = $remote->create_object;
26 }, qr/Can't locate Not\/Found.pm in \@INC/, 'Should fail to load Not::Found';
28 }, undef, 'Checking Module::Runtime use_package_optimistically works correctly.';
33 package My::Data::TestClassLoad;
36 use Class::Load 'load_optional_class';
38 use constant HAS_MISSING_MODULE => load_optional_class('Not::Found');
40 has counter => (is => 'rwp', default => sub { 0 });
42 sub increment { $_[0]->_set_counter($_[0]->counter + 1); }
44 sub has_missing_module { HAS_MISSING_MODULE };
46 package My::Data::TestModuleRuntime;
49 use Module::Runtime 'use_package_optimistically';
51 use constant HAS_MISSING_MODULE => use_package_optimistically('Not::Found');
53 has counter => (is => 'rwp', default => sub { 0 });
55 sub increment { $_[0]->_set_counter($_[0]->counter + 1); }
57 sub create_object { use_package_optimistically('Not::Found')->new() };