# @foo = get_param() # returns the parameter names (or undef if none) # $foo = get_param("param") # returns the named parameter (or undef if not) # @foo = get_param("param") # as above in list context # ================================================== sub get_param { my $self = shift; my $param = shift || undef; unless (exists $self->{get_vars}) { # Set to undef if no args unless ($self->{'request'}->args) { warn "I see no GET vars!\n" if $DEBUG; return $self->{'get_vars'} = undef; } # Now run the query_string through the parser $self->_parse('get_vars', scalar($self->{'request'}->args)); } return undef unless defined $self->{'get_vars'}; return keys %{$self->{'get_vars'}} unless $param; return undef unless exists($self->{'get_vars'}->{$param}); return $self->{'get_vars'}->{$param} unless ref $self->{'get_vars'}->{$param}; return wantarray ? @{ $self->{'get_vars'}->{$param} } : "@{ $self->{'get_vars'}->{$param} }"; return undef; ## Inconceivable! } # ================================================== sub post_param { my $self = shift; my $param = shift || undef; unless (exists $self->{'post_vars'}) { # Set to undef if not POST unless ($self->{'request'}->method_number == M_POST) { warn "I see no POST vars\n" if $DEBUG; return $self->{'post_vars'} = undef; } # Now run the query_string through the parser $self->_parse('post_vars', scalar($self->{'request'}->content)); } return undef unless defined $self->{'post_vars'}; return keys %{$self->{'post_vars'}} unless $param; return undef unless exists($self->{'post_vars'}->{$param}); return $self->{'post_vars'}->{$param} unless ref $self->{'post_vars'}->{$param}; return wantarray ? @{ $self->{'post_vars'}->{$param} } : "@{ $self->{'post_vars'}->{$param} }"; return undef; ## Inconceivable! } # ================================================== sub _parse { my $self = shift; my $dst = shift; my $str = shift; warn "_parse: $dst $str\n" if $DEBUG; foreach my $pair (split /&/, $str) { $pair =~ tr/+/ /; $pair =~ s/%([\da-f][\da-f])/chr( hex($1) )/egi; my( $name, $value ) = split /=/, $pair; $value = $value || ""; if ( exists ($self->{$dst}->{$name}) ) { if ( ref $self->{$dst}->{$name} ) { push @{ $self->{$dst}->{$name} }, $value; } else { $self->{$dst}->{$name} = [ $self->{$dst}->{$name}, $value ]; } } else { $self->{$dst}->{$name} = $value; } } }