Utils.pm

filter: Statementstmt 38.3% 18 / 47 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 17 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 55.5% 5 / 9 Podpod 0.0% 0 / 4 totaltotal 23.4% 23 / 98 CC 16 SCAR 34.4
CC
16
Cov
24%
merge_hashes
72.0
load_config
20.0
can_run
12.2
CRAP 31.1
« Process.pm ↑ Summary ConntrackFormat.pm »
1 package Net::Netfilter::NetFlow::Utils;
2 {
3 2 $Net::Netfilter::NetFlow::Utils::VERSION = '1.113260';
4 }
5  
6 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 2 ▶use base 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 our @EXPORT = qw(
11 load_config
12 format_args
13 can_run
14 merge_hashes
15 );
16  
17 2 ▶use Config::Any 0.15;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 # use Config::Any to load a configuration file
20 0 ▶sub load_config {
Subroutine load_config: not called CC=4 SCAR=30.0
Pod undocumented
21 0 my $name = shift;
22 0 ▶ die "No filename specified to load_config!\n" if !defined $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 0 0 0
23 0 my $config = eval{ Config::Any->load_files({
24 files => [$name],
25 use_ext => 1,
26 flatten_to_hash => 1,
27 0 })->{$name} };
28 0 ▶ die "Failed to load config [$name]\n" if $@ or !defined $config;
Branch: 1 branch
BranchTrueFalseTotal
if $@ or not defined $config 0 0 0
Condition0%0/3
$@ or not defined $config
l!l&&r!l&&!r
000
MC/DC0%0/2
$@ or not defined $config
$@ not defined $config
Truth table0%0/3
A or not(B)
A= $@B= not defined $config
ABresult
1X1
011
000
29 0 return $config;
30 }
31  
32 # interpolate the config vars
33 0 ▶sub format_args {
Subroutine format_args: not called CC=3 SCAR=24.8
Pod undocumented
34 0 my $stub = shift;
35 0 ▶ my $pre = shift || ''; # maybe init_
Condition0%0/2
shift() || ''
l!l
00
MC/DC0%0/1
shift() || ''
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
36 my $rv = sprintf $stub->{"${pre}format"},
37 0 ▶ @{$stub->{"${pre}args"} || []};
Condition0%0/2
$$stub{"${pre}args"} || []
l!l
00
MC/DC0%0/1
$$stub{"${pre}args"} || []
$$stub{"${pre}args"}
Truth table0%0/2
A
A= $$stub{"${pre}args"}
Aresult
11
00
38 0 return split /\s+/, $rv;
39 }
40  
41 # check if we have a program installed, and locate it
42 # borrowed from IPC::Cmd
43 0 ▶sub can_run {
Subroutine can_run: not called CC=4 SCAR=25.0
Pod undocumented
44 0 my $command = shift;
45  
46 2 ▶ use Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
47 0 require File::Spec;
48 0 require ExtUtils::MakeMaker;
49  
50 0 ▶ if( File::Spec->file_name_is_absolute($command) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ('File::Spec'->file_name_is_absolute($command)) { } 0 0 0
51 0 return MM->maybe_command($command);
52 }
53 else {
54 0 for my $dir (
55 (split /\Q$Config{path_sep}\E/, $ENV{PATH}),
56 File::Spec->curdir
57 ) {
58 0 my $abs = File::Spec->catfile($dir, $command);
59 0 ▶ return $abs if $abs = MM->maybe_command($abs);
Branch: 1 branch
BranchTrueFalseTotal
if $abs = "MM"->maybe_command($abs) 0 0 0
60 }
61 }
62 }
63  
64 # recursively merge two hashes together with right-hand precedence
65 # borrowed from Catalyst::Utils
66 0 ▶sub merge_hashes {
Subroutine merge_hashes: not called CC=8 SCAR=42.8
Pod undocumented
67 0 my ( $lefthash, $righthash ) = @_;
68 0 ▶ return $lefthash unless defined $righthash;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $righthash 0 0 0
69  
70 0 my %merged = %$lefthash;
71 0 for my $key ( keys %$righthash ) {
72 0 ▶ my $right_ref = ( ref $righthash->{ $key } || '' ) eq 'HASH';
Condition0%0/2
ref $righthash->{$key} || ''
l!l
00
MC/DC0%0/1
ref $righthash->{$key} || ''
ref $righthash->{$key}
Truth table0%0/2
A
A= ref $righthash->{$key}
Aresult
11
00
73 0 ▶ my $left_ref = ( ( exists $lefthash->{ $key } && ref $lefthash->{ $key } ) || '' ) eq 'HASH';
Condition0%0/5
exists $lefthash->{$key} && ref $lefthash->{$key} || ''
l!l
00
exists $lefthash->{$key} and ref $lefthash->{$key}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $lefthash->{$key} && ref $lefthash->{$key} || ''
exists $lefthash->{$key} ref $lefthash->{$key}
Truth table0%0/3
A and B
A= exists $lefthash->{$key}B= ref $lefthash->{$key}
ABresult
111
0X0
100
74 0 ▶ if( $right_ref and $left_ref ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($right_ref and $left_ref) { } 0 0 0
Condition0%0/3
$right_ref and $left_ref
!ll&&!rl&&r
000
MC/DC0%0/2
$right_ref and $left_ref
$right_ref $left_ref
Truth table0%0/3
A and B
A= $right_refB= $left_ref
ABresult
0X0
100
111
75 $merged{ $key } = merge_hashes(
76 0 $lefthash->{ $key }, $righthash->{ $key }
77 );
78 }
79 else {
80 0 $merged{ $key } = $righthash->{ $key };
81 }
82 }
83  
84 0 return \%merged;
85 }
86  
87 __END__
« Process.pm ↑ Summary ConntrackFormat.pm »