"Fossies" - the Fresh Open Source Software Archive

Member "install-tl-20200916/tlpkg/tlperl/site/lib/URI/file/Win32.pm" (10 Mar 2019, 1757 Bytes) of package /windows/misc/install-tl.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Perl source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 package URI::file::Win32;
    2 
    3 use strict;
    4 use warnings;
    5 
    6 use parent 'URI::file::Base';
    7 
    8 use URI::Escape qw(uri_unescape);
    9 
   10 our $VERSION = '1.76';
   11 
   12 sub _file_extract_authority
   13 {
   14     my $class = shift;
   15 
   16     return $class->SUPER::_file_extract_authority($_[0])
   17     if defined $URI::file::DEFAULT_AUTHORITY;
   18 
   19     return $1 if $_[0] =~ s,^\\\\([^\\]+),,;  # UNC
   20     return $1 if $_[0] =~ s,^//([^/]+),,;     # UNC too?
   21 
   22     if ($_[0] =~ s,^([a-zA-Z]:),,) {
   23     my $auth = $1;
   24     $auth .= "relative" if $_[0] !~ m,^[\\/],;
   25     return $auth;
   26     }
   27     return undef;
   28 }
   29 
   30 sub _file_extract_path
   31 {
   32     my($class, $path) = @_;
   33     $path =~ s,\\,/,g;
   34     #$path =~ s,//+,/,g;
   35     $path =~ s,(/\.)+/,/,g;
   36 
   37     if (defined $URI::file::DEFAULT_AUTHORITY) {
   38     $path =~ s,^([a-zA-Z]:),/$1,;
   39     }
   40 
   41     return $path;
   42 }
   43 
   44 sub _file_is_absolute {
   45     my($class, $path) = @_;
   46     return $path =~ m,^[a-zA-Z]:, || $path =~ m,^[/\\],;
   47 }
   48 
   49 sub file
   50 {
   51     my $class = shift;
   52     my $uri = shift;
   53     my $auth = $uri->authority;
   54     my $rel; # is filename relative to drive specified in authority
   55     if (defined $auth) {
   56         $auth = uri_unescape($auth);
   57     if ($auth =~ /^([a-zA-Z])[:|](relative)?/) {
   58         $auth = uc($1) . ":";
   59         $rel++ if $2;
   60     } elsif (lc($auth) eq "localhost") {
   61         $auth = "";
   62     } elsif (length $auth) {
   63         $auth = "\\\\" . $auth;  # UNC
   64     }
   65     } else {
   66     $auth = "";
   67     }
   68 
   69     my @path = $uri->path_segments;
   70     for (@path) {
   71     return undef if /\0/;
   72     return undef if /\//;
   73     #return undef if /\\/;        # URLs with "\" is not uncommon
   74     }
   75     return undef unless $class->fix_path(@path);
   76 
   77     my $path = join("\\", @path);
   78     $path =~ s/^\\// if $rel;
   79     $path = $auth . $path;
   80     $path =~ s,^\\([a-zA-Z])[:|],\u$1:,;
   81 
   82     return $path;
   83 }
   84 
   85 sub fix_path { 1; }
   86 
   87 1;