NAME
Egg::Dispatch::Standard - Dispatch of Egg standard.
SYNOPSIS
package MyApp::Dispatch;
use Dispatch::Standard;
# If HASH is used for the key, the refhash function is used.
Egg->dispatch_map( refhash(
# 'ANY' matches to the method of requesting all.
# The value of label is used with page_title.
{ ANY => '_default', label => 'index page.' }=> sub {
my($e, $dispatch)= @_;
$e->template('document/default.tt');
},
# Empty CODE decides the template from the mode name that becomes a hit.
# In this case, it is 'help.tt'.
help => sub { },
# When the request method is only GET, 'GET' is matched.
{ GET => 'bbs_view', label => 'BBS' } => sub {
my($e, $dispatch)= @_;
.... bbs view code.
},
# When the request method is only POST, 'POST' is matched.
{ POST => 'bbs_post', label => 'BBS Contribution.' } => sub {
my($e, $dispatch)= @_;
.... bbs post code.
},
# 'A' is an alias of 'ANY'.
{ A => 'blog', label => 'My BLOG' }=>
# The refhash function for remembrance' sake when you use HASH for the key.
refhash(
# Prior processing can be defined.
_begin => sub {
my($e, $dispatch)= @_;
... blog begin code.
},
# 'G' is an alias of 'GET'.
# The regular expression can be used for the action. A rear reference is the
# third argument that extends to CODE.
{ G => qr{^article_(\d{4}/\d{2}/\d{2})}, label => 'Article' } => sub {
my($e, $dispatch, $parts)= @_;
... data search ( $parts->[0] ).
},
# 'P' is an alias of 'POST'.
{ 'P' => 'edit', label => 'BLOG Edit Form.' } => sub {
my($e, $dispatch)= @_;
... edit code.
},
# Processing can be defined after the fact.
_end => sub {
my($e, $dispatch)= @_;
... blog begin code.
},
),
) );
DESCRIPTION
It is dispatch of the Egg standard.
Dipatti is processed according to the content defined in 'dispatch_map'.
Dipatti of the layered structure is treatable.
The value of the point where the action the final reaches should be CODE reference.
Objec of the project and the handler object of dispatch are passed for the CODE reference.
Besides, when the key to the name of 'default_mode' exists in the retrieval hierarchy, it matches it to it if the matched action is not found.
It corresponds to the key to the HASH form by using the refhash function. see Tie::RefHash.
Label is set, and the request method can be limited and it match it to the request by using the key to the HASH form.
The regular expression can be used for the key. As a result, it is possible to correspond to a flexible request pattern. Moreover, it is passed to the third argument of the CODE reference by the list if there is a rear reference. However, a rear reference can obtain only the one that matched to oneself. In a word, what matched by a shallower hierarchy cannot be referred to.
qr{^baz_(.+)}=> { # <- This cannot be referred to.
# It only has to pull it out for oneself by using $e->request->path etc.
qr{^boo_(.+)}=> sub { # <- Naturally, this can be referred to.
my($d, $e, $p)= @_;
},
},
When '_begin' key is defined, prior is processed.
It processes it after the fact when '_end' key is defined.
To the same hierarchy as the action that becomes a hit when neither '_begin' nor '_end' key are found. It looks for the one of a shallower hierarchy. To make the search stopped on the way, an empty CODE reference is defined somewhere of the hierarchy.
hoge => {
hoo => {
baa => {
match => sub {},
},
},
# It stops here.
_begin => sub {},
_end => sub {},
},
EXPORT FUNCTION
It is a function exported to the controller and the dispatch class of the project.
refhash ([HASH])
It is Tie::RefHash as for received HASH. After Tie is done, the content is returned by the HASH reference.
Whenever the key to the HASH form is set to 'dispatch_map', it is made by way of this function.
It doesn't go well even if the HASH reference is passed to this function. Please pass it by a usual HASH form.
my $hashref = refhash (
{ A => '_default', label=> 'index page.' } => sub {},
{ A => 'help', label=> 'help page.' } => sub {},
);
METHODS
Egg::Dispatch has been succeeded to.
dispatch
The Egg::Dispatch::Standard::handler object is returned.
my $d= $e->dispatch;
mode_param
The parameter name to decide the action of dispatch is setup.
Egg->mode_param('mode');
If the access control of the URI base is done, it is not necessary to set it.
HANDLER METHODS
mode_now
The value in which the list of the matched action ties by '/' delimitation is returned.
label ([NUMBER])
The list of the matched action is returned by the ARRAY reference.
When the figure is given, the corresponding value is returned.
SEE ALSO
Egg::Release, Egg::Dispatch, Tie::RefHash,
AUTHOR
Masatoshi Mizuno <lushe@cpan.org>
COPYRIGHT AND LICENSE
Copyright (C) 2008 Bee Flag, Corp. <http://egg.bomcity.com/>, All Rights Reserved.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.6 or, at your option, any later version of Perl 5 you may have available.