Delegate/List.pm

filter: Statementstmt 20.3% 12 / 59 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 25.0% 3 / 12 Podpod 88.8% 8 / 9 totaltotal 21.1% 23 / 109 CC 20 SCAR 32.3
CC
20
Cov
14%
add
72.0
log
12.0
trans00
12.0
CRAP 25.3
« Delegate/SimpleHttp.pm ↑ Summary Logger.pm »
1 #================================ List.pm ===================================
2 # Filename: List
3 # Description: Internal class for managing a list of delegates.
4 # Original Author: Dale M. Amon
5 # Revised by: $Author: amon $
6 # Date: $Date: 2008-08-28 23:20:19 $
7 # Version: $Revision: 1.5 $
8 # License: LGPL 2.1, Perl Artistic or BSD
9 #
10 #=============================================================================
11 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Fault::ErrorHandler;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 package Fault::Delegate::List;
15 1 ▶use vars qw{@ISA};
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 @ISA = qw( UNIVERSAL );
17  
18 #=============================================================================
19 # CLASS METHODS
20 #=============================================================================
21 1 my %fault = ();
22  
23 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod documented
24 0 my ($class,@list) = @_;
25 0 my $self = bless {}, $class;
26  
27 0 %fault = ();
28 0 $self->{'list'} = {};
29  
30 0 $self->add (@list);
31  
32 # If we had no good delegates, default to command line.
33 0 ▶ scalar keys %{$self->{'list'}} or $self->add (Fault::Delegate::Stdout->new);
Branch: 1 branch
BranchTrueFalseTotal
scalar keys %{$$self{"list"};} or $self->add("Fault::Delegate::Stdout"->new) 0 0 0
34  
35 0 return $self;
36 }
37  
38 #=============================================================================
39 # INSTANCE METHODS
40 #=============================================================================
41  
42 0 ▶sub add ($@) {
Subroutine add: not called CC=8 SCAR=42.8
Pod documented
43 0 my ($self, @list) = @_;
44  
45 0 foreach my $d (@list) {
46 0 ▶ next if (!defined $d);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $d 0 0 0
47  
48 0 ▶ if (! ((ref $d) &&
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $d and ref $d ne "HASH" and $d->can("log")) 0 0 0
Condition0%0/6
ref $d and ref $d ne "HASH" and $d->can("log")
!ll&&!rl&&r
000
ref $d and ref $d ne "HASH"
!ll&&!rl&&r
000
MC/DC0%0/3
ref $d and ref $d ne "HASH" and $d->can("log")
ref $d ref $d ne "HASH" $d->can("log")
Truth table0%0/4
A and B and C
A= ref $dB= ref $d ne "HASH"C= $d->can("log")
ABCresult
0XX0
10X0
1100
1111
49 ((ref $d) ne "HASH") &&
50 $d->can("log"))) {
51 0 Fault::ErrorHandler->warn
52 ("Fault::Logger->new: Ignoring an invalid logger delegate " .
53 "object. A delegate must at the very least support a 'log' " .
54 "method. Read the docs and fix your code.");
55 0 next;}
56 0 my $list = $self->{'list'};
57 0 $list->{$d} = $d;
58 0 ▶ if ($d->can ("initfaults")) {
Branch: 1 branch
BranchTrueFalseTotal
if ($d->can("initfaults")) 0 0 0
59 0 foreach my $m (eval{$d->initfaults}) {$fault{$m}=1;}
60 }
61 }
62 0 return 1;
63 }
64  
65 #-----------------------------------------------------------------------------
66  
67 0 ▶sub delegates ($) {values %{shift->{'list'}};}
Subroutine delegates: not called CC=1 SCAR=6.9
Pod documented
68 0 ▶sub fault_exists ($$) {my ($s,$m)=@_; return ($fault{$m->msg}) ? 1 : 0;}
Subroutine fault_exists: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
$fault{$m->msg} ? : 0 0 0
69  
70 #-----------------------------------------------------------------------------
71 # Apply a Delegate Protocol Methdo to each Delegate
72 #-----------------------------------------------------------------------------
73  
74 0 ▶sub log ($$@) {
Subroutine log: not called CC=3 SCAR=24.8
Pod documented
75 0 my ($s,$msg,@rest) = @_;
76  
77 0 foreach my $l ($s->delegates) {
78 0 ▶ (eval ($l->log ($msg,@rest))) ||
Branch: 1 branch
BranchTrueFalseTotal
eval $l->log($msg, @rest) or "Fault::ErrorHandler"->warn('Failed to report: "' . $msg->msg . qq[" due to Delegate error "$@"!]), (return 0) 0 0 0
79 (Fault::ErrorHandler->warn("Failed to report: \"" .
80 $msg->msg .
81 "\" due to Delegate error \"$@\"!"),
82 return 0);
83 }
84 0 return 1;
85 }
86  
87 #------------------------------------------------------------------------------
88 # Log on condition still low.
89  
90 0 ▶sub trans00 ($$@) {
Subroutine trans00: not called CC=3 SCAR=24.8
Pod documented
91 0 my ($s,$msg,@rest) = @_;
92  
93 0 foreach my $l ($s->delegates) {
94 0 ▶ ($l->can ("trans00")) && eval($l->trans00($msg,@rest));
Branch: 1 branch
BranchTrueFalseTotal
$l->can("trans00") and eval $l->trans00($msg, @rest) 0 0 0
95 }
96 0 return 0;
97 }
98  
99 #------------------------------------------------------------------------------
100 # Log on condition rising edge.
101  
102 0 ▶sub trans01 ($$@) {
Subroutine trans01: not called CC=3 SCAR=24.8
Pod documented
103 0 my ($s,$msg,@rest) = @_;
104  
105 0 $fault{$msg->msg} = 1;
106 0 foreach my $l ($s->delegates) {
107 0 ▶ ($l->can ("trans01")) && eval($l->trans01($msg,@rest));
Branch: 1 branch
BranchTrueFalseTotal
$l->can("trans01") and eval $l->trans01($msg, @rest) 0 0 0
108 }
109 0 return 0;
110 }
111  
112 #------------------------------------------------------------------------------
113 # Log on condition falling edge.
114  
115 0 ▶sub trans10 ($$@) {
Subroutine trans10: not called CC=3 SCAR=24.8
Pod documented
116 0 my ($s,$msg,@rest) = @_;
117  
118 0 foreach my $l ($s->delegates) {
119 0 ▶ ($l->can ("trans10")) && eval($l->trans10($msg,@rest));
Branch: 1 branch
BranchTrueFalseTotal
$l->can("trans10") and eval $l->trans10($msg, @rest) 0 0 0
120 }
121 0 return 0;
122 }
123  
124 #------------------------------------------------------------------------------
125 # Log on condition still high.
126  
127 0 ▶sub trans11 ($$@) {
Subroutine trans11: not called CC=3 SCAR=24.8
Pod documented
128 0 my ($s,$msg,@rest) = @_;
129  
130 0 delete $fault{$msg->msg};
131 0 foreach my $l ($s->delegates) {
132 0 ▶ ($l->can ("trans11")) && eval($l->trans11($msg,@rest));
Branch: 1 branch
BranchTrueFalseTotal
$l->can("trans11") and eval $l->trans11($msg, @rest) 0 0 0
133 }
134 0 return 0;
135 }
136
137 #=============================================================================
138 # POD DOCUMENTATION
139 #=============================================================================
140 # You may extract and format the documention section with the 'perldoc' cmd.
141  
142 =head1 NAME
143  
144 Fault::Delegate::List - Internal class for managing a list of delegates.
145  
146 =head1 SYNOPSIS
147  
148 use Fault::Delegate::List;
149 $self = Fault::Delegate::List->new (@delegates);
150 $bool = $self->add (@delegates);
151 @delegates = $self->delegates;
152 $bool = $self->log ($msg,@rest);
153 $bool = $self->trans00 ($msg,@rest);
154 $bool = $self->trans01 ($msg,@rest);
155 $bool = $self->trans10 ($msg,@rest);
156 $bool = $self->trans11 ($msg,@rest);
157  
158 =head1 Inheritance
159  
160 UNIVERSAL
161  
162 =head1 Description
163  
164 Internal class for managing a list of delegates.
165  
166 =head1 Examples
167  
168 None.
169  
170 =head1 Class Variables
171  
172 None.
173  
174 =head1 Instance Variables
175  
176 list Contains a pointer to a hash of delegate pointers.
177  
178 =head1 Class Methods
179  
180 =over 4
181  
182 =item B<$self = Fault::Delegate::List-E<gt>new(@delegates)>
183  
184 Create an instance of Fault::Delegate::List and initialize it with the
185 contents of @delegates. The list may be null.
186  
187 If a delegate has an initfaults method, it is executed and the results
188 merged into the current list of active faults.
189  
190 =head1 Instance Methods
191  
192 =over 4
193  
194 =item B<$bool = $self-E<gt>add (@delegates)>
195  
196 Add each member of a list of delegates, that is not already present, to the
197 internal list of delegates. The list may be empty.
198  
199 A member of the list is included only if it is a pointer to an object that
200 has a log method.
201  
202 If a delegate has an initfaults method, it is executed and the results
203 merged into the current list of active faults.
204  
205 =item B<@delegates = $self-E<gt>delegates>
206  
207 Returns a list of delegate objects suitable for iteration. The list may be
208 empty.
209  
210 =item B<$bool = $self-E<gt>log ($msg,@rest)>
211  
212 Send a message to each delegate for logging.
213  
214 =item B<$bool = $self-E<gt>trans00 ($msg,@rest)>
215  
216 Send a message to each delegate for 4 state fault monitoring in the case
217 that $msg was in a Fault Clear state previously and still is.
218  
219 =item B<$bool = $self-E<gt>trans01 ($msg,@rest)>
220  
221 Send a message to each delegate for 4 state fault monitoring in the case
222 that $msg was in a Fault Clear state previously and is now in a Fault
223 Raised state.
224  
225 =item B<$bool = $self-E<gt>trans10 ($msg,@rest)>
226  
227 Send a message to each delegate for 4 state fault monitoring in the case
228 that $msg was in a Fault Raised state previously but is now in a Fault
229 Clear state.
230  
231 =item B<$bool = $self-E<gt>trans11 ($msg,@rest)>
232  
233 Send a message to each delegate for 4 state fault monitoring in the case
234 that $msg was in a Fault Raised state previously and still is.
235  
236 =item B<@faults = $self-E<gt>initfaults>
237  
238 Ask each delegate to return a current list of faults for this process from
239 its persistant storage. Returns an empty list if there are none or the
240 delegate class has no such memory or if it does and is unable to retrieve
241 data from it.
242  
243 =back 4
244  
245 =head1 Private Class Method
246  
247 None.
248  
249 =head1 Private Instance Methods
250  
251 None.
252  
253 =head1 Errors and Warnings
254  
255 None.
256  
257 =head1 KNOWN BUGS
258  
259 See TODO.
260  
261 =head1 SEE ALSO
262  
263 None.
264  
265 =head1 AUTHOR
266  
267 Dale Amon <amon@vnl.com>
268  
269 =cut
270
271 #=============================================================================
272 # CVS HISTORY
273 #=============================================================================
274 # $Log: List.pm,v $
275 # Revision 1.5 2008-08-28 23:20:19 amon
276 # perldoc section regularization.
277 #
278 # Revision 1.4 2008-08-17 21:56:37 amon
279 # Make all titles fit CPAN standard.
280 #
281 # Revision 1.3 2008-05-09 18:24:55 amon
282 # Bugs and changes due to pre-release testing
283 #
284 # Revision 1.2 2008-05-08 20:22:50 amon
285 # Minor bug fixes; shifted fault table and initfault from Logger to List
286 #
287 # Revision 1.1 2008-05-07 18:16:12 amon
288 # A class to manage a list of logger delegates
289 #
290 # $DATE Dale Amon <amon@vnl.com>
291 # Created.
292 1 1;
« Delegate/SimpleHttp.pm ↑ Summary Logger.pm »