lib/Net/SinFP3/Output/OsOnly.pm untested

filter: Statementstmt 0.0% 0 / 49 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 8 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 0.0% 0 / 5 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 79 CC 6 SCAR 32.6
CC
6
Cov
0%
run
42.0
take
2.0
BEGIN
2.0
CRAP 26.0
1 #
2 # $Id: OsOnly.pm,v 008243d3e89a 2018/07/21 14:54:07 gomor $
3 #
4 package Net::SinFP3::Output::OsOnly;
5 use strict;
6 use warnings;
7  
8 use base qw(Net::SinFP3::Output);
9 __PACKAGE__->cgBuildIndices;
10  
11 sub take {
12 return [
13 'Net::SinFP3::Result::Active',
14 'Net::SinFP3::Result::Passive',
15 'Net::SinFP3::Result::PortError',
16 'Net::SinFP3::Result::Unknown',
17 ];
18 }
19  
20 sub run {
21 my $self = shift->SUPER::run(@_) or return;
22  
23 my $global = $self->global;
24 my $log = $global->log;
25 my @results = $global->result;
26  
27 my $buf = '';
28 my $first = 1;
29 my %os = ();
30 for my $r (@results) {
31 my $ref = ref($r);
32 if ($ref =~ /^Net::SinFP3::Result::Unknown$/) {
33 $buf .= $r->printSignature."\n";
34 $buf .= $r->print."\n";
35 print $buf;
36 return 1;
37 }
38 elsif ($ref =~ /^Net::SinFP3::Result::PortError$/) {
39 $buf .= $r->printSignature."\n";
40 $buf .= $r->print."\n";
41 print $buf;
42 return 1;
43 }
44 elsif ($ref =~ /^Net::SinFP3::Result::Active$/
45 || $ref =~ /^Net::SinFP3::Result::Passive$/) {
46 if ($first) {
47 $buf .= $r->printSignature."\n";
48 $first = 0;
49 }
50 (exists($os{$r->os}) && $r->matchScore >= $os{$r->os}->matchScore)
51 ? ($os{$r->os} = $r)
52 : ($os{$r->os} = $r);
53 }
54 else {
55 $log->warning("Don't know what to do with this result object ".
56 "with type: [$ref]");
57 }
58 }
59  
60 # Sort by score
61 my %byScore = ();
62 for my $k (keys %os) {
63 my $r = $os{$k};
64 push @{$byScore{$r->matchScore}}, $r;
65 }
66  
67 for my $k (sort { $b <=> $a } keys %byScore) {
68 my $list = $byScore{$k};
69 for my $r (@$list) {
70 my $str = $r->ipVersion.': [score:'.$r->matchScore.']: '.
71 $r->matchMask.'/'.$r->matchType.': '.$r->os."\n";
72 $buf .= $str;
73 }
74 }
75  
76 print $buf;
77  
78 return 1;
79 }
80  
81 1;
82  
83 __END__