CSTA.pm

filter: Statementstmt 23.8% 35 / 147 Branchbran 0.0% 0 / 32 Conditioncond 0.0% 0 / 27 MC/DCmcdc 0.0% 0 / 17 Subroutinesub 30.0% 9 / 30 Podpod 0.0% 0 / 13 totaltotal 16.5% 44 / 266 CC 29 SCAR 33.1
CC
29
Cov
17%
read_pdu
90.0
_safe_copy
56.0
init
30.0
CRAP 27.4
↑ Summary CSTA/ASN.pm »
1 package Net::CSTA;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 require Exporter;
7 1 ▶use AutoLoader qw(AUTOLOAD);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 our @ISA = qw(Exporter);
10  
11 # Items to export into callers namespace by default. Note: do not export
12 # names by default without a very good reason. Use EXPORT_OK instead.
13 # Do not simply export all your public functions/methods/constants.
14  
15 # This allows declaration use Net::CSTA ':all';
16 # If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
17 # will save memory.
18 1 our %EXPORT_TAGS = ( 'all' => [ qw(
19
20 ) ] );
21  
22 1 our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
23  
24 1 our @EXPORT = qw(
25
26 );
27  
28 1 our $VERSION = '0.04';
29 1 ▶use IO::Socket::INET;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 1 ▶use Net::CSTA::ASN qw(CSTAapdu);
Subroutine BEGIN: called CC=1 SCAR=0.0
31 1 ▶use Convert::ASN1 qw(:io);
Subroutine BEGIN: called CC=1 SCAR=0.0
32  
33 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod undocumented
34 0 my $self = shift;
35 0 ▶ my $class = ref $self || $self;
Condition0%0/3
ref $self || $self
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table0%0/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
36 0 my %me = @_;
37 0 my $this = bless \%me,$class;
38 0 $this->init();
39 }
40  
41 package Net::CSTA::PDU;
42 1 ▶use Net::CSTA::ASN qw(CSTAapdu);
Subroutine BEGIN: called CC=1 SCAR=0.0
43 1 ▶use MIME::Base64;
Subroutine BEGIN: called CC=1 SCAR=0.0
44  
45 0 ▶sub decode {
Subroutine decode: not called CC=2 SCAR=17.9
46 0 my $self = shift;
47 0 ▶ my $class = ref $self || $self;
Condition0%0/3
ref $self || $self
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table0%0/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
48 0 my $pdu = shift;
49 0 my $this = bless $CSTAapdu->decode($pdu),$class;
50 0 $this->init();
51 }
52  
53 0 ▶sub _hexenc {
Subroutine _hexenc: not called CC=1 SCAR=6.9
54 0 join(":",map { sprintf("%2.2x",$_); } unpack("C*",$_[0]))
55 }
56  
57 0 ▶sub isError {
Subroutine isError: not called CC=1 SCAR=6.9
58 0 my $self = shift;
59 0 defined $self->{typeOfError};
60 }
61  
62 0 ▶sub _b64 {
Subroutine _b64: not called CC=1 SCAR=6.9
63 0 my $x = encode_base64($_[0]);
64
65 0 chomp($x);
66 0 $x;
67 }
68  
69 0 ▶sub _safe_copy {
Subroutine _safe_copy: not called CC=7 SCAR=40.3
70 0 my $self = shift;
71
72 0 my $copy;
73 SWITCH: {
74 0 ▶ UNIVERSAL::isa($self,'ARRAY') and do {
Branch: 1 branch
BranchTrueFalseTotal
UNIVERSAL::isa($self, "ARRAY") and do { $copy = []; foreach $_ (@{$self;}) { push @{$copy;}, _safe_copy($_); } }, last SWITCH 0 0 0
75 0 $copy = [];
76 0 foreach (@{$self})
77 {
78 0 push(@{$copy},_safe_copy($_));
79 }
80 },last SWITCH;
81
82 0 ▶ UNIVERSAL::isa($self,'HASH') || UNIVERSAL::isa($self,'Net::CSTA::PDU') and do {
Branch: 1 branch
BranchTrueFalseTotal
UNIVERSAL::isa($self, "HASH") || UNIVERSAL::isa($self, "Net::CSTA::PDU") and do { $copy = {}; foreach $_ (keys %{$self;}) { $copy->{$_} = _safe_copy($self->{$_}); } }, last SWITCH 0 0 0
Condition0%0/3
UNIVERSAL::isa($self, "HASH") or UNIVERSAL::isa($self, "Net::CSTA::PDU")
l!l&&r!l&&!r
000
MC/DC0%0/2
UNIVERSAL::isa($self, "HASH") or UNIVERSAL::isa($self, "Net::CSTA::PDU")
UNIVERSAL::isa($self, "HASH") UNIVERSAL::isa($self, "Net::CSTA::PDU")
Truth table0%0/3
A or B
A= UNIVERSAL::isa($self, "HASH")B= UNIVERSAL::isa($self, "Net::CSTA::PDU")
ABresult
1X1
011
000
83 0 $copy = {};
84 0 foreach (keys %{$self})
85 {
86 0 $copy->{$_} = _safe_copy($self->{$_});
87 }
88 },last SWITCH;
89
90 0 do {
91 0 ▶ $copy = $self =~ /^[[:print:]^>^<^^=]*$/ ? $self : _hexenc($self);
Branch: 1 branch
BranchTrueFalseTotal
$self =~ /^[[:print:]^>^<^^=]*$/ ? : 0 0 0
92 },last SWITCH;
93 };
94
95 0 $copy;
96 }
97  
98 0 ▶sub toXML {
Subroutine toXML: not called CC=1 SCAR=0.6
99 0 my $pdu = _safe_copy($_[0]);
100 1 ▶ use XML::Simple;
Subroutine BEGIN: called CC=1 SCAR=0.0
101
102 0 XMLout($pdu,RootName=>'csta');
103 }
104  
105 0 ▶sub init {
Subroutine init: not called CC=1 SCAR=6.9
106 0 $_[0];
107 }
108  
109 package Net::CSTA;
110  
111 0 ▶sub init {
Subroutine init: not called CC=5 SCAR=34.0
Pod undocumented
112 0 my $self = shift;
113 $self->{_csock} = IO::Socket::INET->new(Proto=>'tcp',PeerHost=>$self->{Host},PeerPort=>$self->{Port})
114 0 ▶ or die "Unable to connect to CSTA server at $self->{Host}:$self->{Port}: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
$self->{"_csock"} = "IO::Socket::INET"->new("Proto", "tcp", "PeerHost", $self->{"Host"}, "PeerPort", $self->{"Port"}) or die qq[Unable to connect to CSTA server at $self->{"Host"}:$self->{"Port"}: $!\n] 0 0 0
115 0 ▶ $self->{_ssock} = IO::Socket::INET->new(Proto=>'udp',LocalHost=>'localhost',LocalPort=>$self->{LocalPort} || 3333)
Branch: 1 branch
BranchTrueFalseTotal
$self->{"_ssock"} = "IO::Socket::INET"->new("Proto", "udp", "LocalHost", "localhost", "LocalPort", $self->{"LocalPort"} || 3333) or die "Unable to create local UDP port: $!\n" 0 0 0
Condition0%0/2
$self->{'LocalPort'} || 3333
l!l
00
MC/DC0%0/1
$self->{'LocalPort'} || 3333
$self->{'LocalPort'}
Truth table0%0/2
A
A= $self->{'LocalPort'}
Aresult
11
00
116 or die "Unable to create local UDP port: $!\n";
117 0 $self->{_req} = $$;
118 0 ▶ $self->{Debug} = 0 unless defined $self->{Debug};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"Debug"} 0 0 0
119 0 $self;
120 }
121  
122 0 ▶sub next_request {
Subroutine next_request: not called CC=1 SCAR=6.9
Pod undocumented
123 0 $_[0]->{_req}++;
124 }
125  
126 0 ▶sub this_request {
Subroutine this_request: not called CC=1 SCAR=6.9
Pod undocumented
127 0 $_[0]->{_req};
128 }
129  
130 sub debug
131 0 ▶{
Subroutine debug: not called CC=1 SCAR=6.9
Pod undocumented
132 0 $_[0]->{Debug};
133 }
134  
135 sub close
136 0 ▶{
Subroutine close: not called CC=2 SCAR=17.9
Pod undocumented
137 0 my $self = shift;
138 0 ▶ my $sock = shift || $self->{_csock};
Condition0%0/3
shift() || $self->{'_csock'}
l!l&&r!l&&!r
000
MC/DC0%0/2
shift() || $self->{'_csock'}
shift() $self->{'_csock'}
Truth table0%0/3
A || B
A= shift()B= $self->{'_csock'}
ABresult
1X1
011
000
139 0 shutdown($sock,2);
140 0 close($sock);
141 }
142  
143 0 ▶sub write_pdu {
Subroutine write_pdu: not called CC=4 SCAR=30.0
Pod undocumented
144 0 my $self = shift;
145 0 my $pdu = shift;
146 0 my $len = length($pdu);
147 0 ▶ my $sock = shift || $self->{_csock};
Condition0%0/3
shift() || $self->{'_csock'}
l!l&&r!l&&!r
000
MC/DC0%0/2
shift() || $self->{'_csock'}
shift() $self->{'_csock'}
Truth table0%0/3
A || B
A= shift()B= $self->{'_csock'}
ABresult
1X1
011
000
148  
149 0 ▶ if ($self->debug > 1)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->debug > 1) 0 0 0
150 {
151 0 warn "C ---> S\n";
152 0 Convert::ASN1::asn_dump(*STDERR, $pdu);
153 0 ▶ Convert::ASN1::asn_hexdump(*STDERR, $pdu) if $self->debug > 2;
Branch: 1 branch
BranchTrueFalseTotal
if $self->debug > 2 0 0 0
154 }
155  
156 0 $sock->write(pack "n",$len);
157 0 $sock->write($pdu);
158 }
159  
160 0 ▶sub read_pdu {
Subroutine read_pdu: not called CC=9 SCAR=45.0
Pod undocumented
161 0 my $self = shift;
162 0 ▶ my $timeout = shift || undef;
Condition0%0/2
shift() || undef
l!l
00
MC/DC0%0/1
shift() || undef
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
163 0 ▶ my $sock = shift || $self->{_csock};
Condition0%0/3
shift() || $self->{'_csock'}
l!l&&r!l&&!r
000
MC/DC0%0/2
shift() || $self->{'_csock'}
shift() $self->{'_csock'}
Truth table0%0/3
A || B
A= shift()B= $self->{'_csock'}
ABresult
1X1
011
000
164  
165 0 my $buf = "";
166
167 0 my ($rin,$win,$ein) = ("","","");
168 0 my ($rout,$wout,$eout) = ("","","");
169
170 0 vec($rin,$sock->fileno,1) = 1;
171 0 $ein = $rin | $win;
172
173 0 my $n = select($rout=$rin,$wout=$win,$eout=$ein,$timeout);
174 0 ▶ return undef unless $n > 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $n > 0 0 0 0
175
176 0 eval {
177 0 ▶ local $SIG{ALRM} = sub { die "alarm\n" };
Subroutine __ANON__: not called CC=1 SCAR=6.9
178 0 ▶ alarm ($timeout || 30);
Condition0%0/2
$timeout || 30
l!l
00
MC/DC0%0/1
$timeout || 30
$timeout
Truth table0%0/2
A
A= $timeout
Aresult
11
00
179 0 my $nread = $sock->sysread($buf,2);
180 0 my $len = unpack "n",$buf;
181 0 $sock->sysread($buf,$len);
182 0 alarm 0;
183 0 ▶ }; if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
184 0 ▶ die unless $@ eq "alarm\n";
Branch: 1 branch
BranchTrueFalseTotal
unless $@ eq "alarm\n" 0 0 0
185 0 warn "Caught timeout\n";
186 0 return undef;
187 }
188  
189 0 ▶ if ($self->debug > 1)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->debug > 1) 0 0 0
190 {
191 0 warn "C <--- S\n";
192 0 Convert::ASN1::asn_dump(*STDERR, $buf);
193 0 ▶ Convert::ASN1::asn_hexdump(*STDERR, $buf) if $self->debug > 2;
Branch: 1 branch
BranchTrueFalseTotal
if $self->debug > 2 0 0 0
194 }
195 0 $buf;
196 }
197  
198 0 ▶sub send_and_receive {
Subroutine send_and_receive: not called CC=1 SCAR=6.9
Pod undocumented
199 0 my $self = shift;
200  
201 0 $self->send(@_);
202 0 $self->receive();
203 }
204  
205 0 ▶sub request {
Subroutine request: not called CC=1 SCAR=6.9
Pod undocumented
206 0 my $self = shift;
207 0 my %op = @_;
208  
209 0 $op{invokeID} = $self->next_request;
210 0 $self->send_and_receive(svcRequest=>\%op);
211 }
212  
213 0 ▶sub send {
Subroutine send: not called CC=1 SCAR=6.9
Pod undocumented
214 0 my $self = shift;
215 0 my $pdu = $CSTAapdu->encode(@_);
216  
217 0 $self->write_pdu($pdu);
218 }
219  
220 0 ▶sub receive {
Subroutine receive: not called CC=2 SCAR=17.9
Pod undocumented
221 0 my $self = shift;
222 0 my $pdu = $self->read_pdu(@_);
223 0 ▶ return undef unless $pdu;
Branch: 1 branch
BranchTrueFalseTotal
unless $pdu 0 0 0
224  
225 0 Net::CSTA::PDU->decode($pdu);
226 }
227  
228 0 ▶sub recv_pdu {
Subroutine recv_pdu: not called CC=4 SCAR=30.0
Pod undocumented
229 0 my $self = shift;
230 0 ▶ my $sock = shift || $self->{_ssock};
Condition0%0/3
shift() || $self->{'_ssock'}
l!l&&r!l&&!r
000
MC/DC0%0/2
shift() || $self->{'_ssock'}
shift() $self->{'_ssock'}
Truth table0%0/3
A || B
A= shift()B= $self->{'_ssock'}
ABresult
1X1
011
000
231  
232 0 my $buf = "";
233 0 my $nread = $sock->recv($buf,2);
234 0 my $len = unpack "n",$buf;
235 0 $sock->recv_pdu($buf,$len);
236  
237 0 ▶ if ($self->debug > 1)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->debug > 1) 0 0 0
238 {
239 0 warn "C <--- S\n";
240 0 Convert::ASN1::asn_dump(*STDERR, $buf);
241 0 ▶ Convert::ASN1::asn_hexdump(*STDERR, $buf) if $self->debug > 2;
Branch: 1 branch
BranchTrueFalseTotal
if $self->debug > 2 0 0 0
242 }
243
244 0 $buf;
245 }
246  
247 # Preloaded methods go here.
248  
249 # Autoload methods go after =cut, and are processed by the autosplit program.
250  
251 1 1;
252 __END__
↑ Summary CSTA/ASN.pm »