| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package App::HL7::Send; | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 4 |  |  | 4 |  | 75449 | use strict; | 
|  | 4 |  |  |  |  | 25 |  | 
|  | 4 |  |  |  |  | 114 |  | 
| 4 | 4 |  |  | 4 |  | 21 | use warnings; | 
|  | 4 |  |  |  |  | 8 |  | 
|  | 4 |  |  |  |  | 127 |  | 
| 5 |  |  |  |  |  |  |  | 
| 6 | 4 |  |  | 4 |  | 1895 | use Class::Utils qw(set_params); | 
|  | 4 |  |  |  |  | 120311 |  | 
|  | 4 |  |  |  |  | 95 |  | 
| 7 | 4 |  |  | 4 |  | 301 | use Error::Pure qw(err); | 
|  | 4 |  |  |  |  | 9 |  | 
|  | 4 |  |  |  |  | 150 |  | 
| 8 | 4 |  |  | 4 |  | 7913 | use Getopt::Std; | 
|  | 4 |  |  |  |  | 216 |  | 
|  | 4 |  |  |  |  | 230 |  | 
| 9 | 4 |  |  | 4 |  | 1903 | use Net::HL7::Connection; | 
|  | 4 |  |  |  |  | 106423 |  | 
|  | 4 |  |  |  |  | 144 |  | 
| 10 | 4 |  |  | 4 |  | 29 | use Net::HL7::Message; | 
|  | 4 |  |  |  |  | 8 |  | 
|  | 4 |  |  |  |  | 94 |  | 
| 11 | 4 |  |  | 4 |  | 1951 | use Perl6::Slurp qw(slurp); | 
|  | 4 |  |  |  |  | 6490 |  | 
|  | 4 |  |  |  |  | 24 |  | 
| 12 |  |  |  |  |  |  |  | 
| 13 |  |  |  |  |  |  | our $VERSION = 0.04; | 
| 14 |  |  |  |  |  |  |  | 
| 15 |  |  |  |  |  |  | # Constructor. | 
| 16 |  |  |  |  |  |  | sub new { | 
| 17 | 2 |  |  | 2 | 1 | 1702 | my ($class, @params) = @_; | 
| 18 |  |  |  |  |  |  |  | 
| 19 |  |  |  |  |  |  | # Create object. | 
| 20 | 2 |  |  |  |  | 22 | my $self = bless {}, $class; | 
| 21 |  |  |  |  |  |  |  | 
| 22 |  |  |  |  |  |  | # Process params. | 
| 23 | 2 |  |  |  |  | 12 | set_params($self, @params); | 
| 24 |  |  |  |  |  |  |  | 
| 25 |  |  |  |  |  |  | # Object. | 
| 26 | 2 |  |  |  |  | 19 | return $self; | 
| 27 |  |  |  |  |  |  | } | 
| 28 |  |  |  |  |  |  |  | 
| 29 |  |  |  |  |  |  | # Run. | 
| 30 |  |  |  |  |  |  | sub run { | 
| 31 | 1 |  |  | 1 | 1 | 3 | my $self = shift; | 
| 32 |  |  |  |  |  |  |  | 
| 33 |  |  |  |  |  |  | # Process arguments. | 
| 34 | 1 |  |  |  |  | 6 | $self->{'_opts'} = { | 
| 35 |  |  |  |  |  |  | 'h' => 0, | 
| 36 |  |  |  |  |  |  | }; | 
| 37 | 1 | 50 | 33 |  |  | 6 | if (! getopts('h', $self->{'_opts'}) || @ARGV < 3 | 
|  |  |  | 33 |  |  |  |  | 
| 38 |  |  |  |  |  |  | || $self->{'_opts'}->{'h'}) { | 
| 39 |  |  |  |  |  |  |  | 
| 40 | 1 |  |  |  |  | 122 | print STDERR "Usage: $0 [-h] [--version] host port hl7_file|-\n"; | 
| 41 | 1 |  |  |  |  | 15 | print STDERR "\t-h\t\tPrint help.\n"; | 
| 42 | 1 |  |  |  |  | 11 | print STDERR "\t--version\tPrint version.\n"; | 
| 43 | 1 |  |  |  |  | 18 | 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 0; | 
| 77 |  |  |  |  |  |  | } | 
| 78 |  |  |  |  |  |  |  | 
| 79 |  |  |  |  |  |  | 1; | 
| 80 |  |  |  |  |  |  |  | 
| 81 |  |  |  |  |  |  |  | 
| 82 |  |  |  |  |  |  | __END__ |