blib/lib/NetAddr/IP/Obfuscate.pm

filter: Statementstmt 41.1% 21 / 51 Branchbran 0.0% 0 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 55.5% 5 / 9 Podpod 0.0% 0 / 1 totaltotal 35.6% 26 / 73 CC 7 SCAR 19.1
CC
7
Cov
33%
do_obfu
12.0
_burp_file
12.0
__ANON__
6.0
CRAP 6.7
↑ Summary
1 package NetAddr::IP::Obfuscate;
2  
3 1 require 5.006_000; # Needed for NetAddr::IP and the $fh in _slurp_file
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 require Exporter;
7  
8 1 our @ISA = qw(Exporter);
9  
10 1 ▶use vars qw($VERSION @EXPORT);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 $VERSION = '0.02';
13 1 @EXPORT = qw(do_obfu);
14  
15 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use NetAddr::IP::Find;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 0 ▶sub do_obfu {
Subroutine do_obfu: not called CC=3 SCAR=24.8
Pod undocumented
19  
20 0 my %obfuscated;
21 my $infile;
22 0 my $net;
23 0 my $outfile;
24  
25 0 ▶ if (scalar(@_) == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ == 0) { } 0 0 0
26 # No arguments, supply some sane defaults
27 0 $infile = "-";
28 0 $net = "10.0.0.0/8";
29 0 $outfile = "STDOUT";
30  
31 } else {
32  
33 0 ($infile,$net,$outfile) = @_;
34  
35 }
36  
37  
38 0 my $text_ref = _slurp_file ($infile);
39  
40 0 my $ip = NetAddr::IP->new("$net");
41  
42 0 ▶ find_ipaddrs($$text_ref, sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
43 0 my($ipaddr, $orig) = @_;
44 0 ▶ return $obfuscated{$orig} if exists $obfuscated{$orig};
Branch: 1 branch
BranchTrueFalseTotal
if exists $obfuscated{$orig} 0 0 0
45 0 ++$ip;
46 0 $obfuscated{$orig} = $ip->addr;
47 0 });
48  
49 0 _burp_file ($outfile, $text_ref);
50  
51 0 ▶ return values %obfuscated if wantarray();
Branch: 1 branch
BranchTrueFalseTotal
if wantarray 0 0 0
52  
53 0 return scalar(keys %obfuscated);
54  
55 }
56  
57  
58 0 ▶sub _slurp_file {
Subroutine _slurp_file: not called CC=2 SCAR=17.9
59  
60 0 my $infile = shift;
61  
62 0 ▶ open( my $fh, $infile ) or croak "Unable to open $infile in _slurp_file: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, $infile or croak("Unable to open $infile in _slurp_file: $!\n") 0 0 0
63  
64 0 my $text = do { local( $/ ) ; <$fh> } ;
65  
66 0 return \$text;
67  
68 }
69  
70 0 ▶sub _burp_file {
Subroutine _burp_file: not called CC=3 SCAR=24.8
71  
72 0 my $outfile = shift;
73 0 my $text_ref = shift;
74  
75 0 ▶ if ($outfile eq "STDOUT") {
Branch: 1 branch
BranchTrueFalseTotal
if ($outfile eq 'STDOUT') { } 0 0 0
76  
77 0 print $$text_ref;
78  
79 } else {
80  
81 0 ▶ open( my $fh, ">$outfile" ) or croak "Unable to open $outfile in _burp_file: $!\n" ;
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">$outfile" or croak("Unable to open $outfile in _burp_file: $!\n") 0 0 0
82  
83 0 print $fh $$text_ref ;
84  
85 }
86  
87 }
88  
89 1 1;
90  
91 __END__
↑ Summary