SeedServe.pm

filter: Statementstmt 61.0% 36 / 59 Branchbran 18.7% 3 / 16 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 90.0% 9 / 10 Podpod 100% 2 / 2 totaltotal 57.4% 50 / 87 CC 9 SCAR 26.8
CC
9
Cov
52%
loop
34.9
_init
3.1
__ANON__
2.0
CRAP 14.6
↑ Summary SeedServe/Server.pm »
1 package Net::SeedServe;
2  
3 7 ▶use 5.008;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 7 ▶use IO::Socket::INET;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 7 ▶use IO::All;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 7 our $VERSION = '0.2.7';
11  
12 sub new
13 3 ▶{
Subroutine new: called CC=1 SCAR=0.0
Pod documented
14 3 my $class = shift;
15 3 my $self = +{};
16 3 bless $self, $class;
17 3 $self->_init(@_);
18 3 return $self;
19 }
20  
21 sub _init
22 3 ▶{
Subroutine _init: called CC=3 SCAR=11.2
23 3 my $self = shift;
24  
25 3 my %args = (@_);
26  
27 3 ▶ my $port = $args{'port'} or
Branch: 1 branch
BranchTrueFalseTotal
my $port = $args{"port"} or die "Port not specified!" 3 0 3
28 die "Port not specified!";
29  
30 3 $self->{'port'} = $port;
31  
32 3 ▶ $self->{'status_file'} = $args{'status_file'} or
Branch: 1 branch
BranchTrueFalseTotal
$self->{"status_file"} = $args{"status_file"} or die "Success file not specified" 3 0 3
33 die "Success file not specified";
34  
35 3 return 0;
36 }
37  
38 sub _update_status_file
39 3 ▶{
Subroutine _update_status_file: called CC=1 SCAR=0.0
40 3 my $self = shift;
41 3 my $string = shift;
42  
43 3 io()->file($self->{'status_file'})->print("$string\n");
44 }
45  
46 sub loop
47 3 ▶{
Subroutine loop: called CC=7 SCAR=35.5
Pod documented
48 3 my $self = shift;
49  
50 3 my $serving_socket;
51  
52 $serving_socket =
53 IO::Socket::INET->new(
54 Listen => 5,
55 LocalAddr => 'localhost',
56 3 LocalPort => $self->{'port'},
57 Proto => 'tcp'
58 );
59 3 ▶ if (!defined($serving_socket))
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $serving_socket) 3 0 3
60 {
61 3 $self->_update_status_file("Status:Error");
62 3 die $@;
63 }
64  
65 $self->_update_status_file(
66 0 "Status:Success\tPort:" . $self->{'port'} . "\tPID:$$"
67 );
68  
69 0 my @queue;
70 my $next_seed;
71  
72 0 ▶ my $clear = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
73 0 @queue = ();
74 0 $next_seed = 1;
75 0 };
76  
77 0 $clear->();
78  
79 0 ▶ while (my $conn = $serving_socket->accept())
Branch: 1 branch
BranchTrueFalseTotal
if (my $conn = $serving_socket->accept) 0 0 0
80 {
81 0 my $request = $conn->getline();
82 0 my $response;
83 0 ▶ if ($request =~ /^FETCH/)
Branch: 3 branches
BranchTrueFalseTotal
if ($request =~ /^FETCH/) { } 0 0 0
elsif ($request =~ /^CLEAR/) { } 0 0 0
elsif ($request =~ /^ENQUEUE ((?:\d+,)+)/) { } 0 0 0
84 {
85 0 my $seed;
86 0 ▶ if ($seed = shift(@queue))
Branch: 1 branch
BranchTrueFalseTotal
if ($seed = shift @queue) { } 0 0 0
87 {
88 0 $response = $seed;
89 0 $next_seed = $seed+1;
90 }
91 else
92 {
93 0 $response = $next_seed++;
94 }
95 }
96 elsif ($request =~ /^CLEAR/)
97 {
98 0 $clear->();
99 0 $response = "OK";
100 }
101 elsif ($request =~ /^ENQUEUE ((?:\d+,)+)/)
102 {
103 0 my $nums = $1;
104 0 $nums =~ s{,$}{};
105 0 push @queue, split(/,/, $nums);
106 0 $response = "OK";
107 }
108 else
109 {
110 0 $response = "ERROR";
111 }
112 0 $conn->print("$response\n");
113 }
114 }
115  
116 7 1;
117 __END__
↑ Summary SeedServe/Server.pm »