From: Arthur Axel 'fREW' Schmidt Date: Fri, 11 Jan 2013 01:45:28 +0000 (-0600) Subject: check for with/set_logger at import time X-Git-Tag: v0.005000_01~3 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=84d7d9ee2754784b80f49f2456a49429086821e3;p=p5sagit%2FLog-Contextual.git check for with/set_logger at import time --- diff --git a/lib/Log/Contextual.pm b/lib/Log/Contextual.pm index 9e8ca08..e5ea999 100644 --- a/lib/Log/Contextual.pm +++ b/lib/Log/Contextual.pm @@ -55,27 +55,19 @@ sub before_import { $router->before_import(%router_args); - $spec->add_export( - '&set_logger', - sub { - my $router = $class->router; + if ($exports->{'&set_logger'}) { + die ref($router) . " does not support set_logger()" + unless $router->does('Log::Contextual::Role::Router::SetLogger'); - die ref($router) . " does not support set_logger()" - unless $router->does('Log::Contextual::Role::Router::SetLogger'); - - return $router->set_logger(@_); - }) if $exports->{'&set_logger'}; - - $spec->add_export( - '&with_logger', - sub { - my $router = $class->router; + $spec->add_export('&set_logger', sub { $router->set_logger(@_) }) + } - die ref($router) . " does not support with_logger()" - unless $router->does('Log::Contextual::Role::Router::WithLogger'); + if ($exports->{'&with_logger'}) { + die ref($router) . " does not support with_logger()" + unless $router->does('Log::Contextual::Role::Router::WithLogger'); - return $router->with_logger(@_); - }) if $exports->{'&with_logger'}; + $spec->add_export('&with_logger', sub { $router->with_logger(@_) }) + } my @levels = @{$class->arg_levels($spec->config->{levels})}; for my $level (@levels) {