home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / perl_ste.zip / auto / URI / URL / file / newlocal.al < prev    next >
Text File  |  1997-11-28  |  767b  |  26 lines

  1. # NOTE: Derived from ./blib/lib/URI/URL/file.pm.  Changes made here will be lost.
  2. package URI::URL::file;
  3.  
  4. sub newlocal {
  5.     my($class, $path) = @_;
  6.  
  7.     Carp::croak("Only implemented for Unix and OS/2 file systems")
  8.       unless $ostype eq "unix" or $^O =~ /os2|mswin32/i;
  9.     # XXX: Should implement the same thing for other systems
  10.  
  11.     my $url = new URI::URL "file:";
  12.     unless (defined $path and
  13.             ($path =~ m:^/: or 
  14.          ($^O eq 'os2' and Cwd::sys_is_absolute($path)) or
  15.          ($^O eq 'MSWin32' and $path =~ m<^[A-Za-z]:[\\/]|^[\\/]{2}>))) {
  16.     require Cwd;
  17.     my $cwd = Cwd::fastcwd();
  18.     $cwd =~ s:/?$:/:; # force trailing slash on dir
  19.     $path = (defined $path) ? $cwd . $path : $cwd;
  20.     }
  21.     $url->path($path);
  22.     $url;
  23. }
  24.  
  25. 1;
  26.