File: load_optional.t

package info (click to toggle)
libobject-remote-perl 0.004004-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 520 kB
  • sloc: perl: 2,395; makefile: 10
file content (55 lines) | stat: -rw-r--r-- 1,553 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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');
    ok(!$remote->has_missing_module, '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') && !!$INC{'Not/Found.pm'};

has counter => (is => 'rwp', default => sub { 0 });

sub increment { $_[0]->_set_counter($_[0]->counter + 1); }

sub has_missing_module { HAS_MISSING_MODULE };