source: cache file names without package include paths
authorMischa POSLAWSKY <perl@shiar.org>
Sun, 29 Oct 2023 00:39:42 +0000 (02:39 +0200)
committerMischa POSLAWSKY <perl@shiar.org>
Sun, 29 Oct 2023 01:42:08 +0000 (02:42 +0100)
source.plp

index d7d7cb50da39a02247be400b341b7b63ae770bee..b586dbe2b028d439a5ee069b2520cc41c04e3e15 100644 (file)
@@ -65,6 +65,7 @@ else {
                say "<h1>Source of $href</h1>";
        };
 
+       my $path = $source;
        if ($source =~ m{(?:/|^)\.}) {
                Abort("File request not permitted", '403 source not allowed');
        }
@@ -72,15 +73,15 @@ else {
                $source .= '.pm';
                for (0 .. $#INC) {
                        -e ($_ = "$INC[$_]/$source") or next;
-                       $source = $_;
+                       $path = $_;
                        last;
                }
        }
-       -r $source or Abort("Requested file not found", '404 source not found');
-       my $size = (stat $source)->[7];
+       -r $path or Abort("Requested file not found", '404 source not found');
+       my $size = (stat $path)->[7];
 
        my $cachefile = "source/$source.html";
-       if (-e $cachefile and (stat $cachefile)->[9] >= (stat $source)->[9]) {
+       if (-e $cachefile and (stat $cachefile)->[9] >= (stat $path)->[9]) {
                say '<pre>';
                print ReadFile($cachefile);
                say '</pre>';
@@ -97,7 +98,7 @@ else {
                        or die 'early versions are buggy under FastCGI';
                delete $Text::VimColor::SYNTAX_TYPE{Underlined};
                return Text::VimColor->new(
-                       file => $source,
+                       file => $path,
                        vim_options => [@Text::VimColor::VIM_OPTIONS, '+:set enc=utf-8'],
                )->marked;
        }) {
@@ -133,7 +134,7 @@ else {
        }
        else {
                say '<pre>';
-               print EscapeHTML(decode_utf8(ReadFile($source)));
+               print EscapeHTML(decode_utf8(ReadFile($path)));
                say '</pre>';
        }