package MyApp::DBConnection
use Moose;
has dbh => {
is => 'ro'
};
sub BUILD {
#load the config from a config file, etc.
#create the connection, set the handle. Etc, etc.
}
1;
package MyApp;
use Moose;
has dbConnection (is => 'ro', isa => 'MyApp::DBConnection', default => sub { MyApp::DBConnection->new() });
1;
####
package MyApp::DB::User;
use Moose;
has dbh => (is => 'ro', required => 1);
sub runQuery {
return $shift->dbh->selectrow_array("sp_msforeachtable 'SELECT * FROM \?'");
}
####
#someplace in MyApp
sub doSomethingWithUser {
my $self = shift;
my $user = MyApp::DB::User->new({dbh => $self->DBConnection->dbh});
1;
}