Saftpresse/Config.pm

filter: Statementstmt 23.2% 13 / 56 Branchbran 0.0% 0 / 18 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 30.0% 3 / 10 Podpod 0.0% 0 / 4 totaltotal 15.6% 16 / 102 SCAR 47.4
CC
13
Cov
16%
_get_hash_node
30.0
_get_hash_value
20.0
get_node
12.0
CRAP 114.4
« Saftpresse/Plugin/Syslog.pm ↑ Summary Saftpresse/Plugin/Postfix/Smtpd.pm »
1 package Log::Saftpresse::Config;
2  
3 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 # ABSTRACT: configuration option parser for Log::Saftpresse
6 1 our $VERSION = '1.5'; # VERSION
7  
8 1 ▶use Tie::IxHash;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Config::General qw(ParseConfig);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 sub ordered_hash_ref {
12 0 ▶ tie my %hash, 'Tie::IxHash', @_;
Subroutine ordered_hash_ref: not called CC=1 SCAR=6.9
Pod undocumented
13 0 return \%hash;
14 }
15  
16 has 'defaults' => (
17 is => 'rw', lazy => 1,
18 default => sub {
19 0 ▶ tie my %defaults, "Tie::IxHash";
Subroutine __ANON__: not called CC=1 SCAR=6.9
20 0 %defaults = (
21 'counters' => {
22 'flush_interval' => '0',
23 },
24 'logging' => {
25 level => 'INFO',
26 file => undef, # log to syslog
27 },
28 Input => ordered_hash_ref(
29 stdin => {
30 module => 'Stdin',
31 },
32 ),
33 Plugin => ordered_hash_ref(
34 syslog => {
35 module => 'SyslogFile',
36 },
37 ),
38 CounterOutput => ordered_hash_ref (
39 dump_counters => {
40 module => 'Dump',
41 },
42 ),
43 Output => ordered_hash_ref (
44 dump_json => {
45 module => 'JSON',
46 },
47 ),
48 );
49 0 return \%defaults;
50 },
51 1 );
52  
53 1 has 'config' => ( is => 'rw' );
54  
55 sub load_config {
56 0 ▶ my ( $self, $file ) = @_;
Subroutine load_config: not called CC=2 SCAR=17.9
Pod undocumented
57 0 ▶ if( ! -f $file ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-f $file) 0 0 0
58 0 die('configuration file '.$file.' does not exist!');
59 }
60  
61 0 tie my %config_hash, "Tie::IxHash";
62 0 %config_hash = ParseConfig(
63 -AllowMultiOptions => 'no',
64 -ConfigFile => $file,
65 -Tie => "Tie::IxHash"
66 );
67 0 $self->config( \%config_hash );
68  
69 0 return;
70 }
71  
72 sub _get_hash_node {
73 0 ▶ my $hash = shift;
Subroutine _get_hash_node: not called CC=5 SCAR=34.0
74 0 my @path = @_;
75 0 my $cur = $hash;
76  
77 0 ▶ if( ! defined $hash ) { return; }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $hash) 0 0 0
78  
79 0 ▶ while( my $element = shift @path ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $element = shift @path) 0 0 0
80 0 ▶ if( defined $cur->{$element}
Branch: 1 branch
BranchTrueFalseTotal
if (defined $cur->{$element} and ref $cur->{$element} eq 'HASH') { } 0 0 0
Condition0%0/3
defined $cur->{$element} and ref $cur->{$element} eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $cur->{$element} and ref $cur->{$element} eq "HASH"
defined $cur->{$element} ref $cur->{$element} eq "HASH"
Truth table0%0/3
A and B
A= defined $cur->{$element}B= ref $cur->{$element} eq "HASH"
ABresult
0X0
100
111
81 && ref $cur->{$element} eq 'HASH' ) {
82 0 $cur = $cur->{$element};
83 0 } else { return; }
84 }
85  
86 0 return $cur;
87 }
88  
89 sub _get_hash_value {
90 0 ▶ my $hash = shift;
Subroutine _get_hash_value: not called CC=4 SCAR=30.0
91 0 my $key = pop;
92 0 my @path = @_;
93  
94 0 my $cur = _get_hash_node( $hash, @path );
95  
96 0 ▶ if( defined $cur
Branch: 1 branch
BranchTrueFalseTotal
if (defined $cur and defined $cur->{$key} and not ref $cur->{$key}) 0 0 0
Condition0%0/6
defined $cur and defined $cur->{$key} and not ref $cur->{$key}
!ll&&!rl&&r
000
defined $cur and defined $cur->{$key}
!ll&&!rl&&r
000
MC/DC0%0/3
defined $cur and defined $cur->{$key} and not ref $cur->{$key}
defined $cur defined $cur->{$key} not ref $cur->{$key}
Truth table0%0/4
A and B and not(C)
A= defined $curB= defined $cur->{$key}C= not ref $cur->{$key}
ABCresult
0XX0
10X0
1100
1111
97 && defined $cur->{$key}
98 && ! ref($cur->{$key}) ) {
99 0 return $cur->{$key};
100 }
101 0 return;
102 }
103  
104 sub get_node {
105 0 ▶ my $self = shift;
Subroutine get_node: not called CC=3 SCAR=24.8
Pod undocumented
106 0 my $node;
107 0 ▶ if( $node = _get_hash_node( $self->config, @_ ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node = _get_hash_node($self->config, @_)) 0 0 0
108 0 return $node;
109 }
110 0 ▶ if( $node = _get_hash_node( $self->defaults, @_ ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node = _get_hash_node($self->defaults, @_)) 0 0 0
111 0 return $node;
112 }
113 0 return;
114 }
115  
116 sub get {
117 0 ▶ my $self = shift;
Subroutine get: not called CC=3 SCAR=24.8
Pod undocumented
118 0 my $value;
119  
120 0 ▶ if( $value = _get_hash_value( $self->config, @_ ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value = _get_hash_value($self->config, @_)) 0 0 0
121 0 return $value;
122 }
123 0 ▶ if( $value = _get_hash_value( $self->defaults, @_ ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value = _get_hash_value($self->defaults, @_)) 0 0 0
124 0 return $value;
125 }
126 0 return;
127 }
128  
129 1 1;
130  
131 __END__
132  
133 =pod
134  
135 =encoding UTF-8
136  
137 =head1 NAME
138  
139 Log::Saftpresse::Config - configuration option parser for Log::Saftpresse
140  
141 =head1 VERSION
142  
143 version 1.5
144  
145 =head1 AUTHOR
146  
147 Markus Benning <ich@markusbenning.de>
148  
149 =head1 COPYRIGHT AND LICENSE
150  
151 This software is Copyright (c) 1998 by James S. Seymour, 2015 by Markus Benning.
152  
153 This is free software, licensed under:
154  
155 The GNU General Public License, Version 2, June 1991
156  
157 =cut
« Saftpresse/Plugin/Syslog.pm ↑ Summary Saftpresse/Plugin/Postfix/Smtpd.pm »