[Html-widget] attributes

Carl Franks fireartist at gmail.com
Fri Sep 22 14:44:28 CEST 2006


I've just responded to an rt bug, where the poster had been bitten by
$w->element( 'Textfield', 'foo' )
    ->size( 10 )
    ->attributes( { disabled => 'disabled' } );

Setting attributes in this way overwrites on the current attributes
hash, and wipes out the 'size' which internally is saved as an
attribute.
Not good.

I suggest we allow an attributes hash-ref to be passed as the last argument to
HTML::Widget->new()
and
$w->elements()

This would change the above example to:
$w->element( 'Textfield', 'foo', { disabled => 'disabled' } )
    ->size( 10 );

There are a couple of alternatives, but they're less than ideal.

We can already do:
$w->element( 'Textfield', 'foo' )
    ->size( 10 )
    ->attributes->{disabled} = 'disabled' ;
But this isn't great, as you can't add further methods onto the method-chain.

If multiple values are passed to attributes(), rather than a hash-ref,
add them to the current attributes hash.
However, I think
attributes( disabled => 'disabled' );
is too close, visually, to
attributes( { disabled => 'disabled' } );

Add AUTOLOAD to HTML::Widget::Accessor, and make sure
HTML::Widget::Accessor is always last in the inheritance chain.
Then assume that anything AUTOLOAD catches is intended to be an attribute.
Unfortunately, misspelt method names would no longer be fatal, they'd
get turned into attributes.

Does anyone have any other ideas, or comments on my proposal?

Carl



More information about the Html-widget mailing list