home *** CD-ROM | disk | FTP | other *** search
/ CLIX - Fazer Clix Custa Nix / CLIX-CD.cdr / mac / lib / URI / URL / http.pm < prev    next >
Text File  |  1997-06-23  |  2KB  |  69 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. *user     = \&URI::URL::bad_method;
  10. *password = \&URI::URL::bad_method;
  11.  
  12.  
  13. # @ISA = qw(AutoLoader)      # This comment is needed by AutoSplit.
  14. sub keywords;
  15. sub query_form;
  16. 1;
  17. __END__
  18.  
  19. # Note that the following two methods does not return the old
  20. # value if they are used to set a new value.
  21. # The risk of croaking is to high :-)  We will eventually rely
  22. # on undefined wantarray (require perl5.004).
  23.  
  24. # Handle ...?dog+bones type of query
  25. sub keywords {
  26.     my $self = shift;
  27.     $old = $self->{'query'};
  28.     if (@_) {
  29.     # Try to set query string
  30.     $self->equery(join('+', map { URI::Escape::uri_escape($_, $URI::URL::reserved) } @_));
  31.     return undef;
  32.     }
  33.     return undef unless defined $old;
  34.     Carp::croak("Query is not keywords") if $old =~ /=/;
  35.     map { URI::Escape::uri_unescape($_) } split(/\+/, $old);
  36. }
  37.  
  38. # Handle ...?foo=bar&bar=foo type of query
  39. sub query_form {
  40.     my $self = shift;
  41.     $old = $self->{'query'};
  42.     if (@_) {
  43.     # Try to set query string
  44.     my @query;
  45.     my($key,$vals);
  46.         my $esc = $URI::URL::reserved . $URI::URL::unsafe;
  47.     while (($key,$vals) = splice(@_, 0, 2)) {
  48.         $key = '' unless defined $key;
  49.         $key =  URI::Escape::uri_escape($key, $esc);
  50.         $vals = [$vals] unless ref($vals) eq 'ARRAY';
  51.         my $val;
  52.         for $val (@$vals) {
  53.         $val = '' unless defined $val;
  54.         $val = URI::Escape::uri_escape($val, $esc);
  55.         push(@query, "$key=$val");
  56.         }
  57.     }
  58.     $self->equery(join('&', @query));
  59.     return undef;
  60.     }
  61.     return undef unless defined $old;
  62.     return () unless length $old;
  63.     Carp::croak("Query is not a form") unless $old =~ /=/;
  64.     map { s/\+/ /g; URI::Escape::uri_unescape($_) }
  65.      map { split(/=/, $_, 2)} split(/&/, $old);
  66. }
  67.  
  68. 1;
  69.