package DBI_Wrapper; sub new { my $class = shift; my $self = bless { dbh => [], active => 0, }, $class; } sub add_dbhs { my $self = shift; push @{$self->{dbh}}, @_; } sub AUTOLOAD { my $meth = our $AUTOLOAD; (my $func = $meth) =~ s/.*:://; my $self = shift; my $start = $self->{active}; my $dbh; while (1) { $dbh = $self->{dbh}->[$self->{active}]; eval { $dbh->ping }; last unless $@; $self->{active}++; $self->{active} %= @{$self->{dbh}}; die "No valid DBH found\n" if $self->{active} == $start; } return $dbh->$meth( @_ ); }
Or, something like that. :-)
------
We are the carpenters and bricklayers of the Information Age.
Then there are Damian modules.... *sigh* ... that's not about being less-lazy -- that's about being on some really good drugs -- you know, there is no spoon. - flyingmoose
I shouldn't have to say this, but any code, unless otherwise stated, is untested
In reply to Re: Connecting to Multiple Databases
by dragonchild
in thread Connecting to Multiple Databases
by antonybr
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |