iAct - A multi-lingual web development and templating framework built on Apache and mod_perl.
<% # This snippet goes in an html file, accessible through Apache
and handled by iAct's ContentHandler %>
<table>
<tr>
<th><% lang en %>Param<% lang es %>Parámetro<% /lang %></th>
<th><% lang en %>Value<% lang es %>Valor<% /lang %></th>
</tr>
<% call My::App::list_params repeat="one_param" %>
<% section "one_param" %>
<tr>
<td><$ name $></td>
<td><$ value $></td>
</tr>
<% /section %>
</table>
# And this is My/App.pm : package My::App; use strict; use iA;
sub list_params {
my ($self, $args) = @_;
my ($txt, $sec) = ("", $args->{repeat});
foreach my $p (iA::param()) {
$self->assign_raw(name => iA::escapeHTML($p),
value => iA::escapeHTML(param($p))
);
$txt .= $self->fetch($sec);
}
$txt;
}
1;
iAct is a web development and templating framework built on Apache and mod_perl.
The basic premise of iAct is that a webpage is not a linear sequence of html markup, but a collection of named chunks called sections, which insert themselves into more general templates. iAct encourages structured reuse of html code and design elements, by moving all the ``skeleton'' code (<html>, <body>, <table>s used for layout, etc) out of the individual html pages, into template files. These templates can in turn embed themselves into more general templates.
This results in a global tree hierarchy of templates, with the URL-mapped pages as its leaves. A small, purely declarative language is used to define sections within pages, use parent templates, import sections from other files, and define gaps where named content should be inserted.
From this language, Perl routines can be called by their name, and their output inserted into the stream. These perl subs have full access to the sections on the file they were called from, and on the templates it uses.
iAct is thoroughly multi-lingual; content can be entered in multiple languages, in separate files (blah.html.en, blah.html.es) or within a single file, using the <% lang %> command. This is integrated all the way to the ContentHandler, which determines a language preference list from the user's request, and sets the right http headers for the response language.
The iA module provides functions to access global properties of the current connection, such as cookies, form parameters and file uploads. It also provides common utility functions for web programming, such as URL and HTML escaping.
See also the iA::Page documentation, for the list of methods available to manipulate sections, filters, and other page elements.
There are several ways to call functions in the iA module:
use iA;
sub whatever {
my $name = iA::param("name");
return iA::escapeHTML($name);
}
sub whatever {
my ($self, $args) = @_;
my $name = $self->param("name");
return $self->escapeHTML($name);
}
use iA;
sub whatever {
my $ia = new iA;
my $name = $ia->param("name");
return $ia->escapeHTML($name);
}
The functions in iA.pm deal with data associated with the current HTTP connection, which is naturally a global object. The object-oriented interface is only a calling convention provided for convenience.
Calling functions directly by their qualified names (eg. iA::param(``blah'')) is the recommended interface, and also the fastest one.
Note: it is a security hole to copy text strings provided by (untrusted) users into webpages shown to other users, without HTML-escaping them first!
Apache notes are a table key=value pairs that can be accessed by the various Apache modules, at each step of the processing chain. This wrapper always uses the ``main'' request object, so notes stick through subrequests.
If you don't provide a value, this function returns the current value of the note for the given key.
iA::set_cookie(-name => "blah", -value => "erf",
-expires => '+3d');
Some methods available on iA::Page objects include assign,
assign_raw and fetch. See the iA::Page documentation for
details.
The $filename is absolute. $options is a hashref with parameters to be passed to iA::Page. The only recognized option is 'lang', which introduces an arrayref of language names, by preference order; eg.
my $page = iA::get_page("/path/to/file.html",
{ lang => [ "en", "es" ] });
The only interesting method available on iA::Template objects is
page, which evaluates and returns the HTML page.
The $filename is relative to the HTML root directory. $options is a hashref with parameters to be passed to iA::Page. The only recognized option is 'lang', which introduces an arrayref of language names, by preference order; eg.
my $tmpl = iA::get_template("/path/to/file.html",
{ lang => [ "en", "es" ] });
The 2nd param tells it what to do with keys that already exist:
This is useful for <% call %>'ed subs when they want to push the params they've been passed as global params, and access them through iA::param(). The idiom is:
sub myfunction {
my ($self, $args) = @_;
iA::set_params($args);
...
}
These params always override any old values for keys that already existed.
time() can save a few system calls by cache-ing the
result within a request.
Time values are 32-bit integers, counting the number of seconds since 1 Jan 1970.
Most user code shouldn't need this, but it is needed to get to iA::notes().
Note that this will preserve form parameters if the form's method was GET, but not if it was POST.
This functions accepts the following options:
my ($foo, $bar, $zoinx) = iA::param1("foo", "bar", "zoinx");
If the file was uploaded, this function returns a list with 4 elements:
If there was no file upload by that name, returns undef.
is_upload($name)Simply checks to see if a filename has been entered in a file form field. Returns 1 if it's there, 0 otherwise.
The user's privileges are taken from iA::param('priv'), which is a
comma-separated list of keywords. Optionally, the first keyword can
be a number, in which case has_priv($number_smaller_than_that) will
return true.
The global privilege configuration (list of known privileges, implied privs, etc) is in iA::Config.
This function applies to this request only; kept parameters can be read again (with iA::param()) at the next request, but you will have to call iA::keep() again if you want to keep preserving them.
See the iA::State module for details about iAct's client-side state management.
The filename is relative to the HTML root directory.
This is useful for returning ``exceptional'' content, and to show pages done with systems other than iAct (eg. CGI::FastTemplate).
The language parameter is optional, and represents the language in which the HTML contents are.
This is useful to implement ``download''-type links, when the item to be downloaded is a file.
The mime_type parameter is optional. If given, it specifies the mime type to return in the returned HTTP headers; otherwise the mime type is just whatever Apache guessed from the URL, usually 'text/html'.
Debug mode can be entered by appending ``?debug=1'' to the end of URLs; you need to be logged-in, and have privileges, for debug mode to work.
my $ia = new iA;
my $name = $ia->param("name");
perl, httpd, mod_perl, the iA::Page manpage, the iA::Template manpage, the iA::CMS manpage