Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Structuring multiple CGI::Application modules

by valdez (Monsignor)
on Jun 25, 2004 at 21:49 UTC ( [id://369754]=note: print w/replies, xml ) Need Help??


in reply to Structuring multiple CGI::Application modules

When I need to share authorization code between different C::A applications, I put the necessary code in the cgiapp_prerun() method of a base module; then every application use that module and inherits everything needed, including some common run modes (i.e. login, login_failed, etc). BTW, this is also the suggested solution in CGI::Application documentation.
The following is a stripped down example from my code:

package MyApp::Base; use base 'CGI::Application'; sub cgiapp_init { my $self = shift; # init your application: session, database, whatever is needed ... # set the name of the run mode CGI param $self->mode_param('rm'); # shared run modes $self->run_modes('login' => 'login', 'AUTOLOAD' => 'autoload_exception'); return; } ... sub session { return shift->param('SESSION'); } ... sub cgiapp_prerun { my $self = shift; my $runmode = shift; my $user = $self->session->param('user'); unless ($user) { $self->prerun_mode( 'login' ); } }
Then in your application you only need to say:
package MyApp::Application1; use base 'MyApp::Base'; ...
and your application will be accessible only to authorized users.

HTH, Valerio

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://369754]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (5)
As of 2024-04-19 13:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found