From: Arthur Axel 'fREW' Schmidt Date: Fri, 19 Feb 2010 23:29:03 +0000 (-0600) Subject: auto sub wrapping X-Git-Tag: v0.00100~29 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=98833ffb46fc58270ddf518f95c6b84db21c249a;p=p5sagit%2FLog-Contextual.git auto sub wrapping --- diff --git a/lib/Log/Contextual.pm b/lib/Log/Contextual.pm index 32f24f0..251c44d 100644 --- a/lib/Log/Contextual.pm +++ b/lib/Log/Contextual.pm @@ -16,8 +16,11 @@ sub set_logger (&) { $Get_Logger = $_[0]; } -sub with_logger (&&) { - local $Get_Logger = $_[0]; +sub with_logger { + my $logger = $_[0]; + $logger = do { my $l = $logger; sub { $l } } + if ref $logger ne 'CODE'; + local $Get_Logger = $logger; $_[1]->(); } diff --git a/t/log.t b/t/log.t index 21b49a1..1ad7cf9 100644 --- a/t/log.t +++ b/t/log.t @@ -10,9 +10,9 @@ my $var_logger2 = VarLogger->new; my $var_logger3 = VarLogger->new; WITHLOGGER: { - with_logger { $var_logger2 } sub { + with_logger sub { $var_logger2 } => sub { - with_logger { $var_logger1 } sub { + with_logger $var_logger1 => sub { log_debug { 'nothing!' } }; log_debug { 'frew!' }; @@ -30,7 +30,7 @@ SETLOGGER: { } SETWITHLOGGER: { - with_logger { $var_logger1 } sub { + with_logger $var_logger1 => sub { log_debug { 'nothing again!' } };