home *** CD-ROM | disk | FTP | other *** search
/ Acorn User 10 / AU_CD10.iso / Updates / Perl / Perl_Libs / site_perl / URI / URL / http.pm < prev    next >
Encoding:
Perl POD Document  |  1998-04-17  |  1.5 KB  |  58 lines

  1. package URI::URL::http;
  2. require URI::URL::_generic;
  3. @ISA = qw(URI::URL::_generic);
  4.  
  5. sub default_port { 80 }
  6.  
  7. require Carp;
  8.  
  9. # @ISA = qw(AutoLoader)      # This comment is needed by AutoSplit.
  10. sub keywords;
  11. sub query_form;
  12. # 1;
  13. # __END__
  14.  
  15. # Handle ...?dog+bones type of query
  16. sub keywords {
  17.     my $self = shift;
  18.     $old = $self->{'query'};
  19.     if (@_) {
  20.     # Try to set query string
  21.     $self->equery(join('+', map { URI::Escape::uri_escape($_, $URI::URL::reserved) } @_));
  22.     }
  23.     return if !defined($old) || !defined(wantarray);
  24.  
  25.     Carp::croak("Query is not keywords") if $old =~ /=/;
  26.     map { URI::Escape::uri_unescape($_) } split(/\+/, $old);
  27. }
  28.  
  29. # Handle ...?foo=bar&bar=foo type of query
  30. sub query_form {
  31.     my $self = shift;
  32.     $old = $self->{'query'};
  33.     if (@_) {
  34.     # Try to set query string
  35.     my @query;
  36.     my($key,$vals);
  37.         my $esc = $URI::URL::reserved . $URI::URL::unsafe;
  38.     while (($key,$vals) = splice(@_, 0, 2)) {
  39.         $key = '' unless defined $key;
  40.         $key =  URI::Escape::uri_escape($key, $esc);
  41.         $vals = [$vals] unless ref($vals) eq 'ARRAY';
  42.         my $val;
  43.         for $val (@$vals) {
  44.         $val = '' unless defined $val;
  45.         $val = URI::Escape::uri_escape($val, $esc);
  46.         push(@query, "$key=$val");
  47.         }
  48.     }
  49.     $self->equery(join('&', @query));
  50.     }
  51.     return if !defined($old) || length($old) == 0 || !defined(wantarray);
  52.     Carp::croak("Query is not a form") unless $old =~ /=/;
  53.     map { s/\+/ /g; URI::Escape::uri_unescape($_) }
  54.      map { /=/ ? split(/=/, $_, 2) : ($_ => '')} split(/&/, $old);
  55. }
  56.  
  57. 1;
  58.