blib/lib/Net/Peep/Client.pm

filter: Statementstmt 55.9% 159 / 284 Branchbran 31.8% 35 / 110 Conditioncond 17.5% 7 / 40 MC/DCmcdc 5.0% 1 / 20 Subroutinesub 75.0% 27 / 36 Podpod 0.0% 0 / 21 totaltotal 44.8% 229 / 511 CC 77 SCAR 38.7
CC
77
Cov
46%
filter
240.0
MainLoop
90.0
shutdown
42.0
CRAP 48.1
« blib/lib/Net/Peep/Mail.pm ↑ Summary blib/lib/Net/Peep/Client/Pinger.pm »
1 package Net::Peep::Client;
2  
3 8 require 5.00503;
4 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 # use warnings; # commented out for 5.005 compatibility
6 8 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 8 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 8 ▶use Socket;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 8 ▶use Getopt::Long;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 8 ▶use File::Tail;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 8 ▶use Pod::Text;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 8 ▶use Net::Peep::BC;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 8 ▶use Net::Peep::Log;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 8 ▶use Net::Peep::Parser;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 8 ▶use Net::Peep::Notifier;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 8 require Exporter;
18  
19 8 ▶use vars qw{ @ISA %EXPORT_TAGS @EXPORT_OK @EXPORT $VERSION };
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 8 @ISA = qw(Exporter);
22 8 %EXPORT_TAGS = ( 'all' => [ qw( INTERVAL MAX_INTERVAL ADJUST_AFTER ) ] );
23 8 @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
24 8 @EXPORT = qw( );
25 8 $VERSION = do { my @r = (q$Revision: 1.12 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r };
26  
27 # These are in seconds and are the parameters for File::Tail
28  
29 # File Tail uses the idea of intervals and predictions to try to keep
30 # blocking time at a maximum. These three parameters are the ones that
31 # people will want to tune for performance vs. load. The smaller the
32 # interval, the higher the load but faster events are picked up.
33  
34 # The interval that File::Tail waits before checking the log
35 8 ▶use constant INTERVAL => 0.1;
Subroutine BEGIN: called CC=1 SCAR=0.0
36 # The maximum interval that File::Tail will wait before checking the
37 # log
38 8 ▶use constant MAX_INTERVAL => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
39 # The time after which File::Tail adjusts its predictions
40 8 ▶use constant ADJUST_AFTER => 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
41  
42 4 ▶sub new {
Subroutine new: called CC=2 SCAR=7.4
Pod undocumented
43  
44 4 my $self = shift;
45 4 ▶ my $class = ref($self) || $self;
Condition33%1/3
ref $self || $self
l!l&&r!l&&!r
040
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table33%1/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
46 4 my $this = {};
47 4 bless $this, $class;
48  
49 } # end sub new
50  
51 118 ▶sub name {
Subroutine name: called CC=2 SCAR=6.9
Pod undocumented
52  
53 118 my $self = shift;
54 118 ▶ if (@_) { $self->{'NAME'} = shift; }
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 4 114 118
55 118 return $self->{'NAME'};
56  
57 } # end sub name
58  
59 1 ▶sub callback {
Subroutine callback: called CC=2 SCAR=7.0
Pod undocumented
60  
61 1 my $self = shift;
62 1 my $callback = shift;
63 1 ▶ confess "Cannot register callback: Expecting a code reference. (Got [$callback].)"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $callback eq "CODE" 0 1 1
64 unless ref($callback) eq 'CODE';
65 1 $self->{"__CALLBACK"} = $callback;
66 1 return 1;
67  
68 } # end sub callback
69  
70 0 ▶sub getCallback {
Subroutine getCallback: not called CC=2 SCAR=17.9
Pod undocumented
71  
72 0 my $self = shift;
73 confess "Cannot get callback: A callback has not been set yet."
74 0 ▶ unless exists $self->{"__CALLBACK"};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"__CALLBACK"} 0 0 0
75 0 return $self->{"__CALLBACK"};
76  
77 } # end sub getCallback
78  
79 4 ▶sub parser {
Subroutine parser: called CC=2 SCAR=7.0
Pod undocumented
80  
81 4 my $self = shift;
82 4 my $parser = shift;
83 4 ▶ confess "Cannot register parser: Expecting a code reference. (Got [$parser].)"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $parser eq "CODE" 0 4 4
84 unless ref($parser) eq 'CODE';
85 4 $self->{"__PARSER"} = $parser;
86 4 return 1;
87  
88 } # end sub parser
89  
90 1 ▶sub getParser {
Subroutine getParser: called CC=2 SCAR=7.1
Pod undocumented
91  
92 1 my $self = shift;
93 confess "Cannot get parser: A parser has not been set yet."
94 1 ▶ unless exists $self->{"__PARSER"};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"__PARSER"} 0 1 1
95 1 return $self->{"__PARSER"};
96  
97 } # end sub getParser
98  
99 1 ▶sub runParser {
Subroutine runParser: called CC=1 SCAR=0.0
Pod undocumented
100  
101 1 my $self = shift;
102 1 my @text = @_;
103  
104 1 my $parser = $self->getParser();
105 1 &$parser(@text);
106  
107 } # end sub runParser
108  
109 0 ▶sub loop {
Subroutine loop: not called CC=2 SCAR=17.9
Pod undocumented
110  
111 0 my $self = shift;
112 0 ▶ if (@_) { $self->{"__LOOP"} = shift; }
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
113 0 return $self->{"__LOOP"};
114  
115 } # end sub loop
116  
117 0 ▶sub peck {
Subroutine peck: not called CC=3 SCAR=24.8
Pod undocumented
118  
119 0 my $self = shift;
120 0 my $conf = $self->conf();
121  
122 0 ▶ unless (exists $self->{"__PEEP"}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"__PEEP"}) 0 0 0
123 0 ▶ if ($conf->getOptions()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($conf->getOptions) { } 0 0 0
124 0 $self->{"__PEEP"} = Net::Peep::BC->new( $self->name(), $conf );
125 } else {
126 0 confess "Error: Expecting options to have been parsed by now.";
127 }
128 }
129 0 return $self->{"__PEEP"};
130  
131 } # end sub peck
132  
133 4 ▶sub initialize {
Subroutine initialize: called CC=14 SCAR=26.8
Pod undocumented
134  
135 4 my $self = shift;
136 4 my %options = @_;
137  
138 4 my $conf = $self->conf();
139  
140 4 $conf->client($self);
141  
142 my (
143 4 $config,
144 $logfile,
145 $debug,
146 $daemon,
147 $output,
148 $pidfile,
149 $autodiscovery,
150 $server,
151 $port,
152 $silent,
153 $help) = ('/etc/peep.conf','',0,1,'','',1,'','',0,0);
154  
155 4 my %standardOptions = (
156 'config=s' => \$config,
157 'logfile=s' => \$logfile,
158 'debug=s' => \$debug,
159 'daemon!' => \$daemon,
160 'output=s' => \$output,
161 'pidfile=s' => \$pidfile,
162 'autodiscovery!' => \$autodiscovery,
163 'server=s' => \$server,
164 'port=s' => \$port,
165 'silent' => \$silent,
166 'help' => \$help
167 );
168  
169 4 for my $option (keys %standardOptions) {
170 44 ▶ if (exists $options{$option}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $options{$option}) 3 41 44
171 3 delete $standardOptions{$option};
172 }
173 }
174  
175 4 my %allOptions = (%options,%standardOptions);
176  
177 4 GetOptions(%allOptions);
178  
179 # set the debug level first so we can start printing debugging
180 # messages
181 4 ▶ $Net::Peep::Log::logfile = $output if $output;
Branch: 1 branch
BranchTrueFalseTotal
if $output 0 4 4
182 4 ▶ $Net::Peep::Log::debug = $debug if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 4 4
183  
184 4 my $found;
185  
186 4 ▶ if (-f ${$allOptions{'config=s'}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f ${$allOptions{'config=s'};}) { } 3 1 4
187 3 $found = ${$allOptions{'config=s'}};
188 } else {
189 1 for my $dir ('.','/usr/local/etc','/usr','/usr/local','/opt') {
190 1 ▶ if (-f "$dir/peep.conf") {
Branch: 1 branch
BranchTrueFalseTotal
if (-f "$dir/peep.conf") 1 0 1
191 1 $found = "$dir/peep.conf";
192 1 last;
193 }
194 }
195 }
196  
197 4 ▶ if ($found) {
Branch: 1 branch
BranchTrueFalseTotal
if ($found) { } 4 0 4
198 4 $self->logger()->debug(1,"The Peep configuration file has been identified as [$found]");
199 } else {
200 0 $self->logger()->log("No peep configuration file could be found. Exiting gracefully ....");
201 0 exit 2;
202 }
203  
204 4 $conf->setOption('config',$found);
205 0 ▶ $conf->setOption('logfile',${$allOptions{'logfile=s'}}) if ${$allOptions{'logfile=s'}} ne '';
Branch: 1 branch
BranchTrueFalseTotal
if ${$allOptions{"logfile=s"};} ne "" 0 4 4
206 4 $conf->setOption('debug',${$allOptions{'debug=s'}});
207 4 $conf->setOption('daemon',${$allOptions{'daemon!'}});
208 4 $conf->setOption('output',${$allOptions{'output=s'}});
209 0 ▶ $conf->setOption('pidfile',${$allOptions{'pidfile=s'}}) if ${$allOptions{'pidfile=s'}} ne '';
Branch: 1 branch
BranchTrueFalseTotal
if ${$allOptions{"pidfile=s"};} ne "" 0 4 4
210 4 $conf->setOption('autodiscovery',${$allOptions{'autodiscovery!'}});
211 4 ▶ $conf->setOption('server',${$allOptions{'server=s'}}) if ${$allOptions{'server=s'}} ne '';
Branch: 1 branch
BranchTrueFalseTotal
if ${$allOptions{"server=s"};} ne "" 3 1 4
212 4 ▶ $conf->setOption('port',${$allOptions{'port=s'}}) if ${$allOptions{'port=s'}} ne '';
Branch: 1 branch
BranchTrueFalseTotal
if ${$allOptions{"port=s"};} ne "" 3 1 4
213 4 $conf->setOption('silent',${$allOptions{'silent'}});
214 4 $conf->setOption('help',${$allOptions{'help'}});
215  
216 4 ▶ return $help ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$help ? : 0 4 4
217  
218 } # end sub initialize
219  
220 0 ▶sub MainLoop {
Subroutine MainLoop: not called CC=9 SCAR=45.0
Pod undocumented
221  
222 0 my $self = shift;
223 0 my $sleep = shift;
224  
225 0 ▶ my $client = $self->name() || confess "Cannot begin main loop: Client name not specified.";
Condition0%0/2
$self->name || confess('Cannot begin main loop: Client name not specified.')
l!l
00
MC/DC0%0/1
$self->name || confess('Cannot begin main loop: Client name not specified.')
$self->name
Truth table0%0/2
A
A= $self->name
Aresult
11
00
226 0 ▶ my $conf = $self->conf() || confess "Cannot begin main loop: Configuration object not found.";
Condition0%0/2
$self->conf || confess('Cannot begin main loop: Configuration object not found.')
l!l
00
MC/DC0%0/1
$self->conf || confess('Cannot begin main loop: Configuration object not found.')
$self->conf
Truth table0%0/2
A
A= $self->conf
Aresult
11
00
227  
228 0 my $fork = $conf->getOption('daemon');
229  
230 0 ▶ if ($fork) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fork) 0 0 0
231  
232 0 $self->logger()->debug(7,"Running in daemon mode. Forking ...");
233  
234 0 ▶ if (fork()) {
Branch: 1 branch
BranchTrueFalseTotal
if (fork) 0 0 0
235 # If we're here, then we're the parent
236 0 close (STDIN);
237 0 close (STDOUT);
238 0 close (STDERR);
239 0 exit(0);
240 }
241  
242 0 $self->logger()->debug(7,"\tForked.");
243  
244 # Else we're the child. Let's write out our pid
245 0 my $pid = 0;
246 0 ▶ if ($conf->optionExists('pidfile')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($conf->optionExists('pidfile')) { } 0 0 0
247 0 ▶ my $pidfile = $conf->getOption('pidfile') || confess "Cannot fork: Pidfile not found.";
Condition0%0/2
$conf->getOption('pidfile') || confess('Cannot fork: Pidfile not found.')
l!l
00
MC/DC0%0/1
$conf->getOption('pidfile') || confess('Cannot fork: Pidfile not found.')
$conf->getOption('pidfile')
Truth table0%0/2
A
A= $conf->getOption('pidfile')
Aresult
11
00
248 0 ▶ if (open PIDFILE, ">$pidfile") {
Branch: 1 branch
BranchTrueFalseTotal
if (open PIDFILE, ">$pidfile") { } 0 0 0
249 0 select (PIDFILE); $| = 1; # autoflush
250 0 select (STDERR);
251 0 print PIDFILE "$$\n";
252 0 close PIDFILE;
253 0 $pid = 1;
254 } else {
255 0 $self->logger()->log("Warning: Couldn't open pid file: No pidfile option.");
256 0 $self->logger()->log("\tContinuing anyway ...");
257 }
258 } else {
259 0 $self->logger()->log("Warning: Couldn't open pid file: Pidfile option not specified.");
260 0 $self->logger()->log("\tContinuing anyway ...");
261 }
262  
263 }
264  
265 0 my $sub = $self->getCallback();
266 0 ▶ if ($sleep) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sleep) { } 0 0 0
267 0 while (1) {
268 0 $self->logger()->debug(9,"Executing callback from within infinite loop ...");
269 0 &$sub();
270 0 $self->logger()->debug(9,"\tSleeping [$sleep] seconds ...");
271 0 sleep($sleep);
272 }
273 } else {
274 0 $self->logger()->debug(9,"Executing callback ...");
275 0 &$sub();
276 }
277  
278 } # end sub MainLoop
279  
280 4 ▶sub configure {
Subroutine configure: called CC=7 SCAR=24.0
Pod undocumented
281  
282 4 my $self = shift;
283 4 ▶ my $conf = $self->conf()
Condition50%1/2
$self->conf || confess('Cannot parse configuration object: Configuration object not found')
l!l
40
MC/DC0%0/1
$self->conf || confess('Cannot parse configuration object: Configuration object not found')
$self->conf
Truth table50%1/2
A
A= $self->conf
Aresult
11
00
284 || confess "Cannot parse configuration object: Configuration object not found";
285 4 Net::Peep::Parser->new()->load($conf);
286  
287 4 ▶ my @version = $self->conf()->versionExists()
Branch: 1 branch
BranchTrueFalseTotal
$self->conf->versionExists ? : 4 0 4
288 ? split /\./, $self->conf()->getVersion()
289 : ();
290  
291 4 my $config = $conf->getOption('config');
292 4 ▶ unless (@version && $version[0] >= 0 && $version[1] >= 4 && $version[2] > 3) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@version and $version[0] >= 0 and $version[1] >= 4 and $version[2] > 3) 0 4 4
Condition33%3/9
@version and $version[0] >= 0 and $version[1] >= 4 and $version[2] > 3
!ll&&!rl&&r
004
@version and $version[0] >= 0 and $version[1] >= 4
!ll&&!rl&&r
004
@version and $version[0] >= 0
!ll&&!rl&&r
004
MC/DC0%0/4
@version and $version[0] >= 0 and $version[1] >= 4 and $version[2] > 3
@version $version[0] >= 0 $version[1] >= 4 $version[2] > 3
Truth table20%1/5
A and B and C and D
A= @versionB= $version[0] >= 0C= $version[1] >= 4D= $version[2] > 3
ABCDresult
0XXX0
10XX0
110X0
11100
11111
293  
294 0 print STDERR <<"eop";
295  
296 [$0] Warning: The configuration file
297  
298 $config
299  
300 appears to use an old configuration file syntax. You may want to
301 update your configuration to be consistent with the 0.4.4 release.
302 The older syntax may not be supported as of the 0.5.0 release.
303  
304 eop
305  
306 ;
307  
308 }
309  
310 4 return $conf;
311  
312 } # end sub configure
313  
314 20 ▶sub conf {
Subroutine conf: called CC=2 SCAR=6.9
Pod undocumented
315  
316 20 my $self = shift;
317 20 ▶ $self->{"__CONF"} = Net::Peep::Conf->new() unless exists $self->{"__CONF"};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"__CONF"} 4 16 20
318 20 return $self->{"__CONF"};
319  
320 } # end sub conf
321  
322 0 ▶sub pods {
Subroutine pods: not called CC=3 SCAR=24.8
Pod undocumented
323  
324 0 my $self = shift;
325 0 my $message = shift;
326  
327 0 ▶ print "\n$message\n\n" if $message;
Branch: 1 branch
BranchTrueFalseTotal
if $message 0 0 0
328  
329 0 ▶ open(POD,$0) || die "Cannot print help text for $0: $!";
Branch: 1 branch
BranchTrueFalseTotal
open POD, $0 or die "Cannot print help text for $0: $!" 0 0 0
330 0 Pod::Text->new()->parse_from_filehandle(\*POD);
331 0 close POD;
332  
333 0 exit 0;
334  
335 } # end sub pods
336  
337 # returns a logging object
338 15 ▶sub logger {
Subroutine logger: called CC=2 SCAR=6.9
Pod undocumented
339  
340 15 my $self = shift;
341 15 ▶ if ( ! exists $self->{'__LOGGER'} ) { $self->{'__LOGGER'} = new Net::Peep::Log }
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"__LOGGER"}) 4 11 15
342 15 return $self->{'__LOGGER'};
343  
344 } # end sub logger
345  
346 # Remove our pidfile with garbage collection (if it exists) The client
347 # needs to call this function explicitly upon receipt of a signal with
348 # the appropriate reference.
349 0 ▶sub shutdown {
Subroutine shutdown: not called CC=6 SCAR=37.4
Pod undocumented
350 0 my $self = shift;
351 0 print STDERR "Shutting down ...\n";
352 0 my $notifier = new Net::Peep::Notifier;
353 0 print STDERR "\tFlushing notification buffers ...\n";
354 0 my $n = $notifier->force();
355 0 ▶ my $string = $n ?
Branch: 1 branch
BranchTrueFalseTotal
$n ? : 0 0 0
356 "\t$n notifications were flushed from the buffers.\n" :
357 "\tNo notifications were flushed from the buffers: The buffers were empty.\n";
358 0 print STDERR $string;
359 0 my $conf = $self->conf();
360 0 ▶ my $pidfile = defined $conf && $conf->optionExists('pidfile') && -f $conf->getOption('pidfile')
Branch: 1 branch
BranchTrueFalseTotal
defined $conf && $conf->optionExists('pidfile') && -f $conf->getOption('pidfile') ? : 0 0 0
Condition0%0/6
defined $conf and $conf->optionExists("pidfile") and -f $conf->getOption("pidfile")
!ll&&!rl&&r
000
defined $conf and $conf->optionExists("pidfile")
!ll&&!rl&&r
000
MC/DC0%0/3
defined $conf and $conf->optionExists("pidfile") and -f $conf->getOption("pidfile")
defined $conf $conf->optionExists("pidfile") -f $conf->getOption("pidfile")
Truth table0%0/4
A and B and C
A= defined $confB= $conf->optionExists("pidfile")C= -f $conf->getOption("pidfile")
ABCresult
0XX0
10X0
1100
1111
361 ? $conf->getOption('pidfile') : '';
362 0 ▶ if ($pidfile) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pidfile) 0 0 0
363 0 print STDERR "\tUnlinking pidfile ", $pidfile, " ...\n";
364 0 unlink $pidfile;
365 }
366 0 print STDERR "Done.\n";
367 }
368  
369 2 ▶sub getConfigSection {
Subroutine getConfigSection: called CC=8 SCAR=20.8
Pod undocumented
370  
371 2 my $self = shift;
372 2 my $section = shift;
373 2 my @text = @_;
374  
375 2 my @return;
376 2 my $read = 0;
377 2 for my $line (@text) {
378 64 ▶ if ($line =~ /^\s*$section/) {
Branch: 3 branches
BranchTrueFalseTotal
if ($line =~ /^\s*$section/) { } 1 63 64
elsif ($line =~ /^\s*end events/) { } 2 61 63
elsif ($read) { } 12 49 61
379 1 $read = 1;
380 } elsif ($line =~ /^\s*end events/) {
381 2 $read = 0;
382 } elsif ($read) {
383 12 ▶ next if $line =~ /^\s*#/ || $line =~ /^\s*$/;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^\s*#/ or $line =~ /^\s*$/ 2 10 12
Condition66%2/3
$line =~ /^\s*#/ or $line =~ /^\s*$/
l!l&&r!l&&!r
2010
MC/DC50%1/2
$line =~ /^\s*#/ or $line =~ /^\s*$/
$line =~ /^\s*#/ $line =~ /^\s*$/
Truth table66%2/3
A or B
A= $line =~ /^\s*#/B= $line =~ /^\s*$/
ABresult
1X1
011
000
384 10 push @return, $line;
385 } else {
386 # do nothing
387 }
388 }
389 2 ▶ return wantarray ? @return : \@return;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 2 0 2
390  
391 } # end sub getConfigSection
392  
393 1 ▶sub tempParseDefaults {
Subroutine tempParseDefaults: called CC=5 SCAR=27.4
Pod undocumented
394  
395 1 my $self = shift;
396 1 my @text = @_;
397  
398 1 my $conf = $self->conf();
399  
400 1 for my $line ($self->getConfigSection('default',@text)) {
401  
402 0 ▶ if ($line =~ /^\s*([\w\-]+)\s+(\S+)\s*$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^\s*([\w\-]+)\s+(\S+)\s*$/) 0 0 0
403 0 my ($option,$value) = ($1,$2);
404 0 ▶ if ($conf->optionExists($option)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($conf->optionExists($option)) { } 0 0 0
405 0 $self->logger()->debug(6,"\t\tNot setting option [$option]: It has already been set (possibly from the command-line).");
406 } else {
407 0 $self->logger()->debug(6,"\t\tSetting option [$option] to value [$value].");
408 0 ▶ $conf->setOption($option,$value) unless $conf->optionExists($option);
Branch: 1 branch
BranchTrueFalseTotal
unless $conf->optionExists($option) 0 0 0
409 }
410 }
411  
412 }
413  
414 } # sub tempParseDefaults
415  
416 0 ▶sub getGroups {
Subroutine getGroups: not called CC=4 SCAR=30.0
Pod undocumented
417  
418 0 my $self = shift;
419 0 my $conf = $self->conf();
420 0 ▶ unless (exists $self->{'GROUPS'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"GROUPS"}) 0 0 0
421 0 ▶ my $groups = $conf->optionExists('groups') ? $conf->getOption('groups') : '';
Branch: 1 branch
BranchTrueFalseTotal
$conf->optionExists('groups') ? : 0 0 0
422 0 my @groups = split /,/, $groups;
423 0 $self->{'GROUPS'} = \@groups;
424 }
425 0 ▶ return wantarray ? @{$self->{'GROUPS'}} : $self->{'GROUPS'};
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
426
427 } # end sub getGroups
428  
429 0 ▶sub getExcluded {
Subroutine getExcluded: not called CC=4 SCAR=30.0
Pod undocumented
430  
431 0 my $self = shift;
432 0 my $conf = $self->conf();
433 0 ▶ unless (exists $self->{'EXCLUDED'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"EXCLUDED"}) 0 0 0
434 0 ▶ my $excluded = $conf->optionExists('excluded') ? $conf->getOption('excluded') : '';
Branch: 1 branch
BranchTrueFalseTotal
$conf->optionExists('excluded') ? : 0 0 0
435 0 my @excluded = split /,/, $excluded;
436 0 $self->{'EXCLUDED'} = \@excluded;
437 }
438 0 ▶ return wantarray ? @{$self->{'EXCLUDED'}} : $self->{'EXCLUDED'};
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
439
440 } # end sub getExcluded
441  
442 0 ▶sub filter {
Subroutine filter: not called CC=15 SCAR=54.8
Pod undocumented
443  
444 0 my $self = shift;
445 0 ▶ my $object = shift || confess "Object not found";
Condition0%0/2
shift() || confess('Object not found')
l!l
00
MC/DC0%0/1
shift() || confess('Object not found')
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
446 0 my $nogrp = shift;
447  
448 0 my $conf = $self->conf();
449
450 0 my $return = 0;
451
452 0 my $name = $object->name();
453  
454 0 ▶ unless ($nogrp) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($nogrp) 0 0 0
455  
456 0 $self->logger()->debug(9,"Checking group [$name] against group and excluded group lists ...");
457  
458 0 my $group = $object->group();
459  
460 0 my @groups = ();
461 0 my @exclude = ();
462  
463 0 @groups = $self->getGroups('groups');
464 0 @exclude = $self->getExcluded('exclude');
465
466 0 ▶ if (grep /^all$/, @groups) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep /^all$/, @groups) { } 0 0 0
467 0 $return = 1;
468 } else {
469 0 for my $group_option (@groups) {
470 0 ▶ $return = 1 if $group eq $group_option;
Branch: 1 branch
BranchTrueFalseTotal
if $group eq $group_option 0 0 0
471 }
472 }
473
474 0 for my $exclude_option (@exclude) {
475 0 ▶ $return = 0 if $group eq $exclude_option;
Branch: 1 branch
BranchTrueFalseTotal
if $group eq $exclude_option 0 0 0
476 }
477
478 0 ▶ $self->logger()->debug(8,"[$name] will be ignored: The group [$group] is either not in the group ".
Branch: 1 branch
BranchTrueFalseTotal
if $return == 0 0 0 0
479 "list [@groups] or it is in the excluded list [@exclude].") if $return == 0;
480 }
481  
482 0 my $hosts = $object->hosts();
483 0 ▶ my @version = $conf->versionExists() ? split /\./, $conf->getVersion() : ();
Branch: 1 branch
BranchTrueFalseTotal
$conf->versionExists ? : 0 0 0
484
485 0 ▶ if (@version && $version[0] >= 0 && $version[1] >= 4 && $version[2] > 3) {
Branch: 1 branch
BranchTrueFalseTotal
if (@version and $version[0] >= 0 and $version[1] >= 4 and $version[2] > 3) 0 0 0
Condition0%0/9
@version and $version[0] >= 0 and $version[1] >= 4 and $version[2] > 3
!ll&&!rl&&r
000
@version and $version[0] >= 0 and $version[1] >= 4
!ll&&!rl&&r
000
@version and $version[0] >= 0
!ll&&!rl&&r
000
MC/DC0%0/4
@version and $version[0] >= 0 and $version[1] >= 4 and $version[2] > 3
@version $version[0] >= 0 $version[1] >= 4 $version[2] > 3
Truth table0%0/5
A and B and C and D
A= @versionB= $version[0] >= 0C= $version[1] >= 4D= $version[2] > 3
ABCDresult
0XXX0
10XX0
110X0
11100
11111
486 0 ▶ if ($object->pool()->isInHostPool($Net::Peep::Notifier::HOSTNAME)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($object->pool->isInHostPool($Net::Peep::Notifier::HOSTNAME)) { } 0 0 0
487 0 $return = 1;
488 } else {
489 0 $return = 0;
490 0 $self->logger()->debug(8,"[$name] will be ignored: Host [$Net::Peep::Notifier::HOSTNAME] ".
491 "is not in the host pool [$hosts].");
492 }
493 }
494
495 0 return $return;
496
497 } # end sub filter
498  
499 8 1;
500  
501 __END__
« blib/lib/Net/Peep/Mail.pm ↑ Summary blib/lib/Net/Peep/Client/Pinger.pm »