[Maypole] when dynamic method generation is not your friend

From: Seth Gordon (sethg at ropine.com)
Date: Fri Dec 03 2004 - 14:50:59 GMT


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 at ropine.com // http://dynamic.ropine.com/yo/ //

_______________________________________________ maypole mailing list maypole at lists.netthink.co.uk http://lists.netthink.co.uk/listinfo/maypole



This archive was generated by hypermail 2.1.3 : Thu Feb 24 2005 - 22:25:57 GMT