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

NAME

Document::Transform::Backend::MongoDB - Talk to a MongoDB via a simple interface

VERSION

version 1.110530

SYNOPSIS

    use Document::Transform::Backend::MongoDB;

    my $backend = Document::Transform::Backend::MongoDB->new(
        host => $ENV{MONGOD}
        database_name => 'foo',
        transform_collection => 'transforms',
        document_collection => 'documents');

    my $doc = $backend->fetch_document_from_key(
        MongoDB::OID->new(value => 'deadbeef'));

DESCRIPTION

So you need Document::Transform to talk MongoDB. You're in luck, bucko, because this module is your godsend. And it comes by default! Now, there are a couple of different ways to instantiate this and different levels of attributes that can be filled. You can plug in the collections, you can plug in collection names and a database instance, you can plug in collection names, a database name, and connection instance. And if you don't have any instances then some connection info, database name, and collection names are all you need! So it is like you pick your level of support when calling into a PBS telethon.

PUBLIC_ATTRIBUTES

document_constraint

    is: ro, isa: Moose::Meta::TypeConstraint
    builder: _build_document_constraint, lazy: 1

This attribute implements "document_constraint" in Document::Transform::Role::Backend and provides a meaningful type constraint built using "document_id_key" in the where clause to check for the appropriate keys in the data structure that represents a document.

transform_constraint

    is: ro, isa: Moose::Meta::TypeConstraint
    builder: _build_transform_constraint, lazy: 1

This attribute implements "transform_constraint" in Document::Transform::Role::Backend and provides a meaningful type constraint built using "transform_id_key" in the where clause to check for the appropriate keys in the data structure that represents a transform.

host

    is: ro, isa: Str

host contains the host string provided to the MongoDB::Connection constructor.

connection

    is: ro, isa: MongoDB::Connection, lazy: 1

This attribute holds the MongoDB connection object. If this isn't provided and it is accessed, a connection will be constructed using the "host" attribute.

database_name

    is: ro, isa: Str

If the collections are not provided, this attribute must be provided as a means to access the collections named in the "transform_collection" and "document_collection"

database

    is: ro, isa: MongoDB::Database, lazy: 1

This attribute holds the MongoDB data in which the transform and document collections are held. If this isn't provided in the constructor, one will be constructed using the value from "database_name". If there is no value, an exception will be thrown.

document_collection

    is: ro, isa: Str

If a collection is not passed to "documents", this attribute will be used to access a collection from the "database".

documents

    is: ro, isa: MongoDB::Collection, lazy: 1

This attribute holds the collection from MongoDB that should be the documents that should be fetched for transformation. If a collection is not passed to the constructor, one will be pulled from the database using the value from "document_collection"

transform_collection

    is: ro, isa: Str

If a collection is not passed to "transforms", this attribute will be used to access a collection from the "database".

transforms

    is: ro, isa: MongoDB::Collection, lazy: 1

This attribute holds the collection from MongoDB that should be the transforms that should be fetched for transformation. If a collection is not passed to the constructor, one will be pulled from the database using the value from "transform_collection"

document_id_key

    is: ro, isa: Str,
    default: '_id',

transform_id_key

    is: ro, isa: Str,
    +default: '_id',

reference_id_key

    is: ro, isa: Str,
    +default: 'source',

This attribute holds the key used in the transform to reference the document to which this transform should occur.

PUBLIC_METHODS

fetch_document_from_key

    (Defined)

This method implements the "fetch_document_from_key" in Docoument::Transform::Role::Backend method. It takes a single key that should match a document within the documents collection with the right "document_id_key" attribute.

fetch_transform_from_key

    (Defined)

This method implements the "fetch_transform_from_key" in Docoument::Transform::Role::Backend method. It takes a single key that should match a transform within the transforms collection with the right "transform_id_key" attribute.

fetch_document_from_transform

    (Transform)

This method implements the "fetch_document_from_transform" in Docoument::Transform::Role::Backend method. It takes a Transform defined by "transform_constraint" that has DBRef to a document stored with in the "reference_id_key" attribute of the transform.

fetch_transform_from_document

This method is a no-op implementation of "fetch_transform_from_document" in Docoument::Transform::Role::Backend.

store_document

This method implements the "Document::Transform::Role::Backend/store_document" method with one key notable option. In addition to the document to store, a second boolean value can be passed to denote whether a "safe" insert/update should take place.

This method makes use of "document_id_key" to perform an update of the document.

store_transform

This method implements the "Document::Transform::Role::Backend/store_transform" method with one key notable option. In addition to the transform to store, a second boolean value can be passed to denote whether a "safe" insert/update should take place.

This method makes use of "transform_id_key" to perform an update of the transform.

has_document

    (Defined)

This method implements "has_document" in Document::Transform::Role::Backend. Simply provide a key and it will check Mongo if such a document exists using "document_id_key"

has_transform

    (Defined)

This method implements "has_transform" in Document::Transform::Role::Backend. Simply provide a key and it will check Mongo if such a transform exists using "transform_id_key"

is_same_document

    (Document, Document)

This method implements "is_same_document" in Document::Transform::Role::Backend. It does a string comparison between the two documents values stored in "document_id_key". If using the default '_id' value for "document_id_key", this will stringify the MongoDB::OID objects down to their hex key and compare them.

is_same_transform

    (Transform, Transform)

This method implements "is_same_transform" in Transform::Transform::Role::Backend. It does a string comparison between the two transforms values stored in "transform_id_key". If using the default '_id' value for "transform_id_key", this will stringify the MongoDB::OID objects down to their hex key and compare them.

AUTHOR

Nicholas R. Perez <nperez@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2010 by Infinity Interactive.

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