* Dennis Schön <[EMAIL PROTECTED]> [2006-07-14 11:25]:
> I narrowed the problem down to the following code in
> HTMLWidget.pm line 43:
> 
> my %cb = map {$_->name => undef if 
> $_->isa('HTML::Widget::Element::Checkbox')} @{ $result->{_elements} };

Yes, which is because in a block that ends on an `if` statement,
if the conditional is false, then it becomes the value of the
block.

    $ perl -e'print "[$_]\n" for map { ( "foo" => 1 ) if !!$_ } qw( 1 0 0 0 1 0 
0 1 )'
    [foo]
    [1]
    []
    []
    []
    [foo]
    [1]
    []
    []
    [foo]
    [1]

See all those false values? They screw up the hash.

Don’t use `if` (and for that matter, `for` and `while`) as the
last statement in a block that’s supposed to have a value.

Compare:

    $ perl -e'print "[$_]\n" for map { !!$_ ? ( "foo" => 1 ) : () } qw( 1 0 0 0 
1 0 0 1 )'
    [foo]
    [1]
    [foo]
    [1]
    [foo]
    [1]

So the right way to write that code “fancily” is thus:

    my %cb = map {
        $_->isa( 'HTML::Widget::Element::Checkbox' )
            ? ( $_->name => undef )
            : ()
    } @{ $result->{_elements} };

Regards,
-- 
#Aristotle
*AUTOLOAD=*_;sub _{s/(.*)::(.*)/print$2,(",$\/"," ")[defined wantarray]/e;$1};
&Just->another->Perl->hacker;

_______________________________________________
List: http://lists.rawmode.org/cgi-bin/mailman/listinfo/dbix-class
Wiki: http://dbix-class.shadowcatsystems.co.uk/
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/trunk/DBIx-Class/
Searchable Archive: http://www.mail-archive.com/[email protected]/

Reply via email to