HTTP::Router::Debug - HTTP::Router::Debug documentation


HTTP-Router documentation Contained in the HTTP-Router distribution.

Index


Code Index:

NAME

Top

HTTP::Router::Debug

SYNOPSIS

Top

    use HTTP::Router;
    use HTTP::Router::Debug;

    my $router = HTTP::Router->define(...);

    print $router->routing_table->draw;
    # or
    $router->show_table;

METHODS

Top

routing_table

Returns a Text::SimpleTable object for routing information.

show_table

Constructs and Prints a table for routing information.

AUTHOR

Top

Takatoshi Kitano <kitano.tk@gmail.com>

NAKAGAWA Masaki <masaki@cpan.org>

LICENSE

Top

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

SEE ALSO

Top

HTTP::Router, Text::SimpleTable


HTTP-Router documentation Contained in the HTTP-Router distribution.

package HTTP::Router::Debug;

use strict;
use warnings;
use Text::SimpleTable;

our @EXPORT = qw(show_table routing_table);

sub import {
    require HTTP::Router;
    no strict 'refs';
    for my $name (@EXPORT) {
        *{"HTTP::Router::$name"} = \&{$name};
    }
}

sub show_table {
    my $table = $_[0]->routing_table->draw;
    print "$table\n";
}

sub routing_table {
    my $self = shift;

    my $table = Text::SimpleTable->new(
        [qw(35 path)      ],
        [qw(10 method)    ],
        [qw(10 controller)],
        [qw(10 action)    ],
    );

    for my $route ($self->routes) {
        my $method = $route->conditions->{method};
        $method = [ $method ] unless ref $method;

        $table->row(
            $route->path,
            join(',', @$method),
            $route->params->{controller},
            $route->params->{action}
        );
    }

    return $table;
}

1;