Para::Frame - Web application framework
Para::Frame is a system to use for dynamic web sites. It runs as a backend daemon taking page requests from a Apache mod_perl client and returns a HTTP response.
In httpd.conf :
<Perl> unshift @INC, '/usr/local/paraframe/lib'; </Perl> PerlModule Para::Frame::Client
In .htaccess :
<FilesMatch ".tt$|^$"> SetHandler perl-script </FilesMatch> PerlHandler Para::Frame::Client ErrorDocument 404 /page_not_found.tt PerlSetVar port 7788
In some/public/file.tt :
[% META title="Hello world" %] <p>This is a simple template</p>
Para::Frame->watchdog_startup
Starts the Para::Frame::Watchdog.
You may want to use /daemonize instead.
Either we know we have something to read or we are expecting an answer shortly
Only call this if you KNOW where is a value to get. The answer may not be the one you were waiting for, so you may have to call this method several times.
This will also handle incoming data coming AFTER your answer, if there is any such data to be handled.
In usmmary: It reads all there is and returns
Exceptions: If nothing was gotten before the timeout (5 secs), an exception will be thrown.
TODO: Cleanup return code...
cancel_and_close( $req, $client, $reason )
$req may be undef
Para::Frame->daemonize( $run_watchdog )
Starts the paraframe daemon in the background. If $run_watchdog
is
true, lets Para::Frame::Watchdog start and watch over the daemon.
Para::Frame->restart()
Restarts the daemon. We asume that we will restart in the background, with a watchdog.
TODO: Will try to detect if the process is not a daemon and in that case restart in the foreground. (Must place new process in same terminal)
Para::Frame->kill_children()
Para::Frame->go_down()
Assumes that we will exit one way or another after this. Thus, we will shut down the signal handling before killing the childs, and NOT turn it on afterwards.
RUNS bgjobs!
Para::Frame->add_hook( $label, \&code )
Adds code to be run on special occations. This adds the code to the hook. The actual hook is added (created) by adding the hook label to %HOOK and then run the hook using /run_hook.
Availible hooks are:
Runs just after the main PF configure. Before DB connection. Before startup.
Runs just before the main_loop
.
Runs then the watchdog send a MEMORY
notice.
Runs then the exception is catched by Para::Frame::Result/exception.
Runs in the child just after the fork.
Called with filepath as argument on each reload of a module. Will also be called on first load of module if loaded by compile() method.
Runs just before the request is done.
Runs before user logged in, in Para::Frame::Action::user_login
Runs after user logged in, in Para::Frame::Action::user_login
Runs after user logged out, in Para::Frame::User/logout
Runs after each DB connect from Para::Frame::DBIx/connect
Runs before committing each DB, from Para::Frame::DBIx/commit
Runs after a rollback for each DB, from Para::Frame::DBIx/rollback
Runs just before switching from one request to another. Not Switching from one request to another can be done several times before the request is done.
Runs before the result page starts to render.
Runs often, between requests.
For adding jobs that should be done in the background, when there is nothing else to do or when it hasen't run in a while.
Para::Frame->run_hook( $req, $label );
Runs hooks with label $label.
Para::Frame->add_global_tt_params( \%params )
Adds all params to the global params to be used for all templates. Replacing existing params if the name is the same.
Will tell watchdog to restart server by forking.
See also Para::Frame::Watchdog/open_logfile
Para::Frame->configure( \%cfg )
Configures paraframe before startup. The configuration is stored in
$Para::Frame::CFG
These configuration params are used:
This is a listref of server paths. Each path should bee a dir that
holds a html
dir, or a dev
dir, for compiled sites. See
Para::Frame::Site/appback.
Must be defined
A string that gives the base part of the package name for actions.
Must be defined
Example: If you set appbase to My::App
, the action my_action
will be looked for as My::App::Action::my_action.
This should be a listref of elements, each to be treated as fallbacks
for Para::Frame::Site/appbase. If no actions are found under
Para::Frame::Site/appbase one after one of the elements in
appfmly
are tried. See Para::Frame::Site/appfmly.
Defaults to none.
The path to application. This is the dir that holds the lib
and
possibly the var
dirs. See Para::Frame::Site/approot.
Must be defined
A coderef that generates a user object to be used for background jobs.
Defaults to code that get
guest
from /user_class.
Sets global $Para::Frame::DEBUG
value that will be used as default
debug value for all sessions.
Default is 0.
The dir to store the paraframe log.
Default is $dir_var/log
The dir to store the process pid.
Default is $dir_var/run
The base for /dir_log and /dir_run and /ttcdir.
Default is /var
The class to use for localizations. Should be a subclass to Para::Frame::L10N.
Defaults to Para::Frame::L10N
A ref to an array of scalar two letter strings of the language codes the sites supports. This config will be the default if no list is given to the specific site. See Para::Frame::Site/languages.
Specifies what to set LC_ALL to, except LC_NUMERIC that is set to C. The default is sv_SE.
The file to use for logging.
Defaults to /dir_log followed by /parframe_$port.log
The dir that holds paraframe.
Default is /usr/local/paraframe
The file group to set files to that are created.
Default is staff
The file to use for storing the paraframe pid.
Defaults to /dir_run followed by /parframe_$port.pid
The port top listen on for incoming requests.
Defaults to 7788
.
The class to use for sessions. Should be a subclass to Para::Frame::Session.
Defaults to Para::Frame::Session
If true, accepts hosts in request even if no matching site has been
created. See Para::Frame::Site/get_by_req. site_auto
can also
be the name of a site to use for the template site.
... document this
The class to use for representing sites. Should be a subclass to Para::Frame::Site.
Defaults to Para::Frame::Site
th
is a ref to a hash of Para::Frame::Burner objects. You should
use the default configuration.
There are three standard burners.
html = The burner used for all tt pages plain = The burner used for emails and other plain text things html_pre = The burner for precompiling of tt pages
Example for adding a filter to the html burner:
Para::Frame::Burner->get_by_type('html')->add_filters({ 'upper_case' => sub{ return uc($_[0]) }, });
See also Para::Frame::Burner
Sets the time zone for Para::Frame::Time.
Defaults to local
Sets the default presentation of times using Para::Frame::Time/format_datetime
Defaults to %Y-%m-%d %H.%M
Calls Para::Frame::Time/set_stringify with the param.
Adds a list of Template::Plugin bases. Always adds Para::Frame::Template::Plugin.
Defaults to the empty list.
Adds a list of TT plugin loaders. Always adds Template::Plugins and
gives it tt_plugins
The directory that holds the compiled templates.
Defaults to /dir_var/ttc or /appback/var/ttc or
/approot/var/ttc followed by /var/ttc
.
The default umask for created files.
Defaults 0007
The class to use for user identification. Should be a subclass to Para::Frame::User.
Defaults to Para::Frame::User
The number of workers to spawn during startup. The sooner a worker is spawned, the less memory will it use. The workers lives on til the next server HUP. More workes will spawn on demand.
Defaults to 0
Para::Frame->Session
Returns the /session_class string.
Para::Frame->User
Returns the /user_class string.
Returns the /paraframe dir.
Returns a report in plain text of server status
Para::Frame->flag_restart()
The standard functions availible in templates.
Most of them exists in both from client and not client.
See also Para::Frame::Widget and Para::Frame::Renderer::TT/set_tt_params
Jonas Liljegren <jonas@paranormal.se>