In addition to additional_base_classes, as recommended earlier, you can also just declare packages and subs after building the loader. Here is a trimmed-down example of my database.pl script, this is pre-loaded by mod_perl so that my website (which is HTML::Mason based) will have access to all the database objects it needs. In this snippet of code the classes JSK::Tag and JSK::Software are generated by Class::DBI::Loader from the tag and software tables in the database.
use Class::DBI::Loader; use Data::Dumper; my $loader = Class::DBI::Loader->new( dsn => 'DBI:Pg:dbname=jasonk', user => 'jasonk', password => 'yeah, right, I'll leave this in, sure', relationships => 1, options => { AutoCommit => 1 }, additional_classes => [qw(Class::DBI::AbstractSearch)], additional_base_classes => [qw(JSK::DBUtils)], ); # calling additional Class::DBI functions on the generated # classes is easy JSK::Tag->columns(Stringify => qw(tag)); # This package is for additional_base_classes, I don't # have a table called 'dbutils', but all the generated # Class::DBI tables inherit from this package. package JSK::DBUtils; use strict; use warnings; use Carp qw(croak); sub some_cool_db_function { ... } # The JSK::Software package is initially generated by # Class::DBI::Loader to go with the 'software' table # in the database, this just adds methods to that class package JSK::Software; use strict; use warnings; sub released { my $self = shift; return defined $self->release_date; }
| We're not surrounded, we're in a target-rich environment! |
|---|
In reply to Re: Class::DBI::Loader and transactions
by jasonk
in thread Class::DBI::Loader and transactions
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |