| Egg-Release documentation | Contained in the Egg-Release distribution. |
Egg::Dispatch - Base class for dispatch.
It is a base class for dispatch.
To do the function as Dispatch, necessary minimum method is offered.
The setting of dispatch is returned.
When DISPATCH_HASH is given, it is set as dispatch.
Egg->dispatch_map (
_default => sub {},
hoge => sub { ... },
);
Egg::Base has been succeeded to.
Constructor.
$e->action is returned.
$e->stash is returned.
$e->config is returned.
$e->page_title is returned.
The URI passing to decided action is assembled and it returns it.
Accessor to treat mode.
Accessor to treat label.
The mode of default is returned.
It is revokable in 'deispath_default_name' of the configuration. Default is '_default'.
The template name of default is returned.
It is revokable in 'template_default_name' of the configuration. Default is 'index'.
Masatoshi Mizuno <lushe&64;cpan.org>
Copyright (C) 2008 Bee Flag, Corp. <http://egg.bomcity.com/>.
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.
| Egg-Release documentation | Contained in the Egg-Release distribution. |
package Egg::Dispatch; # # Masatoshi Mizuno E<lt>lusheE<64>cpan.orgE<gt> # # $Id: Dispatch.pm 337 2008-05-14 12:30:09Z lushe $ # use strict; use warnings; use Carp qw/ croak /; our $VERSION= '3.00'; sub import { my($class)= @_; my($project)= $class=~m{^([^\:]+)}; no strict 'refs'; ## no critic no warnings 'redefine'; *{"${class}::code"}= sub { shift if ref($_[0]); my $pkg= shift || croak q{ I want include package name. }; $pkg= "${project}::$pkg"; my $method= shift || croak q{ I want method name. }; $pkg->require or die $@; $pkg->can($method) || croak qq{ '$method' method is not found. }; }; *{"${class}::mode_param"}= sub { my $proto= shift; return 0 if ref($proto); my $pname= shift || croak(q{ I want param name. }); my $name_uc= uc $project; *{"${proto}::_get_mode"}= sub { $ENV{"${name_uc}_REQUEST_PARTS"} || $_[0]->request->param($pname) || return (undef); }; }; $class; } sub dispatch_map { my $e= shift; return $e->_dispatch_map unless @_; my $hash= $_[0] ? ($_[1] ? {@_}: $_[0]): return 0; $e->_dispatch_map( $e->_dispatch_map_check($hash, (ref($e) || $e)) ); } *run_modes= \&dispatch_map; sub _dispatch_map_check { $_[1] || {} } sub _get_mode { 0 } package Egg::Dispatch::handler; use strict; use warnings; use base qw/ Egg::Base /; __PACKAGE__->mk_accessors(qw/ mode label default_mode default_name /); sub new { shift->SUPER::new(@_)->_initialize } sub action { shift->e->action(@_) } sub stash { $_[0]->e->stash } sub config { $_[0]->e->config } sub page_title { shift->e->page_title(@_) } sub target_action { my($self)= @_; my $action= $self->action || return ""; @$action ? '/'. join('/', @$action): ""; } sub _initialize { my($self)= @_; my $cf= $self->e->config; $self->{label} = []; $self->{action}= []; $self->{page_title}= ""; $self->{default_name}= $cf->{template_default_name} || 'index'; $self->{default_mode}= $cf->{deispath_default_name} || '_default'; $self; } sub _example_code { 'none.' } 1; __END__