Egg::Plugin::Dispatch::Standard - Dispatch of Egg standard.


  use Egg qw/ Dispatch::Standard /;
  # If HASH is used for the key, the refhash function is used.
  __PACKAGE__->run_modes( 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($dispatch, $e)= @_;
  # Empty CODE decides the template from the mode name that becomes a hit.
  # In this case, it is ''.
  help => sub { },
  # When the request method is only GET, 'GET' is matched.
  { GET => 'bbs_view', label => 'BBS' } => sub {
    my($dispatch, $e)= @_;
    .... bbs view code.
  # When the request method is only POST, 'POST' is matched.
  { POST => 'bbs_post', label => 'BBS Contribution.' } => sub {
    my($dispatch, $e)= @_;
    .... 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.
    # Prior processing can be defined.
    _begin => sub {
      my($dispatch, $e)= @_;
      ... 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($dispatch, $e, $parts)= @_;
      ... data search ( $parts->[0] ).
    # 'P' is an alias of 'POST'.
    { 'P' => 'edit', label => 'BLOG Edit Form.' } => sub {
      my($dispatch, $e)= @_;
      ... edit code.
    # Processing can be defined after the fact.
    _end => sub {
      my($dispatch, $e)= @_;
      ... blog begin code.
    ) );


It is Dispatch of the Egg standard.

* HASH is set from the controller to run_modes and Dispatch is defined.

* HASH of the layered structure is appreciable.

* The value of the point where the action the final reaches should be CODE.

* E::P::Dispatch::handler and the object of the project are passed to CODE.

* It matches in the retrieval hierarchy of the action and if '_default' key is found, it matches it to it.

* 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 CODE by the ARRAY reference 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 shallow hierarchy cannot be referred to.

  qr{^baz_(.+)}=> { # <- This cannot be referred to.
     # It is OK if it pulls it out for oneself by using $e-E<gt>request-E<gt>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.

* It looks for the one of a shallower hierarchy when neither '_begin' nor '_end' are found from the hierarchy that becomes a hit. Please define empty CODE somewhere of the hierarchy when you want to make the search stopped on the way.

  hoge => {
     hoo => {
        baa => {
           match => sub {},
        # It stops here.
        _begin => sub {},
        _end   => sub {},


It is a function compulsorily exported by the controller of the project.

refhash ( [HASH] )

Whenever the key to the HASH form is set to run_modes, it is made by way of this function.

This function returns received HASH and after Tie is done by Tie::RefHash, the HASH is returned by the reference.

* Please it doesn't operate normally even if you pass HASH Rifaren to this function. Please pass usual HASH.

   my $hashref = refhash (
     { A => '_default', label=> 'index page.' } => sub {},
     { A => 'help',     label=> 'help page.'  } => sub {},


Egg::Plugin::Dispatch has been succeeded to. Please refer for that method.


The handler object is returned.


see Egg::Plugin::Dispatch.


Egg::Plugin::Dispatch::handler has been succeeded to. Please refer for that method of the handler.


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.


Egg::Plugin::Dispatch, Egg::Release,


Masatoshi Mizuno <>


Copyright (C) 2007 by Bee Flag, Corp. <>, 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.