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;
( run in 1.096 second using v1.01-cache-2.11-cpan-df04353d9ac )