NAME
MongoDBI::Document::Config - Configuration for a MongoDBI Document Class
VERSION
version 0.0.10
SYNOPSIS
package main;
my $cds = CDDB::Album;
$cds->config->set_collection('some_classes');
$cds->config->set_database('test');
$cds->config->options->{safe} = 0; # on error, continue
1;
DESCRIPTION
MongoDBI::Document::Config is a trait attached to the MongoDBI configuration object created with/for each document class.
ATTRIBUTES
_mongo_connection
The _mongo_connection attribute contains the MongoDB::Connection object of the current class. Access it directly as follows:
package main;
my $cds = CDDB::Album;
$cds->config->_mongo_connection;
_mongo_collection
The _mongo_collection attribute contains the MongoDB::Collection object of the current class. Access it directly as follows:
package main;
my $cds = CDDB::Album;
$cds->config->_mongo_collection;
collection
The collection attribute contains the MongoDB::Collection attributes used to create the object. Access it directly as follows:
package main;
my $cds = CDDB::Album;
$cds->config->collection;
# get collection name
$cds->config->collection->{name};
database
The database attribute contains the MongoDB::Database attributes used to create the object. Access it directly as follows:
package main;
my $cds = CDDB::Album;
$cds->config->database;
# get database name
$cds->config->database->{name};
fields
The fields attribute contains a hashref of field configurations generated by the key() keyword. Learn more about the key() keyword at MongoDBI::Document::Sugar. Access the fields attribute directly as follows:
package main;
my $cds = CDDB::Album;
$cds->config->field;
# get field info
$cds->config->fields->{$name};
print $cds->config->fields->{$name}->{is};
print $cds->config->fields->{$name}->{isa};
indexes
The indexes attribute contains a hashref of index configurations generated by the index() keyword. Learn more about the index() keyword at MongoDBI::Document::Sugar. Access the indexes attribute directly as follows:
package main;
my $cds = CDDB::Album;
$cds->config->indexes;
# run through all indexes
for (@{$cds->config->indexes}) {
...
}
# print field names of the first registered index
print $_ for keys $cds->config->indexes->[0]->[0];
options
The options attribute may contains the arguments that will be passed to the MongoDB::Collection collection altering operations such as insert, update, remove and save.
Note: Setting this attribute will affect those collection altering operations. Note: Safe Mode is enabled by default!
Access it directly as follows:
package main;
my $cds = CDDB::Album;
$cds->config->options->{safe} = 0;
searches
The searches attribute contains a hashref of filter specifications generated by the filter() keyword. Learn more about the filter() keyword at MongoDBI::Document::Sugar. Access the searches attribute directly as follows:
package main;
my $cds = CDDB::Album;
$cds->config->searches;
# get search routine
$cds->config->searches->{$name};
# execute a search routine
my $search = $cds->config->search->{$name}->($cds->config->search);
METHODS
set_collection
The set_collection method stashes the attributes that will used to create a MongoDB::Collection object when the database connection is made. Utilize this method as follows:
package main;
my $cds = CDDB::Album;
$cds->config->set_collection('albums');
# semantically correct
$cds->config->set_database(name => 'albums');
# sophisticated version
$cds->config->set_database(name => $cds, naming => [
short, plural, decamel
]);
# valid naming convention keys are:
* same - as-is
* short - only the final portion of the package name
* plural - unintelligent 's' adder
* decamel - MyApp becomes my_app
* undercolon - :: becomes _
* lower/lc - lowercase string
* upper/uc - uppercase string
* default - same as (decamel, undercolon, lower, plural)
set_database
The set_database method stashes the attributes that will used to create a MongoDB::Database object when the database connection is made. Utilize this method as follows:
package main;
my $cds = CDDB::Album;
$cds->config->set_database('test');
# semantically correct
$cds->config->set_database(name => 'test');
AUTHOR
Al Newkirk <awncorp@cpan.org>
COPYRIGHT AND LICENSE
This software is copyright (c) 2011 by awncorp.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.