File Coverage

blib/lib/Alvis/Pipeline/Write.pm
Criterion Covered Total %
statement 25 25 100.0
branch 8 10 80.0
condition n/a
subroutine 6 6 100.0
pod 3 3 100.0
total 42 44 95.4


line stmt bran cond sub pod time code
1             # $Id: Write.pm,v 1.7 2005/10/24 14:02:44 mike Exp $
2              
3             package Alvis::Pipeline::Write;
4 5     5   34 use vars qw(@ISA);
  5         8  
  5         307  
5             @ISA = qw(Alvis::Pipeline);
6              
7 5     5   26 use strict;
  5         10  
  5         163  
8 5     5   28 use warnings;
  5         8  
  5         1881  
9              
10              
11             sub new {
12 6     6 1 13005110 my $class = shift();
13 6         148 my(%opts) = @_;
14              
15 6         48 my $this = bless {}, $class;
16 6 100       262 $this->{host} = delete $opts{host}
17             or die "new($class) with no host";
18 5 100       46 $this->{port} = delete $opts{port}
19             or die "new($class) with no port";
20              
21 4         145 $this->_setopts(%opts);
22 4 100       161 $this->{socket} = new IO::Socket::INET(PeerAddr => $this->{host},
23             PeerPort => $this->{port},
24             Proto => "tcp")
25             or die("can't connect to '" . $this->{host} . "', ",
26             "port '" . $this->{port} . "': $!");
27              
28 3         8223 binmode $this->{socket}, ":utf8";
29 3         16 return $this;
30             }
31              
32              
33             # Protocol. Each packet consists of the following:
34             # 1. Magic string "Alvis::Pipeline\n"
35             # 2. Decimal-rendered protocol version-number [initially 1] followed by "\n"
36             # 3. Decimal-rendered integer byte-count, followed by "\n"
37             # 4. Binary object of length specified in #2.
38             # 5. Magic string "--end--\n";
39             #
40             sub write {
41 16     16 1 631 my $this = shift();
42 16         82 my($xmlDocument) = @_;
43              
44 16 50       42 $xmlDocument = $xmlDocument->toString()
45             if ref($xmlDocument);
46              
47 16         25 my $socket = $this->{socket};
48 16         106 $socket->print("Alvis::Pipeline\n",
49             1, "\n",
50             length($xmlDocument), "\n",
51             $xmlDocument,
52             "--end--\n");
53             }
54              
55              
56             sub close {
57 3     3 1 108 my $this = shift();
58              
59 3 50       72 $this->{socket}->close()
60             or die "can't close socket: $!";
61             }
62              
63              
64             1;