blib/lib/App/HL7/Send.pm

filter: Statementstmt 68.5% 37 / 54 Branchbran 10.0% 1 / 10 Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 100% 10 / 10 Podpod 100% 2 / 2 totaltotal 61.1% 52 / 85 CC 8 SCAR 28.3
CC
8
Cov
57%
run
35.0
BEGIN
1.0
BEGIN
1.0
CRAP 17.0
↑ Summary
1 package App::HL7::Send;
2  
3 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 4 ▶use Class::Utils qw(set_params);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use Error::Pure qw(err);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 ▶use Getopt::Std;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 ▶use Net::HL7::Connection;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 4 ▶use Net::HL7::Message;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 4 ▶use Perl6::Slurp qw(slurp);
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 4 our $VERSION = 0.05;
14  
15 # Constructor.
16 2 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
17 2 my ($class, @params) = @_;
18  
19 # Create object.
20 2 my $self = bless {}, $class;
21  
22 # Process params.
23 2 set_params($self, @params);
24  
25 # Object.
26 2 return $self;
27 }
28  
29 # Run.
30 1 ▶sub run {
Subroutine run: called CC=8 SCAR=35.6
Pod documented
31 1 my $self = shift;
32  
33 # Process arguments.
34 1 $self->{'_opts'} = {
35 'h' => 0,
36 };
37 1 ▶ if (! getopts('h', $self->{'_opts'}) || @ARGV < 3
Branch: 1 branch
BranchTrueFalseTotal
if (not &getopts("h", $self->{"_opts"}) or @ARGV < 3 or $self->{"_opts"}{"h"}) 1 0 1
Condition33%2/6
not &getopts("h", $self->{"_opts"}) or @ARGV < 3 or $self->{"_opts"}{"h"}
l!l&&r!l&&!r
100
not &getopts("h", $self->{"_opts"}) or @ARGV < 3
l!l&&r!l&&!r
010
MC/DC0%0/3
not &getopts("h", $self->{"_opts"}) or @ARGV < 3 or $self->{"_opts"}{"h"}
not &getopts("h", $self->{"_opts"}) @ARGV < 3 $self->{"_opts"}{"h"}
Truth table25%1/4
not(A) or B or C
A= not &getopts("h", $self->{"_opts"})B= @ARGV < 3C= $self->{"_opts"}{"h"}
ABCresult
1XX1
01X1
0011
0000
38 || $self->{'_opts'}->{'h'}) {
39  
40 1 print STDERR "Usage: $0 [-h] [--version] host port hl7_file|-\n";
41 1 print STDERR "\t-h\t\tPrint help.\n";
42 1 print STDERR "\t--version\tPrint version.\n";
43 1 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 ▶ if ($self->{'_hl7_file'} eq '-') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'_hl7_file'} eq '-') { } 0 0 0
52 0 ▶ while (my $line = <STDIN>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline STDIN)) 0 0 0
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 ▶ if (! $msg) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($msg) 0 0 0
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 ▶ if (! $conn) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($conn) 0 0 0
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 4 1;
80  
81  
82 __END__
↑ Summary