home *** CD-ROM | disk | FTP | other *** search
/ isnet Internet / Isnet Internet CD.iso / prog / hiz / 09 / 09.exe / adynware.exe / perl / lib / site / URI / URL / news.pm < prev    next >
Encoding:
Perl POD Document  |  1999-12-28  |  1.5 KB  |  73 lines

  1. package URI::URL::news;
  2. require URI::URL;
  3. @ISA = qw(URI::URL);
  4.  
  5. use URI::Escape;
  6.  
  7. sub new {
  8.     my($class, $init, $base) = @_;
  9.     my $self = bless { }, $class;
  10.     $self->{'scheme'}  = lc($1) if $init =~ s/^\s*([\w\+\.\-]+)://;
  11.     $self->groupart(uri_unescape($init));
  12.     $self->base($base) if $base;
  13.     $self;
  14. }
  15.  
  16. sub groupart {
  17.     my $self = shift;
  18.     my $old = $self->{'path'};
  19.     if (@_) {
  20.     my $p = shift;
  21.     if (defined $p && $p =~ /\@/) {
  22.         $p =~ s/^<(.*)>$/$1/;  # "<" and ">" should not be part of it
  23.     }
  24.     $self->{'path'} = $p;
  25.     }
  26.     $old;
  27. }
  28.  
  29. *path = \&groupart;
  30.  
  31. sub article   {
  32.     my $self = shift;
  33.     Carp::croak("Illegal article id name (does not contain '\@')")
  34.       if @_ && $_[0] !~ /\@/;
  35.     my $old = $self->groupart(@_);
  36.     return undef if $old !~ /\@/;
  37.     $old;
  38. }
  39.  
  40.  
  41. sub group {
  42.     my $self = shift;
  43.     Carp::croak("Illegal group name (contains '\@')")
  44.       if @_ && $_[0] =~ /\@/;
  45.     my $old = $self->groupart(@_);
  46.     return undef if $old =~ /\@/;
  47.     $old;
  48. }
  49.  
  50. sub crack
  51. {
  52.     my $self = shift;
  53.     ('news',             # scheme
  54.      undef,              # user
  55.      undef,              # passwd
  56.      undef,              # host
  57.      undef,              # port
  58.      $self->{'path'},    # path
  59.      undef,              # params
  60.      undef,              # query
  61.      undef               # fragment
  62.     )
  63. }
  64.  
  65.  
  66. sub as_string {
  67.     my $self = shift;
  68.     my $scheme = $self->{'scheme'} || "news";
  69.     "$scheme:" . uri_escape($self->{'path'});
  70. }
  71.  
  72. 1;
  73.