MooseX::ClassAttribute would likely help.

However what your doing is not really all that bad if your only doing it in one place.

Personally I would make the dbh a regular attribute and use some kind of dependency injection to provide the actual DBI handle.

- Stevan

On May 5, 2009, at 12:59 PM, Dan Horne wrote:

Hi

I have an application base class that is inherited by all classes within an application. It has a couple of globals that are also accessible to the subclasses - namely a database handle and a Log4perl logger. For example, the db handle code looks something like:

our $DBH;

sub dbh {
        my $self = shift;

        unless ($DBH) {
             $DBH = DBI->connect(...);
       }

      return $DBH;
}

How would I go about achieving this functionality using a Moose idiom?

Dan

Reply via email to