package MyApp::DB;
use Rose::DB;
our @ISA = qw(Rose::DB);
MyApp::DB->register_db(
domain => 'default',
type => 'default',
driver => 'mysql',
database => 'mydb',
host => 'localhost',
username => 'someuser',
password => 'mysecret');
1;
####
package MyApp::DB::Object;
use Rose::DB::Object;
our @ISA = qw(Rose::DB::Object);
sub init_db { MyApp::DB->new }
1;
##
##
package MyApp::DB::Gallery;
use MyApp::DB::Object;
our @ISA = qw(MyApp::DB::Object);
__PACKAGE__->meta->table('galleries');
__PACKAGE__->meta->columns(...);
sub new
{
my($class, %args) = @_;
my $dir = $args{'directory'};
if (-e $dir) {
die "directory '$dir' exists";
}
mkdir $dir or die "mkdir($dir) - $!";
# The following is roughly equivalent to find_or_create()
my $self = $class->SUPER::new(%args);
$self->load(speculative => 1); # Find...
if($self->not_found) {
$self->save; # ...or create
}
return $self;
}
1;
##
##
package MyApp::Table;
...
sub add_leg
{
my($self, $leg) = @_;
$leg->table_id($self->id); # tie leg to this table
$leg->save;
push(@{$self->{'legs'}}, $leg);
}