GX::Router

Module Version: 0.2000_01

NAME

GX::Router - Router component

SYNOPSIS

package MyApp::Router;

use GX::Router;

__PACKAGE__->setup(

routes => [
{
controller => 'Blog',
action => 'show_latest',
path => '/blog/latest'
},
{
controller => 'Blog',
action => 'show_post',
path => '/blog/posts/{id}'
}
],

default_action => [ 'Error', 'page_not_found' ]

);

1;

DESCRIPTION

This module provides the GX::Router class which extends the GX::Component::Singleton class.

METHODS

Constructor

new

Returns the router component instance.

$router = $router_class->new;
Returns:
Exceptions:

Public Methods

All public methods can be called both as instance and class methods.

add_route

Registers the given route.

$router->add_route( $route );
Arguments:
Exceptions:

default_action

Returns the default action.

$action = $router->default_action;
Returns:

match

Returns a GX::Route::Match object if one of the registered routes matches the request, otherwise undef.

$result = $router->match( $context );
Arguments:
Returns:

path_for_action

Returns the path portion of an URI that would be routed to the specified action.

$path = $router->path_for_action( %arguments );
Arguments:
  • action ( GX::Action object ) [ required ]

    The action for which to construct the path.

  • parameters ( HASH reference )

    A reference to a hash with values for the dynamic parts of the path.

Returns:
  • $path ( string | undef )
Exceptions:

If no reversible routes are associated with the given action, undef is returned. If the path cannot be constructed (for example if required path parameters are missing), a GX::Exception will be thrown.

Alternative syntax:

$path = $router->path_for_action( $action );
Arguments:
Returns:
  • $path ( string | undef )
Exceptions:

remove_route

Unregisters the specified route.

$router->remove_route( $route );
Arguments:
Exceptions:

routes

Returns the registered routes.

@routes = $router->routes;
Returns:

setup

Sets up the component.

$router->setup( %options );
Options:
  • default_action ( GX::Action object | ARRAY reference )

    A default action.

  • routes ( ARRAY reference )

    A reference to an array with route definitions. Routes defined here have the highest priority.

Exceptions:

uri_for_action

Constructs an URI that would be routed to the specified action.

$uri = $router->uri_for_action( %arguments );
Arguments:
  • action ( GX::Action object ) [ required ]

    The action for which to construct the URI.

Additional, route-dependent arguments:
  • fragment ( string )

    The fragment identifier of the URI.

  • host ( string )

    The hostname to use as the authority component of the URI.

  • parameters ( HASH reference )

    A reference to a hash with values for the dynamic parts of the URI.

  • path ( string )

    The path portion of the URI.

  • port ( integer )

    The port number to append to the hostname.

  • query ( string )

    The query component of the URI.

  • scheme ( string )

    The scheme part of the URI. Defaults to "http".

Returns:
  • $uri ( string | undef )
Exceptions:

If no reversible routes are associated with the specified action, undef is returned. If the URI cannot be constructed (for example if required path parameters are missing), a GX::Exception will be thrown.

Alternative syntax:

$uri = $router->uri_for_action( $action );
Arguments:
Returns:
  • $uri ( string | undef )
Exceptions:

Internal Methods

resolve

Handler.

$router->resolve( $context );
Arguments:

AUTHOR

Jörg A. Uzarek <uzarek@runlevelnull.de>

COPYRIGHT AND LICENSE

Copyright © 2009-2011 Jörg A. Uzarek.

This module is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License Version 3 as published by the Free Software Foundation.