View on
MetaCPAN is shutting down
For details read Perl NOC. After June 25th this page will redirect to
Jesse Luehrs > Bread-Board-Declare-0.14 > Bread::Board::Declare



Annotate this POD



Open  0
View/Report Bugs
Module Version: 0.14   Source   Latest Release: Bread-Board-Declare-0.16


Bread::Board::Declare - create Bread::Board containers as normal Moose objects


version 0.14


  package MyApp;
  use Moose;
  use Bread::Board::Declare;

  has dsn => (
      is    => 'ro',
      isa   => 'Str',
      value => 'dbi:mysql:my_db',

  has dbic => (
      is           => 'ro',
      isa          => 'MyApp::Model::DBIC',
      dependencies => ['dsn'],
      lifecycle    => 'Singleton',

  has tt => (
      is  => 'ro',
      isa => 'MyApp::View::TT',
      dependencies => {
          template_root => dep(value => './root/templates'),

  has controller => (
      is           => 'ro',
      isa          => 'MyApp::Controller',
      dependencies => {
          model => 'dbic',
          view  => 'tt',

  MyApp->new->controller; # new controller object with new model and view
      model => MyApp::Model::KiokuDB->new,
  )->controller; # new controller object with new view and kioku model


This module is a Moose extension which allows for declaring Bread::Board container classes in a more straightforward and natural way. It sets up Bread::Board::Container as the superclass, and creates services associated with each attribute that you create, according to these rules:

Constructor parameters for services (dependencies, lifecycle, etc) can also be passed into the attribute definition; these will be forwarded to the service constructor. See Bread::Board::Declare::Meta::Role::Attribute::Service for a full list of additional parameters to has.

If infer => 1 is passed in the attribute definition, the class in the type constraint will be introspected to find its required dependencies, and those dependencies will be automatically fulfilled as much as possible by corresponding services in the container. See Bread::Board::Manual::Concepts::Typemap for more information.

In addition to creating the services, this module also modifies the attribute reader generation, so that if the attribute has no value, a value will be resolved from the associated service. It also modifies the get method on services so that if the associated attribute has a value, that value will be returned immediately. This allows for overriding service values by passing replacement values into the constructor, or by calling setter methods.

Note that default/builder doesn't make a lot of sense in this setting, so they are explicitly disabled. In addition, multiple inheritance would just cause a lot of problems, so it is also disabled (although single inheritance and role application works properly).



  dependencies => {
      foo => dep('foo'),
      bar => dep(value => 'bar'),

This is a helper function for specifying dependency lists. Passing a single argument will explicitly mark it as a dependency to be resolved by looking it up in the container. This isn't strictly necessary (the dependency specifications for Bread::Board have a coercion which does this automatically), but being explicit can be easier to understand at times.

This function can also take a hash of arguments. In that case, an anonymous service is created to satisfy the dependency. The hash is passed directly to the constructor for the appropriate service: if the value parameter is passed, a Bread::Board::Literal service will be created, if the block parameter is passed, a Bread::Board::BlockInjection service will be created, and if the class parameter is passed, a Bread::Board::ConstructorInjection service will be created. Note that these anonymous services cannot have dependencies themselves, nor can they be depended on by other services.


No known bugs.

Please report any bugs through RT: email bug-bread-board-declare at, or browse to




You can find this documentation for this module with the perldoc command.

    perldoc Bread::Board::Declare

You can also look for information at:


Jesse Luehrs <doy at tozt dot net>


This software is copyright (c) 2013 by Jesse Luehrs.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

syntax highlighting: