Skip to content

Instantly share code, notes, and snippets.

@zby
Created March 6, 2012 15:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zby/1986741 to your computer and use it in GitHub Desktop.
Save zby/1986741 to your computer and use it in GitHub Desktop.
Bread::Board synopsis
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