ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/lib/AnyEvent/Log.pm
(Generate patch)

Comparing AnyEvent/lib/AnyEvent/Log.pm (file contents):
Revision 1.5 by root, Wed Aug 17 22:03:03 2011 UTC vs.
Revision 1.7 by root, Thu Aug 18 18:02:11 2011 UTC

23or package groups. 23or package groups.
24 24
25=head1 LOG FUNCTIONS 25=head1 LOG FUNCTIONS
26 26
27These functions allow you to log messages. They always use the caller's 27These functions allow you to log messages. They always use the caller's
28package as a "logging module/source". Also, The main logging function is 28package as a "logging module/source". Also, the main logging function is
29easily available as C<AnyEvent::log> or C<AE::log> when the C<AnyEvent> 29callable as C<AnyEvent::log> or C<AE::log> when the C<AnyEvent> module is
30module is loaded. 30loaded.
31 31
32=over 4 32=over 4
33 33
34=cut 34=cut
35 35
251=back 251=back
252 252
253=head1 CONFIGURATION FUNCTIONALITY 253=head1 CONFIGURATION FUNCTIONALITY
254 254
255None, yet, except for C<PERL_ANYEVENT_VERBOSE>, described in the L<AnyEvent> manpage. 255None, yet, except for C<PERL_ANYEVENT_VERBOSE>, described in the L<AnyEvent> manpage.
256#TODO
256 257
257=over 4 258=over 4
258 259
259=item $ctx = AnyEvent::Log::ctx [$pkg] 260=item $ctx = AnyEvent::Log::cfg [$pkg]
260 261
261Returns the I<context> object for the given package name (or previously 262Returns a I<config> object for the given package name (or previously
262created package-less context). If no package name, or C<undef>, is given, 263created package-less configuration). If no package name, or C<undef>, is
263then it creates a new anonymous context that is not tied to any package. 264given, then it creates a new anonymous context that is not tied to any
265package.
264 266
265=cut 267=cut
266 268
267sub ctx(;$) { 269sub cfg(;$) {
268 my $name = shift; 270 my $name = shift;
269 271
270 my $ctx = defined $name ? $CTX{$name} : undef; 272 my $ctx = defined $name ? $CTX{$name} : undef;
271 273
272 unless ($ctx} { 274 unless ($ctx) {
273 $ctx = bless {}, "AnyEvent::Log::Ctx"; 275 $ctx = bless {}, "AnyEvent::Log::Ctx";
274 $name = $ctx+0 unless defined $name; 276 $name = -$ctx unless defined $name;
275 $CTX{ 277 $ctx->{name} = $name;
276
277 if (defined $name) {
278 my $ctx = {};
279 $CTX{$ctx+0} = $ctx; 278 $CTX{$name} = $ctx;
280 } else {
281 $CTX{
282 } 279 }
280
281 $ctx
282}
283
284package AnyEvent::Log::Ctx;
285
286sub DESTROY {
287 # if only one member is remaining (name!) then delete this context
288 delete $CTX{$_[0]{name}}
289 if 1 == scalar keys %{ $_[0] };
283} 290}
284 291
2851; 2921;
286 293
287=back 294=back

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines