allow glob references to be transferred
[scpubgit/Object-Remote.git] / t / transfer.t
1 use strictures 1;
2 use Test::More;
3 use Test::Fatal;
4 use FindBin;
5
6 $ENV{PERL5LIB} = join(
7   ':', ($ENV{PERL5LIB} ? $ENV{PERL5LIB} : ()), qw(lib t/lib)
8 );
9
10 use Object::Remote;
11
12 my $strA = 'foo';
13 my $strB = 'bar';
14
15 is exception {
16   my $proxy = ORTestTransfer->new::on('-', value => \$strA);
17   is_deeply $proxy->value, \$strA, 'correct value after construction';
18 }, undef, 'scalar refs - no errors during construction';
19
20 is exception {
21   my $proxy = ORTestTransfer->new::on('-');
22   $proxy->value(\$strB);
23   is_deeply $proxy->value, \$strB, 'correct value after construction';
24 }, undef, 'scalar refs - no errors during attribute set';
25
26 my $data_file = "$FindBin::Bin/data/numbers.txt";
27
28 is exception {
29   my $out = '';
30   open my $fh, '>', \$out or die "Unable to open in-memory file: $!\n";
31   my $proxy = ORTestGlobs->new::on('-', handle => $fh);
32   ok $proxy->handle, 'filehandle was set';
33   ok $proxy->write('foo'), 'write was successful';
34   is $out, 'foo', 'write reached target';
35 }, undef, 'filehandles - no error during construction';
36
37 is exception {
38   my $proxy = ORTestGlobs->new::on('-');
39   my $handle = $proxy->gethandle;
40   print $handle 'foo';
41   is $proxy->getvalue, 'foo', 'correct value written';
42   $handle->autoflush(1);
43 }, undef, 'filehandles - no error during remote handle';
44
45 is exception {
46   my $proxy = ORTestGlobs->new::on('-');
47   my $rhandle = $proxy->getreadhandle($data_file);
48   my @lines = <$rhandle>;
49   chomp @lines;
50   is_deeply \@lines, [1 .. 5], 'reading back out of the handle';
51 }, undef, 'filehandles - no error during remote read';
52
53 is exception {
54   my $proxy = ORTestGlobs->new::on('-');
55   my $rhandle = $proxy->getreadhandle($data_file);
56   binmode $rhandle;
57 }, undef, 'filehandles - no errors during binmode';
58
59 done_testing;