[html-formfu] default_args for base classes

Daniel Hilton danhiruton at gmail.com
Tue May 4 23:12:21 GMT 2010


Hello,

I've just begun using HTML::FormFu, and have some suggestions for
default_args.  I'd like to be able to apply defaults to any base
class, not just the actual blessed name of the object.  To be
specific, I'd like to do this:

---
default_args:
  elements:
    _Field:
      container_tag: li
...

instead of this:

---
default_args:
  elements:
    Button:
      container_tag: li
    Checbox:
      container_tag: li
    Password:
      container_tag: li
    File:
      container_tag: li
    Radio:
      container_tag: li
    Text:
      container_tag: li
    Textarea:
      container_tag: li
    Multi:
      container_tag: li
    etc...
...

I've attached a patch that provides this functionality, but there are
a few things that will certainly warrant discussion.

First, I actually attached two patches.  The first
('refactor-object-util') should make no functional changes to
anything, but it minimizes much of the copied/pasted code in
ObjectUtil (to avoid having to apply my other changes to 10 different
copies of essentially the same function).  I accomplished this by
adding generic methods (_single_component, get_component,
get_components, etc.) which are then called by the specific methods
(_single_validator, et al.).  So the copied/pasted methods still
exist, but they are limited to one or two lines each.  It may have
been more appropriate to use something like 'mk_component_accessor' to
build the other methods at compile time, but that's all a bit too much
voodoo for me at this point.

The second patch ('inherit-default-args') has the functional changes.

I should mention that it uses Class::ISA to find the list of package
names for which to look for defaults.  This means it uses the perl 5
depth-first algorithm instead of C3.  I'm not sure how much diamond
inheritance there is that would make this an issue, but since I
noticed that other places in the code are using C3, I'm disclaiming
the fact that, at the moment, my patch doesn't.

It also has the potential to change the behavior of existing form
configs.  If this is too undesirable, my patch could be altered to
leave the default behavior as it currently is, and use new syntax to
conditionally use the new behavior (for example '*Block' to apply
defaults to HTML::FormFu::Element::Block and any derived types).

Finally, I made only a tiny change to the documentation.  If the patch
is accepted it may warrant a bit more explicit documentation than what
I provided.  (I'd be happy to enhance it).

Dan Hilton
-------------- next part --------------
A non-text attachment was scrubbed...
Name: refactor-object-util
Type: application/octet-stream
Size: 19142 bytes
Desc: not available
Url : http://lists.scsys.co.uk/pipermail/html-formfu/attachments/20100504/0=
5177b85/refactor-object-util-0001.obj
-------------- next part --------------
A non-text attachment was scrubbed...
Name: inherit-default-args
Type: application/octet-stream
Size: 4445 bytes
Desc: not available
Url : http://lists.scsys.co.uk/pipermail/html-formfu/attachments/20100504/0=
5177b85/inherit-default-args-0001.obj


More information about the HTML-FormFu mailing list