… | |
… | |
23 | or package groups. |
23 | or package groups. |
24 | |
24 | |
25 | =head1 LOG FUNCTIONS |
25 | =head1 LOG FUNCTIONS |
26 | |
26 | |
27 | These functions allow you to log messages. They always use the caller's |
27 | These functions allow you to log messages. They always use the caller's |
28 | package as a "logging module/source". Also, The main logging function is |
28 | package as a "logging module/source". Also, the main logging function is |
29 | easily available as C<AnyEvent::log> or C<AE::log> when the C<AnyEvent> |
29 | callable as C<AnyEvent::log> or C<AE::log> when the C<AnyEvent> module is |
30 | module is loaded. |
30 | loaded. |
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 | |
255 | None, yet, except for C<PERL_ANYEVENT_VERBOSE>, described in the L<AnyEvent> manpage. |
255 | None, 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 | |
261 | Returns the I<context> object for the given package name (or previously |
262 | Returns a I<config> object for the given package name (or previously |
262 | created package-less context). If no package name, or C<undef>, is given, |
263 | created package-less configuration). If no package name, or C<undef>, is |
263 | then it creates a new anonymous context that is not tied to any package. |
264 | given, then it creates a new anonymous context that is not tied to any |
|
|
265 | package. |
264 | |
266 | |
265 | =cut |
267 | =cut |
266 | |
268 | |
267 | sub ctx(;$) { |
269 | sub 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 | |
|
|
284 | package AnyEvent::Log::Ctx; |
|
|
285 | |
|
|
286 | sub 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 | |
285 | 1; |
292 | 1; |
286 | |
293 | |
287 | =back |
294 | =back |