Next, lets get our application's database setup configured and running. For the purposes of this tutorial, we're going to drop all our files into a single application module called MyApp. This will keep it all clean and neat. In accordance with standard Perl package setup, you'll need to create a directory called MyApp within your Perl include path, typically /usr/lib/perl5 or something similar.
Inside this directory, let's create our database configuration file called DB.pm with the following settings:
package MyApp::DB;First is the package declaration, then we pull in the Rose:DB files. Next we create a private registry for our Rose::DB class that keeps it isolated from any other setups. Last we have our actual configuration settings for the database. The driver in this case is MySQL, but could be any of the compatible drivers (postgres, etc). The rest - database, host, username, and password are standard fare for database configuration.
use Rose::DB;
our @ISA = qw(Rose::DB);
__PACKAGE__->use_private_registry;
__PACKAGE__->register_db(
driver => 'mysql',
database => 'my_db',
host => 'localhost',
username => 'my_user',
password => 'my_pass'
);
That's all we need to get started with a basic Rose::DB application. Now we can include our custom MyApp::DB class in a script like so:
use MyApp::DB;This is the first step towards using Rose::DB::Object and setting up our Object-Relational Mapping.
Previous: What is Object-Relational Mapping?
