[cgiapp] error subclassing CGIApp
P Kishor
punk.kish at gmail.com
Wed Aug 5 13:22:27 EDT 2009
I have a pretty basic app modeled after the Perl CGI-App MVC pattern
by Mark Rajcok. It looks like so
index.cgi
-----------------------------------------------------
use MyApp;
my $App = 'MyApp';
CGI::Application::Dispatch->dispatch(
table => [
'welcome' => { app => $App, rm => 'welcome', },
'view' => { app => $App, rm => 'view', },
'account_prefs' => { app => $App, rm => 'account_prefs', },
'account_admin' => { app => $App, rm => 'account_admin', },
'' => { app => $App, rm => 'welcome', },
],
);
=====================================================
BaseCGIApp.pm
-----------------------------------------------------
package BaseCGIApp;
use strict;
use base 'CGI::Application';
use CGI::Simple;
use CGI::Application::Plugin::DBH qw(dbh dbh_config);
use CGI::Application::Plugin::Session;
use CGI::Application::Plugin::LogDispatch;
use CGI::Application::Plugin::Authentication;
sub cgiapp_get_query { my $self = shift; CGI::Simple->new(); }
# Configure the session once during the init stage
sub cgiapp_init {
my $self = shift;
$self->authen->config(
CREDENTIALS => [ 'username', 'password' ],
DRIVER => [
'DBI',
DBH => $self->dbh,
TABLE => 'users',
CONSTRAINTS => { 'username' => '__CREDENTIAL_1__',
'MD5:password' => '__CREDENTIAL_2__' },
],
LOGIN_RUNMODE => 'account_login',
LOGOUT_RUNMODE => 'welcome',
POST_LOGIN_RUNMODE => 'view',
POST_LOGIN_CALLBACK => \&_account_update_session_on_login,
);
}
sub setup {
my $self = shift;
$self->mode_param(path_info => 1, param => 'rm');
$self->start_mode('welcome');
$self->run_modes(
# unprotected runmodes
'account_create' => 'account_create',
'account_mail_pwd' => 'account_mail_pwd',
# protected runmodes
'account_login' => 'account_login',
'account_prefs' => 'account_prefs',
'account_admin' => 'account_admin',
);
$self->authen->protected_runmodes(
'account_prefs',
'account_admin'
);
}
sub cgiapp_prerun { my $self = shift; }
sub account_login {..}
sub account_prefs {..}
sub account_admin {..}
=====================================================
MyApp.pm
-----------------------------------------------------
package MyApp;
use strict;
use base 'BaseCGIApp';
sub setup {
my $self = shift;
$self->start_mode('welcome');
$self->run_modes(
'welcome' => 'welcome', # unprotected runmode
'view' => 'view', # protected runmode
);
$self->authen->protected_runmodes('view',);
}
sub welcome {..}
sub view {..}
=====================================================
The following work
http://../
http://../welcome
The following fail with the error "CGI::Application::Dispatch error! Not Found"
http://../view
http://../account_prefs
In other words, all protected runmodes are "not found." What am I doing wrong?
By the way, if I do away with the BaseCGIApp.pm, and move all the
runmodes into one single package 'MyApp' then everything works
properly.
--
Puneet Kishor http://www.punkish.org
Carbon Model http://carbonmodel.org
Charter Member, Open Source Geospatial Foundation http://www.osgeo.org
Science Commons Fellow, http://sciencecommons.org/about/whoweare/kishor
Nelson Institute, UW-Madison http://www.nelson.wisc.edu
-----------------------------------------------------------------------
Assertions are politics; backing up assertions with evidence is science
=======================================================================
Sent from Madison, WI, United States
More information about the cgiapp
mailing list