The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Egg::D::Stand - Standard dispatch for Egg.

SYNOPSIS

Example of code in which dispatch is made from control.

 sub create_dispatch {
        my($e)= @_;
        $e->{dispatch}= Egg::D::Stand->_new($e);
 }

DESCRIPTION

When the constructor is called, dispatch_map of dispatch on the project side is called.

How the behavior at each request is done on the dispatch_map side has been decided. How to call sub-dispatch can be decided with dispatch_map.

If finished of the call of the constructor is effective, nothing is done.

It is an example of dispatch_map as follows.

 package MYPROJECT::D;
 use strict;
 use Egg::Const;
 
 sub dispatch_map {
        my($dis, $e)= @_;
        #
        # The directory name of Request Path of the first hierarchy is received.
        # If it is empty, ARGS is returned to call _default
        #  of MYPROJECT::D::Root.
        #
        my $dir1= $e->snip->[0] || return qw{ Root };
        if ($dir1=~/^hoge/) {
                #
                # The directory name of the second hierarchy is received.
                # If it is empty, the template definition is returned. (It is 0 to
                #  actually extend.)
                # And, it tries always to call _begin and _end though _default of
                # Root is not called.
                #
                my $dir2= $e->snip->[1]
                  || return $dis->_template('/hoge/index.tt');
                if ($dir2=~/^foo/) {
                        #
                        # Processing is entrusted to index (method)
                        #  of MYPROJECT::D::Foo. 
                        # The thing that $e->response->body is defined or template by
                        # index is expected.
                        #
                        return qw{ Foo index };
                } else {
                        #
                        # The method of the leading part of MYPROJECT::D::Foo is undefined.
                        # It defines it directly guessing the template.
                        # _begin and _end are called.
                        # When 1 is given to the second argument of make, existence under
                        # of $e->config->{root} is checked.
                        # 404 is returned in case of not being.
                        #
                        return ('Foo', 0, $dis->_template_make("/$dir1/$dir2", 1));
                }
        } elsif ($dir1=~/^boo/) {
                #
                # _default of MYPROJECT::D::Boo operates if it is empty.
                #
                my $dir2= $e->snip->[1] || return qw{ Boo };
                if ($dir=~/.+\.txt$/) {
                        #
                        # If the second hierarchy is a file name, contents of a suitable
                        # file are returned. And, $e->responce->body is defined.
                        #
                        $e->responce->content_type('text/plain');
                        open FH, "/path/to/boo.txt" || return $e->finished( NOT_FOUND );
                        $e->responce->body( join '', <FH> );
                        close FH;
                        return 0;
                } else {
                        return $e->finished( FORBIDDEN ); # Forbidden is returned.
                }
        }
        #
        # All requests not matched above are returned by _default
        # of MYPROJECT::D::Root.
        #
        return return qw{ Root };
        #
        #
        # Or, when you return Not Found.
        return $e->finished( NOT_FOUND );
        #
 }

METHODS

$e->_template([TEMPLATE PATH], [1]);

The template is decided. When 1 is given to the second argument of make, existence under of $e->config->{root} is checked. 404 is returned in case of not being.

$e->_template_make([REQUEST PATH], [1]);

Template is guessed by given Path. After a suitable template is decided, processing is passed to $e->_template.

$e->_call([PACKAGE NAME]);

After the name supplemented with MYPROJECT::D is packaged in require, the name is returned.

SEE ALSO

Egg::Release

AUTHOR

Masatoshi Mizuno, <mizuno@bomcity.com>

COPYRIGHT AND LICENSE

Copyright (C) 2006 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.