« The Beast from the East | Main | a tree fire »

bless you my child

Hat tip to StrayTaoist over on #cabal for not only fixing my inheritance problem but for also showing me a nifty alternative for getting a database handle in my object.
I always have a connect function, which I accessed very simply in my other functions via
my $dbh = myconnect(), killing the database handle on exit on that call.
The suggestion was to cache the handle in the object from the connect function, something I didn't think of doing, I always thought the handle should be disconnected after each function call.
So my connect function returns $self->{_dbh};
The final code, which is much improved, makes the handle available during the construction of the object.
bless { _dbh => $class->myconnect }, $class
so $self->_dbh is available immediately on construction of a new object.
I always constructed objects with an empty bless, I had no idea you could pass bless a call to a function as it's first argument, but it works and it's fast.