NAME

MongoDBI::Application - MongoDBI Application Class and Document Class Controller

VERSION

version 0.0.4

SYNOPSIS

package CDDB;

use MongoDBI;

app {

    # shared mongodb connection
    database => {
        name => 'mongodbi_cddb',
        host => 'mongodb://localhost:27017'
    },

    # load child doc classes
    classes => {
        self => 1 # loads CDDB::*
    }

};

1;

DESCRIPTION

MongoDBI::Application is used to load and configure associated document classes. It is essentially the application hub (or starting-point). Because all MongoDBI document classes can have their own database configuration, and thus need to be setup individually, MongoDBI::Application can be used to bring those individual classes together to form a single application.

MongoDBI::Application exports the app() method which allows you to configure your application having the configuration applied to all associated document classes. MongoDBI::Application will also load all associated classes and make them available through the class() method after instantiation.

Modeling your database schema will involve learning how models are crafted using MongoDBI::Document, please read that documentation towards getting started. Enjoy!!!

EXPORTS

app

The app method will be exported into the calling class allowing it to configure all associated document classes. MongoDBI::Document classes are designed so that each class may use a different database connection for greater flexibility, however there are times when you will want/need all of your application's document classes to share a single database connection and MongoDBI::Application allows you to do that. MongoDBI::Application can also preload specified classes.

The following examples are recognized parameters the app() method uses to configure your application.

# share mongodb connection across all document classes
app {
    
    # shared mongodb connection
    # accepts all parameters MongoDB::Connection does
    database => {
        name => 'mongodbi_cddb',
        host => 'mongodb://localhost:27017'
    }
    
};

# load desired document classes 
app {
    
    classes => {
        self => 1, # loads all classes under the current namespace
        load => [
            'Other::Classes',
            'More::Classes',
        ]
    }
    
};

ATTRIBUTES

config

The config attribute gives you access to the MongoDBI::Application class configuration although it is likely you will never need to used it as the important elements are all exposed via methods.

my $app = App->new;

$app->config;

METHODS

class

The class method returns the class (string, uninstantiated) for the associated document class registered by the app() method. The class method accepts a class short-name and returns the fully-qualified class name.

my $app = App->new;

# base class name under same namespace not required (e.g. app_*)

my $foo = $app->class('foo'); # returns App::Foo;
my $bar = $app->class('bar_baz'); # returns App::BarBaz;

# must specify the base class name on foreign classes

my $xyz = $app->class('app2_xyz'); # returns App2::XYZ;

# if you're a stickler for convention,
# you can also use case-appropriate syntax

my $foo = $app->class('Foo'); # returns App::Foo;
my $bar = $app->class('BarBaz'); # returns App::BarBaz;

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.