Quoting Steve Comrie <[EMAIL PROTECTED]>:
> > You could have a cgiapp_prerun in your superclass, and also have one in
> your
> > application module. If you want both to be executed, then you just have
> to
> > remember to call $self->SUPER::cgiapp_prerun() in the cgiapp_prerun of
> your
> > application modules. This can give you great flexibility. YMMV
>
> That's exactly my point .. you could have both and call one using SUPER ..
> (in my CGIApp Order of Operators article I talked about using that method
> for cgiapp_init) but you have to remember to do it in every module. One of
> my systems right now has over 25 application modules.
I'm sure you have a 'barebones template' of an application module that you use
to start coding, so that shouldn't be a big issue.
> If you don't connect to the db or access session or config files until
> cgiapp_prerun that means you can't perform any database queries in setup()
> either, because setup gets called before cgiapp_prerun.
Agreed. But I am only advocating to put the functionality where it belongs.
Getting back to the original question, if he never uses the DB in setup, then he
can simplify his error handling by putting the connect code in cgiapp_prerun.
That was really my only point.
Personally I don't connect to the database unless a runmode actually needs a
database connection. This is easily accomplished with a helper function that
connects on demand. Something like this:
sub runmode1 {
my $self = shift;
my $db = $self->get_db() || return $self->error('Database connect failure');
...
}
sub get_db {
my $self = shift;
if (!$self->{_db}) {
# Connect to the DB (return false on failure)
}
return $self->{_db};
}
That is just an simple example of how you could get an db handle on demand. I
have been using Class::DBI lately, and it handles the DB connection for me. I
just instantiate my table objects, and it does the work of connecting to the DB.
> I just don't see the point of using cgiapp_prerun &
> $self->SUPER::cgiapp_prerun() when you have 2 other perfectly good functions
> that get called every time cgiapp executes.
My point is just to use those functions when you need them. Don't just use them
because they are there.
Both ways work. In fact both ways work well... We just differ on the semantics
of the implementation. TMTOWTDI
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]