I believe what you are considering is object-oriented programming,
which can make a lot of sense, if you build your objects correctly.
You decide which information is allowed to be stored in the object,
and which methods (functions) will be handled internally by the
object. Then you just pass around one variable, usually called
'$self'. When you want a dbh, you could run:
my $dbh = $self->dbh;
That's it ! Great idea. Thus, there will be only a few things to change in
koha.
You could very easily create a 'prepare' method in self, that would in
turn run 'prepare' on the dbh.
sub prepare {
my $self = shift;
my $query = shift || return;
my $dbh = $self->dbh || return;
my $sth = $dbh->prepare($query);
unless ($sth) {
warn $dbh->errstr;
}
return $sth;
}
Each method would handle its own error handling, when appropriate.
Adding methods for 'param' and 'stopwords' would also be really easy.
Let me know if you need any help, if you decide to go this route. I
now write most of my code in an object-oriented style, because I find
it much easier to keep track of where everything is. Then you can
also inherit methods from other objects, and all sorts of fun stuff
(perhaps down the road a ways).
I'm very poor at Perl-OOP, so any help is greatly welcomed ;-)