X-Git-Url: http://git.shiar.net/perl/html-form-simple.git/blobdiff_plain/bb5bd81e03c47ff9cc779c5109bd6e042219a1f8..48891d33a852d6db31113e4e7c10e1cda5771ce3:/lib/HTML/Form/Simple.pm diff --git a/lib/HTML/Form/Simple.pm b/lib/HTML/Form/Simple.pm index 3a58c79..911b864 100644 --- a/lib/HTML/Form/Simple.pm +++ b/lib/HTML/Form/Simple.pm @@ -164,38 +164,42 @@ sub select { sub radio { my $self = shift; - my ($name, $label, $value, $attr) = $self->_attr(3, @_); + my ($name, $label, $rows, $attr) = $self->_attr(3, @_); - if (not defined $value) { + if (not defined $rows) { if (defined $label) { - $value = ref $label eq 'ARRAY' ? [1 .. $#$label+1] : [1]; + $rows = ref $label eq 'ARRAY' ? [1 .. $#$label+1] : [1]; } else { - $value = [{}]; + $rows = [{}]; } } - elsif (ref $value ne 'ARRAY') { - $value = [$value]; + elsif (ref $rows ne 'ARRAY') { + $rows = [$rows]; } if (defined $label) { - $_ = ref $_ eq 'HASH' ? {%$_} : {value => $_} for @$value; - $_->{label} = ref $label eq 'ARRAY' ? shift @$label : $label for @$value; + $rows = [ map { ref $_ eq 'HASH' ? {%$_} : {value => $_} } @$rows ]; + if (ref $label eq 'ARRAY') { + $rows->[$_]->{label} = $label->[$_] for 0 .. $#$rows; + } else { + $_->{label} = $label for @$rows; + } } - $self->select($name, $value, {%$attr, type => 'radio'}); + $self->select($name, $rows, {%$attr, type => 'radio'}); } sub check { my $self = shift; my ($name, $label, $checked, $attr) = $self->_attr(3, @_); - my $rows = defined $label ? ref $label eq 'ARRAY' ? $label : [$label] : [{}]; + 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; + $rows->[$_]->{checked} = $checked->[$_] for 0 .. $#$rows; + push @$rows, map { {checked => $_} } @$checked[@$rows .. $#$checked]; } else { $_->{checked} = $checked for @$rows;