From: Arthur Axel 'fREW' Schmidt Date: Sat, 3 Nov 2012 06:20:38 +0000 (-0500) Subject: factor can checks out into roles X-Git-Tag: v0.005000_01~14 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=1df0e2c465ddcaeab2a4acf89658ab13e32fc8ca;p=p5sagit%2FLog-Contextual.git factor can checks out into roles --- diff --git a/lib/Log/Contextual.pm b/lib/Log/Contextual.pm index 0296af3..70348b6 100644 --- a/lib/Log/Contextual.pm +++ b/lib/Log/Contextual.pm @@ -108,22 +108,20 @@ sub after_import { return arg_router()->after_import(@_) } sub set_logger { my $router = arg_router(); - my $meth = $router->can('set_logger'); die ref($router) . " does not support set_logger()" - unless defined $meth; + unless $router->does('Log::Contextual::Role::Router::SetLogger'); - return $router->$meth(@_); + return $router->set_logger(@_); } sub with_logger { my $router = arg_router(); - my $meth = $router->can('with_logger'); die ref($router) . " does not support with_logger()" - unless defined $meth; + unless $router->does('Log::Contextual::Role::Router::WithLogger'); - return $router->$meth(@_); + return $router->with_logger(@_); } 1; diff --git a/lib/Log/Contextual/Role/Router/SetLogger.pm b/lib/Log/Contextual/Role/Router/SetLogger.pm new file mode 100644 index 0000000..cebe6c5 --- /dev/null +++ b/lib/Log/Contextual/Role/Router/SetLogger.pm @@ -0,0 +1,8 @@ +package Log::Contextual::Role::Router::SetLogger; + +use Moo::Role; + +requires 'set_logger'; + +1; + diff --git a/lib/Log/Contextual/Role/Router/WithLogger.pm b/lib/Log/Contextual/Role/Router/WithLogger.pm new file mode 100644 index 0000000..7268937 --- /dev/null +++ b/lib/Log/Contextual/Role/Router/WithLogger.pm @@ -0,0 +1,8 @@ +package Log::Contextual::Role::Router::WithLogger; + +use Moo::Role; + +requires 'with_logger'; + +1; + diff --git a/lib/Log/Contextual/Router.pm b/lib/Log/Contextual/Router.pm index 09235ac..08e4577 100644 --- a/lib/Log/Contextual/Router.pm +++ b/lib/Log/Contextual/Router.pm @@ -3,7 +3,9 @@ package Log::Contextual::Router; use Moo; use Scalar::Util 'blessed'; -with 'Log::Contextual::Role::Router'; +with 'Log::Contextual::Role::Router', + 'Log::Contextual::Role::Router::SetLogger', + 'Log::Contextual::Role::Router::WithLogger'; eval { require Log::Log4perl;