lib/Net/SinFP3.pm

filter: Statementstmt 25.8% 44 / 170 Branchbran 0.0% 0 / 46 Conditioncond 0.0% 0 / 15 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 68.7% 11 / 16 Podpod 100% 2 / 2 totaltotal 22.3% 57 / 255 CC 39 SCAR 46.9
CC
39
Cov
19%
_do
210.0
run
156.0
new
71.4
CRAP 108.5
« lib/Net/SinFP3/Ext/TCP.pm ↑ Summary lib/Net/SinFP3/Mode/Active.pm »
1 #
2 # $Id: SinFP3.pm,v 008243d3e89a 2018/07/21 14:54:07 gomor $
3 #
4 package Net::SinFP3;
5 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 our $VERSION = '1.24';
9  
10 2 ▶use base qw(Class::Gomor::Array DynaLoader);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 our @AS = qw(
12 global
13 );
14 2 our @AA = qw(
15 db
16 mode
17 search
18 input
19 output
20 );
21 2 __PACKAGE__->cgBuildIndices;
22 2 __PACKAGE__->cgBuildAccessorsScalar(\@AS);
23 2 __PACKAGE__->cgBuildAccessorsArray (\@AA);
24  
25 2 our %EXPORT_TAGS = (
26 matchType => [qw(
27 NS_MATCH_TYPE_S1S2S3
28 NS_MATCH_TYPE_S1S2
29 NS_MATCH_TYPE_S2
30 )],
31 matchMask => [qw(
32 NS_MATCH_MASK_HEURISTIC0
33 NS_MATCH_MASK_HEURISTIC1
34 NS_MATCH_MASK_HEURISTIC2
35 )],
36 );
37  
38 our @EXPORT_OK = (
39 2 @{$EXPORT_TAGS{matchType}},
40 2 @{$EXPORT_TAGS{matchMask}},
41 );
42  
43 2 ▶use constant NS_MATCH_TYPE_S1S2S3 => 'S1S2S3';
Subroutine BEGIN: called CC=1 SCAR=0.0
44 2 ▶use constant NS_MATCH_TYPE_S1S2 => 'S1S2';
Subroutine BEGIN: called CC=1 SCAR=0.0
45 2 ▶use constant NS_MATCH_TYPE_S2 => 'S2';
Subroutine BEGIN: called CC=1 SCAR=0.0
46  
47 2 ▶use constant NS_MATCH_MASK_HEURISTIC0 => 'BH0FH0WH0OH0MH0SH0LH0';
Subroutine BEGIN: called CC=1 SCAR=0.0
48 2 ▶use constant NS_MATCH_MASK_HEURISTIC1 => 'BH1FH1WH1OH1MH1SH1LH1';
Subroutine BEGIN: called CC=1 SCAR=0.0
49 2 ▶use constant NS_MATCH_MASK_HEURISTIC2 => 'BH2FH2WH2OH2MH2SH2LH2';
Subroutine BEGIN: called CC=1 SCAR=0.0
50  
51 2 ▶use Net::SinFP3::Worker qw(:consts);
Subroutine BEGIN: called CC=1 SCAR=0.0
52  
53 0 ▶sub new {
Subroutine new: not called CC=9 SCAR=42.7
Pod documented
54 0 my $class = shift;
55 0 my %param = @_;
56  
57 # Sets unbuffered STDOUT
58 0 $|++;
59  
60 0 ▶ if (!exists($param{output})
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $param{"output"} and exists $param{"input"} and exists $param{"mode"} and exists $param{"search"} and exists $param{"global"} and exists $param{"db"}) 0 0 0
Condition0%0/15
exists $param{"output"} and exists $param{"input"} and exists $param{"mode"} and exists $param{"search"} and exists $param{"global"} and exists $param{"db"}
!ll&&!rl&&r
000
exists $param{"output"} and exists $param{"input"} and exists $param{"mode"} and exists $param{"search"} and exists $param{"global"}
!ll&&!rl&&r
000
exists $param{"output"} and exists $param{"input"} and exists $param{"mode"} and exists $param{"search"}
!ll&&!rl&&r
000
exists $param{"output"} and exists $param{"input"} and exists $param{"mode"}
!ll&&!rl&&r
000
exists $param{"output"} and exists $param{"input"}
!ll&&!rl&&r
000
MC/DC0%0/6
exists $param{"output"} and exists $param{"input"} and exists $param{"mode"} and exists $param{"search"} and exists $param{"global"} and exists $param{"db"}
exists $param{"output"} exists $param{"input"} exists $param{"mode"} exists $param{"search"} exists $param{"global"} exists $param{"db"}
Truth table0%0/7
A and B and C and D and E and F
A= exists $param{"output"}B= exists $param{"input"}C= exists $param{"mode"}D= exists $param{"search"}E= exists $param{"global"}F= exists $param{"db"}
ABCDEFresult
0XXXXX0
10XXXX0
110XXX0
1110XX0
11110X0
1111100
1111111
61 || !exists($param{input})
62 || !exists($param{mode})
63 || !exists($param{search})
64 || !exists($param{global})
65 || !exists($param{db})) {
66 0 die("[-] ".__PACKAGE__.": You must provide all of the following ".
67 "attributes: output, input, mode, search, db, global\n");
68 }
69  
70 0 my $self = $class->SUPER::new(
71 db => [],
72 input => [],
73 mode => [],
74 search => [],
75 output => [],
76 @_,
77 );
78  
79 0 my $log = $self->global->log;
80  
81 {
82 0 ▶ no strict 'vars';
Subroutine BEGIN: called CC=1 SCAR=0.2
83 0 for my $var ('output', 'input', 'db', 'mode', 'search') {
84 0 my $idx = '$__'.$var;
85 0 my $ref = ref($self->[eval($idx)]);
86 0 ▶ if ($ref !~ /^ARRAY$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ref =~ /^ARRAY$/) 0 0 0
87 0 $log->fatal("$var attribute must be an ARRAYREF and it is [$ref]");
88 }
89 }
90 }
91  
92 0 return $self;
93 }
94  
95 0 ▶sub _do {
Subroutine _do: not called CC=14 SCAR=53.5
96 0 my $self = shift;
97  
98 0 my $global = $self->global;
99 0 my $log = $global->log;
100 0 my $input = $global->input;
101 0 my $next = $global->next;
102  
103 0 $log->info("Starting of job with Next ".$next->print);
104  
105 0 my @db = $self->db;
106 0 my @mode = $self->mode;
107 0 my @search = $self->search;
108 0 my @output = $self->output;
109  
110 0 ▶ $input->postRun or return;
Branch: 1 branch
BranchTrueFalseTotal
$input->postRun or return 0 0 0
111  
112 0 for my $db (@db) {
113 0 $log->verbose("Starting of DB [".ref($db)."]");
114 0 $global->db($db);
115 0 ▶ $db->init or $log->fatal("Unable to init [".ref($db)."] module");
Branch: 1 branch
BranchTrueFalseTotal
$db->init or $log->fatal('Unable to init [' . ref($db) . '] module') 0 0 0
116 0 ▶ $db->run or next;
Branch: 1 branch
BranchTrueFalseTotal
$db->run or next 0 0 0
117 0 $log->verbose("Running of DB [".ref($db)."]: Done");
118 0 for my $mode (@mode) {
119 0 $global->mode($mode);
120  
121 0 $log->verbose(
122 "Running with Next: ".$next->print." with type [".ref($next)."]"
123 );
124 0 $log->verbose("Starting of Mode [".ref($mode)."]");
125 0 ▶ $mode->init or $log->fatal("Unable to init [".ref($mode)."] module");
Branch: 1 branch
BranchTrueFalseTotal
$mode->init or $log->fatal('Unable to init [' . ref($mode) . '] module') 0 0 0
126 0 ▶ $mode->run or next;
Branch: 1 branch
BranchTrueFalseTotal
$mode->run or next 0 0 0
127 0 $log->verbose("Running of Mode [".ref($mode)."]: Done");
128  
129 0 for my $search (@search) {
130 0 $global->search($search);
131  
132 0 $log->verbose("Starting of Search [".ref($search)."]");
133 0 ▶ $search->init or $log->fatal("Unable to init [".ref($search).
Branch: 1 branch
BranchTrueFalseTotal
$search->init or $log->fatal('Unable to init [' . ref($search) . '] module') 0 0 0
134 "] module");
135 0 ▶ my $result = $search->run or next;
Branch: 1 branch
BranchTrueFalseTotal
my $result = $search->run or next 0 0 0
136 0 $global->result($result);
137 0 $log->verbose("Running of Search [".ref($search)."]: Done");
138  
139 0 $mode->postSearch;
140  
141 0 for my $output (@output) {
142 0 $global->output($output);
143  
144 0 $log->verbose("Starting of Output [".ref($output)."]");
145 0 $output->firstInit;
146 0 ▶ $output->init or $log->fatal("Unable to init [".ref($output).
Branch: 1 branch
BranchTrueFalseTotal
$output->init or $log->fatal('Unable to init [' . ref($output) . '] module') 0 0 0
147 "] module");
148 0 ▶ $output->run or next;
Branch: 1 branch
BranchTrueFalseTotal
$output->run or next 0 0 0
149 0 $output->post;
150 0 $log->verbose("Running of Output [".ref($output)."]: Done");
151 }
152 0 $search->post;
153 }
154 0 $mode->post;
155 }
156 # To have persistent $dbh, we MUST post() in main process
157 #$db->post;
158 }
159  
160 0 return 1;
161 }
162  
163 0 ▶sub _getWorkerModel {
Subroutine _getWorkerModel: not called CC=7 SCAR=40.3
164 0 my $self = shift;
165  
166 0 my $global = $self->global;
167 0 my $log = $global->log;
168  
169 0 my $model;
170 0 ▶ if ($global->worker =~ /fork/i) {
Branch: 3 branches
BranchTrueFalseTotal
if ($global->worker =~ /fork/i) { } 0 0 0
elsif ($global->worker =~ /thread/i) { } 0 0 0
elsif ($global->worker =~ /single/i) { } 0 0 0
171 0 eval "use Net::SinFP3::Worker::Fork";
172 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
173 0 chomp($@);
174 0 $log->fatal("Unable to use worker model Fork: error [$@]");
175 }
176 0 $model = 'Net::SinFP3::Worker::Fork';
177 }
178 elsif ($global->worker =~ /thread/i) {
179 0 eval "use Net::SinFP3::Worker::Thread";
180 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
181 0 chomp($@);
182 0 $log->fatal("Unable to use worker model Thread: error [$@]");
183 }
184 0 $model = 'Net::SinFP3::Worker::Thread';
185 }
186 elsif ($global->worker =~ /single/i) {
187 0 eval "use Net::SinFP3::Worker::Single";
188 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
189 0 chomp($@);
190 0 $log->fatal("Unable to use worker model Single: error [$@]");
191 }
192 0 $model = 'Net::SinFP3::Worker::Single';
193 }
194  
195 0 return $model;
196 }
197  
198 0 ▶sub run {
Subroutine run: not called CC=12 SCAR=50.5
Pod documented
199 0 my $self = shift;
200  
201 0 my $global = $self->global;
202 0 my $log = $global->log;
203 0 my @input = $self->input;
204 0 my @output = $self->output;
205  
206 # Beware, recursive loop
207 0 $log->global($global);
208  
209 0 my $worker = $self->_getWorkerModel->new(
210 global => $global,
211 );
212  
213 0 $log->info("Loaded Input: ".join(', ', map { ref($_) } $self->input));
214 0 $log->info("Loaded DB: ".join(', ', map { ref($_) } $self->db));
215 0 $log->info("Loaded Mode: ".join(', ', map { ref($_) } $self->mode));
216 0 $log->info("Loaded Search: ".join(', ', map { ref($_) } $self->search));
217 0 $log->info("Loaded Output: ".join(', ', map { ref($_) } $self->output));
218  
219 0 for my $output (@output) {
220 0 $output->preInit;
221 }
222  
223 0 my $job = 0;
224 0 for my $input (@input) {
225 0 $log->info("Starting of Input [".ref($input)."]");
226 0 ▶ $input->init or $log->fatal("Unable to init [".ref($input)."] module");
Branch: 1 branch
BranchTrueFalseTotal
$input->init or $log->fatal('Unable to init [' . ref($input) . '] module') 0 0 0
227  
228 0 $global->input($input);
229  
230 0 ▶ while (my $next = $input->run) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $next = $input->run) 0 0 0
231 0 ▶ last unless defined($next);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $next 0 0 0
232  
233 0 ▶ my @next = (ref($next) =~ /^ARRAY$/) ? @$next : ( $next );
Branch: 1 branch
BranchTrueFalseTotal
ref($next) =~ /^ARRAY$/ ? : 0 0 0
234 0 for my $next (@next) {
235 0 $global->job(++$job);
236 0 $global->next($next);
237  
238 $worker->init(
239 0 ▶ callback => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
240 0 $self->_do;
241 },
242 0 ▶ ) or $log->fatal("Unable to init [".ref($worker)."] module");
Branch: 1 branch
BranchTrueFalseTotal
$worker->init("callback", sub { $self->_do; } ) or $log->fatal('Unable to init [' . ref($worker) . '] module') 0 0 0
243  
244 # We are just before fork()ing or thread()ing.
245 # Now, all data will be copied to the new process.
246 0 my $r = $worker->run;
247 0 ▶ if ($r == NS_WORKER_SUCCESS) {
Branch: 1 branch
BranchTrueFalseTotal
if ($r == 1) 0 0 0
248 0 $input->postFork;
249 0 next;
250 }
251  
252 # Father process will skip that part
253 0 $log->verbose("Running of job with Next ".$next->print.": Done");
254  
255 0 $worker->post;
256 }
257 }
258 0 $global->job(0);
259 0 $input->post;
260 0 $log->verbose("Running of Input [".ref($input)."]: Done");
261 }
262  
263 0 $worker->clean;
264  
265 0 for my $db ($self->db) {
266 0 $db->post;
267 }
268  
269 0 for my $output (@output) {
270 0 $output->lastPost;
271 }
272  
273 0 $log->info("Done: operation successful");
274  
275 0 return 1;
276 }
277  
278 2 1;
279  
280 __END__
« lib/Net/SinFP3/Ext/TCP.pm ↑ Summary lib/Net/SinFP3/Mode/Active.pm »