On Mon, Jun 20, 2005 at 01:38:42PM -0400, Sam Tregar wrote: > On Mon, 20 Jun 2005, Tim Bunce wrote: > > > > Can you suggest a good > > > place to put the code to collect open handles? Knowing nothing about > > > the internals I'm guessing connect() is the right spot. > > > > Actually _new_handle() in DBI.pm > > > > But first we need an API. A reasonable first draft would be to add a > > $h->{ChildHandles} attribute that's a hash where the values of the hash > > are the child handles. (The keys of the hash are irrelevant but unique. > > The hash will have undef elements for any old handles that have been > > destroyed so we'll need to prune them occasionally, but that can wait.) > > That sounds like a start, but how would I get that hash if I didn't > have a handle to start with? I'm imagining: > > $handles = DBI->ChildHandles();
$drh = DBI->install_driver('mysql'); $all_mysql_dbh = $drh->{ChildHandles}; (install_driver doesn't reinstall the driver if it's already loaded) > But I'm not sure I understand what "child" means in this context. > Perhaps: > > $handles = $dbh->{ActiveHandles}; > $handles = DBI->ActiveHandles(); > > That implies that the hash that comes back would be stripped of > inactive handles which sounds like a good things to me. Perhaps but let's keep it very simple to start with - just the attribute. > > So, given that API, you could start by trying something like this: > > > > weaken($parent->{ChildHandles}{$h} = $h); > > > > just after the call to DBI::_setup_handle($h, $imp_class, $parent, > > $imp_data); > > You'll need a use Scalar::Util qw(weaken); at the top. > > Sounds right. We'll need to do a probe for weaken() support though > (Redhat, in its infinite wisdom, shipped Perl 5.6.x without weaken() > in one of their distros). Would you rather have it at install-time or > run-time? Try something like this near the top of DBI.pm my $have_weaken = eval { require Scalar::Util; defined &Scalar::Util::weaken }; then Scalar::Util::weaken(...) if $have_weaken; > > That's a basic hack that might work well enough for you to write some > > tests that pass (add a new t/71childh.t test file). > > Will do. > > Thanks for the help! If there's ever a ballot for best CPAN > maintainer you've got my vote. Thanks! I always feel there's so much more I could be doing. What I need to do is try to open up the process more so others can contribute - which is where you come in :-) Tim.