5 no warnings 'qw'; # you know what you doing
6 no warnings 'uninitialized'; # save some useless checks for more legible code
7 use open ':std' => ':utf8';
13 my ($text, $html) = @_;
14 print '<p class="error"><strong>Fatal error</strong>: '.$html."</p>\n\n";
20 our $Time = [Time::HiRes::gettimeofday];
24 our $showkeys = !exists $get{keys} ? undef :
25 ($get{keys} ne '0' && ($get{keys} || 'always'));
27 $header{content_type} = 'text/html; charset=utf-8';
31 my @avail = ref $avail eq 'ARRAY' ? @{$avail} : $avail or return;
32 my %styles = map {$_ => $_} @avail;
34 if (defined( my $setstyle = $get{style} )) {
35 $style = $styles{ $setstyle };
38 my $cookie = CGI::Cookie->new(
40 -value => $setstyle || '',
41 -path => '/', # site-wide; current page is confusing to most users
42 -expires => $setstyle ? '+5y' : '-1d',
43 ) or die "empty object returned\n";
44 AddCookie($cookie->as_string);
45 } or warn "Unable to create style cookie: $@";
48 $style ||= exists $cookie{style} && $styles{ $cookie{style} } || $avail[0];
51 '<link rel="%s" type="text/css" media="all" href="%s" title="%s">',
52 $_ eq $style ? 'stylesheet' : 'alternate stylesheet', "/$_.css?1.9", $_
59 my $mod = stat $_ or next;
60 $mod = $mod->mtime or next;
61 $lastmod = $mod if $mod gt $lastmod;
64 for ($ENV{HTTP_IF_MODIFIED_SINCE} || ()) {
65 next if str2time($_) < $lastmod;
66 $header{status} = '304 Same old';
70 $header{'Last-Modified'} = time2str($lastmod);
76 # announce and check data modification
78 $ENV{SCRIPT_FILENAME},
79 (grep { /\bShiar_/ } values %INC),
80 $meta->{data} ? @{ $meta->{data} } : (),
82 $header{'Cache-Control'} = sprintf 'max-age: ', 24*60*60;
85 $meta->{stylesheet} ||= [qw'light dark circus mono red terse'];
86 $meta->{charset} ||= 'utf-8';
88 ref $_ eq 'ARRAY' or $_ = [$_] for $meta->{raw};
91 push @{ $meta->{raw} }, (
92 '<!--[if lte IE 6]><style> .help dl.legend dt {margin:0 0 1px} </style><![endif]-->',
93 '<!--[if lte IE 7]><style> .help dl.legend dd {float:none} </style><![endif]-->',
94 !$showkeys ? '<style type="text/css"> .no {visibility:hidden} </style>'
95 : $showkeys eq 'ghost' ? '<style type="text/css"> .no, .alias {opacity:.5} </style>'
97 '<script type="text/javascript" src="/keys.js?1.6"></script>',
101 ref $_ eq 'ARRAY' and $_ = join ' ', @$_ for $meta->{description};
102 ref $_ eq 'ARRAY' and $_ = join ', ', @$_ for $meta->{keywords};
103 ref $_ eq 'ARRAY' and $_ = join "\n", @$_ for $meta->{raw};
106 my $Dev = $ENV{HTTP_HOST} =~ /\bdev\./;
107 my ($file) = $ENV{SCRIPT_FILENAME} =~ m{ ([^/]+) \.plp$ }x;
110 $header{content_type} = "text/html; charset=$meta->{charset}";
116 <meta http-equiv="content-type" content="$header{content_type}">
117 <title>$meta->{title}</title>
118 <meta name="description" content="$meta->{description}">
119 <meta name="keywords" content="$meta->{keywords}">
120 <meta name="viewport" content="width=device-width, initial-scale=1">
121 <link rel="icon" type="image/png" href="/clip.png">
123 say for stylesheet($meta->{stylesheet});
124 say for $meta->{raw} || ();
125 say '<meta name="robots" content="noindex">' if $Dev;
126 say qq{</head>\n\n<body id="$file">};
128 # development version indicator
129 printf '<p style="%s">beta</p>', join('; ',
133 'border: 1ex solid red',
134 'border-width: 1ex 0',
136 'background: inherit',
139 # prepare trailing output
143 <a href="/" rel="start">sheet.shiar.nl</a>/$file.<a href="/source/$file.plp"
144 rel="source" title="Written in Perl">plp</a>
145 version <a href="http://git.shiar.nl/sheet.git/history/HEAD:/$file.plp"
146 rel="vcs-git" title="Git repository">$meta->{version}</a>
147 created by <a href="http://shiar.nl/" rel="author">Shiar</a> •
148 <a href="http://www.fsf.org/licensing/licenses/agpl-3.0.html" rel="license copyright"
149 title="Licensed under the GNU Affero General Public License, version 3">AGPLv3</a>
151 say sprintf '• %.3fs', Time::HiRes::tv_interval($Time) if $Dev;