line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::Netfilter::NetFlow::Utils; |
2
|
|
|
|
|
|
|
{ |
3
|
|
|
|
|
|
|
$Net::Netfilter::NetFlow::Utils::VERSION = '1.113260'; |
4
|
|
|
|
|
|
|
} |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
24324
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
44
|
|
7
|
1
|
|
|
1
|
|
5
|
use warnings FATAL => 'all'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
51
|
|
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
6
|
use base 'Exporter'; |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
174
|
|
10
|
|
|
|
|
|
|
our @EXPORT = qw( |
11
|
|
|
|
|
|
|
load_config |
12
|
|
|
|
|
|
|
format_args |
13
|
|
|
|
|
|
|
can_run |
14
|
|
|
|
|
|
|
merge_hashes |
15
|
|
|
|
|
|
|
); |
16
|
|
|
|
|
|
|
|
17
|
1
|
|
|
1
|
|
1091
|
use Config::Any 0.15; |
|
1
|
|
|
|
|
12857
|
|
|
1
|
|
|
|
|
214
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# use Config::Any to load a configuration file |
20
|
|
|
|
|
|
|
sub load_config { |
21
|
0
|
|
|
0
|
0
|
|
my $name = shift; |
22
|
0
|
0
|
|
|
|
|
die "No filename specified to load_config!\n" if !defined $name; |
23
|
0
|
|
|
|
|
|
my $config = eval{ Config::Any->load_files({ |
|
0
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
files => [$name], |
25
|
|
|
|
|
|
|
use_ext => 1, |
26
|
|
|
|
|
|
|
flatten_to_hash => 1, |
27
|
|
|
|
|
|
|
})->{$name} }; |
28
|
0
|
0
|
0
|
|
|
|
die "Failed to load config [$name]\n" if $@ or !defined $config; |
29
|
0
|
|
|
|
|
|
return $config; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# interpolate the config vars |
33
|
|
|
|
|
|
|
sub format_args { |
34
|
0
|
|
|
0
|
0
|
|
my $stub = shift; |
35
|
0
|
|
0
|
|
|
|
my $pre = shift || ''; # maybe init_ |
36
|
0
|
0
|
|
|
|
|
my $rv = sprintf $stub->{"${pre}format"}, |
37
|
0
|
|
|
|
|
|
@{$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
|
|
|
|
|
|
|
sub can_run { |
44
|
0
|
|
|
0
|
0
|
|
my $command = shift; |
45
|
|
|
|
|
|
|
|
46
|
1
|
|
|
1
|
|
11
|
use Config; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
344
|
|
47
|
0
|
|
|
|
|
|
require File::Spec; |
48
|
0
|
|
|
|
|
|
require ExtUtils::MakeMaker; |
49
|
|
|
|
|
|
|
|
50
|
0
|
0
|
|
|
|
|
if( File::Spec->file_name_is_absolute($command) ) { |
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
|
0
|
|
|
|
|
return $abs if $abs = MM->maybe_command($abs); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
# recursively merge two hashes together with right-hand precedence |
65
|
|
|
|
|
|
|
# borrowed from Catalyst::Utils |
66
|
|
|
|
|
|
|
sub merge_hashes { |
67
|
0
|
|
|
0
|
0
|
|
my ( $lefthash, $righthash ) = @_; |
68
|
0
|
0
|
|
|
|
|
return $lefthash unless defined $righthash; |
69
|
|
|
|
|
|
|
|
70
|
0
|
|
|
|
|
|
my %merged = %$lefthash; |
71
|
0
|
|
|
|
|
|
for my $key ( keys %$righthash ) { |
72
|
0
|
|
0
|
|
|
|
my $right_ref = ( ref $righthash->{ $key } || '' ) eq 'HASH'; |
73
|
0
|
|
0
|
|
|
|
my $left_ref = ( ( exists $lefthash->{ $key } && ref $lefthash->{ $key } ) || '' ) eq 'HASH'; |
74
|
0
|
0
|
0
|
|
|
|
if( $right_ref and $left_ref ) { |
75
|
0
|
|
|
|
|
|
$merged{ $key } = merge_hashes( |
76
|
|
|
|
|
|
|
$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__ |