Commit | Line | Data |
542d5b5c |
1 | use strictures 1; |
2 | use Test::More; |
3 | |
abef6e5b |
4 | $ENV{OBJECT_REMOTE_TEST_LOGGER} = 1; |
f129bfaf |
5 | |
542d5b5c |
6 | use Object::Remote::Connector::Local; |
7 | use Object::Remote; |
8 | use Object::Remote::ModuleSender; |
9 | |
10 | $ENV{PERL5LIB} = join( |
11 | ':', ($ENV{PERL5LIB} ? $ENV{PERL5LIB} : ()), qw(lib) |
12 | ); |
13 | |
e8ba6092 |
14 | my $mod_content = do { |
15 | open my $fh, '<', 't/lib/ORTestClass.pm' |
16 | or die "can't read ORTestClass.pm: $!"; |
17 | local $/; |
18 | <$fh> |
19 | }; |
20 | my $modules = { |
21 | 'ORTestClass.pm' => $mod_content, |
22 | }; |
542d5b5c |
23 | |
e8ba6092 |
24 | sub TestModuleProvider::INC { |
25 | my ($self, $module) = @_; |
26 | if (my $data = $self->{modules}{$module}) { |
27 | open my $fh, '<', \$data |
7e7848a3 |
28 | or die "Unable to open in-memory file: $!"; |
e8ba6092 |
29 | return $fh; |
30 | } |
31 | return; |
32 | } |
542d5b5c |
33 | |
e8ba6092 |
34 | my %sources = ( |
35 | basic => [ 't/lib' ], |
36 | sub => [ sub { |
37 | if (my $data = $modules->{$_[1]}) { |
38 | open my $fh, '<', \$data |
7e7848a3 |
39 | or die "Unable to open in-memory file: $!"; |
e8ba6092 |
40 | return $fh; |
41 | } |
42 | return; |
43 | } ], |
44 | dynamic_array => [ [ sub { |
45 | my $mods = $_[0][1]; |
46 | if (my $data = $mods->{$_[1]}) { |
47 | open my $fh, '<', \$data |
7e7848a3 |
48 | or die "Unable to open in-memory file: $!"; |
e8ba6092 |
49 | return $fh; |
50 | } |
51 | return; |
52 | }, $modules ] ], |
53 | object => [ bless { modules => $modules }, 'TestModuleProvider' ], |
7e7848a3 |
54 | filter_sub => [ sub { |
55 | if (my $data = $modules->{$_[1]}) { |
56 | my @lines = split /\n/, $data; |
57 | my $read = join("\n", 0..$#lines); |
58 | open my $fh, '<', \$read |
59 | or die "welp $!"; |
60 | return ($fh, sub { |
61 | chomp; |
62 | my $ret = $_ != $#lines ? 1 : 0; |
63 | $_ = $lines[$_]; |
64 | return $ret; |
65 | }); |
66 | } |
67 | return; |
68 | } ], |
69 | feed_sub => [ sub { |
70 | if (my $data = $modules->{$_[1]}) { |
71 | my @lines = split /(\n)/, $data; |
72 | return sub { |
73 | $_ = shift @lines; |
74 | return @lines ? 1 : 0; |
75 | }; |
76 | } |
77 | return; |
78 | } ], |
676438a1 |
79 | ); |
542d5b5c |
80 | |
e8ba6092 |
81 | for my $source (sort keys %sources) { |
82 | my $ms = Object::Remote::ModuleSender->new( |
83 | dir_list => $sources{$source}, |
84 | ); |
85 | my $connection = Object::Remote::Connector::Local->new( |
86 | module_sender => $ms, |
87 | )->connect; |
88 | |
89 | my $counter = Object::Remote->new( |
90 | connection => $connection, |
91 | class => 'ORTestClass' |
92 | ); |
93 | |
94 | isnt($$, $counter->pid, "$source sender: Different pid on the other side"); |
542d5b5c |
95 | |
e8ba6092 |
96 | is($counter->counter, 0, "$source sender: Counter at 0"); |
542d5b5c |
97 | |
e8ba6092 |
98 | is($counter->increment, 1, "$source sender: Increment to 1"); |
542d5b5c |
99 | |
e8ba6092 |
100 | is($counter->counter, 1, "$source sender: Counter at 1"); |
101 | } |
542d5b5c |
102 | |
103 | done_testing; |