BrLock/SomePerlFunc.pm

filter: Statementstmt 40.7% 11 / 27 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 57.1% 4 / 7 Podpod 0.0% 0 / 3 totaltotal 36.5% 15 / 41 CC 3 SCAR 12.0
CC
3
Cov
35%
send_udp_string
6.0
send_tcp_string
6.0
choose_integer
2.0
CRAP 3.3
« BrLock/BrXML.pm ↑ Summary BrLock.pm »
1 package BrLock::SomePerlFunc;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use IO::Socket;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use base 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 our @EXPORT = qw(choose_integer send_tcp_string send_udp_string);
7  
8 # choose_integer(x):
9 # returns a random integer between 0 and x.
10 0 ▶sub choose_integer {
Subroutine choose_integer: not called CC=1 SCAR=6.9
Pod undocumented
11 0 my $max_integer = $_[0];
12 0 srand time; # not a really good seed, however...
13 0 return int (rand $max_integer);
14 0 return $max_integer - 1;
15 }
16  
17 # send_udp_string(str, ip, port):
18 # this function sends the string str as a udp message to the host
19 # ip:port.
20 # Return values:
21 # 0 -> ok; the message was throw correctly (note we can never
22 # ensure if a udp package has arrived)
23 # 1 -> error (probably with socket creation).
24  
25 0 ▶sub send_udp_string {
Subroutine send_udp_string: not called CC=2 SCAR=17.9
Pod undocumented
26 0 my ($str, $ip, $port) = @_;
27 0 my $sock = new IO::Socket::INET (
28 PeerAddr => $ip,
29 PeerPort => $port,
30 Proto => 'udp',
31 );
32 # return if cannot create a socket.
33 0 ▶ return 1 unless $sock ;
Branch: 1 branch
BranchTrueFalseTotal
unless $sock 0 0 0
34 # throw the package.
35 0 print $sock $str;
36 0 close $sock;
37 0 return 0;
38 }
39  
40 # send_tcp_string(str, ip, port):
41 # this function sends the string str as a tcp message to the host
42 # ip:port.
43 # Return values:
44 # 0 -> ok; the message was sent correctly
45 # 1 -> error (probably with socket creation).
46  
47 0 ▶sub send_tcp_string {
Subroutine send_tcp_string: not called CC=2 SCAR=17.9
Pod undocumented
48 0 my ($str, $ip, $port) = @_;
49 0 my $sock = new IO::Socket::INET (
50 PeerAddr => $ip,
51 PeerPort => $port,
52 Proto => 'tcp',
53 timeout => 0,
54 );
55 # return if cannot create a socket.
56 0 ▶ return 1 unless $sock ;
Branch: 1 branch
BranchTrueFalseTotal
unless $sock 0 0 0
57 # throw the package.
58 0 print $sock $str;
59 0 close $sock;
60 0 return 0;
61 }
62  
63 1 ▶BEGIN{
Subroutine BEGIN: called CC=1 SCAR=0.0
64 }
65 1 return 1;
« BrLock/BrXML.pm ↑ Summary BrLock.pm »