| 1 | #============================= ErrorHandler.pm =============================== | ||||||||||
| 2 | # Filename: ErrorHandler.pm | ||||||||||
| 3 | # Description: An error handler. | ||||||||||
| 4 | # Original Author: Dale M. Amon | ||||||||||
| 5 | # Revised by: $Author: amon $ | ||||||||||
| 6 | # Date: $Date: 2008-08-28 23:20:19 $ | ||||||||||
| 7 | # Version: $Revision: 1.6 $ | ||||||||||
| 8 | # License: LGPL 2.1, Perl Artistic or BSD | ||||||||||
| 9 | # | ||||||||||
| 10 | #============================================================================= | ||||||||||
| 11 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | |||||||||||
| 13 | package Fault::ErrorHandler; | ||||||||||
| 14 | 1 | ▶ | use vars qw{@ISA}; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | 1 | @ISA = qw( UNIVERSAL ); | |||||||||
| 16 | |||||||||||
| 17 | #============================================================================= | ||||||||||
| 18 | # Class Methods | ||||||||||
| 19 | #============================================================================= | ||||||||||
| 20 | 1 | my $ERRORHANDLER = undef; | |||||||||
| 21 | |||||||||||
| 22 | 0 | ▶ | sub new { | ||||||||
|
Subroutine
new: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 23 | 0 | my ($class) = @_; | |||||||||
| 24 | 0 | ▶ | $ERRORHANDLER || ($ERRORHANDLER = bless {}, $class); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 25 | 0 | return $ERRORHANDLER; | |||||||||
| 26 | } | ||||||||||
| 27 | |||||||||||
| 28 | #------------------------------------------------------------------------------ | ||||||||||
| 29 | |||||||||||
| 30 | 0 | ▶ | sub warn { | ||||||||
|
Subroutine
warn: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 31 | 0 | my ($class,$msg) = @_; | |||||||||
| 32 | 0 | ▶ | defined $msg || ($msg = "<Null warning message>"); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 33 | 0 | chomp $msg; | |||||||||
| 34 | 0 | ▶ | $ERRORHANDLER || $class->new; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 35 | 0 | warn "$msg\n"; | |||||||||
| 36 | 0 | return 1; | |||||||||
| 37 | } | ||||||||||
| 38 | |||||||||||
| 39 | #------------------------------------------------------------------------------ | ||||||||||
| 40 | |||||||||||
| 41 | 0 | ▶ | sub die { | ||||||||
|
Subroutine
die: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 42 | 0 | my ($class,$msg) = @_; | |||||||||
| 43 | 0 | ▶ | defined $msg || ($msg = "<Null warning message>"); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 44 | 0 | chomp $msg; | |||||||||
| 45 | 0 | ▶ | $ERRORHANDLER || $class->new; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 46 | 0 | die "$msg\n"; | |||||||||
| 47 | } | ||||||||||
| 48 | |||||||||||
| 49 | #============================================================================= | ||||||||||
| 50 | # Pod Documentation | ||||||||||
| 51 | #============================================================================= | ||||||||||
| 52 | # You may extract and format the documentation section with the 'perldoc' cmd. | ||||||||||
| 53 | |||||||||||
| 54 | =head1 NAME | ||||||||||
| 55 | |||||||||||
| 56 | Fault::ErrorHandler - A base error handler class. | ||||||||||
| 57 | |||||||||||
| 58 | =head1 SYNOPSIS | ||||||||||
| 59 | |||||||||||
| 60 | use Fault::ErrorHandler; | ||||||||||
| 61 | $class_object = Fault::ErrorHandler->new; | ||||||||||
| 62 | $flg = Fault::ErrorHandler->warn ($msg); | ||||||||||
| 63 | $flg = $class_object->warn ($msg); | ||||||||||
| 64 | Fault::ErrorHandler->die ($msg); | ||||||||||
| 65 | $class_object->die ($msg); | ||||||||||
| 66 | |||||||||||
| 67 | =head1 Inheritance | ||||||||||
| 68 | |||||||||||
| 69 | Base Class | ||||||||||
| 70 | |||||||||||
| 71 | =head1 Description | ||||||||||
| 72 | |||||||||||
| 73 | This Class does not have instance objects, only a single 'Class Object'. It | ||||||||||
| 74 | is always referenced under the Class name. This makes it very easy for code | ||||||||||
| 75 | at any level or location within a system to send error messages in a | ||||||||||
| 76 | predetermined manner. While this particular class is just a cover for Perl | ||||||||||
| 77 | warn and die, one could subclass it to do just about anything.. | ||||||||||
| 78 | |||||||||||
| 79 | At the moment this class may seem trivial, however the intention is to add | ||||||||||
| 80 | code that will detect and use other methods of warn and die, such as Gtk | ||||||||||
| 81 | dialog panels, if they are present. I will impliment that when I find my | ||||||||||
| 82 | round tuit(*) | ||||||||||
| 83 | |||||||||||
| 84 | * Round tuits were invented by Paula Shubock of CMU in the early 1980's. The | ||||||||||
| 85 | first was a yellow circle with a centered calligraphic 'tuit'! | ||||||||||
| 86 | |||||||||||
| 87 | =head1 Examples | ||||||||||
| 88 | |||||||||||
| 89 | use Fault::ErrorHandler; | ||||||||||
| 90 | my $classobj = Fault::ErrorHandler->new; | ||||||||||
| 91 | my $didwarn = Fault::ErrorHandler->warn ("Dont do that!"); | ||||||||||
| 92 | my $didwarn = $classobj->warn ("Stop it!"); | ||||||||||
| 93 | Fault::ErrorHandler->die ("ARRRGGH!!!"); | ||||||||||
| 94 | $classobj->die ("R.I.P"); | ||||||||||
| 95 | |||||||||||
| 96 | =head1 Instance Variables | ||||||||||
| 97 | |||||||||||
| 98 | None. | ||||||||||
| 99 | |||||||||||
| 100 | =head1 Class Methods | ||||||||||
| 101 | |||||||||||
| 102 | =over 4 | ||||||||||
| 103 | |||||||||||
| 104 | =item B<$class_object = Fault::ErrorHandler-E<gt>new> | ||||||||||
| 105 | |||||||||||
| 106 | Generate the ErrorHandler object if it doesn't exist; otherwise just return | ||||||||||
| 107 | the existing class object. | ||||||||||
| 108 | |||||||||||
| 109 | =item B<$flg = Fault::ErrorHandler-E<gt>warn ($msg)> | ||||||||||
| 110 | |||||||||||
| 111 | =item B<$flg = $class_object-E<gt>warn ($msg)> | ||||||||||
| 112 | |||||||||||
| 113 | Issue the specified warning message and return true if successful. If there | ||||||||||
| 114 | is no message, it prints "<Null warning message>". | ||||||||||
| 115 | |||||||||||
| 116 | =item B<Fault::ErrorHandler-E<gt>die ($msg)> | ||||||||||
| 117 | |||||||||||
| 118 | =item B<$class_object-E<gt>die ($msg)> | ||||||||||
| 119 | |||||||||||
| 120 | Issue the specified die message and then commit hari-kari. If there is no | ||||||||||
| 121 | message, it prints "<Null warning message>". | ||||||||||
| 122 | |||||||||||
| 123 | =back 4 | ||||||||||
| 124 | |||||||||||
| 125 | =head1 Instance Methods | ||||||||||
| 126 | |||||||||||
| 127 | None. | ||||||||||
| 128 | |||||||||||
| 129 | =head1 Private Class Methods | ||||||||||
| 130 | |||||||||||
| 131 | None. | ||||||||||
| 132 | |||||||||||
| 133 | =head1 Private Instance Methods | ||||||||||
| 134 | |||||||||||
| 135 | None. | ||||||||||
| 136 | |||||||||||
| 137 | =head1 Errors and Warnings | ||||||||||
| 138 | |||||||||||
| 139 | None. | ||||||||||
| 140 | |||||||||||
| 141 | =head1 KNOWN BUGS | ||||||||||
| 142 | |||||||||||
| 143 | See TODO. | ||||||||||
| 144 | |||||||||||
| 145 | =head1 SEE ALSO | ||||||||||
| 146 | |||||||||||
| 147 | None. | ||||||||||
| 148 | |||||||||||
| 149 | =head1 AUTHOR | ||||||||||
| 150 | |||||||||||
| 151 | Dale Amon <amon@vnl.com> | ||||||||||
| 152 | |||||||||||
| 153 | =cut | ||||||||||
| 154 | |||||||||||
| 155 | #============================================================================= | ||||||||||
| 156 | # CVS HISTORY | ||||||||||
| 157 | #============================================================================= | ||||||||||
| 158 | # $Log: ErrorHandler.pm,v $ | ||||||||||
| 159 | # Revision 1.6 2008-08-28 23:20:19 amon | ||||||||||
| 160 | # perldoc section regularization. | ||||||||||
| 161 | # | ||||||||||
| 162 | # Revision 1.5 2008-08-17 21:56:37 amon | ||||||||||
| 163 | # Make all titles fit CPAN standard. | ||||||||||
| 164 | # | ||||||||||
| 165 | # Revision 1.4 2008-05-09 18:24:55 amon | ||||||||||
| 166 | # Bugs and changes due to pre-release testing | ||||||||||
| 167 | # | ||||||||||
| 168 | # Revision 1.3 2008-05-07 17:43:05 amon | ||||||||||
| 169 | # Documentation changes | ||||||||||
| 170 | # | ||||||||||
| 171 | # Revision 1.2 2008-05-04 14:34:12 amon | ||||||||||
| 172 | # Tidied up code and docs. | ||||||||||
| 173 | # | ||||||||||
| 174 | # Revision 1.1.1.1 2008-05-02 16:34:37 amon | ||||||||||
| 175 | # Fault and Log System. Pared off of DMA base lib. | ||||||||||
| 176 | # | ||||||||||
| 177 | # Revision 1.7 2008-04-18 14:07:54 amon | ||||||||||
| 178 | # Minor documentation format changes | ||||||||||
| 179 | # | ||||||||||
| 180 | # Revision 1.6 2008-04-18 11:34:39 amon | ||||||||||
| 181 | # Wrote logger delegate abstract superclass to simplify the code in all the | ||||||||||
| 182 | # delegate classes. | ||||||||||
| 183 | # | ||||||||||
| 184 | # Revision 1.5 2008-04-11 22:25:23 amon | ||||||||||
| 185 | # Add blank line after cut. | ||||||||||
| 186 | # | ||||||||||
| 187 | # Revision 1.4 2008-04-11 18:56:35 amon | ||||||||||
| 188 | # Fixed quoting problem with formfeeds. | ||||||||||
| 189 | # | ||||||||||
| 190 | # Revision 1.3 2008-04-11 18:39:15 amon | ||||||||||
| 191 | # Implimented new standard for headers and trailers. | ||||||||||
| 192 | # | ||||||||||
| 193 | # Revision 1.2 2008-04-10 15:01:08 amon | ||||||||||
| 194 | # Added license to headers, removed claim that the documentation section still | ||||||||||
| 195 | # relates to the old doc file. | ||||||||||
| 196 | # | ||||||||||
| 197 | # Revision 1.1.1.1 2004-08-29 21:31:53 amon | ||||||||||
| 198 | # Dale's library of primitives in Perl | ||||||||||
| 199 | # | ||||||||||
| 200 | # 20040813 Dale Amon <amon@vnl.com> | ||||||||||
| 201 | # Moved to DMA:: from Archivist:: | ||||||||||
| 202 | # to make it easier to enforce layers. | ||||||||||
| 203 | # | ||||||||||
| 204 | # 20030108 Dale Amon <amon@vnl.com> | ||||||||||
| 205 | # Created. | ||||||||||
| 206 | 1 | 1; | |||||||||