summary refs log tree commit diff
path: root/lib/Plack/Middleware/Debug/Dancer/Routes.pm
blob: aeed51656fbd788962ee8961009013adc16fadd0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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);

sub run {
    my ( $self, $env, $panel ) = @_;

    return sub {
        my $hash_routes = {};
        foreach my $app ( Dancer::App->applications ) {
            my $routes = $app->{registry}->{routes};
            foreach my $method (keys %$routes) {
                foreach (@{$routes->{$method}}) {
                    $hash_routes->{$method}->{$_->{_compiled_regexp}} = $_->{_params};
                }
            }
                # 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;

=head1 SYNOPSIS

To activate this panel:

    plack_middlewares:
      Debug:
        - panels
        -
          - Dancer::Routes