Last active
December 25, 2015 22:19
-
-
Save xenoterracide/7048828 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 MyContainer; | |
| use 5.010; | |
| use Moose; | |
| use Bread::Board; | |
| sub instance { | |
| state $locator = __PACKAGE__->new; | |
| return $locator; | |
| } | |
| sub BUILD { | |
| my $self = shift; | |
| container $self => as { | |
| service config => ( | |
| class => 'Config::Merge', | |
| lifecycle => 'Singleton', | |
| block => sub { Config::Merge->new('/path/to/config'); }, | |
| ); | |
| service dbh => ( | |
| class => 'DBI::db', | |
| lifecycle => 'Singleton', | |
| dependencies => { | |
| config => depends_on('config'), | |
| }, | |
| block => sub { | |
| my $s = shift; | |
| my $config = $s->param('config'); | |
| return DBI->connect( $config->('db.dsn'), $config->('db.user'), $config->('db.pass') ); | |
| }, | |
| ); | |
| }; | |
| } | |
| package ProductVariant; | |
| sub _load_categories { | |
| ... | |
| my $dbh = MyContainer->instance>resolve( service => 'dbh' ); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment