Stevan Little > MongoDBx-Bread-Board-Container-0.003 > MongoDBx::Bread::Board::Container

Download:
MongoDBx-Bread-Board-Container-0.003.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Source  

NAME ^

MongoDBx::Bread::Board::Container

VERSION ^

version 0.003

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.

mongo_connection_class

This is the name of the MongoDB connection class, it default to MongoDB::Connection, which is what you want to use most of the time, but if you want something else then you put it here.

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

syntax highlighting: