YATT::Lite::WebMVC0::SiteApp - PSGI Handler for yatt
# In app.psgi use FindBin; use YATT::Lite::WebMVC0::SiteApp -as_base; use YATT::Lite qw/Entity *CON/; return do { my $site = MY->new(doc_root => "$FindBin::Bin/html"); #----- You can define entities here. ---- Entity session => sub { my ($this, $key) = @_; my $sess = $CON->get_session or return; $sess->param($key); }; if (YATT::Lite::Factory->want_object) { # When app.psgi is loaded from yatt support scripts(eg. yatt lint), # return bare object, not app. $site; } else { # Otherwise, normal PSGI. You can use Plack::Builder and/or middleware. $site->to_app; } };
SiteApp
is a Factory of DirApp, which is a web specific subclass of YATT::Lite.
SiteApp takes a template directory tree at startup and becomes a PSGI application.
When SiteApp called for incoming request, it first determins a sub-directory for the request. Then SiteApp looks for DirApp from own cache, load/build it when necessary, and finally invoke DirApp to handle do rest of work.
SiteApp accepts YATT::Lite::Object style configurations.
Document root of this PSGI application. *.yatt should be placed under this. Usually, $FindBin::Bin/html
Namespace of per-directory YATT::Lite class. Default is MyYATT
. This will also be used as a base class of each YATT::Lite
instances. This class will be loaded at startup (but can be missing). If it exists, it must be a subclass of YATT::Lite
.
The application directory where app.psgi lives in. Sometime omissible, but recommended to set as $FindBin::Bin
.
Base DirApp for all DirApp under doc_root
. A.k.a inheritance of app-directory. Omissible. Usually, $FindBin::Bin/ytmpl.
If your app.psgi is located under subpath, specify this. You can refer this from *.yatt via &yatt:site_prefix();
.
Default charset for HTTP response headers. Default is utf-8.
Encoding of *.yatt and HTTP response body, respectively.
XXX: should note about widechars....
By default, yatt turns specific parameters into hashes/arrays like PHP and Ruby on Rails. This feature is useful(I hope), but is experimental. So if you don't want this feature, turn this config on.
Requests other than *.yatt, *.ytmpl, *.ydo are passed to this PSGI app. Default is:
Plack::App::File->new(root => $self->{cf_doc_root})->to_app
Room for your Model instance. If it is given and it has startup
method is implemented, $backend->startup($siteapp, @all_dirapps)
will be called when prepare_app
.
PSGI entry function. SiteApp uses $env
as following:
If $env->{REDIRECT_STATUS}
is 200
and has non empty $env->{PATH_TRANSLATED}
, yatt tries to serve specified path.
Otherwise, yatt examines $env->{PATH_INFO}
under doc_root and app_base, in this order.
PSGI startup hook.
Aid for batch execution.
Build helper for YATT::Lite::WebMVC0::Connection object. $parent_fh
can be undef. If specified, $con->flush
will flush buffered contents to $parent_fh.