[Catalyst] html-widget/accessor - by design?

Matt S Trout dbix-class at trout.me.uk
Fri Mar 10 19:05:03 CET 2006


Sebastian Riedel wrote:
> 10.03.2006 17:34 Carl Franks:
> 
>> I've just added a change to html-widget, so that if you add an Upload
>> element, then
>> $widget->enctype( 'multipart/form-data' )
>> is automatically called (because file uploads don't work without it)
>>
>> In my change, I've done a test on:
>> if ( $type eq 'Upload' )
>>
>> I had wanted to do:
>> if ( $type eq 'Upload' && not defined $self->enctype )
>>
>> However, this doesn't work, because if an enctype hasn't been set yet,
>> enctype() returns the $widget object.
>> I find this a bit strange - it this behaviour used anywhere?
>>
>> The enctype() behaviour is defined in widget/accessor.pm
>> mk_attr_accessors() subroutine
>> at this line:
>> return ( $_[0]->{attributes}->{$name} || $_[0] ) unless @_ > 1;
> 
> We use chained accessors for everything, it's one of the design  
> fundamentals of H::W.

Right, but the chaining should be on set, not on get, so I think this 
behaviour is still erroneous. I'd expect it to behave something like

sub enctype {
   my $self = shift;
   if (@_) {
     $self->{attributes}->{enctype} = shift;
     return $self;
   } else {
     return $self->{attributes}->{enctype};
   }
}



More information about the Catalyst mailing list