Mark Stosberg <[EMAIL PROTECTED]> writes:
> Also functions could be added to make it easier to handle inputs with
> multiple values. For me, I think the functions like CGI.pm's "param" and "append"
> would be must intuitive. These functions would not care about ordering
> like value() does, they would just set the first value that works.
Would this method work for you?
sub HTML::Form::param {
my $self = shift;
if (@_) {
my $name = shift;
my @inputs;
for ($self->inputs) {
my $n = $_->name;
next if !defined($n) || $n ne $name;
push(@inputs, $_);
}
if (@_) {
# set
die "No '$name' parameter exists" unless @inputs;
while (@_) {
my $v = shift;
my $err;
for my $i (0 .. @inputs-1) {
eval {
$inputs[$i]->value($v);
};
unless ($@) {
undef($err);
splice(@inputs, $i, 1);
last;
}
$err ||= $@;
}
die $err if $err;
}
}
else {
# get
my @v;
for (@inputs) {
push(@v, $_->value);
}
return wantarray ? @v : $v[0];
}
}
else {
# list parameter names
my @n;
my %seen;
for ($self->inputs) {
my $n = $_->name;
next if !defined($n) || $seen{$n}++;
push(@n, $n);
}
return @n;
}
}