From: Tomas Valla Date: Sun, 10 Aug 2003 01:30:50 +0000 (+0000) Subject: Recognition of variable types in parse_args is now automatic. X-Git-Tag: holmes-import~1217 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=6c2620fb1aa59ee5dae987b11ff038f6f107d5a3;p=libucw.git Recognition of variable types in parse_args is now automatic. --- diff --git a/lib/perl/CGI.pm b/lib/perl/CGI.pm index cf790880..aeb6c505 100644 --- a/lib/perl/CGI.pm +++ b/lib/perl/CGI.pm @@ -55,10 +55,11 @@ sub parse_arg_string($) { if (!/^$rx$/) { $_ = $arg->{'default'}; } } - if (defined $arg->{'array'}) { - push @{$arg->{'array'}}, $_; - } else { + my $r = ref($arg->{'var'}); + if ($r eq 'SCALAR') { ${$arg->{'var'}} = $_; + } elsif ($r eq 'ARRAY') { + push @{$arg->{'var'}}, $_; } } } @@ -66,10 +67,13 @@ sub parse_arg_string($) { sub parse_args($) { $arg_table = shift @_; foreach my $a (values %$arg_table) { + my $r = ref($a->{'var'}); defined($a->{'default'}) or $a->{'default'}=""; - die "Should define either 'var' or 'array'" if defined($a->{'var'})+defined($a->{'array'})!=1; - defined $a->{'var'} and ${$a->{'var'}} = $a->{'default'}; - defined $a->{'array'} and @{$a->{'array'}} = (); + if ($r eq 'SCALAR') { + ${$a->{'var'}} = $a->{'default'}; + } elsif ($r eq 'ARRAY') { + @{$a->{'var'}} = (); + } } defined $ENV{"GATEWAY_INTERFACE"} or die "Not called as a CGI script"; my $method = $ENV{"REQUEST_METHOD"};