Created
March 7, 2012 09:27
-
-
Save zby/1992168 to your computer and use it in GitHub Desktop.
Moose based had made Factory (instead of Bread::Board)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
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