NAME

Thunderhorse::Router::Location - Router location implementation

SYNOPSIS

# locations are typically created through the router
$router->add('/path/:id' => {
	to => 'handler',
	action => 'http.get',
	order => 10,
	pagi_middleware => sub ($app) { ... },
});

DESCRIPTION

This class represents a single routing location in Thunderhorse. It extends Gears::Router::Location::SigilMatch to add Thunderhorse-specific functionality like action filtering, PAGI app support, and middleware wrapping. Locations are created by the router and handle matching URL patterns to controller actions.

INTERFACE

Inherits all interface from Gears::Router::Location, and adds the interface documented below.

Attributes

action

Action pattern to match. Format is scope.method where both parts can be wildcards *. If not passed, any action will match successfully.

Available in constructor

name

The name of this location. Auto-generated if not provided, based on action and pattern.

Name must be unique and deterministic. Names which are auto-generated are always unique, but they are only deterministic if the locations are built in a deterministic manner. Non-deterministic locations may cause problems when caching with multiple workers.

Available in constructor

to

The destination for this location. Can be a code reference or a string naming a method in the controller. If not provided, the location is considered to be unimplemented - nothing will get run if it gets matched, but "pagi_middleware" will still get executed. Having unimplemented bridges is considered a valid use case for this behavior.

Available in constructor

order

Integer controlling the order in which locations are matched. Lower numbers are matched first. Default is 0.

Available in constructor

pagi

Boolean indicating whether the to destination is a native PAGI application. Default is false. Must be manually set to true if the intent is to have a PAGI application handling the route - there is currently no autodetection of PAGI apps.

Available in constructor

pagi_middleware

Code reference that wraps the location's PAGI app in middleware. The code ref receives the PAGI app as an argument and should return a wrapped PAGI app.

Available in constructor

controller

The controller instance in which context this location will be executed.

Available in constructor

pagi_app

The built PAGI application for this location. Built lazily by combining the destination handler with any middleware. This is the actual entry point that gets called when the location matches.

Methods

new

$object = $class->new(%args)

Standard Mooish constructor. Consult "Attributes" section for available constructor arguments.

get_destination

$coderef = $object->get_destination()

Returns the destination code reference for this location. If to is already a code reference, returns it directly. If to is a string, looks up the method on the controller. Returns undef if no destination is set.

SEE ALSO

Thunderhorse::Router, Gears::Router::Location::SigilMatch