Re: Dissappearing Lexicals

2000-08-31 Thread David E. Wheeler

Matt Sergeant wrote:
 
 On Wed, 30 Aug 2000, mgraham wrote:
 [snip]
  Personally, I've given up on package-scoped lexicals entirely, and
  moved everything into "use vars".  It's a pain, because you lose the
  encapsulation and you have to declare and assign the variables
  separately.  But it generally seems much more robust and predictable.
 
 This is a real worry for anyone using the Tie::SecureHash sort of thing to
 hide access to private variables.

Okay, I'll try to whip up a quick example today of this issue and submit
it to the list. It seems worthwhile to me to try to get this bug(?)
squashed for the reason Matt brings up and others.

David



Dissappearing Lexicals

2000-08-29 Thread David E. Wheeler

Hi All,

I've encounted a strange problem with our mod_perl installation. I have
a library for handling DBI stuff, and store the $dbh in a package-level
lexical. The $dbh is not populated until the first time a DBI call is
made - which is during a request and therefore always after Apache
forks. The $dbh is then used by various functions exported into other
modules.

However, in some of these functions, $dbh seems to be out of scope! In
other words, In some functions, the $dbh works fine, while in others, it
says "cannot call method 'selectcol_arrayref' on an undefined value."
Sure enough, it thinks that $dbh is undefined, even though it will show
up defined in other functions called just prior to or after the function
that attempts to call selectcol_arrayref. I have not my'd it within the
scope of the function - it is only declared at the package-level.

Now, I've managed to solve the problem by simply making $dbh a package
variable (use vars '$dbh';). However, the package-level lexical *was*
working on Friday, but would not as of yesterday!

Anyone got any ideas what the heck is happening to the value stored in
$dbh? I can provide more details about the construction of my DBI
library if you think that will help diagnose the problem.

Details: All DBI calls are made in one request, so there's no chance of
some calls being in different forks where $dbh may not yet have been
defined. Also, the DBI library I've written works fine when run from the
shell - it's only in mod_perl that it fails.

The setup: Solaris 2.4 running Apache 1.3.12  mod_perl 1.24. DBI is
version 1.14 and DBD::Oracle version 1.06.

TIA!

David