Skip to content

Instantly share code, notes, and snippets.

@lestrrat
Created March 5, 2009 22:57
Show Gist options
  • Save lestrrat/74622 to your computer and use it in GitHub Desktop.
Save lestrrat/74622 to your computer and use it in GitHub Desktop.
use Bread::Board;
my $c = Bread::Board->new();
# Parameters are bound to the main bread board container
$c->param('configfile' => '/path/to/file.conf');
# You can create a service that depends on this param
$c->inject(config =>
Bread::Board::Service::Deferred->new(
code => sub {
my ($self, $c) = @_;
my $filename = $c->param('configfile');
my $cfg = Config::Any->load_files({ files => [ $filename ], use_ext => 1 });
return $cfg->[0]->{$fielname};
}
)
});
# Fetch the value!
$c->value('config');
# You may want to be flexible using parameterized services
$c->inject('Schema/:name' =>
Bread::Board::Service::Parameterized->new(
code => sub {
my ($self, $c, $params) = @_;
my $config = $c->value('config');
my $name = $params->{name};
my $class = "MyApp::Schema::$name";
Class::MOP::load_class($class);
$class->connection($c->value('config')->{"Schema::$name"});
}
);
);
my $main_db = $c->value('Schema/MainDB');
my $anoterh_db = $c->value('Schema/AnotherDB');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment