File Coverage

lib/Log/Message/Handlers.pm
Criterion Covered Total %
statement 10 23 43.4
branch n/a
condition n/a
subroutine 4 11 36.3
pod 8 8 100.0
total 22 42 52.3


line stmt bran cond sub pod time code
1             package Log::Message::Handlers;
2 2     2   14 use if $] > 5.017, 'deprecate';
  2         4  
  2         13  
3 2     2   462 use strict;
  2         5  
  2         89  
4 2     2   11 use vars qw[$VERSION];
  2         3  
  2         1084  
5              
6             $VERSION = '0.08';
7              
8             =pod
9              
10             =head1 NAME
11              
12             Log::Message::Handlers - Message handlers for Log::Message
13              
14             =head1 SYNOPSIS
15              
16             # Implicitly used by Log::Message to serve as handlers for
17             # Log::Message::Item objects
18              
19             # Create your own file with a package called
20             # Log::Message::Handlers to add to the existing ones, or to even
21             # overwrite them
22              
23             $item->carp;
24              
25             $item->trace;
26              
27              
28             =head1 DESCRIPTION
29              
30             Log::Message::Handlers provides handlers for Log::Message::Item objects.
31             The handler corresponding to the level (see Log::Message::Item manpage
32             for an explanation about levels) will be called automatically upon
33             storing the error.
34              
35             Handlers may also explicitly be called on an Log::Message::Item object
36             if one so desires (see the Log::Message manpage on how to retrieve the
37             Item objects).
38              
39             =head1 Default Handlers
40              
41             =head2 log
42              
43             Will simply log the error on the stack, and do nothing special
44              
45             =cut
46              
47 4     4 1 14 sub log { 1 }
48              
49             =head2 carp
50              
51             Will carp (see the Carp manpage) with the error, and add the timestamp
52             of when it occurred.
53              
54             =cut
55              
56             sub carp {
57 0     0 1   my $self = shift;
58 0           warn join " ", $self->message, $self->shortmess, 'at', $self->when, "\n";
59             }
60              
61             =head2 croak
62              
63             Will croak (see the Carp manpage) with the error, and add the
64             timestamp of when it occurred.
65              
66             =cut
67              
68             sub croak {
69 0     0 1   my $self = shift;
70 0           die join " ", $self->message, $self->shortmess, 'at', $self->when, "\n";
71             }
72              
73             =head2 cluck
74              
75             Will cluck (see the Carp manpage) with the error, and add the
76             timestamp of when it occurred.
77              
78             =cut
79              
80             sub cluck {
81 0     0 1   my $self = shift;
82 0           warn join " ", $self->message, $self->longmess, 'at', $self->when, "\n";
83             }
84              
85             =head2 confess
86              
87             Will confess (see the Carp manpage) with the error, and add the
88             timestamp of when it occurred
89              
90             =cut
91              
92             sub confess {
93 0     0 1   my $self = shift;
94 0           die join " ", $self->message, $self->longmess, 'at', $self->when, "\n";
95             }
96              
97             =head2 die
98              
99             Will simply die with the error message of the item
100              
101             =cut
102              
103 0     0 1   sub die { die shift->message; }
104              
105              
106             =head2 warn
107              
108             Will simply warn with the error message of the item
109              
110             =cut
111              
112 0     0 1   sub warn { warn shift->message; }
113              
114              
115             =head2 trace
116              
117             Will provide a traceback of this error item back to the first one that
118             occurred, clucking with every item as it comes across it.
119              
120             =cut
121              
122             sub trace {
123 0     0 1   my $self = shift;
124              
125 0           for my $item( $self->parent->retrieve( chrono => 0 ) ) {
126 0           $item->cluck;
127             }
128             }
129              
130             =head1 Custom Handlers
131              
132             If you wish to provide your own handlers, you can simply do the
133             following:
134              
135             =over 4
136              
137             =item *
138              
139             Create a file that holds a package by the name of
140             C
141              
142             =item *
143              
144             Create subroutines with the same name as the levels you wish to
145             handle in the Log::Message module (see the Log::Message manpage for
146             explanation on levels)
147              
148             =item *
149              
150             Require that file in your program, or add it in your configuration
151             (see the Log::Message::Config manpage for explanation on how to use a
152             config file)
153              
154             =back
155              
156             And that is it, the handler will now be available to handle messages
157             for you.
158              
159             The arguments a handler may receive are those specified by the
160             C key, when storing the message.
161             See the Log::Message manpage for details on the arguments.
162              
163             =head1 SEE ALSO
164              
165             L, L, L
166              
167             =head1 AUTHOR
168              
169             This module by
170             Jos Boumans Ekane@cpan.orgE.
171              
172             =head1 Acknowledgements
173              
174             Thanks to Ann Barcomb for her suggestions.
175              
176             =head1 COPYRIGHT
177              
178             This module is
179             copyright (c) 2002 Jos Boumans Ekane@cpan.orgE.
180             All rights reserved.
181              
182             This library is free software;
183             you may redistribute and/or modify it under the same
184             terms as Perl itself.
185              
186             =cut
187              
188             1;
189              
190             # Local variables:
191             # c-indentation-style: bsd
192             # c-basic-offset: 4
193             # indent-tabs-mode: nil
194             # End:
195             # vim: expandtab shiftwidth=4: