summary refs log tree commit diff
diff options
context:
space:
mode:
authorfranck cuny <franck@lumberjaph.net>2010-04-18 11:46:33 +0200
committerfranck cuny <franck@lumberjaph.net>2010-04-18 11:46:33 +0200
commiteb4db48d0e65a3c7c23b7372566fa7121f0cd574 (patch)
tree733db3456f1b81203f4c8663f7b0c304854bb474
parentinitial commit (diff)
downloaddancer-debug-eb4db48d0e65a3c7c23b7372566fa7121f0cd574.tar.gz
some dancer specific panel for debugging
-rw-r--r--lib/Dancer/Debug.pm14
-rw-r--r--lib/Plack/Middleware/Debug/Dancer/Logger.pm49
-rw-r--r--lib/Plack/Middleware/Debug/Dancer/Session.pm18
-rw-r--r--lib/Plack/Middleware/Debug/Dancer/Settings.pm30
-rw-r--r--lib/Plack/Middleware/Debug/Dancer/Version.pm15
-rw-r--r--lib/Plack/Middleware/Debug/Dancer/logs/production.log16
6 files changed, 140 insertions, 2 deletions
diff --git a/lib/Dancer/Debug.pm b/lib/Dancer/Debug.pm
index dea1d82..4d0f7f0 100644
--- a/lib/Dancer/Debug.pm
+++ b/lib/Dancer/Debug.pm
@@ -9,11 +9,21 @@ __END__
 
 =head1 NAME
 
-Dancer::Debug -
+Dancer::Debug - Extension for Dancer specific panel to L<Plack::Middleware::Debug>
 
 =head1 SYNOPSIS
 
-  use Dancer::Debug;
+    my $handler = sub {
+        my $env     = shift;
+        my $request = Dancer::Request->new($env);
+        Dancer->dance($request);
+    };
+
+    $handler = builder {
+        enable "Debug",
+            panels => [qw/Dancer::Settings Dancer::Logger Parameters Dancer::Version/];
+        $handler;
+    };
 
 =head1 DESCRIPTION
 
diff --git a/lib/Plack/Middleware/Debug/Dancer/Logger.pm b/lib/Plack/Middleware/Debug/Dancer/Logger.pm
new file mode 100644
index 0000000..3fdc4e9
--- /dev/null
+++ b/lib/Plack/Middleware/Debug/Dancer/Logger.pm
@@ -0,0 +1,49 @@
+package Plack::Middleware::Debug::Dancer::Logger;
+use 5.008;
+use strict;
+use warnings;
+use parent qw(Plack::Middleware::Debug::Base);
+use Dancer::Logger;
+use Class::Method::Modifiers qw(install_modifier);
+our $VERSION = '0.07';
+
+# 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;
+    $psgi_env->{'plack.middleware.dancer_log'} .= "[warning] $_[0]\n";
+    $self->$orig(@_);
+};
+
+install_modifier 'Dancer::Logger', 'around', 'error' => sub {
+    my $orig = shift;
+    my $self = shift;
+    $psgi_env->{'plack.middleware.dancer_log'} .= "[error] $_[0]\n";
+    $self->$orig(@_);
+};
+
+install_modifier 'Dancer::Logger', 'around', 'debug' => sub {
+    my $orig = shift;
+    my $self = shift;
+    $psgi_env->{'plack.middleware.dancer_log'} .= "[debug] $_[0]\n";
+    $self->$orig(@_);
+};
+
+sub run {
+    my($self, $env, $panel) = @_;
+    $psgi_env = $env;
+
+    return sub {
+        my $res = shift;
+
+        my $log = delete $env->{'plack.middleware.dancer_log'};
+        if ($log) {
+            $panel->content("<pre>$log</pre>");
+        }
+        $psgi_env = undef;
+    };
+}
+
+1;
+__END__
diff --git a/lib/Plack/Middleware/Debug/Dancer/Session.pm b/lib/Plack/Middleware/Debug/Dancer/Session.pm
new file mode 100644
index 0000000..055676a
--- /dev/null
+++ b/lib/Plack/Middleware/Debug/Dancer/Session.pm
@@ -0,0 +1,18 @@
+package Plack::Middleware::Debug::Dancer::Session;
+use 5.008;
+use strict;
+use warnings;
+use parent qw(Plack::Middleware::Debug::Base);
+use Dancer::Session;
+
+sub run {
+    my ( $self, $env, $panel ) = @_;
+
+    return sub {
+        my $session = Dancer::Session->get();
+        my @settings = map { $_ => $session->{$_}} keys %$session;
+        $panel->content( sub { $self->render_list_pairs( \@settings ) } );
+    };
+}
+
+1;
diff --git a/lib/Plack/Middleware/Debug/Dancer/Settings.pm b/lib/Plack/Middleware/Debug/Dancer/Settings.pm
new file mode 100644
index 0000000..cf10748
--- /dev/null
+++ b/lib/Plack/Middleware/Debug/Dancer/Settings.pm
@@ -0,0 +1,30 @@
+package Plack::Middleware::Debug::Dancer::Settings;
+use 5.008;
+use strict;
+use warnings;
+use parent qw(Plack::Middleware::Debug::Base);
+use Class::Method::Modifiers qw/install_modifier/;
+use Dancer::Config;
+
+#my $psgi_env;
+# install_modifier 'Dancer', 'around', 'start' => sub {
+#     my $orig = shift;
+#     my $self = shift;
+#     $psgi_env->{'plack.middleware.dancer_settings'} = $self->config;
+#     $self->$orig(@_);
+# };
+
+sub run {
+    my ( $self, $env, $panel ) = @_;
+#    $psgi_env = $env;
+
+    return sub {
+        my $res = shift;
+        my $settings = Dancer::Config->settings();
+#        my $settings = $env->{'plack.middleware.dancer_settings'};
+        my @settings = map { $_ => $settings->{$_}} keys %$settings;
+        $panel->content( sub { $self->render_list_pairs( \@settings ) } );
+    };
+}
+
+1;
diff --git a/lib/Plack/Middleware/Debug/Dancer/Version.pm b/lib/Plack/Middleware/Debug/Dancer/Version.pm
new file mode 100644
index 0000000..fe05275
--- /dev/null
+++ b/lib/Plack/Middleware/Debug/Dancer/Version.pm
@@ -0,0 +1,15 @@
+package Plack::Middleware::Debug::Dancer::Version;
+use 5.008;
+use strict;
+use warnings;
+use parent qw(Plack::Middleware::Debug::Base);
+
+sub run {
+    my ( $self, $env, $panel ) = @_;
+
+    return sub {
+        $panel->nav_subtitle($Dancer::VERSION);
+    };
+}
+
+1;
diff --git a/lib/Plack/Middleware/Debug/Dancer/logs/production.log b/lib/Plack/Middleware/Debug/Dancer/logs/production.log
new file mode 100644
index 0000000..8ebe41b
--- /dev/null
+++ b/lib/Plack/Middleware/Debug/Dancer/logs/production.log
@@ -0,0 +1,16 @@
+[30912]  warn @0.000413> [hit #1] THIS IS A LOG in /home/franck/perl5/perlbrew/perls/perl-5.12.0/lib/site_perl/5.12.0/Class/Method/Modifiers.pm l. 74
+[30912] error @0.000553> [hit #1] THIS IS AN ERROR in /home/franck/perl5/perlbrew/perls/perl-5.12.0/lib/site_perl/5.12.0/Class/Method/Modifiers.pm l. 74
+[30912]  warn @0.000390> [hit #4] THIS IS A LOG in /home/franck/perl5/perlbrew/perls/perl-5.12.0/lib/site_perl/5.12.0/Class/Method/Modifiers.pm l. 74
+[30912] error @0.000515> [hit #4] THIS IS AN ERROR in /home/franck/perl5/perlbrew/perls/perl-5.12.0/lib/site_perl/5.12.0/Class/Method/Modifiers.pm l. 74
+[30912]  warn @0.000402> [hit #6] THIS IS A LOG in /home/franck/perl5/perlbrew/perls/perl-5.12.0/lib/site_perl/5.12.0/Class/Method/Modifiers.pm l. 74
+[30912] error @0.000521> [hit #6] THIS IS AN ERROR in /home/franck/perl5/perlbrew/perls/perl-5.12.0/lib/site_perl/5.12.0/Class/Method/Modifiers.pm l. 74
+[30912]  warn @0.000434> [hit #8] THIS IS A LOG in /home/franck/perl5/perlbrew/perls/perl-5.12.0/lib/site_perl/5.12.0/Class/Method/Modifiers.pm l. 74
+[30912] error @0.000558> [hit #8] THIS IS AN ERROR in /home/franck/perl5/perlbrew/perls/perl-5.12.0/lib/site_perl/5.12.0/Class/Method/Modifiers.pm l. 74
+[30912]  warn @0.000420> [hit #9] THIS IS A LOG in /home/franck/perl5/perlbrew/perls/perl-5.12.0/lib/site_perl/5.12.0/Class/Method/Modifiers.pm l. 74
+[30912] error @0.000549> [hit #9] THIS IS AN ERROR in /home/franck/perl5/perlbrew/perls/perl-5.12.0/lib/site_perl/5.12.0/Class/Method/Modifiers.pm l. 74
+[30991]  warn @0.000388> [hit #1] THIS IS A LOG in /home/franck/perl5/perlbrew/perls/perl-5.12.0/lib/site_perl/5.12.0/Class/Method/Modifiers.pm l. 74
+[30991] error @0.001183> [hit #1] THIS IS AN ERROR in /home/franck/perl5/perlbrew/perls/perl-5.12.0/lib/site_perl/5.12.0/Class/Method/Modifiers.pm l. 74
+[31205]  warn @0.000421> [hit #1] THIS IS A LOG in /home/franck/perl5/perlbrew/perls/perl-5.12.0/lib/site_perl/5.12.0/Class/Method/Modifiers.pm l. 74
+[31205] error @0.000535> [hit #1] THIS IS AN ERROR in /home/franck/perl5/perlbrew/perls/perl-5.12.0/lib/site_perl/5.12.0/Class/Method/Modifiers.pm l. 74
+[31260]  warn @0.000435> [hit #1] THIS IS A LOG in /home/franck/perl5/perlbrew/perls/perl-5.12.0/lib/site_perl/5.12.0/Class/Method/Modifiers.pm l. 74
+[31260] error @0.000549> [hit #1] THIS IS AN ERROR in /home/franck/perl5/perlbrew/perls/perl-5.12.0/lib/site_perl/5.12.0/Class/Method/Modifiers.pm l. 74