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
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 printf '<li><a href="/source/%s">%1$s</a></li>'."\n", EscapeHTML($_);
55 print "<h1>Source of $source</h1>\n";
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";
70 if (eval { require Text::VimColor and Text::VimColor->VERSION(0.12) }) {
71 delete $Text::VimColor::SYNTAX_TYPE{Underlined};
73 Statement => 'strong',
78 my $hl = Text::VimColor->new(
80 vim_options => [@Text::VimColor::VIM_OPTIONS, '+:set enc=utf-8'],
82 my $parsed = $hl->marked;
85 my $tag = $_->[0] && ($TYPETAG{ $_->[0] } || 'span');
87 print "<$tag$arg class=\"sy-\l$_->[0]\">" if $tag;
88 if (!$_->[0] || $_->[0] eq 'Constant'
89 and $_->[1] =~ s{^(['"]?)(/?[a-z0-9_.]+\.(?:plp?|css|js))(?=\1$)}{}) {
90 printf '%s<a href="%s">%s</a>', $1, "/source/$2", $2;
92 if (!$_->[0] and $_->[1] =~ s/^(\s*)([A-Z]\w+(?:::\w+)+)(?![^;\s])//) {
93 printf '%s<a href="%s">%s</a>', $1, "/source/$2", $2;
95 print Text::VimColor::_xml_escape($_->[1]);
96 print "</$tag>" if $tag;
103 print EscapeHTML(Encode::decode_utf8(ReadFile($source)));