NAME
Egg::Release - WEB application framework release.
NOTES
As for Egg, debugging is not completed in still a lot of parts. It is evaluation version release at the present stage.
SYNOPSIS
First of all, please install Helper script.
The installer is in eg of the source decompression folder. or ../Egg/Helper (Perl Lib) internally.
# perl ./egg/install-helper.pl [install path]
or
# perl /usr/lib/perl5/.../Egg/Helper/install-helper.pl [install path]
Please specify a suitable place such as /usr/bin for [install path].
# create_project.pl MY_PROJECT [-o /output/path]
!! When -o is omitted, current dir is an output destination.
If trigger.cgi operates by Console, it might be unquestionable.
# /output/path/MY_PROJECT/bin/trigger.cgi
Warning: The output code of Default is EUC-JP.
Please make controller, dispatch, and template, etc. now.
Controller:
/output/path/MY_PROJECT/lib/MY_PROJECT.pm
Configuration:
/output/path/MY_PROJECT/lib/MY_PROJECT/config.pm
Dispatch:
/output/path/MY_PROJECT/lib/MY_PROJECT/D.pm
Sub-dispatch:
/output/path/MY_PROJECT/lib/MY_PROJECT/D/Root.pm
DESCRIPTION
Egg is MVC framework that builds an arbitrary module into Model, View, and Controller and makes the WEB application that can be done.
When approaching when the WEB application is constructed, the production work efficiency of the trouble eagle code can be improved if Egg is used.
Default of Model is DBI.
It is possible to use it by loading two or more Model at the same time.
Default of View is HTML::Template.
View module can be easily switched by the setting.
The code concerning some basic operation is written in Controller.
Plugin, encode another, special code is constructed in the controller.
Dispatch corresponding to Request URI can be constructed.
Please separate processing based on The fragment of URL is picked up from snip.
Or, according to the value acquired from param.
About WEB Applicaton that you constructed.
When I can get the report if it is generally accepted, it is glad.
I do so it is necessary to verify and to include it as a standard.
About the character-code union of the request query.
The treatment of the character-code in multi byte language range is important, and sometimes becomes a serious problem.
The default of Egg is processed with EUC though it should be assumed UTF8 for this matter usually recent.
Moreover, the union of character-codes has already been completed.
my $param= $e->request->params;
print $param->{any_param}; # This content is already EUC.
If it wants to do this processing with UTF8, 'character_in' of the configuration is merely assumed to be 'utf8'.
Controller's 'create_encode' method is only detached if the processing of the character-code union is unnecessary.
Please correct the controller as follows if you want to change this processing further.
package [MYPROJECT];
use strict;
use Egg qw/-Debug/;
use ANY_ENCODE;
__PACKAGE__->__egg_setup;
# Using $e->encode by this becomes possible.
sub create_encode { ANY_ENCODE->new }
# And, please prepare a suitable method of synchronization with 'character_in'.
sub unicode_conv {
my($e, $str)= @_;
#
# Here changes depending on the module for the character-code processing.
#
$e->encode->convert(\$str)->unicode;
}
sub euc_jp_conv {
my($e, $str)= @_;
$e->encode->convert(\$str)->euc_jp;
}
sub shift_jis_conv {
my($e, $str)= @_;
$e->encode->convert(\$str)->shift_jis;
}
#
# Some plugins might have the direct call of encode in the character-code processing.
# I think that they demand the methods such as set, a, and b perhaps.
# Therefore, when this method is actually adopted, wrappar might be needed.
#
ENVIRONMENT
Egg evaluates several environment variables.
Please replace the part of [MYPROJECT] with own project name and read.
[MYPROJECT]_DISPATCHER
The module of the name of 'Egg::D::$ENV{[MYPROJECT]_DISPATCHER}' is used as Dispath.
[MYPROJECT]_CUSTOM_DISPATCHER
The module of [MYPROJECT]_CUSTOM_DISPATCHER is used as Dispath.
[MYPROJECT]_UNLOAD_DISPATCHER
The module of [MYPROJECT]_CUSTOM_DISPATCHER is used as Dispath.
However, require is not done.
However, dispatch->_setup
is called.
[MYPROJECT]_MODEL
The module used as MODEL can be specified. Please delimit it by ',' or ';' when you specify the plural.
The MODEL setting of configuration is also effective.
[MYPROJECT]_VIEW
The module used as VIEW can be specified.
The VIEW setting of configuration becomes invalid.
[MYPROJECT]_REQUEST
An arbitrary module can be used for the Request processing.
However, because the handler is not generated, it is necessary to prepare it by oneself.
PLUGINS
Egg supports the plugin that can be used like Catalyst.
The specified plugin name is usually supplemented with 'Egg::Plugin' and evaluated. For instance, it is developed with the name of 'Filter' when assuming 'Egg::Plugin::Filter'.
When the name that starts by + is specified, an untouched name is used. For instance, '+MyProject::Filter' is evaluated as it is as 'MyProject::Filter'.
use Egg qw/-Debug Filter::EUC_JP +Catalyst::Plugin::FillinForm/;
Moreover, the following calls are supported to the plugin.
Please refer when you make the plugin by oneself.
- 1 $e->setup
-
When starting, it is called.
- 2 $e->prepare
-
It is called because of the object generation preparation immediately before dispatch operates.
- 3 $e->action
-
It is called before VIEW outputs it after dispatch is evaluated. However, if finished is true, it has already been canceled.
- 4 $e->finalize
-
It is called before contents are output after VIEW does output. In a word, it becomes the end of the plugin call.
Please make the chance to pass processing to the following plug-in by beginning ending about the processing of the method of the above-mentioned NEXT.pm.
package Egg::Plugin::MyPlug;
use strict;
use base qw/Class::Data::Inheritable/;
use NEXT;
use ANY_MODULE;
__PACKAGE__->mk_classdata( qw/myplug/ );
sub prepare {
my($e)= @_;
$e->{myplug}= new ANY_MODULE;
$e->NEXT::prepare;
}
#
# The error occurs if Class::Accessor is used to make the accessor.
#
Method of plugin
It is possible to call it if it is assumed $e->method because the method of the plugin is a succession relation to Egg.
FLAGS
An arbitrary flag is set when Egg is read, and it can be referred to later.
* Control file of this.
package [MYPROJECT];
use strict;
use Egg qw/-Debug -foo/;
* This is a code such as dispatch.
if ($e->flag('foo')) {
return TRUE;
} else {
return FALSE;
}
Debug
Egg supports only place 'Debug' flag today.
The Debug flag can be referred to by $e->debug
.
CONFIGURATION
root
Default: [MYPROJECT]/root
It is the one used when Egg chiefly confirms the whereabouts of the template. Please specify the root directory for the template that becomes a main. It doesn't relate to the setting of VIEW.
static_root
Default: [MYPROJECT]/htdocs
Please set the document route for static contents such as the image images and Style Sheets. Place Egg today doesn't use this setting.
title
Default: none.
Title of site. Place Egg today doesn't use this setting.
accessor_names
Default: none.
Please set the name of the accessor that wants to be made by the ARRAY reference. It comes to be able to use the made accessor to put $e->stash
in and out.
character_in
Default: euc
Character-code used by internal processing. 'utf8', 'euc', and 'sjis' can usually be specified. When create_encode method is customized, the code that can be specified is changed.
content_language
Default: none.
When you want to include Content-Language in responce header.
content_type
Default: text/html
Please set Content-Type output with the response header. For instance, to include the character set, it is specified 'text/html; charset=euc-jp' etc.
default_template_extension
Default: .tmpl
Please set the extension when the template name is generated from Dispatch with the automatic operation.
max_snip_deep
Default: 5
It is an upper bound of the depth of the folder in the Path part of Request URL.
redirect_page
Default: HASH reference.
It is a setting concerning the page displayed with redirect_page method of Egg::Response.
Each item of redirect_page:
body_style: Style of body.
div_style: Style of the enclosure frame.
h1_style: Style of message display part.
default_url: Default at url unspecification.
default_wait: Default at wait unspecification.
default_msg: Default at message unspecification.
MODEL
It is a setting of the MODEL.
VIEW
It is a setting of the VIEW.
METHODS
It introduces only the method that seems to be used well here picking it up.
Please see the document of each module for details.
$e
is [MY_PROJECT] object. Egg, Engine::Engine, and the plugin have been succeeded to.
$e->namespace
The class name of e is returned. In a word, it is the same as ref($e).
$e->config
The configuration is returned by the HASH reference.
$e->stash
It is a preservation place to share data. Familiar in Catalyst.
$e->flag([FLAG_NAME]);
Refer to the flag set to Egg.
$e->snip
The ARRAY reference into which the request passing is divided by/is returned.
http://dmainname/hoge/foo/ request for instance is developed as follows.
$e->snip->[0] ... hoge
$e->snip->[1] ... foo
In addition, http://dmainname/hoge/foo/banban.html is a long ages.
$e->snip->[0] ... hoge
$e->snip->[1] ... foo
$e->snip->[2] ... banban.html
The last value becomes a file name at the request to a clear file.
Moreover, please process each value while doubting undef without fail. The error occurs in strict environment if it doesn't do so.
# This makes an error mostly.
if ($e->snip->[1]=~/^hoge/) { .... }
# it is safe.
my $dir= $e->snip->[1] || return $e->finished( NOT_FOUND );
if ($dir=~/^hoge/) { .... }
or
if ($e->snip->[1] && $e->snip->[1]=~/^hoge/) { ... }
$e->dispatch or $e->d
Accessor to dispatch object. However, because sub-dispatch calls class directly, it is not possible to call it from this accessor.
$e->request or $e->req
Accessor to Egg::Request object.
$e->request->param([KEY], [VALUE])
Refer to the value of the request query. The value can be substituted by giving [VALUE].
$e->request->params or $e->request->parameters;
The mass of the request query is returned by the HASH reference.
$e->request->cookie([KEY]);
Refer to Cookie of the specified key. Please use value method when you take out the value that has processed the character-code. Please use plain_value when you take out the value in which nothing is processed as it is.
# The value that has processed the character-code is taken out. my $foo= $e->request->cookie('Foo'); my $foo_value= $foo->value; # An untouched value is taken out. my $foo_value= $foo->plain_value; or my $foo_value= $foo->{value};
This can refer to cookie. Please use $e->response->cookie to set cookie.
$e->request->cookies
The mass of the cookie is returned by the HASH reference.
$e->request->remote_addr or $e->request->address
REMOTE_ADDR of the client is returned.
Egg cannot judge the proxy of the frontend. This will return information wrong according to the environment. Please use 'mod_rpaf' etc. when you use the proxy for the frontend.
$e->request->host_name
The host name that the WEB application operates is returned. Deleted what returns to the port number etc.
$e->request->path
The request path is returned. Without fail '/' enters for the head. Please note a little difference from 'Catalyst'.
This is convenient to bury the action value under <form> of the template.
$e->response or $e->res
Accessor to Egg::Response object.
$e->response->content_type([CONTENT_TYPE]);
The output contents type is defined. $e->config->{content_type} is used in default.
$e->response->no_cache([1 or 0])
Charm to prevent a browser of client from caching it.
$e->response->ok_cache([1 or 0]) or $e->set_cache([1 or 0])
Charm to make a browser of client cache it.
$e->response->cookie([KEY], [HASH reference]);
Cookie is set in the client. Please give the option to pass it to 'CGI::Cookie' by the HASH. First- must omit the item of 'CGI::Cookie' option.
$e->response->cookie( 'foo'=> { value => 'banban', expires=> '+1M', domain => 'domain-name', path => '/hoge', secure => 0, } );
$e->response->cookies
The mass of data for set-cookie is returned by the HASH reference.
my $cookie= $e->response->cookies; $cookie->{foo}= { value=> 'banban', ... ... };
$e->response->redirect([URL], [STATUS]);
Forward is done to specified URL. The response status can be specified. Default is 302.
$e->response->redirect_page([URL], [MESSAGE], [OPTION]);
When the screen is done in Forward, page contents are displayed once. The value that is made to the option and done is the same as 'redirect_page' of configuration.
$e->response->body([CONTENT]); or $e->response->output([CONTENT]);
Contents that want to output are defined directly. When this is set, the processing of the VIEW side is canceled. This method maintains the value without fail by the SCALAR reference.
$e->response->body( "Hello, world!" ); my $body= $e->response->body; print $$body;
$e->encode
The object made from create_encode method is returned.
If $e->encode is effective, the method for some character-code processing can be used.
$e->utf8_conv, $e->euc_conv, $e->sjis_conv
$e->model([MODEL NAME]);
The object of specified MODEL is returned.
$e->view;
The VIEW object is returned.
$e->view->param([KEY], [VALUE]);
When the value is passed to the template engine such as HTML::Template that evaluate param, it uses it.
$e->view->params;
The HASH reference that $e->view->param has treated is returned.
$e->debug;
* Whether it operates by debug mode is checked.
$e->template and $e->error;
It is an accessor to $e->stash.
$e->template('template.tt');
$e->error('error occurs.');
However, please use $e->dispatch->_template when you set the template from 'despatch_map'.
It is $e->template and there is usually no problem from Sub-dispatch.
package [MYPROJECT]::D;
sub dispatch_map {
my($dispat, $e)= @_;
if (.... ) {
# The error occurs in this.
return $e->template('index.tt');
# If it is this, it is safe.
return $dispat->_template('index.tt');
# This is also safe.
$e->template('index.tt');
return 0;
# In a word, after setting the template, $dispat->_template returns 0.
}
}
$e->finished([RESPONSE STATUS]);
It reports on the completion of processing. Some processing is canceled if set in the first half of processing. Please use the response status code when you set this. Please set 200 when you complete processing by the success. If it wants to cause the error, it is 500. And, 'Not Found' is 404. If 500 is given, the second argument is evaluated further as an error message, and it is written in the log. The default of the message is 'Internal Error'.
$e->escape_html([HTML_TEXT]); or $e->encode_entities([HTML_TEXT]);
The HTML tag is invalidated.
$e->unescape_html([PLAIN_TEXT]); or $e->decode_entities([PLAIN_TEXT]);
The HTML tag where it is escaped is made effective.
BUGS
When you find a bug, please email me (<mizuno@bomcity.com>) with a light heart.
SEE ALSO
Egg, Egg::Engine, Egg::Model, Egg::View, Egg::Request, Egg::Response, Egg::D::Stand, Egg::Debug::Base,
THANKS
The code of Egg will partially refer to Catalyst.
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.