File Coverage

blib/lib/App/HL7/Send.pm
Criterion Covered Total %
statement 35 52 67.3
branch 1 8 12.5
condition 2 6 33.3
subroutine 10 10 100.0
pod 2 2 100.0
total 50 78 64.1


line stmt bran cond sub pod time code
1             package App::HL7::Send;
2              
3 4     4   82472 use strict;
  4         23  
  4         119  
4 4     4   21 use warnings;
  4         9  
  4         121  
5              
6 4     4   2003 use Class::Utils qw(set_params);
  4         128082  
  4         83  
7 4     4   311 use Error::Pure qw(err);
  4         9  
  4         150  
8 4     4   8618 use Getopt::Std;
  4         246  
  4         258  
9 4     4   1922 use Net::HL7::Connection;
  4         112358  
  4         154  
10 4     4   34 use Net::HL7::Message;
  4         8  
  4         98  
11 4     4   2284 use Perl6::Slurp qw(slurp);
  4         6779  
  4         26  
12              
13             our $VERSION = 0.03;
14              
15             # Constructor.
16             sub new {
17 2     2 1 1520 my ($class, @params) = @_;
18              
19             # Create object.
20 2         7 my $self = bless {}, $class;
21              
22             # Process params.
23 2         10 set_params($self, @params);
24              
25             # Object.
26 2         18 return $self;
27             }
28              
29             # Run.
30             sub run {
31 1     1 1 2 my $self = shift;
32              
33             # Process arguments.
34 1         6 $self->{'_opts'} = {
35             'h' => 0,
36             };
37 1 50 33     5 if (! getopts('h', $self->{'_opts'}) || @ARGV < 3
      33        
38             || $self->{'_opts'}->{'h'}) {
39              
40 1         112 print STDERR "Usage: $0 [-h] [--version] host port hl7_file|-\n";
41 1         16 print STDERR "\t-h\t\tPrint help.\n";
42 1         12 print STDERR "\t--version\tPrint version.\n";
43 1         17 return 1;
44             }
45 0           $self->{'_hl7_host'} = $ARGV[0];
46 0           $self->{'_hl7_port'} = $ARGV[1];
47 0           $self->{'_hl7_file'} = $ARGV[2];
48              
49             # Get hl7_file.
50 0           my $hl7;
51 0 0         if ($self->{'_hl7_file'} eq '-') {
52 0           while (my $line = ) {
53 0           $hl7 .= $line;
54             }
55             } else {
56 0           $hl7 = slurp($self->{'_hl7_file'});
57             }
58              
59             # Create message.
60 0           my $msg = Net::HL7::Message->new($hl7);
61 0 0         if (! $msg) {
62 0           err 'Cannot parse HL7 file.', 'File', $self->{'_hl7_file'};
63             }
64              
65             # Create connection.
66             my $conn = Net::HL7::Connection->new($self->{'_hl7_host'},
67 0           $self->{'_hl7_port'});
68 0 0         if (! $conn) {
69 0           err 'Cannot connect to host.';
70             }
71              
72             # Send.
73 0           $conn->send($msg);
74 0           print "Message was send.\n";
75              
76 0           return;
77             }
78              
79             1;
80              
81              
82             __END__