Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^4: Does there exist a CPAN module for lazily initialized variables?

by jryan (Vicar)
on Jul 14, 2004 at 19:16 UTC ( [id://374405]=note: print w/replies, xml ) Need Help??


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

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...

  • Comment on Re^4: Does there exist a CPAN module for lazily initialized variables?

Replies are listed 'Best First'.
Re^5: Does there exist a CPAN module for lazily initialized variables?
by diotalevi (Canon) on Jul 14, 2004 at 20:29 UTC

    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?

        Sure you could, but I wouldn't bother tying it at this point. You have to have one globally accessible symbol by which to reach this connection. Either it happens explicitly through &::dbh() or implicitly through tied $::dbh. I'd generally prefer to leave off with the tying to avoid excessive cuteness.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://374405]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (4)
As of 2024-04-24 01:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found