Phoebe/Css.pm untested

filter: Statementstmt 0.0% 0 / 24 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 31 CC 1 SCAR 6.9
CC
1
Cov
0%
serve_css_via_http
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 # -*- mode: perl -*-
2 # Copyright (C) 2017–2021 Alex Schroeder <alex@gnu.org>
3  
4 # This program is free software: you can redistribute it and/or modify it under
5 # the terms of the GNU Affero General Public License as published by the Free
6 # Software Foundation, either version 3 of the License, or (at your option) any
7 # later version.
8 #
9 # This program is distributed in the hope that it will be useful, but WITHOUT
10 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 # FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
12 # details.
13 #
14 # You should have received a copy of the GNU Affero General Public License along
15 # with this program. If not, see <https://www.gnu.org/licenses/>.
16  
17 =encoding utf8
18  
19 =head1 NAME
20  
21 App::Phoebe::Css - use a CSS file for Phoebe wiki served on the web
22  
23 =head1 DESCRIPTION
24  
25 By default, Phoebe comes with its own, minimalistic CSS when serving HTML
26 rendition of pages: they all refer to C</default.css> and when this URL is
27 requested, Phoebe serves a small CSS.
28  
29 With this extension, Phoebe serves an actual F<default.css> in the wiki
30 directory.
31  
32 There is no configuration. Simply add it to your F<config> file:
33  
34 use App::Phoebe::Css;
35  
36 Then create F<default.css> and make it look good. 😁
37  
38 The cache control settings make sure that unless explicitly requested by a user
39 via a reload button, the CSS file is only fetched once per day. That also means
40 that if you change the CSS file, many users might only see a change after 24h.
41 That’s the trade-off…
42  
43 =cut
44  
45 package App::Phoebe::Css;
46 use App::Phoebe qw($server $log);
47 use App::Phoebe::Web;
48 use Modern::Perl;
49 use File::Slurper qw(read_text);
50  
51 no warnings 'redefine';
52 *App::Phoebe::Web::serve_css_via_http = \&serve_css_via_http;
53  
54 sub serve_css_via_http {
55 my $stream = shift;
56 $log->debug("Serving default.css via HTTP");
57 $stream->write("HTTP/1.1 200 OK\r\n");
58 $stream->write("Content-Type: text/css\r\n");
59 $stream->write("Cache-Control: public, max-age=86400, immutable\r\n"); # 24h
60 $stream->write("\r\n");
61 my $dir = $server->{wiki_dir};
62 $stream->write(read_text("$dir/default.css"));
63 }