#!/usr/bin/perl -w -T
my $HOME_DIR;
BEGIN { '/home/somename/public_html/pc'; }
use strict;
use lib '/home/somename/public_html/pc/modules'; # this is where I put MyApp.pm
use lib '/home/somename/perl/usr/lib/perl5/site_perl/5.8.8'; # this is where I installed Perl modules
use CGI::Carp qw(fatalsToBrowser);
use MyApp;
MyApp->new(
,-config_file => '/home/somename/public_html/pc/config/pc.cfg'
)->run;
####
user the_username
password the_password
dsn dbi:mysql:database=somename_database:host=localhost
cgi_session_dsn driver:mysql;serializer:Storable
cookie_path /
####
package MyApp;
use strict;
use base 'CGI::Application';
use CGI::Application::Plugin::AutoRunmode;
use CGI::Application::Plugin::Config::Simple;
use CGI::Application::Plugin::DBH (qw/dbh_config dbh/);
use CGI::Application::Plugin::Session;
sub cgiapp_init {
my ($self, %params) = @_;
# -- config
$self->config_file($params{-config_file});
$self->dbh_config(
$self->config_param('dsn')
,$self->config_param('user')
,$self->config_param('password')
);
# -- session
$self->session_config(
CGI_SESSION_OPTIONS => [
$self->config_param('cgi_session_dsn')
,$self->query
,{Handle=>$self->dbh}
],
DEFAULT_EXPIRY => '+31d', # should this match -expires below? TBD
COOKIE_PARAMS => {
-expires => '+31d'
,-path => $self->config_param('cookie_path')
}
);
}
sub terminate {
my $self = shift;
$self->session->flush if $self->session_loaded;
# CGI::Sesssion documentation says "auto-flushing can be unreliable.
# ...regard it as mandatory that sessions always need to be explicitly
# flushed before the program exits... sub teardown() would be the
# appropriate place to do this.
}
sub display_form : StartRunmode {
my $self = shift;
my $q = $self->query;
my $session_data = $self->session->param('stuff') || 1;
my $result = $q->start_html(-title => 'Client Login')
. $q->start_form
. 'First Name: ' . $q->textfield(-name=>'firstName')
. $q->br . $q->submit
. $q->hidden(-name =>'rm', -value => 'page_2')
. $q->end_form
. $q->br . $session_data
. $q->end_html
;
$session_data++; # reload the page to see the value change above
$self->session->param(stuff=>$session_data);
return $result;
}