[Maypole] Help with Maypole::Model::CDBI::Plain

Jesse Sheidlower jester@panix.com
Sat, 17 Jul 2004 08:58:43 -0400


I've been torturing Simon off-list about this, so I thought
I'd give him a break and let someone else give it a shot.
Has anyone managed to get this working?

I have set up a group of CDBI classes that I am now trying
to use with Maypole, and have already done the setup on the
CDBI side so I don't need to use Loader. After a variety of
missteps, and following the explanations, I have the
following situation: my database is "sfDB"; my CDBI base
class, which for now just establishes the connection, is
"sfDB::DBI", and my tables of interest are "sfDB::Citation",
"::CitationSubject", and "::Subject". The only thing that
the sfDB.pm base does is set up the Maypole-related stuff,
as discussed in the ::Plain docs.

Here's the basic code:

---
package sfDB::DBI;
use base 'Class::DBI::mysql';
__PACKAGE__->set_db('Main', "dbi:mysql:sf","user","password");

package sfDB;

use strict;
use base qw(sfDB::DBI Apache::MVC);

use sfDB::Citation;
use sfDB::Subject;
use sfDB::CitationSubject;

sfDB->config->{model} = "Maypole::Model::CDBI::Plain";
sfDB->setup([qw/sfDB::Citation sfDB::CitationSubject sfDB::Subject/]);
sfDB->config->{uri_base} = "http://localhost/sf/";

package sfDB::Citation;
use strict;

use base 'sfDB::DBI';

__PACKAGE__->has_many(subject => [ CitationSubject => 'subject_id' ]);

sub list :Exported { } # not shown here, but a special list method
---

When I try to run this by going to http://localhost/sf/citation/list,
I get the following error:

[Sat Jul 17 08:54:00 2004] [error] Invalid CODE attribute:
Exported at /usr/local/www/modules/sfDB/Citation.pm line 18

Typically, or originally, this error was associated with issues of
setting up separate model-class modules, and is discussed in the
docs, but the solutions proposed there--either wrapping the "setup"
call in a BEGIN block, or moving the module loading to runtime by
using "sfDB::Citation->require" instead of "use sfDB::Citation",
don't work in this setup.

Anyone have a suggestion for how I'm supposed to be doing this?
I'd like to get around the Loader requirement. And Simon will be
grateful too! 

Thanks!

Jesse Sheidlower