Geomap::FormApp - base class for Geomap form-based applications
use base 'Geomap::FormApp';
###################################################################### # Override these methods from base class ######################################################################
sub validator_profile { my $self = shift; # This should be a valid Data::FormValidator profile hash, with # a profile for each runmode you want to validate. my $profile = { default => { required => [qw( fname lname )], }, }; return $profile; }
sub pretty_errors { my $self = shift; # This should map each 'required' and 'optional' field from the # validator profile to a pretty-printing name my $errors = { fname => 'First Name', lname => 'Last Name', }; return $errors; }
# Sets up run modes, etc. sub setup { my $self = shift; $self->start_mode('default'); $self->mode_param('view'); $self->run_modes( default => \&r_default, confirm => \&r_confirm, errors => \&r_errors, AUTOLOAD => \&bad_runmode, ); }
###################################################################### # Runmodes # Runmodes will generally follow this structure ######################################################################
sub r_default { my $self = shift; # Get CGI query object my $cgi = $self->query();
# Generate content my $errors = $self->param('_ERRORS'); my $vars = { ERRORS => $errors }; my $output = $self->output($vars);
$output = $self->fill_form($output);
# Return content as scalar return $output; }
... Other runmodes go here ...
Geomap::FormApp provides a object-oriented base class for creating form-based web applications.
It is based on, and is a subclass of, CGI::Application. For the most part, Geomap::FormApp works like CGI::Application with some additional methods to simplify building applications.
Geomap::FormApp overrides three standard CGI::Application methods. Overriding these methods in your own application will break Geomap::FormApp's default behavior:
load_tmpl()
cgiapp_prerun()
teardown()
These methods should be overridden in the derived class:
validator_profile()
(See the documentation for Data::FormValidator for details.)
pretty_errors()
setup()
setup()
method, which should be used
to define the start_mode, mode_param, and run_modes for the application.
(See the documentation for CGI::Application for details.)
These methods may also be overridden:
validate_extra($previous,$error)
error()
method to get access to any existing errors (from form validation), and
the add_error()
method to inform the Geomap::FormApp error reporting system
of the error.
(See error(), add_error(), and the section on Error Handling.)
cgiapp_init(@args)
These methods add extra functionality to the standard CGI::Application:
These methods generate output:
output($vars,[$template_file])
output()
attempts
to use a template based on the runmode.
(For example, 'default.html' for the runmode 'default'.)
(See the documentation for Template-Toolkit for details on using template variables.)
error()
The error list is undefined if there have been no errors so far.
Errors can be added to the error list using the add_error()
method.
(See add_error()
and the section on Error Handling for more information.)
add_error($error_code,[$optional_data])
(See add_error()
and the section on Error Handling for more information.)
fill_form($text)
send_email($to,$from,$subject,$message)
send_email()
will use the configuration params 'email_to' or
'email_from' (as set in the new()
constructor).
get_session($session_id)
get_dbh()
get_session_cookie()
get_cookie($key)
set_cookie($key,$value)
clear_cookie($key)
query_data($query,@params)
Each array element represents one row of the result set as a hashref in which the keys are column names and the values are the column values.
query_data_row($query,@params)
query_data_array($query,@params)
update_data($query,@params)
(As with ordinary DBI queries, update_data()
returns '0E0' if zero rows are
affected, and undefined on errors. Perl treats '0E0' as 'zero but true'.)
new($config)
my $formapp = MyApp->new( TMPL_PATH => 'c:/devel/templates', PARAMS => { db => 'geomap:192.168.199.100', db_user => 'webdev', db_pass => '', error_param => '', error_mode => '', email_to => '', email_from => '', } );
The standard Geomap::FormApp configuration options are:
(If both this and 'error_mode' are unset, defaults to displaying the previous runmode.)
(If both this and 'error_param' are unset, defaults to displaying the previous runmode.)
Under Construction.
None by default.
Brad Smithart, <brad@smithart.net>
For Geomap Company