[Maypole] when dynamic method generation is not your friend
Seth Gordon
sethg@ropine.com
Fri, 03 Dec 2004 09:50:59 -0500
So when I tried to get a page of book titles from my library app,
Maypole::CLI would occasionally pass along this error message:
Can't use string ("JeevesLibrary::Titles") as a HASH ref while "strict
refs" in use at /usr/local/libdata/perl5/site_perl/Class/DBI.pm line 494.
In the underlying database, the titles table has an is_public field, so
when Class::DBI creates an accessor for that field, it stomps on the
is_public method Maypole::Model::CDBI had provided--the method that
Maypole was expecting to see when it calls is_applicable. I thought I
had a clever workaround involving accessor_name, but at some point in
all my BEGIN hackery it stopped working, and I was despondent until I
realized there was a brute-force workaround:
package JeevesLibrary::Titles;
sub is_public {
my ($self, $action) = @_;
Maypole::Model::CDBI->is_public( $action );
}
Humble request to the Maypole maintainers: Please add something to the
initialization code that will detect these kinds of conflicts between
the database schema and the methods that Maypole expects to see in its
model classes, and give the user a more helpful diagnostic message than
the one I had to puzzle over.
--
"If John Kerry was the last best hope for the Republic ... then maybe
it wasn't worth saving in the first place. I don't believe that,
though. And neither do you." --Dan Layman-Kennedy
// seth gordon // sethg@ropine.com // http://dynamic.ropine.com/yo/ //