[Petal] BUG: Petal & Autoload (Was var:object/method fails on autoloaded methods)

Jean-Michel Hiver jhiver@mkdoc.com
Sun, 1 Sep 2002 11:48:27 +0100


> I was playing around with using Petal for form processing using CGI.pm, and
> noticed that expressions such as "query/param 'FirstName'" work fine while
> "query/textfield 'FirstName'" fail.  After looking through CGI.pm, I
> realized that the param method is compiled when the module loads, however
> the HTML generating methods are autoloaded on demand.  I was able to correct
> this in the case of CGI.pm using the -compile option, however this will not
> work for other packages using autoloaded methods that do not provide a means
> for overriding the autoload behavior.

Interesting... The reason for this behavior is that Petal is trying to
see if a method exists before invoking it via can(). I didn't know that
can() did return FALSE if the calls were catched using AUTOLOAD.

I consider this as a bug, hence it'll be fixed in the next Petal release
(with a couple of other nasty bugs which have been reported since) which
should be in mid-end october.


> By the way, calling the HTML generating methods of CGI.pm from the Petal
> template provides an extremely simple means to develop forms.  For example,
> the ususal ratnest of loops used to populate a checkbox group can be
> replaced by the simple elegant construct below.  I left in a dummy checkbox
> to give the HTML designer something to look at.
> 
> <span petal:replace="query/checkbox_group 'Choices' choices '' 'true'">
> <input name="Choices" type="checkbox" value="test">Test</input>
> </span>

Thanks for the trick, I was not aware of it. However, I do not like the
fact that CGI.pm encapsulates such HTML widgets. Maybe developing an
HTML form widget adapted to Petal (and its syntax) could be an
interesting idea...

BTW, you could have saved a span tag using the following:

<input
 name="Choices"
 type="checkbox"
 value="test"
 petal:replace="query/checkbox_group 'Choices' choices '' 'true'">Test</input>


Thanks for your interest in Petal!
Cheers,
-- 
IT'S TIME FOR A DIFFERENT KIND OF WEB
================================================================
  Jean-Michel Hiver - Software Director
  jhiver@mkdoc.com
  +44 (0)114 255 8097
================================================================
                                      VISIT HTTP://WWW.MKDOC.COM