1
2# This is a test script of IPC::LDT,
3# using file handles to check the
4# transfer of Perl data.
5
6
7# load modules
8use IPC::LDT;
9use FileHandle;
10use Data::Dumper;
11
12# display number of test
13print "1..4\n";
14
15# build temporary filename
16my $file="/tmp/.$$.ipc.ldt.tmp";
17
18# init the data to transfer
19my $scalar=50;
20my @array=(3, 7, 15);
21my %hash=(a=>'A', z=>'Z');
22my $ref=\$IPC::LDT::VERSION;
23
24# write message
25{
26 # open file
27 open(O, ">$file") or die "[Fatal] Could not open $file for writing.\n";
28
29 # build LDT object
30 my $ldt=new IPC::LDT(handle=>*O, objectMode=>1) or die "[Fatal] Could not build LDT object.\n";
31
32 # send data
33 $ldt->send($scalar, \@array, \%hash, $ref);
34
35 # close the temporary file
36 close(O);
37}
38
39
40# read message
41{
42 # open file
43 open(I, $file) or die "[Fatal] Could not open $file for reading.\n";
44
45 # build LDT object
46 my $ldt=new IPC::LDT(handle=>*I, objectMode=>1) or die "[Fatal] Could not build LDT object.\n";
47
48 # read data
49 my @data=$ldt->receive;
50
51 # perform the checks
52 print $data[0]==$scalar ? 'ok' : 'not ok', "\n";
53 print Dumper(@{$data[1]}) eq Dumper(@array) ? 'ok' : 'not ok', "\n";
54 print Dumper(%{$data[2]}) eq Dumper(%hash)  ? 'ok' : 'not ok', "\n";
55 print ${$data[3]} eq $$ref ? 'ok' : 'not ok', "\n";
56
57 # close the temporary file
58 close(I);
59}
60
61# clean up
62unlink $file;
63