- Introduction
- Model
- Filter
Filter.pm is a localized version of Controller. Among about 20 logic phases, 3/4 of them have already been handled by Genelet, so we rename the local Controller to be Filter.
Project’s Filter
Just like model, you should first inherit project’s Filter.pm from Genelet::Filter, then inherit component’s Filter.pm from that of the project.
When doing project inheritance, you should specify the HTML template system and email delivery module. Genelet::Template and Genelet::SMTP are the standard choices, which are based on TT2 and Net::SMTP respectively. The generic form of Filter.pm is:
package Myproject::Filter; use strict; use Genelet::Filter; use Genelet::Template; use Genelet::SMTP; use vars qw(@ISA); @ISA = qw(Genelet::Filter Genelet::Template Genelet::SMTP); __PACKAGE__->setup_accessors( r => {...}, args => {...}, actions => {}, fks => {} ); sub get_action { my $self = shift; return; } sub preset { my $self = shift; return; } sub before { my $self = shift; my ($model, $extra, $nextextras) = @_; return; } sub after { my $self = shift; my ($model) = @_; return; } 1;
where $self->{R} is the original request object defined in CGI.pm; $self->{ARSG} has collected all incoming data. $self->{ACTIONS} and $self->{FKS} should be defined in component, so are methods get_action, preset, before and after which are 4 specific phases in Genelet’s life cycle.
In case you don’t have any special setup in project, you may simply use:
package Myproject::Filter; use strict; use Genelet::Filter; use Genelet::Template; use Genelet::SMTP; use vars qw(@ISA); @ISA = qw(Genelet::Filter Genelet::Template Genelet::SMTP); 1;
Project’s Filter.pm is a good place to put algorithms that are common in components. For example, calculating visitor’s IP.