package Exported;
# all the usual stuff here...
my $dbh;
sub set_dbh ( $ )
{
( $dbh ) = @_;
}
sub do_query ( $ )
{
my ( $key ) = @_;
return $dbh->selectrow_hashref( ... )
}
####
my $dbh = DBI->connect( ... );
set_dbh( $dbh );
my $answer = do_query( $key );
####
package MyQuery;
sub new
{
my ( $class, $dbh ) = @_;
return bless { dbh => $dbh }, $class;
}
sub do_query
{
my ( $self, $key ) = @_;
return $self->{dbh}->selectrow_hashref( ... );
}
####
my $dbh = DBI->connect( ... );
my $query_obj = MyQuery->new( $dbh );
my $answer = $query_obj->do_query( $key );
####
package Exported;
# blah blah blah :)
our $dbh;
*dbh = \$main::dbh;
# now you can refer to just $dbh and it will use the
# value in $main::dbh
sub do_query ( $ )
{
my ( $key ) = @_;
return $dbh->selectrow_hashref( ... );
}