NAME
MongoDBx::Class::EmbeddedDocument - A MongoDBx::Class embedded (sub-)document role
VERSION
version 1.03
SYNOPSIS
# create an embedded document class
package MyApp::Schema::PersonName;
use MongoDBx::Class::Moose; # use this instead of Moose
use namespace::autoclean;
with 'MongoDBx::Class::EmbeddedDocument';
has 'first_name' => (is => 'ro', isa => 'Str', required => 1, writer => 'set_first_name');
has 'middle_name' => (is => 'ro', isa => 'Str', predicate => 'has_middle_name', writer => 'set_middle_name');
has 'last_name' => (is => 'ro', isa => 'Str', required => 1, writer => 'set_last_name');
sub name {
my $self = shift;
my $name = $self->first_name;
$name .= ' '.$self->middle_name.' ' if $self->has_middle_name;
$name .= $self->last_name;
return $name;
}
__PACKAGE__->meta->make_immutable;
DESCRIPTION
MongoDBx::Class::EmbeddedDocument is a Moose role meant to be consumed by document classes representing embedded documents. These are documents that are entirely contained within parent MongoDB documents.
The role provides expanded embedded documents with some common attributes and useful methods.
ATTRIBUTES
_collection
The MongoDBx::Class::Collection object representing the MongoDB collection in which this embedded document is stored (more correctly, the collection in which the MongoDBx::Class::Document holding this embedded document is stored). This is a required attribute.
_class
A string. The name of the document class of this embedded document. A required attribute.
METHODS
The following methods are provided:
as_hashref()
Returns the embedded document as a hash reference, without the _collection and _class attributes (if they exist).
INTERNAL METHODS
_database()
Convenience shortcut for running $embd_doc->_collection->_database
.
_attributes()
Returns a list of names of all attributes the embedded document object has, minus '_collection' and '_class', sorted alphabetically.
AUTHOR
Ido Perlmuter, <ido at ido50.net>
BUGS
Please report any bugs or feature requests to bug-mongodbx-class at rt.cpan.org
, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=MongoDBx-Class. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
SUPPORT
You can find documentation for this module with the perldoc command.
perldoc MongoDBx::Class::EmbeddedDocument
You can also look for information at:
RT: CPAN's request tracker
AnnoCPAN: Annotated CPAN documentation
CPAN Ratings
Search CPAN
SEE ALSO
MongoDBx::Class::Moose, MongoDBx::Class::Document.
LICENSE AND COPYRIGHT
Copyright 2010-2012 Ido Perlmuter.
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.