Well, I think the eval is working exactly as it should (or at least like
perl thinks it should), in that it is evaluated the first time the module is
loaded, because it is at the top, but after that it has no reason it run
because the script is still running and it isn't in a subroutine that is
called or anything like that.

I think I'll write a subroutine that passes back a dbh handle and call that
sub from every sub I use that interacts with the database - is this the
accepted way to do things?

I should probably reread the camel book chapter on OO and start using that
more, just haven't gotten around to it :-)

Anyways, much thanks for all your help!

Curtis H.

----- Original Message -----
From: "Geoffrey Young" <[EMAIL PROTECTED]>
To: "'Curtis Hawthorne'" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
Sent: Tuesday, July 31, 2001 3:14 PM
Subject: RE: mod_perl/DBI problem

<snip>

> hmph, it's been a while since I've done any Registry.pm work...
>
> basically, all my stuff is OO now, so I use a method handler that inherits
> from a base Util class and call
> my $dbh = $self->connect;
> where Util::connect() contains the eval() construct.  that works like a
> charm.
>
> I don't understand why the eval() isn't working as it should, but maybe
its
> a windows thing or maybe I'm missing something - using eval() as an
> exception handling mechansim ought to execute the code every time,
> regardless of whether perl has seen it already.  perhaps its a nested
eval()
> thing...
>
> at any rate, your suggestions below are good ones to follow - I think
you're
> on the right path.  try creating a util package, or at least a subroutine
> within your script that contains the eval() and passes $dbh back to you
and
> see if that helps.  almost there :)
>
> --Geoff
>
> >
> > Pseudo code of my module:
> > eval {
> >     &connect_to_database;
> > };
> >
> > if($@) {
> >     &writeerror;
> >     &clear(%Connected);
> > }
> >
> > sub dostuff {
> >     return &manipulatedatabase;
> > }
> >
> > sub dothings {
> >     return &querydatabase;
> > }
> >
> > So, should I rewrite it so that it makes a new connection
> > (but not really
> > because of Apache::DBI) in each sub, or have the script call
> > a subroutine
> > that gives it a database handle to pass to each sub, go at it
> > a completely
> > different way, or am I way off in my analysis of the problem?
> >
> > Really confused,
> >
> > Curtis H.
<snip>

Reply via email to