5 if ($source =~ s{(?<=\Q.inc.pl\E)/jsonp?$}{} and -r $source) {
6 # convert perl include to json construct
7 checkmodified($source);
9 my $data = do $source or die $@ || $! || 'read error';
11 my $converter = JSON->new;
12 $converter->utf8->indent->space_after->canonical;
14 $header{content_type} = 'application/json';
15 $header{content_type} = 'text/plain' if exists $get{debug};
16 print $_, '(' for $get{callback} // ();
17 print $converter->encode($data);
18 print ')' for $get{callback} // ();
21 $header{status} = '500 File unavailable';
22 $header{content_type} = 'text/plain';
23 print "Conversion failed: $@";
29 title => "$source source code",
31 description => !$source ? 'Index of source files for this site.' : [
32 "Source code of the $source file at this site,",
33 "with syntax highlighted and references linked."
36 sheet cheat source code perl plp html agpl
38 stylesheet => [qw'light dark mono red'],
44 print "<h1>Source files</h1>";
46 print "<p>Project code distributed under the AGPL. Please contribute back.</p>";
50 say '<li>', showlink($_, "/source/$_");
55 say "<h1>Source of $source</h1>";
57 if ($source =~ m{(?:/|^)\.}) {
58 die "File request not permitted\n";
60 elsif ($source =~ s{::}{/}g or !-e $source) {
63 -e ($_ = "$INC[$_]/$source") or next;
68 -r $source or die "Requested file not found\n";
69 my $size = (stat $source)->[7];
72 $size < 32_768 or die 'large files take too long to parse';
73 require Text::VimColor;
74 Text::VimColor->VERSION(0.12)
75 or die 'early versions are buggy under FastCGI';
76 delete $Text::VimColor::SYNTAX_TYPE{Underlined};
77 return Text::VimColor->new(
79 vim_options => [@Text::VimColor::VIM_OPTIONS, '+:set enc=utf-8'],
83 Statement => 'strong',
90 my ($type, $contents) = @{$_};
91 $contents = decode_utf8($contents);
92 my $tag = $type && ($TYPETAG{$type} || 'span');
94 print "<$tag$arg class=\"sy-\l$type\">" if $tag;
95 if (!$type || $type eq 'Constant'
96 and $contents =~ s{^(['"]?)([/a-z0-9_.-]+\.(?:plp?|css|js))(?=\1$)}{}) {
97 # link other page sources, stylesheets, and javascript
98 print $1 . showlink($2, "/source/$2");
100 if (!$type and $contents =~ s/^(\s*)([A-Z]\w+(?:::\w+)+)(?![^;\s])//) {
101 # link perl module names (Xx::Xx...)
102 print $1 . showlink($2, "/source/$2");
104 if ($type && $type eq 'Comment'
105 and $contents =~ s{^(.*? by )(tools/\S+)}{}) {
106 # link generator scripts (by tools/...)
107 print $1 . showlink($2, "/source/$2");
109 print Text::VimColor::_xml_escape($contents);
110 print "</$tag>" if $tag;
116 print EscapeHTML(decode_utf8(ReadFile($source)));