The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

MongoDBx::Bread::Board::Container - An easy to use Bread::Board container for MongoDB

VERSION

version 0.002

SYNOPSIS

  use MongoDBx::Bread::Board::Container;

  # create a container

  my $c = MongoDBx::Bread::Board::Container->new(
      name            => 'MongoDB',
      host            => $HOST,
      database_layout => {
          test     => [qw[ foo bar ]],
          test_too => [qw[ baz gorch ]]
      }
  );

  # fetch the 'foo' collection
  # from the 'test' database
  my $foo = $c->resolve( service => 'MongoDB/test/foo');

  # get the MongoDB::Database
  # object for the 'test' db
  my $test = $c->resolve( service => 'MongoDB/test_dbh');

  # get the MongoDB::Connection
  # object used for all the above
  my $conn = $c->resolve( service => 'MongoDB/connection');

  # you can also create the container
  # within an existing Bread::Board config

  container 'MyProject' => as {

      # embed the Mongo container ...
      container(
          MongoDBx::Bread::Board::Container->new(
              name            => 'MyMongoDB',
              host            => $HOST,
              database_layout => {
                  test     => [qw[ foo bar ]],
                  test_too => [qw[ baz gorch ]]
              }
          )
      );

      # create services that depend
      # on the MongoDB container
      service 'foobar' => (
          class        => 'FooBar',
          dependencies => {
              collection => 'MyMongoDB/test/foo'
          }
      );
  };

DESCRIPTION

This is a subclass of Bread::Board::Container which can be used to provide services for your MongoDB consuming code. It manages your connection and additionally using the database_layout attribute can provide services to access your databases and collections as well.

ATTRIBUTES

name

This is inherited from Bread::Board::Container, this defaults to 'MongoDB' in this container.

host

The hostname passed to MongoDB::Connection, this defaults to 'mongodb://localhost:27017'.

additional_connection_params

If you want to pass additional parameters to the MongoDB::Connection constructor, just supply them here and they will get merged in with the host and port params.

database_layout

This is a data structure that represents the databases and collections you want to access. It is a HASH ref where the keys are the database names and the values are ARRAY refs of collection names. The set of sub-containers and services will then be created based on this information. See the SYNOPSIS and the tests for more detailed examples.

This attribute is required.

AUTHOR

Stevan Little <stevan.little@iinteractive.com>

COPYRIGHT AND LICENSE

This software is copyright (c) 2011 by Infinity Interactive, Inc..

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