summary refs log tree commit diff
path: root/lib/Plack/Middleware
diff options
context:
space:
mode:
authorfranck cuny <franck@lumberjaph.net>2010-07-26 23:06:37 +0200
committerfranck cuny <franck@lumberjaph.net>2010-07-26 23:06:37 +0200
commit44bc04de7ea88e73809520c4e0262587d277c9f9 (patch)
treedf1a0cfd5bf2d4e4b97d7ee0ccd4c328b47cfb52 /lib/Plack/Middleware
parentswitch do dist.ini (diff)
downloaddancer-debug-44bc04de7ea88e73809520c4e0262587d277c9f9.tar.gz
add new panel: routes (display a list of routes availabe in your application)
Diffstat (limited to 'lib/Plack/Middleware')
-rw-r--r--lib/Plack/Middleware/Debug/Dancer/Routes.pm38
1 files changed, 38 insertions, 0 deletions
diff --git a/lib/Plack/Middleware/Debug/Dancer/Routes.pm b/lib/Plack/Middleware/Debug/Dancer/Routes.pm
new file mode 100644
index 0000000..8d24e57
--- /dev/null
+++ b/lib/Plack/Middleware/Debug/Dancer/Routes.pm
@@ -0,0 +1,38 @@
+package Plack::Middleware::Debug::Dancer::Routes;
+
+# ABSTRACT: Show available and matched routes for your application
+
+use strict;
+use warnings;
+use parent qw(Plack::Middleware::Debug::Base);
+use Dancer::Session;
+
+sub run {
+    my ( $self, $env, $panel ) = @_;
+
+    return sub {
+        my $routes = Dancer::Route::Registry->routes();
+        my $hash_routes;
+
+        foreach my $method ( keys %$routes ) {
+            map {
+                my $name = $_->{method} . ' ' . $_->{route};
+                $hash_routes->{$name} = {
+                    method  => $_->{method},
+                    options => $_->{options},
+                    params  => $_->{params},
+                    route   => $_->{route}
+                };
+            } @{ $routes->{$method} };
+        }
+
+        $panel->title('Dancer::Route');
+        $panel->nav_subtitle(
+            "Dancer::Route (" . ( keys %$hash_routes ) . ")" );
+        $panel->content(
+            sub { $self->render_hash( $hash_routes, [ keys %$hash_routes ] ) }
+        );
+    };
+}
+
+1;