[html-formfu] Unable to create a Callback constraint via populate()

Carl Franks fireartist at gmail.com
Thu Jun 5 13:29:44 BST 2008


2008/5/9 Michele Beltrame <mb at cattlegrid.info>:
> Hi Carl!
>
> Me again. ;-)
>
>> However, I've now changed element() so it does a shallow clone ( using
>> $hashref = {%$hashref} ) instead of dclone().
>> This avoids the immediate butchering by element(). Whether this has
>> any unwanted side-effects further down the line, we'll just have to
>> wait and see.
>
> As arleady noted, this works perfectly for single elements. However, I
> now discovered that something like this:
>
> my $empty_to_undef = sub {
>    [...]
> };
>
> [...]
>    element_defaults => {
>        Text    => {
>            transformers => [{
>                type        => 'Callback',
>                callback    => $empty_to_undef,
>            }],
>        }
>    },
> [...]
>
> triggers the:
>
> Can't store CODE items at /u/www/cheiron/cryo/Cryo/script/../lib/HTML/FormFu/ObjectUtil.pm line 108.
>
> error as before. It seems that coderefs are accepted if I place constraints
> or transformers or whatever inside single elements, but not if I place
> them as element_defaults.

Okay, the only way to get around this, while keeping the support for
closures, is to change clone() to only do a shallow hash copy of
default_elements() instead of a deep clone.

I've had to update all the element/processor/plugin builders to do a
shallow copy of any hashrefs passed to them, so they don't bork
structures that might need to be reused.

Hopefully this'll solve it properly now.

Cheers,
Carl



More information about the HTML-FormFu mailing list