Apache-JAF

 view release on metacpan or  search on metacpan

lib/Apache/JAF.pm  view on Meta::CPAN

=item 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;

=item 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;
 }

=item 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;

=item Apache configuration (F<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>

=back

=head1 DESCRIPTION

=head2 Introduction

Apache::JAF is designed for creation web applications based on MVC (Model-View-Controller)
concept.

=over 4

=item * 

I<Modeller> is JAF descendant

=item *

I<Controller> is Apache::JAF descendant

=item *

and the I<Viewer> is set of the templates using Template-Toolkit markup syntax

=back

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.

=head2 Suggested file structure

Suggested site's on-disk structure is:

  site
   |
   +-- data
   |
   +-- modules
   |
   +-- templates

=over 4

=item I<data> 

document_root of site. All static files (e.g. JavaScripts, pictures, CSSs etc)
must be placed here

=item I<modules>



( run in 0.760 second using v1.01-cache-2.11-cpan-39bf76dae61 )