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