Norma::ORM::Mappable - A Moose role to map database tables to objects
package MyApp::Recipe; use Moose; with 'Norma::ORM::Mappable' => { dbh => $dbh, table_name => 'recipes', }; 1; package main; my $recipe = MyApp::Recipe->new( title => 'Scrambled Eggs', instructions => 'Break two eggs into a bowl...', ); $recipe->save;
A database handle from DBI->connect
The name of the table which should map to this object
A list of column names that should be seen as valid for unique lookups
An arrayref of hashrefs, each hashref specifying a name, class, and nature. The name will be used to create an accessor method on this object. The class should be the class name of another object with Norma::ORM::Mappable role. The nature is one of belongs_to, has_many, or has_one. You may also specify foreign_key and foreign_primary_key as your naming scheme requires. For example, our recipe might have tags and comments:
with 'Neocracy::ORM::Table' => { ... table_name => 'recipes', relationships => [ { name => 'comments', class => 'MyApp::Recipe::Comment', nature => 'has_many', }, { name => 'contributors', class => 'MyApp::Recipe::Contributor', nature => 'belongs_to', }, { name => 'ingredients', class => 'MyApp::Recipe::Ingredient', nature => 'has_many', map_table => 'recipe_ingredients_map', foreign_key => 'ingredient_id', foreign_primary_key => 'recipe_id', } ];
Objects and collections loaded through these relationships will be loaded lazily.
Instantiate an object in preparation for inserting a new row with save() or merge(). Use load() to instatiate an object from an existing row in the database.
Class method to instantiate an object from an existing row in the database.
Write the object to the database, either through an insert or an updated, depending on whether the object was instantiated via new() or load().
Write to the database if the row passes any unique constraints, otherwise instantiate from the already-existing row.
Perform subtype type checking to see that values pass attribute-level constraints.
Delete from the database the row that corresponds to this object.
Class method to return a collection of objects. See Norma::ORM::Collection for details.
Norma, Norma::ORM::Collection
David Chester <davidchester@gmx.net>
This software is copyright (c) 2010-2011 by David Chester.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Norma, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Norma
CPAN shell
perl -MCPAN -e shell install Norma
For more information on module installation, please visit the detailed CPAN module installation guide.