blib/lib/Net/Peep/Parser.pm

filter: Statementstmt 85.4% 211 / 247 Branchbran 75.8% 91 / 120 Conditioncond 44.9% 22 / 49 MC/DCmcdc 3.8% 1 / 26 Subroutinesub 95.4% 21 / 22 Podpod 0.0% 0 / 15 totaltotal 72.2% 346 / 479 CC 91 SCAR 27.9
CC
91
Cov
78%
parseClientNotification
66.8
parseClient
22.1
parseVersion
12.0
CRAP 16.2
« blib/lib/Net/Peep/BC.pm ↑ Summary blib/lib/Net/Peep/Log.pm »
1 package Net::Peep::Parser;
2  
3 10 require 5.00503;
4 10 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 # use warnings; # commented out for 5.005 compatibility
6 10 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 10 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 10 ▶use Net::Peep::Log;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 10 ▶use Net::Peep::Conf;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 10 ▶use Net::Peep::Notifier;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 10 require Exporter;
13  
14 10 ▶use vars qw{ @ISA %EXPORT_TAGS @EXPORT_OK @EXPORT $VERSION };
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 10 @ISA = qw(Exporter);
17 10 %EXPORT_TAGS = ( 'all' => [ qw( ) ] );
18 10 @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
19 10 @EXPORT = qw( );
20 10 $VERSION = do { my @r = (q$Revision: 1.6 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r };
21  
22 5 ▶sub new {
Subroutine new: called CC=2 SCAR=7.4
Pod undocumented
23  
24 5 my $self = shift;
25 5 ▶ my $class = ref($self) || $self;
Condition33%1/3
ref $self || $self
l!l&&r!l&&!r
050
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table33%1/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
26 5 my $this = {};
27 5 bless $this, $class;
28  
29 } # end sub new
30  
31 # On spawning a new configuration file parser, we expect to get
32 # a reference to a hash that contains:
33 # 'config' => Which is a pointer to the configuration file
34 # 'app' => The application for which to get the configuration
35 4 ▶sub load {
Subroutine load: called CC=3 SCAR=11.3
Pod undocumented
36 4 my $self = shift;
37 4 ▶ my $conf = shift || confess "Cannot parse configuration file: No configuration object found.";
Condition50%1/2
shift() || confess('Cannot parse configuration file: No configuration object found.')
l!l
40
MC/DC0%0/1
shift() || confess('Cannot parse configuration file: No configuration object found.')
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
38 4 $self->conf($conf);
39 4 ▶ confess "Peep couldn't find the configuration file [", $conf->getOption('config'), "]: $!"
Branch: 1 branch
BranchTrueFalseTotal
unless -e $conf->getOption("config") 0 4 4
40 unless -e $conf->getOption('config');
41 4 $self->parseConfig();
42  
43 } # end sub load
44  
45 200 ▶sub conf {
Subroutine conf: called CC=2 SCAR=6.9
Pod undocumented
46  
47 200 my $self = shift;
48 200 ▶ if (@_) { $self->{'CONF'} = shift; }
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 4 196 200
49 200 return $self->{'CONF'};
50  
51 } # end sub conf
52  
53 4 ▶sub parseConfig {
Subroutine parseConfig: called CC=11 SCAR=24.0
Pod undocumented
54  
55 4 my $self = shift;
56 4 my $conf = $self->conf()->getOption('config');
57  
58 4 ▶ open FILE, "<$conf" || confess "Could not open [$conf]: $!";
Condition50%1/2
"<$conf" || confess("Could not open [$conf]: $!")
l!l
40
MC/DC0%0/1
"<$conf" || confess("Could not open [$conf]: $!")
"<$conf"
Truth table50%1/2
A
A= "<$conf"
Aresult
11
00
59 4 ▶ while (my $line = <FILE>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline FILE)) 116 4 120
60 116 my $msg = $line;
61 116 chomp $msg;
62 116 $msg = substr $msg, 0, 40;
63 116 $self->logger()->debug(9,"Parsing [$conf] line [$msg ...]");
64 116 ▶ next if $line =~ /^\s*#/;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^\s*#/ 40 76 116
65 # version 0.4.3 had a standalone version tag
66 76 ▶ $self->parseVersion(\*FILE, $1) if $line =~ /^\s*version (.*)/;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^\s*version (.*)/ 0 76 76
67 76 ▶ $self->parseGeneral(\*FILE, $1) if $line =~ /^\s*general/;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^\s*general/ 4 72 76
68 76 ▶ $self->parseNotification(\*FILE, $1) if $line =~ /^\s*notification/;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^\s*notification/ 4 72 76
69 76 ▶ $self->parseClass(\*FILE, $1) if $line =~ /^\s*class (.*)/;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^\s*class (.*)/ 4 72 76
70 76 ▶ $self->parseClient(\*FILE, $1) if $line =~ /^\s*client (.*)/;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^\s*client (.*)/ 16 60 76
71 76 ▶ $self->parseEvents(\*FILE, $1) if $line =~ /^\s*events/;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^\s*events/ 4 72 76
72 76 ▶ $self->parseStates(\*FILE, $1) if $line =~ /^\s*states/;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^\s*states/ 4 72 76
73 # $self->parseHosts(\*FILE, $1) if $line =~ /^\s*hosts/;
74 }
75 4 close FILE;
76  
77 } # end sub parseConfig
78  
79 4 ▶sub parseGeneral {
Subroutine parseGeneral: called CC=8 SCAR=21.2
Pod undocumented
80  
81 4 my $self = shift;
82 4 ▶ my $file = shift || confess "file not found";
Condition50%1/2
shift() || confess('file not found')
l!l
40
MC/DC0%0/1
shift() || confess('file not found')
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
83  
84 4 $self->logger()->debug(1,"Parsing general configuration information ...");
85  
86 4 ▶ while (my $line = <$file>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $file)) 12 0 12
87 12 ▶ next if $line =~ /^\s*#/;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^\s*#/ 0 12 12
88 12 ▶ if ($line =~ /^\s*end/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^\s*end/) { } 4 8 12
89 4 return;
90 } else {
91 8 $line =~ /^\s*([\w-]+)\s+(.*)$/;
92 8 my ($key, $value) = ($1,$2);
93 # Remove any leading or trailing whitespace
94 8 for ($key,$value) { s/^\s+//g; s/\s+$//g; }
95 8 ▶ if ($key eq 'version') {
Branch: 2 branches
BranchTrueFalseTotal
if ($key eq 'version') { } 4 4 8
elsif ($key eq 'sound-path') { } 4 0 4
96 4 $self->conf()->setVersion($value);
97 } elsif ($key eq 'sound-path') {
98 4 $self->conf()->setSoundPath($value);
99 } else {
100 0 $self->logger()->log("Configuration option [$key] not recognized.");
101 }
102 }
103  
104 }
105  
106 } # end sub parseGeneral
107  
108 4 ▶sub parseNotification {
Subroutine parseNotification: called CC=9 SCAR=22.4
Pod undocumented
109  
110 4 my $self = shift;
111 4 ▶ my $file = shift || confess "file not found";
Condition50%1/2
shift() || confess('file not found')
l!l
40
MC/DC0%0/1
shift() || confess('file not found')
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
112  
113 4 $self->logger()->debug(1,"Parsing notification configuration information ...");
114  
115 4 ▶ while (my $line = <$file>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $file)) 28 0 28
116 28 ▶ next if $line =~ /^\s*#/;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^\s*#/ 16 12 28
117 12 ▶ if ($line =~ /^\s*end/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^\s*end/) { } 4 8 12
118 4 return;
119 } else {
120 8 $line =~ /^\s*([\w-]+)\s+(.*)$/;
121 8 my ($key, $value) = ($1,$2);
122 # Remove any leading or trailing whitespace
123 8 for ($key,$value) { s/^\s+//; s/\s+$//; }
124 8 ▶ if ($key eq 'smtp-relays') {
Branch: 2 branches
BranchTrueFalseTotal
if ($key eq 'smtp-relays') { } 4 4 8
elsif ($key eq 'notification-interval') { } 4 0 4
125 4 my (@relays) = split /[\s,]+/, $value;
126 4 $self->logger()->debug(1,"\tFound SMTP relays [@relays]");
127 4 @Net::Peep::Notifier::SMTP_RELAYS = @relays;
128 } elsif ($key eq 'notification-interval') {
129 4 ▶ confess "The notification interval must be an integer value!"
Branch: 1 branch
BranchTrueFalseTotal
unless $value =~ /^\d+$/ 0 4 4
130 unless $value =~ /^\d+$/;
131 4 $self->logger()->debug(1,"\tFound notification interval [$value]");
132 4 $Net::Peep::Notifier::NOTIFICATION_INTERVAL = $value;
133 } else {
134 0 $self->logger()->log("\tNotification option [$key] not recognized.");
135 }
136 }
137  
138 }
139  
140 0 $self->logger()->debug(1,"\tNotification configuration information parsed.");
141  
142 } # end sub parseNotification
143  
144 0 ▶sub parseVersion {
Subroutine parseVersion: not called CC=3 SCAR=24.8
Pod undocumented
145  
146 0 my $self = shift;
147  
148 0 ▶ my $file = shift || confess "file not found";
Condition0%0/2
shift() || confess('file not found')
l!l
00
MC/DC0%0/1
shift() || confess('file not found')
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
149 0 ▶ my $version = shift || confess "version not found";
Condition0%0/2
shift() || confess('version not found')
l!l
00
MC/DC0%0/1
shift() || confess('version not found')
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
150  
151 0 $self->logger()->debug(1,"Parsing version [$version] ...");
152  
153 0 $self->conf()->setVersion($version);
154  
155 0 $self->logger()->debug(1,"\tVersion parsed.");
156  
157 } # end sub parseVersion
158  
159 4 ▶sub parseClass {
Subroutine parseClass: called CC=11 SCAR=24.3
Pod undocumented
160 4 my $self = shift;
161 4 ▶ my $file = shift || confess "file not found";
Condition50%1/2
shift() || confess('file not found')
l!l
40
MC/DC0%0/1
shift() || confess('file not found')
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
162 4 ▶ my $classname = shift || confess "classname not found";
Condition50%1/2
shift() || confess('classname not found')
l!l
40
MC/DC0%0/1
shift() || confess('classname not found')
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
163 4 my (@broadcast, @servers, $newbroadcast);
164 4 my %servports;
165  
166 4 $self->logger()->debug(1,"Parsing class [$classname] ...");
167  
168 4 ▶ while (my $line = <$file>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $file)) 12 0 12
169 12 ▶ if ($line =~ /^\s*end/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^\s*end/) { } 4 8 12
170 #Then check if we should make an entry
171 4 ▶ if (@broadcast && @servers) {
Branch: 1 branch
BranchTrueFalseTotal
if (@broadcast and @servers) 4 0 4
Condition33%1/3
@broadcast and @servers
!ll&&!rl&&r
004
MC/DC0%0/2
@broadcast and @servers
@broadcast @servers
Truth table33%1/3
A and B
A= @broadcastB= @servers
ABresult
0X0
100
111
172 4 $self->conf()->addClass($classname,\@servers);
173  
174 #We need the same broadcast zones as the servers but
175 #We need the different server ports.
176 4 foreach my $server (@servers) {
177 4 my ($name, $port) = split /:/, $server;
178 4 $self->conf()->addServer($classname,{ name => $name, port => $port });
179 4 $self->logger()->debug(1,"\tServer [$name:$port] added.");
180 4 $servports{$port} = 1; #define the key
181 }
182 4 foreach my $zone (@broadcast) {
183 4 my ($ip, $port) = split /:/, $zone;
184 4 $self->logger()->debug(1,"\tBroadcast [$ip:$port] added.");
185 4 $self->conf()->addBroadcast($classname,{ ip => $ip, port => $port });
186 }
187 }
188 4 $self->logger()->debug(1,"\tClass [$classname] parsed.");
189 4 return;
190 } else {
191  
192 8 ▶ push (@broadcast, split(/\s+/, $1) ) if $line =~ /^\s*broadcast (.*)/;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^\s*broadcast (.*)/ 4 4 8
193 8 ▶ push (@servers, split (/\s+/, $1) ) if $line =~ /^\s*server (.*)/;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^\s*server (.*)/ 4 4 8
194  
195 }
196  
197  
198 }
199  
200 } # end sub parseClass
201  
202 16 ▶sub parseClient {
Subroutine parseClient: called CC=21 SCAR=31.0
Pod undocumented
203  
204 16 my $self = shift;
205  
206 16 ▶ my $file = shift || confess "Cannot parse client: File not found";
Condition50%1/2
shift() || confess('Cannot parse client: File not found')
l!l
160
MC/DC0%0/1
shift() || confess('Cannot parse client: File not found')
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
207 16 ▶ my $client = shift || confess "Cannot parse client: Client not found";
Condition50%1/2
shift() || confess('Cannot parse client: Client not found')
l!l
160
MC/DC0%0/1
shift() || confess('Cannot parse client: Client not found')
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
208 16 my %classes;
209  
210 16 $self->logger()->debug(1,"Parsing client [$client] ...");
211  
212 # Let's figure out which classes we're part of and grab the
213 # program's configuration
214 16 ▶ while (my $line = <$file>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $file)) 112 0 112
215  
216 112 ▶ $self->logger()->debug(1,"\tClient [$client] parsed.") and return if $line =~ /^\s*end client $client/;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^\s*end client $client/ 16 96 112
Condition60%3/5
$line =~ /^\s*end client $client/ && ($self->logger->debug(1, "\tClient [$client] parsed.") && (return))
!ll&&!rl&&r
96160
$self->logger->debug(1, "\tClient [$client] parsed.") and return
!ll
016
MC/DC0%0/2
$line =~ /^\s*end client $client/ && ($self->logger->debug(1, "\tClient [$client] parsed.") && (return))
$line =~ /^\s*end client $client/ $self->logger->debug(1, "\tClient [$client] parsed.")
Truth table33%1/3
A && B
A= $line =~ /^\s*end client $client/B= $self->logger->debug(1, "\tClient [$client] parsed.")
ABresult
0X0
100
111
217 96 ▶ next if $line =~ /^\s*#/ or $line =~ /^\s*$/;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^\s*#/ or $line =~ /^\s*$/ 24 72 96
Condition66%2/3
$line =~ /^\s*#/ or $line =~ /^\s*$/
l!l&&r!l&&!r
24072
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
218  
219 72 ▶ if ($line =~ /^\s*class(.*)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^\s*class(.*)/) 16 56 72
220 16 my $class = $1;
221 16 $class =~ s/\s+//g;
222 16 my @classes = split /\s+/, $class;
223 16 foreach my $one (@classes) {
224 16 $classes{$one} = $self->conf()->getClass($one);
225 }
226 }
227  
228 72 ▶ if ($line =~ /^\s*port (\d+)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^\s*port (\d+)/) 16 56 72
229 16 my $port = $1;
230 16 $port =~ s/\s+//g;
231 16 $self->conf()->setClientPort($client,$port);
232 16 $self->logger()->debug(1,"\tPort [$port] set for client [$client].");
233 }
234  
235 72 ▶ if ($line =~ /^\s*default/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^\s*default/) 8 64 72
236 8 my @default;
237  
238 8 ▶ while (my $line = <$file>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $file)) 20 0 20
239 20 ▶ last if $line =~ /^\s*end default/;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^\s*end default/ 8 12 20
240 12 push @default, $line;
241 }
242  
243 8 $self->parseClientDefault($client,@default);
244 }
245  
246 # Note that config specifically looks for "end config" because
247 # it may contain several starts and ends
248 72 ▶ if ($line =~ /^\s*config/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^\s*config/) 16 56 72
249 16 my @config;
250  
251 16 ▶ while (my $line = <$file>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $file)) 424 0 424
252 424 ▶ last if $line =~ /^\s*end config/;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^\s*end config/ 16 408 424
253 408 push @config, $line;
254 }
255  
256 16 $self->parseClientConfig($client,@config);
257 # I believe the parseClientEvents makes this redundant
258 16 $self->conf()->setConfigurationText($client,join '', @config);
259 }
260  
261 # Note that notification specifically looks for "end
262 # notification" because it may contain several starts
263 # and ends
264 72 ▶ if ($line =~ /^\s*notification/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^\s*notification/) 16 56 72
265 16 my @notification;
266  
267 16 ▶ while (my $line = <$file>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $file)) 84 0 84
268 84 ▶ last if $line =~ /^\s*end notification/;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^\s*end notification/ 16 68 84
269 68 push @notification, $line;
270 }
271  
272 16 $self->parseClientNotification($client,@notification);
273 # I believe the parseClientEvents makes this redundant
274 16 $self->conf()->setNotificationText($client,join '', @notification);
275 }
276  
277 }
278  
279 # Now let's swap in the valid classes
280 0 for my $class (keys %classes) { $self->conf()->addClientClass($client,$class); }
281  
282 } # end sub parseClient
283  
284 4 ▶sub parseEvents {
Subroutine parseEvents: called CC=5 SCAR=16.2
Pod undocumented
285  
286 4 my $self = shift;
287 4 ▶ my $file = shift || confess "Cannot parse events: File not found.";
Condition50%1/2
shift() || confess('Cannot parse events: File not found.')
l!l
40
MC/DC0%0/1
shift() || confess('Cannot parse events: File not found.')
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
288  
289 4 $self->logger()->debug(1,"Parsing events ...");
290  
291 4 my $i = 0;
292 # Skip right to the end
293 4 ▶ while (my $line = <$file>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $file)) 84 0 84
294 84 ▶ last if $line =~ /^\s*end/;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^\s*end/ 4 80 84
295 80 ▶ next if $line =~ /^\s*#/;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^\s*#/ 8 72 80
296 72 my ($eventname, $file, $nsounds) = split /\s+/, $line;
297  
298 72 $self->conf()->addEvent($eventname,{
299 file => $file,
300 sounds => $nsounds,
301 index => $i++
302 });
303  
304 72 $self->logger()->debug(1,"\tEvent [$eventname] added.");
305 }
306  
307 } # end sub parseEvents
308  
309 16 ▶sub parseClientConfig {
Subroutine parseClientConfig: called CC=3 SCAR=11.0
Pod undocumented
310  
311 16 my $self = shift;
312 16 ▶ my $who = shift || confess "Cannot parse client configuration: Client not identified.";
Condition50%1/2
shift() || confess('Cannot parse client configuration: Client not identified.')
l!l
160
MC/DC0%0/1
shift() || confess('Cannot parse client configuration: Client not identified.')
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
313 16 my @text = @_;
314  
315 16 my $client = $self->conf()->client();
316 16 my $name = $client->name();
317
318 16 ▶ if ($who eq $name) {
Branch: 1 branch
BranchTrueFalseTotal
if ($who eq $name) 1 15 16
319  
320 1 $self->logger()->debug(1,"\tParsing configuration text for client [$name] ...");
321 1 $client->runParser(@text);
322 1 $self->logger()->debug(1,"\tDone parsing configuration for client [$name].");
323  
324 }
325  
326 # while (my $line = shift @text) {
327 # next if $line =~ /^\s*#/;
328 # next if $line =~ /^\s*$/;
329 # if ($line =~ /^\s*default/) {
330 # @text = $self->parseClientDefault($client,@text);
331 # } elsif ($line =~ /^\s*events/) {
332 # @text = $self->parseClientEvents($client,@text);
333 # } elsif ($line =~ /^\s*hosts/) {
334 # @text = $self->parseClientHosts($client,@text);
335 # } elsif ($line =~ /^\s*uptime/) {
336 # @text = $self->parseClientUptime($client,@text);
337 # } elsif ($line =~ /^\s*procs/) {
338 # @text = $self->parseClientProcs($client,@text);
339 # } elsif ($line =~ /^\s*disk/) {
340 # @text = $self->parseClientDisk($client,@text);
341 # } else {
342 # $line =~ /^\s*(\w+)\s+(\S+)/;
343 # $self->logger()->debug(1,"\t\tClient option [$1] has been set to value [$2].");
344 # $self->conf()->setOption($client,$1,$2);
345 # }
346 # }
347  
348 } # end sub parseClientConfig
349  
350 16 ▶sub parseClientNotification {
Subroutine parseClientNotification: called CC=11 SCAR=42.0
Pod undocumented
351  
352 16 my $self = shift;
353 16 ▶ my $client = shift || confess "Cannot parse client notification: Client not identified.";
Condition50%1/2
shift() || confess('Cannot parse client notification: Client not identified.')
l!l
160
MC/DC0%0/1
shift() || confess('Cannot parse client notification: Client not identified.')
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
354 16 my @text = @_;
355  
356 16 $self->logger()->debug(1,"\tParsing notification for client [$client] ...");
357  
358 16 ▶ while (my $line = shift @text) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $line = shift @text) 68 16 84
359 68 ▶ next if $line =~ /^\s*#/;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^\s*#/ 68 0 68
360 0 ▶ next if $line =~ /^\s*$/;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^\s*$/ 0 0 0
361  
362 0 ▶ if ($line =~ /^\s*(notification-hosts)\s+(.*)$/) {
Branch: 3 branches
BranchTrueFalseTotal
if ($line =~ /^\s*(notification-hosts)\s+(.*)$/) { } 0 0 0
elsif ($line =~ /^\s*(notification-recipients)\s+(.*)$/) { } 0 0 0
elsif ($line =~ /^\s*(notification-level)\s+(\S+)/) { } 0 0 0
363 0 my ($key,$value) = ($1,$2);
364 0 for ($key,$value) { s/^\s+//g; s/\s+$//g; }
365 0 my (@hosts) = split /[\s,]+/, $value;
366 0 $self->logger()->debug(1,"\t\tFound notification hosts [@hosts].");
367 0 $Net::Peep::Notifier::NOTIFICATION_HOSTS{$client} = [ @hosts ];
368 } elsif ($line =~ /^\s*(notification-recipients)\s+(.*)$/) {
369 0 my ($key,$value) = ($1,$2);
370 0 for ($key,$value) { s/^\s+//g; s/\s+$//g; }
371 0 my (@recipients) = split /[\s,]+/, $value;
372 0 $self->logger()->debug(1,"\t\tFound notification recipients [@recipients].");
373 0 $Net::Peep::Notifier::NOTIFICATION_RECIPIENTS{$client} = [ @recipients ];
374 } elsif ($line =~ /^\s*(notification-level)\s+(\S+)/) {
375 0 my ($key,$value) = ($1,$2);
376 0 for ($key,$value) { s/^\s+//g; s/\s+$//g; }
377 0 $self->logger()->debug(1,"\t\tFound notification level [$value].");
378 0 $Net::Peep::Notifier::NOTIFICATION_LEVEL{$client} = $value;
379 } else {
380 0 $line =~ /^\s*(\w+)\s+(\S+)/;
381 0 $self->logger()->debug(1,"\t\tClient notification option [$1] not recognized.");
382 }
383 }
384  
385 } # end sub parseClientNotification
386  
387 # this method was deprecated with the move of client config parsing
388 # into the client objects
389  
390 #sub parseClientEvents {
391 #
392 # my $self = shift;
393 # my $client = shift || confess "Cannot parse client events: Client not identified.";
394 # my @text = @_;
395 #
396 # $self->logger()->debug(1,"\t\tParsing events for client [$client] ...");
397 #
398 # my @version = $self->conf()->versionExists()
399 # ? split /\./, $self->conf()->getVersion()
400 # : ();
401 #
402 # if (@version && $version[0] >= 0 && $version[1] >= 4 && $version[2] > 3) {
403 #
404 # while (my $line = shift @text) {
405 # next if $line =~ /^\s*#/;
406 # last if $line =~ /^\s*end/;
407 #
408 # my $name;
409 # $line =~ /^\s*([\w-]+)\s+([\w-]+)\s+([a-zA-Z])\s+(\d+)\s+(\d+)\s+(\w+)\s+"(.*)"/;
410 #
411 # my $clientEvent = {
412 # 'name' => $1,
413 # 'group' => $2,
414 # 'option-letter' => $3,
415 # 'location' => $4,
416 # 'priority' => $5,
417 # 'status' => $6,
418 # 'regex' => $7
419 # };
420 #
421 # $self->conf()->addClientEvent($client,$clientEvent);
422 # $self->logger()->debug(1,"\t\t\tClient event [$1] added.");
423 #
424 # }
425 #
426 # } elsif (@version && $version[0] >= 0 && $version[1] >= 4 && $version[2] > 1) {
427 #
428 # while (my $line = shift @text) {
429 # next if $line =~ /^\s*#/;
430 # last if $line =~ /^\s*end/;
431 #
432 # my $name;
433 # $line =~ /^\s*([\w-]+)\s+([\w-]+)\s+([a-zA-Z])\s+(\d+)\s+(\d+)\s+"(.*)"/;
434 #
435 # my $clientEvent = {
436 # 'name' => $1,
437 # 'group' => $2,
438 # 'option-letter' => $3,
439 # 'location' => $4,
440 # 'priority' => $5,
441 # 'regex' => $6
442 # };
443 #
444 # $self->conf()->addClientEvent($client,$clientEvent);
445 # $self->logger()->debug(1,"\t\t\tClient event [$1] added.");
446 #
447 # }
448 #
449 # } else {
450 #
451 # while (my $line = shift @text) {
452 # next if $line =~ /^\s*#/;
453 # last if $line =~ /^\s*end/;
454 #
455 # my $name;
456 # $line =~ /([\w-]+)\s+([a-zA-Z])\s+(\d+)\s+(\d+)\s+"(.*)"/;
457 #
458 # my $clientEvent = {
459 # 'name' => $1,
460 # 'option-letter' => $2,
461 # 'location' => $3,
462 # 'priority' => $4,
463 # 'regex' => $5
464 # };
465 #
466 # $self->conf()->addClientEvent($client,$clientEvent);
467 # $self->logger()->debug(1,"\t\t\tClient event [$1] added.");
468 #
469 # }
470 #
471 # }
472 #
473 # return @text;
474 #
475 #} # end sub parseClientEvents
476  
477 # this method was deprecated with the move of client config parsing
478 # into the client objects
479  
480 #sub parseClientHosts {
481 #
482 # my $self = shift;
483 # my $client = shift || confess "Cannot parse client hosts: Client not identified.";
484 # my @text = @_;
485 #
486 # $self->logger()->debug(1,"\t\tParsing hosts for client [$client] ...");
487 #
488 # while (my $line = shift @text) {
489 # next if $line =~ /^\s*$/;
490 # next if $line =~ /^\s*#/;
491 # last if $line =~ /^\s*end/;
492 #
493 # $line =~ /^\s*([\w\-\.]+)\s+([\w\-]+)\s+([\w\-]+)\s+([a-zA-Z])\s+(\d+)\s+(\d+)\s+(\w+)/;
494 #
495 # my ($host,$name,$group,$letter,$location,$priority,$status) =
496 # ($1,$2,$3,$4,$5,$6,$7);
497 #
498 # my $clientHost = {
499 # host => $host,
500 # name => $name,
501 # group => $group,
502 # 'option-letter' => $letter,
503 # location => $location,
504 # priority => $priority,
505 # status => $status
506 # };
507 #
508 # $self->logger()->debug(1,"\t\t\tClient host [$host] added.") if
509 # $self->conf()->addClientHost($client,$clientHost);
510 #
511 # }
512 #
513 # return @text;
514 #
515 #} # end sub parseClientHosts
516  
517 8 ▶sub parseClientDefault {
Subroutine parseClientDefault: called CC=9 SCAR=23.8
Pod undocumented
518  
519 8 my $self = shift;
520 8 ▶ my $client = shift || confess "Cannot parse client defaults: Client not identified.";
Condition50%1/2
shift() || confess('Cannot parse client defaults: Client not identified.')
l!l
80
MC/DC0%0/1
shift() || confess('Cannot parse client defaults: Client not identified.')
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
521 8 my @text = @_;
522  
523 8 $self->logger()->debug(1,"\tParsing defaults for client [$client] ...");
524  
525 8 ▶ my $conf = $self->conf() || confess "Defaults cannot be parsed: No configuration object found.";
Condition50%1/2
$self->conf || confess('Defaults cannot be parsed: No configuration object found.')
l!l
80
MC/DC0%0/1
$self->conf || confess('Defaults cannot be parsed: No configuration object found.')
$self->conf
Truth table50%1/2
A
A= $self->conf
Aresult
11
00
526  
527 8 ▶ while (my $line = shift @text) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $line = shift @text) 12 8 20
528 12 ▶ next if $line =~ /^\s*#/ || $line =~ /^\s*$/;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^\s*#/ or $line =~ /^\s*$/ 0 12 12
Condition33%1/3
$line =~ /^\s*#/ or $line =~ /^\s*$/
l!l&&r!l&&!r
0012
MC/DC0%0/2
$line =~ /^\s*#/ or $line =~ /^\s*$/
$line =~ /^\s*#/ $line =~ /^\s*$/
Truth table33%1/3
A or B
A= $line =~ /^\s*#/B= $line =~ /^\s*$/
ABresult
1X1
011
000
529 12 ▶ if ($line =~ /^\s*([\w\-]+)\s+(\S+)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^\s*([\w\-]+)\s+(\S+)/) 12 0 12
530 12 my ($option,$value) = ($1,$2);
531 12 ▶ if ($conf->optionExists($option)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($conf->optionExists($option)) { } 0 12 12
532 0 $self->logger()->debug(6,"Not setting option [$option]: It has already been set (possibly from the command-line).");
533 } else {
534 12 $self->logger()->debug(6,"Setting option [$option] to value [$value].");
535 12 ▶ $conf->setOption($option,$value) unless $conf->optionExists($option);
Branch: 1 branch
BranchTrueFalseTotal
unless $conf->optionExists($option) 12 0 12
536 }
537 }
538 }
539  
540 8 $self->logger()->debug(1,"\t\tDone.");
541  
542 8 return @text;
543  
544 } # end sub parseClientDefault
545  
546 4 ▶sub parseStates {
Subroutine parseStates: called CC=5 SCAR=16.2
Pod undocumented
547  
548 4 my $self = shift;
549  
550 4 ▶ my $file = shift || confess "Cannot parse states: File not found.";
Condition50%1/2
shift() || confess('Cannot parse states: File not found.')
l!l
40
MC/DC0%0/1
shift() || confess('Cannot parse states: File not found.')
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
551  
552 4 $self->logger()->debug(1,"Parsing states ...");
553  
554 4 my $i = 0;
555 # Skip right to the end
556 4 ▶ while (my $line = <$file>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $file)) 20 0 20
557 20 ▶ last if $line =~ /^\s*end/;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^\s*end/ 4 16 20
558 16 ▶ next if $line =~ /^\s*#/;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^\s*#/ 4 12 16
559 12 my ($statename, $file, $sounds, $fade) = split /\s+/, $line;
560  
561 12 $self->conf()->addState($statename,{
562 file => $file,
563 sounds => $sounds,
564 fade => $fade,
565 index => $i++
566 });
567  
568 12 $self->logger()->debug(1,"\tState [$statename] added.");
569 }
570  
571 } # end sub parseStates
572  
573 # returns a logging object
574 334 ▶sub logger {
Subroutine logger: called CC=2 SCAR=6.9
Pod undocumented
575 334 my $self = shift;
576 334 ▶ if ( ! exists $self->{'__LOGGER'} ) { $self->{'__LOGGER'} = new Net::Peep::Log }
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"__LOGGER"}) 4 330 334
577 334 return $self->{'__LOGGER'};
578 } # end sub logger
579  
580 10 1;
581  
582 __END__
« blib/lib/Net/Peep/BC.pm ↑ Summary blib/lib/Net/Peep/Log.pm »