package MyApp::Contact;First we set add this file to the MyApp package. If you haven't already figured it out, you'll be saving this in your MyApp directory as Contact.pm. Then you tell the interpreter that you're going to use the MyApp::DB file, which contains your database configuration and connection information.
use MyApp::DB;
use base qw(Rose::DB::Object);
__PACKAGE__->meta->setup
(
table => 'contacts',
columns => [ qw(id name email) ],
pk_columns => 'id'
);
sub init_db { MyApp::DB->new }
The next part is where we get into the meat of the Rose::DB Object configuration - the __PACKAGE__->meta->setup function contains all the information that maps the table and fields to the actual object. The first option, table, is simply the name of the table that maps to the object. In this case, it is contacts. For all these tables and files, I like to use the singular version of the name of the object for the pm file, and the plural for the table name itself.
Next comes an array of the actual fields in the database. All you need here is the name of each of the column names and Rose::DB will take care of the rest. For the moment, we only have 3 fields, id, name and email. Finally, pk_columns identifies any primary key fields.
Once that is out of the way, we wrap the MyApp:DB->new function in the object's init_db subroutine so that our Contacts will know what database to use. Then we're ready to start creating and using our new Contact Rose::DB object!
Previous: Preparing our Database for Rose::DB
