check for with/set_logger at import time
Arthur Axel 'fREW' Schmidt [Fri, 11 Jan 2013 01:45:28 +0000 (19:45 -0600)]
lib/Log/Contextual.pm

index 9e8ca08..e5ea999 100644 (file)
@@ -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) {