Marquee Marquee::Plugin::Router - Route generator and container

TABLE OF CONTENTS

NAME

Marquee::Plugin::Router - Route generator and container

SYNOPSIS

my $r = Marquee::Plugin::Router::Route->new;
$r->route(qr{^/index\.html})->to(sub {
    ...
});

$r->route(qr{^/special\.html})->to(sub {
    ...
});

$r->route(qr{^/capture/(.+)-(.+)\.html})->to(sub {
    my ($a, $b) = @_;
    ...
});

$r->route(qr{^/rare/})->via('GET', 'POST')->to(sub {
    ...
});

$r->route(qr{^/rare/})->viax('POST')->to(sub {
    ...
});

$r->route(qr{^/rare/})->viax('post')->to(sub {
    ...
});

$r->route(qr{^/default})->to(sub {
    ...
});

my $bridge = $r->bridge(sub {
    return 1; # or 0
});

$bridge->route(qr{})->to(sub {...});

DESCRIPTION

Marquee::Plugin::Router is a class for generating and storing routes.

ATTRIBUTES

Marquee::Plugin::Router implements the following attributes.

elems

Route entries.

my $elems = $r->elems;

INSTANCE METHODS

Marquee::Plugin::Router implements the following instance methods.

bridge

my $bridge = $r->bridge(sub {
    my $c = Marquee->c;
    return $bool;
});

route

Set a regex that matches to request URI.

$r->route(qr{^/index\.html});

to

Set an action to invoke when the route matches.

$r->to(sub {...});

via

Filters route by HTTP method.

$r->via('GET', 'POST');

viax

Filters route by HTTP method exclusively. The method adds two routes at once which restricts the HTTP method to given one.

$r->route(qr{^/receptor})->viax('POST')->to(sub {...});

# equivalent to..

$r->route(qr{^/receptor})->via('POST')->to(sub {...});
$r->route(qr{^/receptor})->to(sub {
    my $c = Marquee->c;
    $c->app->error_document->serve(404);
});

SEE ALSO

Marquee::Plugin::Router, Marquee, Mojolicious