5 no warnings 'qw'; # you know what you doing
6 no warnings 'uninitialized'; # save some useless checks for more legible code
7 use open IO => ':utf8';
11 use Shiar_Sheet::KeySigns qw(%sign); # dependant on $get{ascii}
14 our $showkeys = !exists $get{keys} ? undef :
15 ($get{keys} ne '0' && ($get{keys} || 'always'));
17 $header{content_type} = 'text/html; charset=utf-8';
20 my %styles = map {$_ => $_} @_;
22 if (exists $get{style}) {
23 $style = $styles{ $get{style} };
25 AddCookie(CGI::Cookie->new(
28 -path => '/', # site-wide; current page is confusing to most users
29 -expires => $style ? '+5y' : '-1d',
33 $style ||= exists $cookie{style} && $styles{ $cookie{style} } || $_[0];
35 return join "\n", map { sprintf(
36 '<link rel="%s" type="text/css" media="all" href="%s" title="%s">',
37 $_ eq $style ? 'stylesheet' : 'alternate stylesheet', "/$_.css", $_
44 my $mod = stat $_ or next;
45 $mod = $mod->mtime or next;
46 $lastmod = $mod if $mod gt $lastmod;
49 for ($ENV{HTTP_IF_MODIFIED_SINCE} || ()) {
50 next if str2time($_) < $lastmod;
51 $header{status} = '304 Same old';
55 $header{'Last-Modified'} = time2str($lastmod);
61 # announce and check data modification
63 $ENV{SCRIPT_FILENAME},
64 (grep { /^Shiar_/ } values %INC),
65 $meta->{data} ? @{ $meta->{data} } : (),
69 $meta->{stylesheet} ||= [qw'light dark circus mono red terse'];
70 $meta->{charset} ||= 'utf-8';
73 push @{ $meta->{raw} }, (
74 '<!--[if lte IE 6]><style> .help dl.legend dt {margin:0 0 1px} </style><![endif]-->',
75 '<!--[if lte IE 7]><style> .help dl.legend dd {float:none} </style><![endif]-->',
76 !$showkeys ? '<style type="text/css"> .no {visibility:hidden} </style>'
77 : $showkeys eq 'ghost' ? '<style type="text/css"> .no, .alias {opacity:.5} </style>'
79 '<script type="text/javascript" src="/keys.js"></script>',
83 ref $_ eq 'ARRAY' and $_ = join ' ', @$_ for $meta->{description};
84 ref $_ eq 'ARRAY' and $_ = join ', ', @$_ for $meta->{keywords};
85 ref $_ eq 'ARRAY' and $_ = join "\n", @$_ for $meta->{rawstyle}, $meta->{raw};
86 ref $_ eq 'ARRAY' and $_ = stylesheet(@$_)."\n" for $meta->{stylesheet};
89 my $sep = $meta->{charset} eq 'utf-8' ? '•' : ' -- ';
90 my ($file) = $ENV{SCRIPT_FILENAME} =~ m{ ([^/]+) \.plp$ }x;
93 $header{content_type} = "text/html; charset=$meta->{charset}";
95 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
96 "http://www.w3.org/TR/html4/loose.dtd">
100 <meta http-equiv="content-type" content="$header{content_type}">
101 <title>$meta->{title}</title>
102 <meta name="description" content="$meta->{description}">
103 <meta name="keywords" content="$meta->{keywords}">
104 <link rel="icon" type="image/png" href="/clip.png">
106 print $_, "\n" for $meta->{stylesheet} || ();
107 print $_, "\n" for $meta->{raw} || ();
108 print qq{</head>\n\n<body id="$file">\n};
110 # prepare trailing output
114 <a href="/" rel="home">sheet.shiar.nl</a>/$file.<a href="/source/$file.plp"
115 rel="code" title="Written in Perl">plp</a>
116 <a href="http://git.shiar.nl/sheet.git/history/HEAD:/$file.plp"
117 rel="vcs-git" title="Git repository">$meta->{version}</a>
118 created by <a href="http://shiar.nl/" rel="author">Shiar</a> $sep
119 <a href="http://www.fsf.org/licensing/licenses/agpl-3.0.html" rel="copyright"
120 title="Licensed under the GNU Affero General Public License, version 3">AGPLv3</a>