in reply to Re^2: Does there exist a CPAN module for lazily initialized variables?
in thread Does there exist a CPAN module for lazily initialized variables?

I really like dbh() because it gives you a runtime chance to automatically reconnect or refresh or whatever as needed which you wouldn't get if you just accessed a global $DBH.
  • Comment on Re^3: Does there exist a CPAN module for lazily initialized variables?

Replies are listed 'Best First'.
Re^4: Does there exist a CPAN module for lazily initialized variables?
by jryan (Vicar) on Jul 14, 2004 at 19:16 UTC

    Yeah, my little class in the root node would do the same thing, since it just checks for definedness. I just want a pretty tied interface to it. I guess I'll just write my own class, and maybe make it general enough for CPAN...

      No, the difference here is that you make this call $dbh->connect_cached() so that instead of just storing your object - you revivify it automatically as needed. I think of this as important for something that will be long running - I'd just go with a plain stored value otherwise.

      sub main::dbh { # for daemons and long running code - reconnect as needed DBI->connect_cached( ... ) } sub main::dbh { # initialize the connection or re-use. $::DBH ||= DBI->connect( ... ) }

        Wouldn't that be something to change in the callback sub that you'd pass to the tie call?