From a9f75bfcfa2a3f9daac927ddfe047e439eb6fad3 Mon Sep 17 00:00:00 2001 From: franck cuny Date: Mon, 2 Aug 2010 21:24:24 +0200 Subject: don't need around, before is enough; don't render log if none --- lib/Plack/Middleware/Debug/Dancer/Logger.pm | 30 +++++++++++------------------ 1 file changed, 11 insertions(+), 19 deletions(-) (limited to 'lib/Plack/Middleware') diff --git a/lib/Plack/Middleware/Debug/Dancer/Logger.pm b/lib/Plack/Middleware/Debug/Dancer/Logger.pm index 487967c..368c62a 100644 --- a/lib/Plack/Middleware/Debug/Dancer/Logger.pm +++ b/lib/Plack/Middleware/Debug/Dancer/Logger.pm @@ -8,27 +8,18 @@ use parent qw(Plack::Middleware::Debug::Base); use Dancer::Logger; use Class::Method::Modifiers qw(install_modifier); -# XXX Not thread/Coro/AE safe. Should use $c->env or something +# # XXX Not thread/Coro/AE safe. Should use $c->env or something my $psgi_env; -install_modifier 'Dancer::Logger', 'around', 'warning' => sub { - my $orig = shift; - my $self = shift; - _add_log( 'warning', $_[0] ); - $self->$orig(@_); +install_modifier 'Dancer::Logger', 'before', 'error' => sub { + _add_log( 'error', @_ ); }; -install_modifier 'Dancer::Logger', 'around', 'error' => sub { - my $orig = shift; - my $self = shift; - _add_log( 'error', $_[0] ); - $self->$orig(@_); +install_modifier 'Dancer::Logger', 'before', 'warning' => sub { + _add_log( 'warning', @_ ); }; -install_modifier 'Dancer::Logger', 'around', 'debug' => sub { - my $orig = shift; - my $self = shift; - _add_log( 'debug', $_[0] ); - $self->$orig(@_); +install_modifier 'Dancer::Logger', 'before', 'debug' => sub { + _add_log( 'debug', @_ ); }; sub _add_log { @@ -42,15 +33,16 @@ sub run { return sub { my $res = shift; - $panel->title('Dancer::Logger'); $panel->nav_subtitle('Dancer::Logger'); - my $logs = delete $env->{'plack.middleware.dancer_log'}; - $panel->content( sub { $self->render_list_pairs($logs) } ); + my $logs = delete $env->{'plack.middleware.dancer_log'} + if $env->{'plack.middleware.dancer_log'}; + $panel->content( sub { $self->render_list_pairs($logs) } ) if $logs; $psgi_env = undef; }; } + 1; =head1 SYNOPSIS -- cgit 1.4.1