From 02a613aad40864c291bb2e8d499050d4aa6fc344 Mon Sep 17 00:00:00 2001 From: Mischa POSLAWSKY Date: Sat, 6 Jun 2020 04:26:59 +0200 Subject: [PATCH] common: enable perl stricture and fix resulting errors --- common.inc.plp | 35 +++++++++++++++++++++-------------- word.plp | 2 +- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/common.inc.plp b/common.inc.plp index 7788049..d0e1c32 100644 --- a/common.inc.plp +++ b/common.inc.plp @@ -1,5 +1,6 @@ <: use 5.014; +use strict; use utf8; use warnings; no warnings 'qw'; # you know what you doing @@ -10,11 +11,13 @@ use File::stat 'stat'; use HTTP::Date; use Encode qw( decode_utf8 ); +our $Dev; + sub Alert { my ($html, $debug) = @_; ref $html eq 'ARRAY' or $html = [$html]; my ($title, @lines) = @{$html}; - $body = "

$title

"; + my $body = "

$title

"; $body .= "\n

$_

" for @lines; $body .= "\n
$debug
" if $Dev and $debug; say "
$body
\n"; @@ -38,21 +41,10 @@ BEGIN { require Time::HiRes; our $Time = [Time::HiRes::gettimeofday()]; - $PLP::ERROR = sub { - my ($text, $html) = @_; - warn $text; - unless ($PLP::sentheaders and $PLP::sentheaders->[0] !~ m{/PLP\.pm$}) { - Html({nocache => 1}); - say '

Page unavailable

'; - } - Alert("Fatal error: $html."); - }; - push @INC, '.'; # user request our $Dev = $ENV{HTTP_HOST} =~ /\bdev\./; - our ($file) = $ENV{SCRIPT_FILENAME} =~ m{ ([^/]+) \.plp$ }x; } our $Request = decode_utf8($ENV{PATH_INFO} =~ s{^/}{}r); @@ -146,6 +138,8 @@ sub Html { '', ) if $meta->{keys}; + my ($file) = $ENV{SCRIPT_FILENAME} =~ m{ ([^/]+) \.plp$ }x; + PLP_START { # leading output say ''; @@ -156,9 +150,9 @@ sub Html { for $header{content_type}; say sprintf '%s', $meta->{title}; say sprintf '', EscapeHTML($_) - for join(' ', @{ $meta->{description} }) || (); + for join(' ', @{ $meta->{description} // [] }) || (); say sprintf '', EscapeHTML($_) - for join(', ', @{ $meta->{keywords} }) || (); + for join(', ', @{ $meta->{keywords} // [] }) || (); say ''; say ''; say for map { @{$_} } $meta->{raw} || (); @@ -192,6 +186,7 @@ sub Html { title="Licensed under the GNU Affero General Public License, version 3" rel="license">AGPLv3 EOT + our $Time; say sprintf '• %.3fs', Time::HiRes::tv_interval($Time) if $Dev and $Time; say '

'; say ''; @@ -199,6 +194,18 @@ EOT }; } +BEGIN { + $PLP::ERROR = sub { + my ($text, $html) = @_; + warn $text; + unless ($PLP::sentheaders and $PLP::sentheaders->[0] !~ m{/PLP\.pm$}) { + Html({nocache => 1}); + say '

Page unavailable

'; + } + Alert("Fatal error: $html."); + }; +} + sub showlink { my ($title, $href, $selected) = @_; return sprintf( diff --git a/word.plp b/word.plp index 508fd06..4552572 100644 --- a/word.plp +++ b/word.plp @@ -90,7 +90,7 @@ sub showimg { $name = "$name" if $name =~ s/\?$//; $name = "
$name
"; - if ($imgname and -e ($img = "data/word/en/$imgname.jpg")) { + if ($imgname and -e (my $img = "data/word/en/$imgname.jpg")) { $name .= sprintf '%s', $img, $imgname; } return sprintf '%s', $hidden && !exists $get{v} && ' hidden', $name; -- 2.30.0