Skip to content

Instantly share code, notes, and snippets.

@xenoterracide
Last active December 25, 2015 22:19
Show Gist options
  • Select an option

  • Save xenoterracide/7048828 to your computer and use it in GitHub Desktop.

Select an option

Save xenoterracide/7048828 to your computer and use it in GitHub Desktop.
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