| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | ######################################################################### | 
| 2 |  |  |  |  |  |  | ## Communication Support | 
| 3 |  |  |  |  |  |  | package GRID::Machine; | 
| 4 |  |  |  |  |  |  |  | 
| 5 | 20 |  |  | 20 |  | 181 | use strict; | 
|  | 20 |  |  |  |  | 34 |  | 
|  | 20 |  |  |  |  | 658 |  | 
| 6 | 20 |  |  | 20 |  | 22384 | use Data::Dumper; | 
|  | 20 |  |  |  |  | 196451 |  | 
|  | 20 |  |  |  |  | 11538 |  | 
| 7 |  |  |  |  |  |  |  | 
| 8 |  |  |  |  |  |  | sub read_operation { | 
| 9 | 0 |  |  | 0 | 1 |  | my $self = shift; | 
| 10 |  |  |  |  |  |  |  | 
| 11 | 0 |  |  |  |  |  | my  $readfunc = $self->{readfunc}; | 
| 12 |  |  |  |  |  |  |  | 
| 13 | 0 |  |  |  |  |  | local $/ = "\n"; | 
| 14 |  |  |  |  |  |  |  | 
| 15 | 0 |  |  |  |  |  | $readfunc->( my $operation, undef ); | 
| 16 | 0 | 0 |  |  |  |  | defined $operation or die "Expected operation\n"; | 
| 17 |  |  |  |  |  |  |  | 
| 18 | 0 |  |  |  |  |  | chomp $operation; | 
| 19 |  |  |  |  |  |  |  | 
| 20 | 0 |  |  |  |  |  | $readfunc->( my $numargs, undef ); | 
| 21 | 0 | 0 |  |  |  |  | defined $numargs or die "Expected number of arguments\n"; | 
| 22 | 0 |  |  |  |  |  | chomp $numargs; | 
| 23 |  |  |  |  |  |  |  | 
| 24 | 0 |  |  |  |  |  | my @args; | 
| 25 | 0 |  |  |  |  |  | while( $numargs ) { | 
| 26 | 0 |  |  |  |  |  | $readfunc->( my $arglen, undef ); | 
| 27 | 0 | 0 | 0 |  |  |  | die "Expected length of argument\n" unless (defined($arglen) && $arglen =~ /^\d+/); | 
| 28 | 0 |  |  |  |  |  | chomp $arglen; | 
| 29 |  |  |  |  |  |  |  | 
| 30 | 0 |  |  |  |  |  | my $arg = ""; | 
| 31 | 0 |  |  |  |  |  | while( $arglen ) { | 
| 32 | 0 |  |  |  |  |  | my $buffer; | 
| 33 | 0 |  |  |  |  |  | my $n = $readfunc->( $buffer, $arglen ); | 
| 34 | 0 | 0 |  |  |  |  | die "read() returned $!\n" unless( defined $n ); | 
| 35 | 0 |  |  |  |  |  | $arg .= $buffer; | 
| 36 | 0 |  |  |  |  |  | $arglen -= $n; | 
| 37 |  |  |  |  |  |  | } | 
| 38 |  |  |  |  |  |  |  | 
| 39 | 0 |  |  |  |  |  | $arg .= '$VAR1'; | 
| 40 | 0 |  |  |  |  |  | my $val = eval "no strict; $arg"; | 
| 41 | 0 | 0 |  |  |  |  | die "Error evaluating argument $arg\n" if $@; | 
| 42 | 0 |  |  |  |  |  | push @args, $val; | 
| 43 | 0 |  |  |  |  |  | $numargs--; | 
| 44 |  |  |  |  |  |  | } | 
| 45 |  |  |  |  |  |  |  | 
| 46 | 0 |  |  |  |  |  | return ( $operation, @args ); | 
| 47 |  |  |  |  |  |  | } | 
| 48 |  |  |  |  |  |  |  | 
| 49 |  |  |  |  |  |  | sub send_operation | 
| 50 |  |  |  |  |  |  | { | 
| 51 | 0 |  |  | 0 | 1 |  | my ( $self, $operation, @args ) = @_; | 
| 52 |  |  |  |  |  |  |  | 
| 53 | 0 |  |  |  |  |  | my $writefunc = $self->{writefunc}; | 
| 54 |  |  |  |  |  |  |  | 
| 55 |  |  |  |  |  |  |  | 
| 56 | 0 |  |  |  |  |  | local $Data::Dumper::Indent = 0; | 
| 57 | 0 |  |  |  |  |  | local $Data::Dumper::Deparse = 1; | 
| 58 | 0 |  |  |  |  |  | local $Data::Dumper::Purity = 1; | 
| 59 | 0 |  |  |  |  |  | local $Data::Dumper::Terse = 0; | 
| 60 |  |  |  |  |  |  |  | 
| 61 |  |  |  |  |  |  | # Buffer this for speed - this makes a big difference | 
| 62 | 0 |  |  |  |  |  | my $buffer = ""; | 
| 63 |  |  |  |  |  |  |  | 
| 64 | 0 |  |  |  |  |  | $buffer .= "$operation\n"; | 
| 65 | 0 |  |  |  |  |  | $buffer .= scalar( @args ) . "\n"; | 
| 66 |  |  |  |  |  |  |  | 
| 67 | 0 |  |  |  |  |  | foreach my $arg ( @args ) { | 
| 68 | 0 |  |  |  |  |  | $arg = Dumper($arg); | 
| 69 | 0 |  |  |  |  |  | $buffer .= length( $arg ) . "\n" . "$arg"; | 
| 70 |  |  |  |  |  |  | } | 
| 71 |  |  |  |  |  |  |  | 
| 72 | 0 |  |  |  |  |  | $writefunc->( $buffer ); | 
| 73 |  |  |  |  |  |  | } | 
| 74 |  |  |  |  |  |  |  | 
| 75 |  |  |  |  |  |  | 1; | 
| 76 |  |  |  |  |  |  |  |