Jesse Luehrs > Bread-Board-Declare-0.15 > Bread::Board::Declare

Download:
Bread-Board-Declare-0.15.tar.gz

Dependencies

Annotate this POD

Website

View/Report Bugs
Module Version: 0.15   Source   Latest Release: Bread-Board-Declare-0.16

NAME ^

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

VERSION ^

version 0.15

SYNOPSIS ^

  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
  MyApp->new(
      model => MyApp::Model::KiokuDB->new,
  )->controller; # new controller object with new view and kioku model

DESCRIPTION ^

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).

EXPORTS ^

dep

  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.

BUGS ^

No known bugs.

Please report any bugs to GitHub Issues at https://github.com/doy/bread-board-declare/issues.

SEE ALSO ^

Bread::Board

SUPPORT ^

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

    perldoc Bread::Board::Declare

You can also look for information at:

AUTHOR ^

Jesse Luehrs <doy@tozt.net>

COPYRIGHT AND LICENSE ^

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

This is free software, licensed under:

  The MIT (X11) License
syntax highlighting: