Created
March 6, 2012 15:13
-
-
Save zby/1986741 to your computer and use it in GitHub Desktop.
Bread::Board synopsis
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
use Bread::Board; | |
my $c = container 'MyApp' => as { | |
service 'log_file_name' => "logfile.log"; | |
service 'logger' => ( | |
class => 'FileLogger', | |
lifecycle => 'Singleton', | |
dependencies => [ | |
depends_on('log_file_name'), | |
] | |
); | |
container 'Database' => as { | |
service 'dsn' => "dbi:SQLite:dbname=my-app.db"; | |
service 'username' => "user234"; | |
service 'password' => "****"; | |
service 'dbh' => ( | |
block => sub { | |
my $s = shift; | |
require DBI; | |
DBI->connect( | |
$s->param('dsn'), | |
$s->param('username'), | |
$s->param('password'), | |
) || die "Could not connect"; | |
}, | |
dependencies => wire_names(qw[dsn username password]) | |
); | |
}; | |
service 'application' => ( | |
class => 'MyApplication', | |
dependencies => { | |
logger => depends_on('logger'), | |
dbh => depends_on('Database/dbh'), | |
} | |
); | |
}; | |
no Bread::Board; # removes keywords | |
# get an instance of MyApplication | |
# from the container | |
my $app = $c->resolve( service => 'application' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment