GX::Route::Dynamic - Dynamic route class
# Load the class use GX::Route::Dynamic; # Create a route object $route = GX::Route::Dynamic->new( action => $application->action( 'Blog', 'show' ), host => 'myblog.com', path => '/posts/{id:\d+}' );
This module provides the GX::Route::Dynamic class which extends the GX::Route class.
new
Returns a new GX::Route::Dynamic object.
$route = GX::Route::Dynamic->new( %attributes );
action ( GX::Action object ) [ required ]
action
The associated action.
constraints ( HASH reference )
constraints
HASH
A reference to a hash with constraints for the route's dynamic parts.
defaults ( HASH reference )
defaults
A reference to a hash with default values for the route's dynamic parts.
host ( string )
host
The hostname pattern to bind the route to. If omitted, the route will match any hostname.
is_reversible ( bool )
is_reversible
A boolean flag indicating whether the route is reversible or not. Defaults to true.
methods ( ARRAY reference )
methods
ARRAY
A reference to an array with the names of the HTTP methods to bind the route to. If omitted, the route will match any method.
path ( string )
path
The path pattern to bind the route to. If omitted, the route will match any path. Trailing slashes are significant.
schemes ( ARRAY reference )
schemes
A reference to an array with the URI schemes to bind the route to. If omitted, the route will match any scheme.
host_regex ( Regexp )
host_regex
Regexp
host_variables ( ARRAY reference )
host_variables
methods_regex ( Regexp )
methods_regex
path_regex ( Regexp )
path_regex
path_variables ( ARRAY reference )
path_variables
reverse_host ( string )
reverse_host
reverse_host_variables ( ARRAY reference )
reverse_host_variables
reverse_path ( string )
reverse_path
reverse_path_variables ( ARRAY reference )
reverse_path_variables
reverse_scheme ( string )
reverse_scheme
schemes_regex ( Regexp )
schemes_regex
$route ( GX::Route::Dynamic object )
$route
GX::Exception
Returns the associated action.
$action = $route->action;
$action ( GX::Action object )
$action
construct_path
Constructs the path portion of an URI that would match the route.
$path = $route->construct_path( %parameters );
%parameters ( named list )
%parameters
Values for the dynamic parts of the path.
$path ( string )
$path
Also see Example #4 below.
construct_uri
Constructs an URI that would match the route.
$uri = $route->construct_uri( %arguments );
fragment ( string )
fragment
The fragment identifier of the URI.
The hostname to use as the authority component of the URI. Defaults to the reverse_host attribute.
parameters ( HASH reference )
parameters
A reference to a hash with values for the dynamic parts of the URI.
The path portion of the URI. Defaults to the reverse_path attribute.
port ( integer )
port
The port number to append to the hostname.
query ( string )
query
The query component of the URI.
scheme ( string )
scheme
The scheme part of the URI. Defaults to the reverse_scheme attribute. "http" is assumed as a fallback.
$uri ( string )
$uri
Returns true if the route is reversible, otherwise false.
$result = $route->is_reversible;
$result ( bool )
$result
match
Returns a GX::Route::Match object if the route matches, otherwise undef.
undef
$result = $route->match( $context );
$context ( GX::Context object )
$context
$result ( GX::Route::Match object | undef )
Internal method.
%constraints = $route->constraints;
%constraints ( named list )
%constraints
%defaults = $route->defaults;
%defaults ( named list )
%defaults
$host = $route->host;
$host ( string | undef )
$host
$host_regex = $route->host_regex;
$host_regex ( Regexp | undef )
$host_regex
@host_variables = $route->host_variables;
@host_variables ( strings )
@host_variables
@methods = $route->methods;
@methods ( strings )
@methods
$methods_regex = $route->methods_regex;
$methods_regex ( Regexp | undef )
$methods_regex
$path = $route->path;
$path ( string | undef )
$path_regex = $route->path_regex;
$path_regex ( Regexp | undef )
$path_regex
@path_variables = $route->path_variables;
@path_variables ( strings )
@path_variables
$reverse_host = $route->reverse_host;
$reverse_host ( string | undef )
$reverse_host
@reverse_host_variables = $route->reverse_host_variables;
@reverse_host_variables ( strings )
@reverse_host_variables
$reverse_path = $route->reverse_path;
$reverse_path ( string | undef )
$reverse_path
@reverse_path_variables = $route->reverse_path_variables;
@reverse_path_variables ( strings )
@reverse_path_variables
$reverse_scheme = $route->reverse_scheme;
$reverse_scheme ( string | undef )
$reverse_scheme
@schemes = $route->schemes;
@schemes ( strings )
@schemes
$schemes_regex = $route->schemes_regex;
$schemes_regex ( Regexp | undef )
$schemes_regex
Host patterns:
host => 'myblog.com' host => 'myblog.com:80' host => 'myblog.{domain:com|org}' host => 'myblog.*' host => '{author:\w+}.myblog.com'
Path patterns:
path => '/posts/{id}' path => '/posts/{id:\d+}' path => '/posts/{id:\d+}.{format:html|xml}' path => '/posts/{year}/{month}/{day}' path => '/posts/{year:\d{4}}/{month:\d{2}}/{day:\d{2}}' path => '/posts/*/{id}'
Using the constraints option:
$route = GX::Route::Dynamic->new( action => $application->action( 'Posts', 'show_by_month' ), path => '/posts/{year}/{month}', constraints => { 'year' => '\d{4}', 'month' => '\d{2}' } );
Path / URI construction:
$route = GX::Route::Dynamic->new( action => $application->action( 'Posts', 'show' ), path => '/posts/{id:\d+}.{format:html|xml}', defaults => { 'format' => 'html' } ); $path = $route->construct_path( 'id' => '123' ); # $path is '/posts/123.html' $path = $route->construct_path( 'id' => '123', 'format' => 'xml' ); # $path is '/posts/123.xml' $uri = $route->construct_uri( host => 'myblog.com', parameters => { 'id' => '123' } ); # $uri is 'http://myblog.com/posts/123.html'
GX::Route::Match
GX::Router
Jörg A. Uzarek <uzarek@runlevelnull.de>
Copyright (c) 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.
To install GX, copy and paste the appropriate command in to your terminal.
cpanm
cpanm GX
CPAN shell
perl -MCPAN -e shell install GX
For more information on module installation, please visit the detailed CPAN module installation guide.