blib/lib/NET/IPFilterSimple.pm

filter: Statementstmt 22.0% 11 / 50 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 25.0% 1 / 4 Podpod 0.0% 0 / 2 totaltotal 14.6% 12 / 82 CC 11 SCAR 35.5
CC
11
Cov
15%
_init
56.0
isValid
20.0
new
6.0
CRAP 34.6
↑ Summary
1 package NET::IPFilterSimple;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 require Exporter;
6  
7 1 our @ISA = qw(Exporter);
8  
9 # Items to export into callers namespace by default. Note: do not export
10 # names by default without a very good reason. Use EXPORT_OK instead.
11 # Do not simply export all your public functions/methods/constants.
12  
13 # This allows declaration use NET::IPFilterSimple ':all';
14 # If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
15 # will save memory.
16 1 our %EXPORT_TAGS = ( 'all' => [ qw(
17 isValid
18 _init
19 ) ] );
20  
21 1 our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
22  
23 1 our @EXPORT = qw(
24 isValid
25 _init
26 );
27  
28 1 our $VERSION = '1.2';
29  
30  
31 0 ▶sub new(){
Subroutine new: not called CC=2 SCAR=17.9
Pod undocumented
32  
33 0 my $class = shift;
34 0 ▶ my %args = ref($_[0])?%{$_[0]}:@_;
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 0 0 0
35 0 my $self = \%args;
36 0 bless $self, $class;
37 0 $self->_init();
38 0 return $self;
39
40 }; # sub new(){
41  
42  
43 0 ▶sub isValid(){
Subroutine isValid: not called CC=4 SCAR=30.0
Pod undocumented
44  
45 0 my $self = shift;
46 0 my $IPtoCheck = shift;
47 0 my $RangesArrayRef = $self->{'_IPRANGES_ARRAY_REF'};
48 0 my $howmany = scalar( @{$RangesArrayRef} );
49  
50 0 $IPtoCheck =~ s/\.//g;
51  
52 0 ▶ for ( my $count=0; $count<=$howmany; $count++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($count <= $howmany) 0 0 0
53
54 0 my ($RangFrom, $RangTo) = split("-", $RangesArrayRef->[$count]);
55
56 0 ▶ if ( $IPtoCheck >= $RangFrom && $IPtoCheck <= $RangTo ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($IPtoCheck >= $RangFrom and $IPtoCheck <= $RangTo) 0 0 0
Condition0%0/3
$IPtoCheck >= $RangFrom and $IPtoCheck <= $RangTo
!ll&&!rl&&r
000
MC/DC0%0/2
$IPtoCheck >= $RangFrom and $IPtoCheck <= $RangTo
$IPtoCheck >= $RangFrom $IPtoCheck <= $RangTo
Truth table0%0/3
A and B
A= $IPtoCheck >= $RangFromB= $IPtoCheck <= $RangTo
ABresult
0X0
100
111
57 0 return 0;
58 };
59  
60 }; # for ( my $count=0; $count<=$howmany; $count++) {
61  
62 0 return 1; # if ip not found in ipfilter.dat its valid
63  
64 }; # sub isValid(){
65  
66  
67  
68 0 ▶sub _init(){
Subroutine _init: not called CC=7 SCAR=40.3
69  
70 0 my $self = shift;
71 0 my $file = $self->{'ipfilter'};
72 0 ▶ die "$self->_init() - Fatal Error no ipfilter.dat given" if ( length $file < 1 );
Branch: 1 branch
BranchTrueFalseTotal
if length $file < 1 0 0 0
73  
74 0 my @IP_Ranges = ();
75  
76 0 ▶ open(RH,"<$file") or die("$self -> _init( $file ) Reading Failed");
Branch: 1 branch
BranchTrueFalseTotal
open RH, "<$file" or die "$self -> _init( $file ) Reading Failed" 0 0 0
77 0 ▶ while (defined( my $entry = <RH>)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $entry = readline RH)) 0 0 0
78 0 chomp($entry);
79
80 0 ▶ next if ( $entry =~ /^#/g || $entry =~ /#/g );
Branch: 1 branch
BranchTrueFalseTotal
if $entry =~ /^#/g or $entry =~ /#/g 0 0 0
Condition0%0/3
$entry =~ /^#/g or $entry =~ /#/g
l!l&&r!l&&!r
000
MC/DC0%0/2
$entry =~ /^#/g or $entry =~ /#/g
$entry =~ /^#/g $entry =~ /#/g
Truth table0%0/3
A or B
A= $entry =~ /^#/gB= $entry =~ /#/g
ABresult
1X1
011
000
81 0 my ($IPRange, undef, $DESC) = split(",", $entry);
82 0 ▶ next if ( $DESC =~ /\[BG\]FreeSP/ig ); # ignore not used ips
Branch: 1 branch
BranchTrueFalseTotal
if $DESC =~ /\[BG\]FreeSP/gi 0 0 0
83 0 my ($IP_Start,$IP_End) = split("-", $IPRange );
84
85 0 $IP_Start =~ s/^\s+//;
86 0 $IP_Start =~ s/\s+$//;
87 0 $IP_End =~ s/^\s+//;
88 0 $IP_End =~ s/\s+$//;
89
90 0 $IP_Start =~ s/\.//g;
91 0 $IP_End =~ s/\.//g;
92
93 0 push(@IP_Ranges, "$IP_Start-$IP_End");
94  
95  
96 }; # while (defined( my $entry = <RH>)) {
97 0 close RH;
98
99 0 $self->{'_IPRANGES_ARRAY_REF'} = \@IP_Ranges;
100  
101 0 return $self;
102  
103 }; # sub _init(){
104  
105  
106  
107 # Preloaded methods go here.
108  
109 1 1;
110 __END__
↑ Summary