3 my $source = $ENV{PATH_INFO};
6 if ($source =~ s{(?<=\Q.inc.pl\E)/jsonp?$}{} and -r $source) {
7 # convert perl include to json construct
8 checkmodified($source);
10 my $data = do $source or die $@ || $! || 'read error';
12 my $converter = JSON->new;
13 $converter->utf8->indent->space_after->canonical;
15 $header{content_type} = 'application/json';
16 $header{content_type} = 'text/plain' if exists $get{debug};
17 print $_, '(' for $get{callback} // ();
18 print $converter->encode($data);
19 print ')' for $get{callback} // ();
22 $header{status} = '500 File unavailable';
23 $header{content_type} = 'text/plain';
24 print "Conversion failed: $@";
30 title => "$source source code",
32 description => !$source ? 'Index of source files for this site.' : [
33 "Source code of the $source file at this site,",
34 "with syntax highlighted and references linked."
37 sheet cheat source code perl plp html agpl
39 stylesheet => [qw'light dark mono red'],
45 print "<h1>Source files</h1>";
47 print "<p>Project code distributed under the AGPL. Please contribute back.</p>";
51 printf '<li><a href="/source/%s">%1$s</a></li>'."\n", EscapeHTML($_);
56 print "<h1>Source of $source</h1>\n";
58 if ($source =~ m{(?:/|^)\.}) {
59 die "File request not permitted\n";
61 elsif ($source =~ s{::}{/}g or !-e $source) {
64 -e ($_ = "$INC[$_]/$source") or next;
69 -r $source or die "Requested file not found\n";
71 if (eval { require Text::VimColor and Text::VimColor->VERSION(0.12) }) {
72 delete $Text::VimColor::SYNTAX_TYPE{Underlined};
74 Statement => 'strong',
79 my $hl = Text::VimColor->new(
81 vim_options => [@Text::VimColor::VIM_OPTIONS, '+:set enc=utf-8'],
83 my $parsed = $hl->marked;
86 my $tag = $_->[0] && ($TYPETAG{ $_->[0] } || 'span');
88 print "<$tag$arg class=\"sy-\l$_->[0]\">" if $tag;
89 if (!$_->[0] || $_->[0] eq 'Constant'
90 and $_->[1] =~ s{^(['"]?)(/?[a-z0-9_.]+\.(?:plp?|css|js))(?=\1$)}{}) {
91 printf '%s<a href="%s">%s</a>', $1, "/source/$2", $2;
93 if (!$_->[0] and $_->[1] =~ s/^(\s*)([A-Z]\w+(?:::\w+)+)(?![^;\s])//) {
94 printf '%s<a href="%s">%s</a>', $1, "/source/$2", $2;
96 print Text::VimColor::_xml_escape($_->[1]);
97 print "</$tag>" if $tag;
104 print EscapeHTML(Encode::decode_utf8(ReadFile($source)));