X-Git-Url: http://git.shiar.net/perl/html-form-simple.git/blobdiff_plain/d5415f8292000c0eba35458ce61500eaff9cd4d1..cb6c92feb70f4246804078114bb8ef37874ab1cd:/lib/HTML/Form/Simple.pm
diff --git a/lib/HTML/Form/Simple.pm b/lib/HTML/Form/Simple.pm
index 6fb9080..4eddc98 100644
--- a/lib/HTML/Form/Simple.pm
+++ b/lib/HTML/Form/Simple.pm
@@ -176,11 +176,20 @@ sub check {
my $self = shift;
my ($name, $label, $checked, $attr) = $self->_attr(3, @_);
- $attr->{label } = $label if defined $label;
- $attr->{checked} = $checked if defined $checked;
- $attr->{value } = '1' unless exists $attr->{value};
+ my $rows = defined $label ? ref $label eq 'ARRAY' ? $label : [$label] : [{}];
+ ref $_ eq 'HASH' or $_ = {label => $_} for @$rows;
+ if (defined $checked) {
+ if (ref $checked eq 'ARRAY') {
+ $_->{checked} = shift @$checked for @$rows;
+ push @$rows, map { {checked => $_} } @$checked;
+ }
+ else {
+ $_->{checked} = $checked for @$rows;
+ }
+ }
+ exists $rows->[$_]->{value} or $rows->[$_]->{value} = $_ + 1 for 0 .. $#$rows;
- $self->select($name, [$attr], {type => 'checkbox'});
+ $self->select($name, $rows, {%$attr, type => 'checkbox'});
}
1;