| 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
| |||||||||||||||||||||||||||||
| 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
Condition0%0/3
$@ or not defined $config
MC/DC0%0/2
$@ or not defined $config
$@
not defined $config
Truth table0%0/3
A or not(B)
A= $@B= not defined $config
| |||||||||||||||||||||||||||||
| 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() || ''
MC/DC0%0/1
shift() || ''
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 36 | my $rv = sprintf $stub->{"${pre}format"}, | ||||||||||||||||||||||||||||
| 37 | 0 | ▶ | @{$stub->{"${pre}args"} || []}; | ||||||||||||||||||||||||||
|
Condition0%0/2
$$stub{"${pre}args"} || []
MC/DC0%0/1
$$stub{"${pre}args"} || []
$$stub{"${pre}args"}
Truth table0%0/2
A
A= $$stub{"${pre}args"}
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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} || ''
MC/DC0%0/1
ref $righthash->{$key} || ''
ref $righthash->{$key}
Truth table0%0/2
A
A= ref $righthash->{$key}
| |||||||||||||||||||||||||||||
| 73 | 0 | ▶ | my $left_ref = ( ( exists $lefthash->{ $key } && ref $lefthash->{ $key } ) || '' ) eq 'HASH'; | ||||||||||||||||||||||||||
|
Condition0%0/5
exists $lefthash->{$key} && ref $lefthash->{$key} || ''
exists $lefthash->{$key} and ref $lefthash->{$key}
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}
| |||||||||||||||||||||||||||||
| 74 | 0 | ▶ | if( $right_ref and $left_ref ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$right_ref and $left_ref
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
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||