Apache-JAF
view release on metacpan or search on metacpan
NAME
Apache::JAF -- mod_perl and Template-Toolkit web applications framework
SYNOPSIS
controller -- a mod_perl module that drives your application
package Apache::JAF::MyJAF;
use strict;
use JAF::MyJAF; # optional
# loading mini-handlers & templates during compilation time
use Apache::JAF (
handlers => '/examples/site/modules/Apache/JAF/MyJAF/pages/', # 'auto' if you want to use suggested file structure
templates => '/examples/site/templates/' # the same comment
);
our @ISA = qw(Apache::JAF);
# determine handler to call
sub setup_handler {
my ($self) = @_;
# the page handler for each URI of sample site is 'do_index'
# you should swap left and right ||-parts for real application
my $handler = 'index' || shift @{$self->{uri}};
return $handler;
}
sub site_handler {
my ($self) = @_;
# common stuff before handler is called
$self->{m} = JAF::MyJAF->new(); # create modeller -- if needed
$self->SUPER::site_handler();
# common stuff after handler is called
return $self->{status}
}
1;
page handler -- controller's method that makes one (or more) pages
sub do_index {
my ($self) = @_;
# page handler must fill $self->{res} hash that process with template
$self->{res}{test} = __PACKAGE__ . 'test';
# and return Apache constant according it's logic
return OK;
}
modeller -- a module that encapsulates application business-logic
package JAF::MyJAF;
use strict;
use DBI;
use base qw( JAF );
sub new {
my ($class, $self) = @_;
$self->{dbh} = DBI->connect(...);
return bless $self, $class;
}
1;
Apache configuration (httpd.conf)
DocumentRoot /examples/site/data
<Location />
<Perl>
use lib qw(/examples/site/modules);
use Apache::JAF::MyJAF;
</Perl>
SetHandler perl-script
PerlHandler Apache::JAF::MyJAF
PerlSetVar Apache_JAF_Templates /examples/site/templates
# optional or can be specified in Apache::JAF descendant (default value is used in example)
PerlSetVar Apache_JAF_Modules /examples/site/modules/Apache/JAF/MyJAF/pages
# optional or can be specified in Apache::JAF descendant (default value is used in example)
PerlSetVar Apache_JAF_Compiled /tmp
</Location>
DESCRIPTION
Introduction
Apache::JAF is designed for creation web applications based on MVC
(Model-View-Controller) concept.
* *Modeller* is JAF descendant
* *Controller* is Apache::JAF descendant
* and the *Viewer* is set of the templates using Template-Toolkit
markup syntax
This separation hardly simplifies the dynamic development of sites by
designers and programmers. Each programmer works on own part of the
project writing separate controller's parts. Designers have to work only
on visual performance of templates.
Suggested file structure
Suggested site's on-disk structure is:
site
|
+-- data
|
+-- modules
|
+-- templates
*data*
document_root of site. All static files (e.g. JavaScripts, pictures,
CSSs etc) must be placed here
*modules*
Storage place for site modules -- must be in @INC's
*templates*
The place of your site's templates. Framework is designed to
reproduce site's structure in this folder. It's just like
document_root for static site.
Request processing pipeline
The "Apache::JAF::handler" intercepts every request for specified
location, and process it's own way:
1 If requested file exists then nothing happens. The handle declines
request with "DECLINE".
2 Otherwise the instance of Apache::JAF's descendant is created and
"setup_handler" method is called. You must override this method and
( run in 1.069 second using v1.01-cache-2.11-cpan-39bf76dae61 )