The usual way would be to store the dbh in a package variable
and have a method for it, i.e.
package TArtLib;
use strict;
use vars qw($dbh);
...
sub dbh {
return $dbh;
}
Then TArt::Editor invokes the method:
package TArt::Editor;
use TArtLib;
...
my $dbh = TArtLib->dbh;
Note the usage of TArtLib inside of TArt::Editor; that relieves the code which
calls TArt::Editor from knowing what other modules are required.
The dbh class method would also be a good place to initialize things
(or call an initialization method) if $dbh is false.
Update:If what you want is one-time initialization, then this is
definitely the way to go. Don't use the package $dbh directly, but
go through a method as shown here; and use that method to do the one-time
initialization:
sub dbh {
unless ($dbh) {
# connect to the database now.
}
return $dbh;
}