Here's my super-class code:
http://mark.stosberg.com/perl/CGIApp2.pm
It's definitely a little raw and under-documented. Hopefully it's good enough to "get the idea".
This is more of an implementation question, then a comment on your code.
I notice whenever people give examples of how they handle Database connections, or Session support in CGI::App, they always use the $self->param() construct to save/access these support modules.
The way I have always done it is to create a method that uses lazy loading to create/access a session module, or DB handle (or any other support modules that are needed).
For example here is how I use CGI::Session in my base class:
sub session {
my $self = shift; if (!$self->{_session}) {
# create CGI::Session object for session handling
$self->{_session} = CGI::Session->new(
'driver:PostgreSQL',
scalar $self->query->cookie(CGI::Session->name),
{ Handle => $self->db }
);
} return $self->{_session};
}This will only create the session object if it is called during the request, and allows for very clear and concise usage in the run modes.
For example in my runmode if I need a session parameter I can use the following:
my $language = $self->session->param('language');
If I were to stash this in the $self->param method that CGI::App provides I would need to do the following:
my $language = $self->param('session')->param('language');
Which just looks clunky and inconvenient to me, and doesn't have the same lazy loading benefit.
I guess the question I want answered, is there something wrong with the way I am implementing this 'session' method? Why don't I see it used more often? It just seems so much easier to me than dealing with $self->param() all the time. I guess the only thing I can see is a possible name space colision with the $self->{_session} key, but that is easy enough to code around.
Cheers,
Cees
--------------------------------------------------------------------- Web Archive: http://www.mail-archive.com/[EMAIL PROTECTED]/ http://marc.theaimsgroup.com/?l=cgiapp&r=1&w=2 To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
