File Coverage

blib/lib/Net/Peep/Conf.pm
Criterion Covered Total %
statement 159 402 39.5
branch 33 178 18.5
condition 39 256 15.2
subroutine 31 63 49.2
pod 0 55 0.0
total 262 954 27.4


line stmt bran cond sub pod time code
1             package Net::Peep::Conf;
2              
3             require 5.00503;
4 3     3   839 use strict;
  3         8  
  3         120  
5             # use warnings; # commented out for 5.005 compatibility
6 3     3   16 use Carp;
  3         4  
  3         160  
7 3     3   1057 use Socket;
  3         4748  
  3         2006  
8 3     3   1205 use Data::Dumper;
  3         11488  
  3         165  
9 3     3   983 use Sys::Hostname;
  3         1515  
  3         146  
10 3     3   23 use Net::Peep::Log;
  3         6  
  3         106  
11 3     3   1833 use Net::Peep::Host;
  3         7  
  3         153  
12              
13             require Exporter;
14              
15 3     3   18 use vars qw{ @ISA %EXPORT_TAGS @EXPORT_OK @EXPORT $VERSION };
  3         7  
  3         20894  
16              
17             @ISA = qw(Exporter);
18             %EXPORT_TAGS = ( 'all' => [ qw( ) ] );
19             @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
20             @EXPORT = qw( );
21             $VERSION = do { my @r = (q$Revision: 1.8 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r };
22              
23             sub new {
24              
25 5     5 0 475 my $self = shift;
26 5   33     34 my $class = ref($self) || $self;
27 5         26 my $this = {};
28 5         28 bless $this, $class;
29              
30             } # end sub new
31              
32             sub logger {
33              
34             # returns a logging object
35 40     40 0 65 my $self = shift;
36 40 100       121 if ( ! exists $self->{'__LOGGER'} ) { $self->{'__LOGGER'} = new Net::Peep::Log }
  4         20  
37 40         296 return $self->{'__LOGGER'};
38              
39             } # end sub logger
40              
41             sub client {
42              
43 117     117 0 148 my $self = shift;
44 117 100       377 if (@_) { $self->{'CLIENT'} = shift; }
  4         31  
45 117         438 return $self->{'CLIENT'};
46              
47             } # end sub client
48              
49             sub setVersion {
50              
51 4     4 0 9 my $self = shift;
52 4   33     15 my $version = shift || confess "Cannot set version: No version information found";
53 4         13 $self->{"__VERSION"} = $version;
54 4         16 $self->logger()->debug(1,"Configuration file version [$version] identified.");
55 4         23 return 1;
56              
57             } # end sub setVersion
58              
59             sub getVersion {
60              
61 5     5 0 9 my $self = shift;
62              
63 5 50       20 if (exists $self->{"__VERSION"}) {
64 5         38 return $self->{"__VERSION"};
65             } else {
66 0         0 confess "Cannot get version: No version information has been set.";
67             }
68              
69             } # end sub getVersion
70              
71             sub versionExists {
72              
73 5     5 0 9 my $self = shift;
74 5         40 return exists $self->{"__VERSION"};
75              
76             } # end sub versionExists
77              
78             sub setSoundPath {
79              
80 4     4 0 8 my $self = shift;
81 4   33     17 my $soundpath = shift || confess "Cannot set sound path: No sound path information found";
82 4         32 $self->{"__SOUNDPATH"} = $soundpath;
83 4         14 $self->logger()->debug(1,"Configuration file soundpath [$soundpath] identified.");
84 4         22 return 1;
85              
86             } # end sub setSoundPath
87              
88             sub getSoundPath {
89              
90 0     0 0 0 my $self = shift;
91              
92 0 0       0 if (exists $self->{"__SOUNDPATH"}) {
93 0         0 return $self->{"__SOUNDPATH"};
94             } else {
95 0         0 confess "Cannot get sound path: No sound path information has been set.";
96             }
97              
98             } # end sub getSoundPath
99              
100             sub soundPathExists {
101              
102 0     0 0 0 my $self = shift;
103 0         0 return exists $self->{"__SOUNDPATH"};
104              
105             } # end sub soundPathExists
106              
107             sub setApp {
108              
109 0     0 0 0 my $self = shift;
110 0   0     0 my $app = shift || confess "Cannot set app: No app information found";
111 0         0 $self->{"__APP"} = $app;
112 0         0 $self->logger()->debug(1,"The application [$app] identified itself.");
113 0         0 return 1;
114              
115             } # end sub setApp
116              
117             sub getApp {
118              
119 0     0 0 0 my $self = shift;
120              
121 0 0       0 if (exists $self->{"__APP"}) {
122 0         0 return $self->{"__APP"};
123             } else {
124 0         0 confess "Cannot get app: No app information has been set.";
125             }
126              
127             } # end sub getApp
128              
129             sub setClientPort {
130              
131 16     16 0 24 my $self = shift;
132 16   33     41 my $client = shift || confess "Cannot set port: No client information found";
133 16   33     47 my $port = shift || confess "Cannot set port: No port information found";
134 16         48 $self->{"__PORT"}->{$client} = $port;
135 16         50 return 1;
136              
137             } # end sub setClientPort
138              
139             sub getClientPort {
140              
141 3     3 0 8 my $self = shift;
142 3   33     12 my $client = shift || confess "Cannot get port: No client information found";
143              
144 3 50       19 if (exists $self->{"__PORT"}->{$client}) {
    50          
145 0         0 return $self->{"__PORT"}->{$client};
146             } elsif ($self->optionExists($client,'port')) {
147 3         18 return $self->getOption($client,'port');
148             } else {
149 0         0 confess "Cannot get port: No port information has been defined for the client [$client].";
150             }
151              
152             } # end sub getClientPort
153              
154             sub addBroadcast {
155              
156 4     4 0 7 my $self = shift;
157 4   33     20 my $class = shift || confess "Cannot add broadcast: No class identifier found";
158 4   33     16 my $value = shift || confess "Cannot add broadcast: No broadcast information found";
159              
160 4 50 33     58 confess "Cannot add broadcast for class [$class]: Either the IP or port number has not been identified."
      33        
161             unless ref($value) eq 'HASH' and exists $value->{'ip'} and exists $value->{'port'};
162              
163 4         17 my $broadcast = $value->{'ip'} . ':' . $value->{'port'};
164              
165 4         8 push @{$self->{"__BROADCAST"}->{$class}}, $value;
  4         21  
166              
167 4         20 return 1;
168              
169             } # end sub addBroadcast
170              
171             sub getBroadcastList {
172              
173 0     0 0 0 my $self = shift;
174              
175 0 0       0 confess "Cannot get broadcast list: No broadcast information has been set."
176             unless exists $self->{"__BROADCAST"};
177              
178 0         0 my @broadcasts = sort keys % { $self->{"__BROADCAST"} };
  0         0  
179              
180 0         0 my @return;
181              
182 0         0 for my $class (@broadcasts) {
183 0         0 push @return, @{$self->{"__BROADCAST"}->{$class}};
  0         0  
184             }
185              
186 0 0       0 return wantarray ? @return : [@return];
187              
188             } # end sub getBroadcastList
189              
190             sub getBroadcast {
191              
192 0     0 0 0 my $self = shift;
193 0   0     0 my $class = shift || confess "Cannot get broadcast: No class identifier found";
194              
195 0 0 0     0 confess "Cannot get information for the broadcast class [$class]: No information has been set."
196             unless exists $self->{"__BROADCAST"} && exists $self->{"__BROADCAST"}->{$class};
197              
198 0 0       0 return wantarray ? @{$self->{"__BROADCAST"}->{$class}} : $self->{"__BROADCAST"}->{$class};
  0         0  
199              
200             } # end sub getBroadcast
201              
202             sub addServer {
203              
204 4     4 0 9 my $self = shift;
205 4   33     23 my $class = shift || confess "Cannot add server: No class identifier found";
206 4   33     17 my $value = shift || confess "Cannot add server: No server information found";
207              
208 4 50 33     50 confess "Cannot add server for class [$class]: Either the name or port number has not been identified."
      33        
209             unless ref($value) eq 'HASH' and exists $value->{'name'} and exists $value->{'port'};
210              
211 4         9 push @{$self->{"__SERVER"}->{$class}}, $value;
  4         250  
212              
213 4         14 return 1;
214              
215             } # end sub addServer
216              
217             sub getServerList {
218              
219 0     0 0 0 my $self = shift;
220              
221 0 0       0 confess "Cannot get server list: No server information has been set."
222             unless exists $self->{"__SERVER"};
223              
224 0         0 my @servers = keys % { $self->{"__SERVER"} };
  0         0  
225              
226 0         0 my @return;
227              
228 0         0 for my $class (@servers) {
229 0         0 push @return, @{$self->{"__SERVER"}->{$class}};
  0         0  
230             }
231              
232 0 0       0 return wantarray ? @return : [@return];
233              
234             } # end sub getServerList
235              
236             sub getServer {
237              
238 3     3 0 5 my $self = shift;
239 3   33     14 my $class = shift || confess "Cannot get server: No class identifier found";
240              
241 3 50 33     30 confess "Cannot get information for the server in class [$class]: No information has been set."
242             unless exists $self->{"__SERVER"} && exists $self->{"__SERVER"}->{$class};
243              
244 3 50       16 return wantarray ? @{$self->{"__SERVER"}->{$class}} : $self->{"__SERVER"}->{$class};
  0         0  
245              
246             } # end sub getServer
247              
248             sub addClass {
249              
250 4     4 0 13 my $self = shift;
251 4   33     17 my $key = shift || confess "Cannot add class: No class identifier found";
252 4   33     16 my $value = shift || confess "Cannot add class: No class information found";
253              
254 4 50       19 confess "Cannot set class [$key]: Expecting an array ref (instead of [$value])."
255             unless ref($value) eq 'ARRAY';
256              
257 4         16 $self->{"__CLASS"}->{$key} = $value;
258              
259 4         12 return 1;
260              
261             } # end sub addClass
262              
263             sub getClassList {
264              
265 6     6 0 12 my $self = shift;
266              
267 6 50       23 confess "Cannot get class list: No class information has been set."
268             unless exists $self->{"__CLASS"};
269              
270 6         8 my @classes = keys % { $self->{"__CLASS"} };
  6         38  
271              
272 6 50       41 return wantarray ? @classes : [@classes];
273              
274             } # end sub getClassList
275              
276             sub getClass {
277              
278 16     16 0 26 my $self = shift;
279 16   33     44 my $key = shift || confess "no class identifier found";
280              
281 16 50 33     143 confess "Cannot get information for the class [$key]: No information has been set."
282             unless exists $self->{"__CLASS"} && exists $self->{"__CLASS"}->{$key};
283              
284 16 50       298 return wantarray ? @ { $self->{"__CLASS"}->{$key} } : $self->{"__CLASS"}->{$key};
  0         0  
285              
286             } # end sub getClass
287              
288             sub addClientClass {
289              
290 0     0 0 0 my $self = shift;
291 0   0     0 my $client = shift || confess "Cannot add client class: No client identifier found";
292 0   0     0 my $value = shift || confess "Cannot add client class: No class identifier found";
293              
294 0         0 push @ { $self->{"__CLIENTCLASS"}->{$client} }, $value;
  0         0  
295              
296 0         0 return 1;
297              
298             } # end sub addClientClasses
299              
300             sub getClientClassList {
301              
302 0     0 0 0 my $self = shift;
303 0   0     0 my $client = shift || confess "Cannot add client classes: No client identifier found";
304              
305 0 0       0 confess "Cannot get class list: No class information has been set."
306             unless exists $self->{"__CLIENTCLASS"}->{$client};
307              
308 0         0 my @classes = @ { $self->{"__CLIENTCLASS"}->{$client} };
  0         0  
309              
310 0 0       0 return wantarray ? @classes : [@classes];
311              
312             } # end sub getClientClasses
313              
314             sub addEvent {
315              
316 72     72 0 91 my $self = shift;
317 72   33     168 my $name = shift || confess "Cannot add event: No event identifier found";
318 72   33     139 my $value = shift || confess "Cannot add event: No event information found";
319              
320 72 50       159 confess "Cannot set event [$name]: Expecting a hash ref (instead of [$value])."
321             unless ref($value) eq 'HASH';
322              
323 72         203 $self->{"__EVENT"}->{$name} = $value;
324              
325 72         151 return 1;
326              
327             } # end sub addEvent
328              
329             sub getEventList {
330              
331 0     0 0 0 my $self = shift;
332              
333 0 0       0 confess "Cannot get event list: No event information has been set."
334             unless exists $self->{"__EVENT"};
335              
336 0         0 my @events = keys % { $self->{"__EVENT"} };
  0         0  
337              
338 0 0       0 return wantarray ? @events : [@events];
339              
340             } # end sub getEventList
341              
342             sub getEvent {
343              
344 0     0 0 0 my $self = shift;
345 0   0     0 my $name = shift || confess "Cannot get event: No event identifier found";
346              
347 0 0 0     0 confess "Cannot get information for the event [$name]: No information has been set."
348             unless exists $self->{"__EVENT"} && exists $self->{"__EVENT"}->{$name};
349              
350 0 0       0 return wantarray ? @ { $self->{"__EVENT"}->{$name} } : $self->{"__EVENT"}->{$name};
  0         0  
351              
352             } # end sub getEvent
353              
354             sub isEvent {
355              
356 0     0 0 0 my $self = shift;
357 0   0     0 my $name = shift || confess "Cannot check event: No event identifier found";
358              
359 0   0     0 return exists $self->{"__EVENT"} && exists $self->{"__EVENT"}->{$name};
360              
361             } # end sub isEvent
362              
363             sub setConfigurationText {
364              
365 16     16 0 20 my $self = shift;
366 16         27 my $client = shift;
367 16         33 my @text = @_;
368              
369 16 50       38 confess "Cannot set configuration text: No client found."
370             unless $client;
371              
372 16 50       41 confess "Cannot set configuration text: No text found."
373             unless @text;
374              
375 16         97 $self->{"__CONFIGURATIONTEXT"}->{$client} = join '', @text;
376              
377 16         40 $self->logger()->debug(1,"\tConfiguration text of length " .
378             length($self->{"__CONFIGURATIONTEXT"}->{$client}) .
379             " added to client [$client].");
380              
381 16         87 return 1;
382              
383             } # end sub setConfigurationText
384              
385             sub getConfigurationText {
386              
387 0     0 0 0 my $self = shift;
388 0         0 my $client = shift;
389              
390 0 0       0 confess "Cannot get configuration text: It has not been set yet."
391             unless exists $self->{"__CONFIGURATIONTEXT"}->{$client};
392              
393 0         0 return $self->{"__CONFIGURATIONTEXT"}->{$client};
394              
395             } # end sub getConfigurationText
396              
397             sub setNotificationText {
398              
399 16     16 0 25 my $self = shift;
400 16         71 my $client = shift;
401 16         37 my @text = @_;
402              
403 16 50       37 confess "Cannot set notification text: No client found."
404             unless $client;
405              
406 16 50       45 confess "Cannot set notification text: No text found."
407             unless @text;
408              
409 16         59 $self->{"__NOTIFICATIONTEXT"}->{$client} = join '', @text;
410              
411 16         37 $self->logger()->debug(1,"Notification text of length " .
412             length($self->{"__NOTIFICATIONTEXT"}->{$client}) .
413             " added to client [$client].");
414              
415 16         100 return 1;
416              
417             } # end sub setNotificationText
418              
419             sub getNotificationText {
420              
421 0     0 0 0 my $self = shift;
422 0         0 my $client = shift;
423              
424 0 0       0 confess "Cannot get notification text: It has not been set yet."
425             unless exists $self->{"__NOTIFICATIONTEXT"}->{$client};
426              
427 0         0 return $self->{"__NOTIFICATIONTEXT"}->{$client};
428              
429             } # end sub getNotificationText
430              
431             sub addState {
432              
433 12     12 0 17 my $self = shift;
434 12   33     37 my $name = shift || confess "Cannot add state: No state identifier found";
435 12   33     34 my $value = shift || confess "Cannot add state: No state information found";
436              
437 12 50       31 confess "Cannot set state [$name]: Expecting a hash ref (instead of [$value])."
438             unless ref($value) eq 'HASH';
439              
440 12         36 $self->{"__STATE"}->{$name} = $value;
441              
442 12         30 return 1;
443              
444             } # end sub addState
445              
446             sub getStateList {
447              
448 0     0 0 0 my $self = shift;
449              
450 0 0       0 confess "Cannot get state list: No state information has been set."
451             unless exists $self->{"__STATE"};
452              
453 0         0 my @states = keys % { $self->{"__STATE"} };
  0         0  
454              
455 0 0       0 return wantarray ? @states : [@states];
456              
457             } # end sub getStateList
458              
459             sub getState {
460              
461 0     0 0 0 my $self = shift;
462 0   0     0 my $name = shift || confess "Cannot get state: No state identifier found";
463              
464 0 0 0     0 confess "Cannot get information for the state [$name]: No information has been set."
465             unless exists $self->{"__STATE"} && exists $self->{"__STATE"}->{$name};
466              
467 0 0       0 return wantarray ? @ { $self->{"__STATE"}->{$name} } : $self->{"__STATE"}->{$name};
  0         0  
468              
469             } # end sub getState
470              
471             sub isState {
472              
473 0     0 0 0 my $self = shift;
474 0   0     0 my $name = shift || confess "Cannot check state: No state identifier found";
475              
476 0   0     0 return exists $self->{"__STATE"} && exists $self->{"__STATE"}->{$name};
477              
478             } # end sub isState
479              
480             sub addClientEvent {
481              
482 0     0 0 0 my $self = shift;
483 0   0     0 my $name = shift || confess "Cannot add client event: No client event identifier found";
484 0   0     0 my $value = shift || confess "Cannot add client event: No client event information found";
485              
486 0 0       0 confess "Cannot set client event [$name]: Expecting a hash ref (instead of [$value])."
487             unless ref($value) eq 'HASH';
488              
489 0         0 my $clientevent = $value->{'name'};
490              
491 0         0 push @ { $self->{"__CLIENTEVENT"}->{$name} }, $value;
  0         0  
492              
493 0         0 return 1;
494              
495             } # end sub addClientEvent
496              
497             sub getClientEventList {
498              
499 0     0 0 0 my $self = shift;
500              
501 0 0       0 confess "Cannot get clientevent list: No clientevent information has been set."
502             unless exists $self->{"__CLIENTEVENT"};
503              
504 0         0 my @clientevents;
505              
506 0         0 for my $client (keys % { $self->{"__CLIENTEVENT"} }) {
  0         0  
507 0         0 push @clientevents, @ { $self->{"__CLIENTEVENT"}->{$client} };
  0         0  
508             }
509              
510 0 0       0 return wantarray ? @clientevents : [@clientevents];
511              
512             } # end sub getClientEventList
513              
514             sub getClientEvents {
515              
516 0     0 0 0 my $self = shift;
517 0   0     0 my $name = shift || confess "Cannot get clientevent: No clientevent identifier found";
518              
519 0 0 0     0 confess "Cannot get information for the clientevent [$name]: No information has been set."
520             unless exists $self->{"__CLIENTEVENT"} && exists $self->{"__CLIENTEVENT"}->{$name};
521              
522 0 0       0 return wantarray ? @ { $self->{"__CLIENTEVENT"}->{$name} } : $self->{"__CLIENTEVENT"}->{$name};
  0         0  
523              
524             } # end sub getClientEvents
525              
526             sub checkClientEvent {
527              
528 0     0 0 0 my $self = shift;
529 0   0     0 my $client = shift || confess "Client not found";
530 0   0     0 my $event = shift || confess "Event not found";
531              
532 0         0 my $return = 0;
533              
534 0         0 my ($group,$letter) = ('','');
535              
536 0 0       0 $group = $event->{'group'} if exists $event->{'group'};
537 0 0       0 $letter = $event->{'option-letter'} if exists $event->{'option-letter'};
538              
539 0         0 my @groups = ();
540 0         0 my @exclude = ();
541 0         0 my @events = ();
542              
543 0 0       0 @events = split //, $self->getOption($client,'events') if $self->optionExists($client,'events');
544 0 0       0 @groups = @{ $self->getOption($client,'groups') } if $self->optionExists($client,'groups');
  0         0  
545 0 0       0 @exclude = @{ $self->getOption($client,'exclude') } if $self->optionExists($client,'exclude');
  0         0  
546              
547             # first check the events option
548            
549 0         0 for my $letter_option (@events) {
550 0 0       0 $return = 1 if $letter eq $letter_option;
551             }
552              
553 0 0       0 if (grep /^all$/, @groups) {
554 0         0 $return = 1;
555 0         0 for my $exclude_option (@exclude) {
556 0 0       0 $return = 0 if $group eq $exclude_option;
557             }
558             } else {
559 0         0 for my $group_option (@groups) {
560 0 0       0 $return = 1 if $group eq $group_option;
561             }
562             }
563              
564 0         0 return $return;
565              
566             } # end sub checkClientEvent
567              
568             sub checkClientHost {
569              
570 0     0 0 0 my $self = shift;
571 0   0     0 my $client = shift || confess "Client not found";
572 0   0     0 my $host = shift || confess "Host not found";
573              
574 0         0 my $return = 0;
575              
576 0         0 my $event = $host->getEvent();
577              
578 0         0 return $self->checkClientEvent($client,$event);
579              
580             } # end sub checkClientHost
581              
582             sub addClientHost {
583              
584 0     0 0 0 my $self = shift;
585 0   0     0 my $client = shift || confess "Cannot add client host: No client identifier found";
586 0   0     0 my $value = shift || confess "Cannot add client host: No client host information found";
587              
588 0 0       0 confess "Cannot set client host for client [$client]: Expecting a hash ref (instead of [$value])."
589             unless ref($value) eq 'HASH';
590              
591 0         0 my $identifier = $value->{'host'};
592              
593 0         0 my ($iaddr,$host,$ip);
594 0 0       0 if ($identifier =~ /^(\d+\.)+\d+$/) {
    0          
595             # we were given an IP address
596 0         0 $ip = $identifier;
597 0         0 $host = inet_aton($ip);
598 0 0       0 $host = gethostbyaddr($host,AF_INET) if $host;
599 0 0 0     0 $self->logger()->log("\t\tThe host name for IP [$ip] could not be found. This host will be ignored.")
600             and return 0 unless $host;
601 0         0 $self->logger()->debug(9,"\t\tThe host name [$host] was found for host [$identifier].");
602             } elsif ($identifier =~ /^([\w-]+\.)+\w+$/) {
603             # we were given a host name
604 0         0 $host = $identifier;
605 0         0 $ip = gethostbyname($identifier);
606             # funny that the next line and previous line can't be combined ... but Socket complains!
607 0 0       0 $ip = inet_ntoa($ip) if $ip;
608 0 0 0     0 $self->logger()->log("\t\tThe IP address for host [$identifier] could not be found. This host will be ignored.")
609             and return 0 unless $ip;
610 0         0 $self->logger()->debug(9,"\t\tThe IP address [$ip] was found for host [$identifier].");
611             } else {
612 0         0 $self->logger()->log("The host name or IP [$identifier] does not appear to be valid. This host will be ignored.");
613 0         0 return;
614             }
615            
616 0         0 my $event = {
617             name => $value->{'name'},
618             group => $value->{'group'},
619             'option-letter' => $value->{'option-letter'},
620             location => $value->{'location'},
621             priority => $value->{'priority'},
622             status => $value->{'status'},
623              
624             };
625              
626 0         0 my $clienthost = new Net::Peep::Host;
627 0         0 $clienthost->setName($host);
628 0         0 $clienthost->setIP($ip);
629 0         0 $clienthost->setEvent($event);
630 0         0 $clienthost->setNotificationLevel($value->{'status'});
631              
632 0         0 push @ { $self->{"__CLIENTHOST"}->{$client} }, $clienthost;
  0         0  
633              
634 0         0 return 1;
635              
636             } # end sub addClientHost
637              
638             sub getClientHostList {
639              
640 0     0 0 0 my $self = shift;
641              
642 0 0       0 confess "Cannot get clienthost list: No client host information has been set."
643             unless exists $self->{"__CLIENTHOST"};
644              
645 0         0 my @clienthosts;
646              
647 0         0 for my $client (keys % { $self->{"__CLIENTHOST"} }) {
  0         0  
648 0         0 push @clienthosts, @ { $self->{"__CLIENTHOST"}->{$client} };
  0         0  
649             }
650              
651 0 0       0 return wantarray ? @clienthosts : [@clienthosts];
652              
653             } # end sub getClientHostList
654              
655             sub getClientHosts {
656              
657 0     0 0 0 my $self = shift;
658 0   0     0 my $client = shift || confess "Cannot get client host: No client identifier found";
659              
660 0 0 0     0 $self->logger()->log("Cannot get host information for the client [$client]: No information has been set.")
      0        
661             and return
662             unless exists $self->{"__CLIENTHOST"} && exists $self->{"__CLIENTHOST"}->{$client};
663              
664 0 0       0 return wantarray ? @{$self->{"__CLIENTHOST"}->{$client}} : $self->{"__CLIENTHOST"}->{$client};
  0         0  
665              
666             } # end sub getClientHosts
667              
668             sub addClientUptime {
669              
670 0     0 0 0 my $self = shift;
671 0   0     0 my $client = shift || confess "Cannot add client uptime: No client identifier found";
672 0   0     0 my $value = shift || confess "Cannot add client uptime: No client uptime information found";
673              
674 0 0       0 confess "Cannot set client uptime setting for client [$client]: Expecting a hash ref (instead of [$value])."
675             unless ref($value) eq 'HASH';
676              
677 0 0 0     0 confess "Cannot set client uptime setting for client [$client]: The hash ref is missing important keys."
      0        
678             unless exists($value->{'name'}) && exists($value->{'value'}) && exists($value->{'status'});
679              
680 0         0 push @ { $self->{"__CLIENTUPTIME"}->{$client} }, $value;
  0         0  
681              
682 0         0 return 1;
683              
684             } # end sub addClientUptime
685              
686             sub getClientUptimeList {
687              
688 0     0 0 0 my $self = shift;
689              
690 0 0       0 confess "Cannot get client uptime settings list: No client uptime information has been set."
691             unless exists $self->{"__CLIENTUPTIME"};
692              
693 0         0 my @clientuptimes;
694              
695 0         0 for my $client (keys % { $self->{"__CLIENTUPTIME"} }) {
  0         0  
696 0         0 push @clientuptimes, @ { $self->{"__CLIENTUPTIME"}->{$client} };
  0         0  
697             }
698              
699 0 0       0 return wantarray ? @clientuptimes : [@clientuptimes];
700              
701             } # end sub getClientUptimeList
702              
703             sub getClientUptimes {
704              
705 0     0 0 0 my $self = shift;
706 0   0     0 my $client = shift || confess "Cannot get client uptime settings: No client identifier found";
707              
708 0 0 0     0 $self->logger()->log("Cannot get uptime information for the client [$client]: No information has been set.")
      0        
709             and return
710             unless exists $self->{"__CLIENTUPTIME"} && exists $self->{"__CLIENTUPTIME"}->{$client};
711              
712 0 0       0 return wantarray ? @{$self->{"__CLIENTUPTIME"}->{$client}} : $self->{"__CLIENTUPTIME"}->{$client};
  0         0  
713              
714             } # end sub getClientUptimes
715              
716             sub addClientProc {
717              
718 0     0 0 0 my $self = shift;
719 0   0     0 my $client = shift || confess "Cannot add client proc: No client identifier found";
720 0   0     0 my $value = shift || confess "Cannot add client proc: No client proc information found";
721              
722 0 0       0 confess "Cannot set client proc setting for client [$client]: Expecting a hash ref (instead of [$value])."
723             unless ref($value) eq 'HASH';
724              
725 0 0 0     0 confess "Cannot set client proc setting for client [$client]: The hash ref is missing important keys."
      0        
726             unless exists($value->{'name'}) && exists($value->{'value'}) && exists($value->{'status'});
727              
728 0         0 push @ { $self->{"__CLIENTPROC"}->{$client} }, $value;
  0         0  
729              
730 0         0 return 1;
731              
732             } # end sub addClientProc
733              
734             sub getClientProcList {
735              
736 0     0 0 0 my $self = shift;
737              
738 0 0       0 confess "Cannot get client proc settings list: No client proc information has been set."
739             unless exists $self->{"__CLIENTPROC"};
740              
741 0         0 my @clientprocs;
742              
743 0         0 for my $client (keys % { $self->{"__CLIENTPROC"} }) {
  0         0  
744 0         0 push @clientprocs, @ { $self->{"__CLIENTPROC"}->{$client} };
  0         0  
745             }
746              
747 0 0       0 return wantarray ? @clientprocs : [@clientprocs];
748              
749             } # end sub getClientProcList
750              
751             sub getClientProcs {
752              
753 0     0 0 0 my $self = shift;
754 0   0     0 my $client = shift || confess "Cannot get client proc settings: No client identifier found";
755              
756 0 0 0     0 $self->logger()->log("Cannot get proc information for the client [$client]: No information has been set.")
      0        
757             and return
758             unless exists $self->{"__CLIENTPROC"} && exists $self->{"__CLIENTPROC"}->{$client};
759              
760 0 0       0 return wantarray ? @{$self->{"__CLIENTPROC"}->{$client}} : $self->{"__CLIENTPROC"}->{$client};
  0         0  
761              
762             } # end sub getClientProcs
763              
764             sub setOption {
765              
766 46     46 0 74 my $self = shift;
767              
768             # The following bit of logic is a bit of a kludge. If you're
769             # wondering why it was done, please contact the author :-)
770              
771 46 50       96 if (@_ == 2) {
    0          
772              
773 46   33     91 my $client = $self->client() || confess "Cannot set client option: Client not specified.";
774 46   33     140 my $name = $client->name() || confess "Cannot set client option: Client name not specified.";
775 46   33     126 my $option = shift || confess "Cannot set client option: Option name not specified.";
776 46         58 my $value = shift;
777 46         130 $self->{"__OPTIONS"}->{$name}->{$option} = $value;
778 46         178 return 1;
779              
780             } elsif (@_ == 3) {
781              
782 0   0     0 my $client = shift || confess "Cannot set client option: Client name not specified.";
783 0   0     0 my $option = shift || confess "Cannot set client option: Option name not specified.";
784 0         0 my $value = shift;
785 0         0 $self->{"__OPTIONS"}->{$client}->{$option} = $value;
786 0         0 return 1;
787              
788             } else {
789              
790 0         0 confess "Cannot set client option: Wrong number of arguments to setOption method.";
791              
792             }
793              
794             } # end sub setOption
795              
796             sub getOption {
797              
798 75     75 0 108 my $self = shift;
799 75         87 my $name;
800             my $option;
801 75 100       333 if (@_ == 1) {
    50          
802 21   33     55 $option = shift || confess "Cannot get client option: Option name not specified.";
803 21   33     56 my $client = $self->client() || confess "Cannot get client option: Client not specified.";;
804 21   33     70 $name = $client->name() || confess "Cannot get client option: Client name not specified.";
805             } elsif (@_ == 2) {
806 54   33     117 $name = shift || confess "Cannot get client option: Client name not specified.";
807 54   33     119 $option = shift || confess "Cannot get client option: Option name not specified.";
808             } else {
809 0         0 confess "Cannot get option [$option]: Incorrect number of arguments to the getOption method.";
810             }
811             # $self->logger()->debug(9,"Getting option [$option] for client [$name] ...");
812 75 50       165 confess "Cannot get option [$option]: The option value has not been set yet."
813             unless $self->optionExists($name,$option);
814 75         433 return $self->{"__OPTIONS"}->{$name}->{$option};
815              
816             } # end sub getOption
817              
818             sub optionExists {
819              
820             # The following bit of logic is a bit of a kludge. If you're
821             # wondering why it was done, please contact the author :-)
822              
823 108     108 0 142 my $self = shift;
824              
825 108         130 my $option;
826             my $name;
827 108 100       258 if (@_ == 1) {
    50          
828 30   33     87 $option = shift || confess "Cannot evaluate client option: Option name not specified.";
829 30   33     64 my $client = $self->client() || confess "Cannot evaluate client option: Client not specified.";;
830 30   33     89 $name = $client->name() || confess "Cannot evaluate client option: Client name not specified.";
831             } elsif (@_ == 2) {
832 78   33     162 $name = shift || confess "Cannot evaluate client option: Client name not specified.";
833 78   33     171 $option = shift || confess "Cannot evaluate client option: Option name not specified.";
834             } else {
835 0         0 confess "Cannot evaluate client option: Wrong number of arguments to optionExists method.";
836             }
837             # $self->logger()->debug(9,"Checking existence of option [$option] for client [$name] ....");
838 108 100 66     689 if (exists $self->{"__OPTIONS"}->{$name}
839             and exists $self->{"__OPTIONS"}->{$name}->{$option}) {
840 84         333 return 1;
841             } else {
842 24         112 return 0;
843             }
844              
845             } # end sub optionExists
846              
847             sub getOptions {
848              
849             # returns the names of all of the currently set options
850 0     0 0 0 my $self = shift;
851 0         0 my $name;
852 0 0       0 if (@_) {
853 0         0 $name = shift;
854             } else {
855 0   0     0 my $client = $self->client() || confess "Cannot get client options: Client not specified.";;
856 0   0     0 $name = $client->name() || confess "Cannot get client options: Client name not specified.";
857             }
858 0 0       0 return () unless exists $self->{"__OPTIONS"}->{$name};
859             return wantarray
860 0         0 ? ( keys % { $self->{"__OPTIONS"}->{$name} } )
  0         0  
861 0 0       0 : [ keys % { $self->{"__OPTIONS"}->{$name} } ];
862              
863             } # end sub getOptions
864              
865             sub getOptionsHash {
866              
867             # returns the names of all of the currently set options
868 3     3 0 8 my $self = shift;
869 3         7 my %return;
870             my $name;
871 3 50       12 if (@_) {
872 3         8 $name = shift;
873             } else {
874 0   0     0 my $client = $self->client() || confess "Cannot get options hash: Client not specified.";;
875 0   0     0 $name = $client->name() || confess "Cannot get options hash: Client name not specified.";
876             }
877 3         5 for my $option (keys % { $self->{"__OPTIONS"}->{$name} }) {
  3         25  
878 36         87 $return{$option} = $self->getOption($name,$option);
879             }
880 3         47 return %return;
881              
882             } # end sub getOptionHash
883              
884             1;
885              
886             __END__