Skip to content

Instantly share code, notes, and snippets.

@zby
Created March 7, 2012 09:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zby/1992168 to your computer and use it in GitHub Desktop.
Save zby/1992168 to your computer and use it in GitHub Desktop.
Moose based had made Factory (instead of Bread::Board)
{
package Factory;
use Moose;
has log_file_name => ( is => 'ro', default => "logfile.log" );
has logger => ( is => 'ro', lazy_build => 1 );
sub _build_logger { FileLogger->new( log_file_name => shift->log_file_name ) }
has dsn => ( is => 'ro', default => "dbi:SQLite:dbname=my-app.db" );
has username => ( is => 'ro', default => "user234" );
has password => ( is => 'ro', default => "****" );
has dbh => ( is => 'ro', lazy_build => 1 );
sub _build_dbh {
my $self = shift;
require DBI;
return DBI->connect(
$self->dsn,
$self->username,
$self->password,
) || die "Could not connect";
};
has application => ( is => 'ro', lazy_build => 1 );
sub _build_application {
my $self = shift;
return MyApplication->new(
logger => $self->logger,
dbh => $self->dbh,
)
}
}
my $application = Factory->new()->application;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment