From: Eric Wong Date: Thu, 26 Sep 2024 00:55:01 +0000 (+0000) Subject: user_content: simplify internal API and use v5.12 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=01ca320aa3190cb2193447fa6afcd8afc1cc7905;p=thirdparty%2Fpublic-inbox.git user_content: simplify internal API and use v5.12 We use {env} and {ibx} everywhere so there's no point in unpacking args. There's no odd unicode_strings problems here, either, so we can use v5.12 and autodie to reduce `or die' checks. --- diff --git a/lib/PublicInbox/UserContent.pm b/lib/PublicInbox/UserContent.pm index f28610f7f..9dacfa0be 100644 --- a/lib/PublicInbox/UserContent.pm +++ b/lib/PublicInbox/UserContent.pm @@ -1,11 +1,11 @@ -# Copyright (C) 2019-2021 all contributors +# Copyright (C) all contributors # License: AGPL-3.0+ # Self-updating module containing a sample CSS for client-side # customization by users of public-inbox. Used by Makefile.PL package PublicInbox::UserContent; -use strict; -use warnings; +use v5.12; +use autodie qw(close open seek); # this sub is updated automatically: sub CSS () { @@ -71,9 +71,9 @@ _ # end of auto-updated sub # return a sample CSS -sub sample ($$) { - my ($ibx, $env) = @_; - my $url_prefix = $ibx->base_url($env); +sub sample ($) { + my ($ctx) = @_; + my $url_prefix = $ctx->{ibx}->base_url($ctx->{env}); my $preamble = <<""; /* * Firefox users: this goes in \$PROFILE_FOLDER/chrome/userContent.css @@ -87,15 +87,16 @@ sub sample ($$) { */ \@-moz-document url-prefix($url_prefix) { /* moz-only */ - $preamble . CSS() . "\n} /* moz-only */\n"; + $preamble . CSS . "\n} /* moz-only */\n"; } # Auto-update this file based on the contents of a CSS file: # usage: perl -I lib __FILE__ contrib/css/216dark.css # (See Makefile.PL) if (scalar(@ARGV) == 1 && -r __FILE__) { - open my $ro, '<', $ARGV[0] or die $!; - my $css = do { local $/; <$ro> } or die $!; + require PublicInbox::IO; + open my $ro, '<', $ARGV[0]; + my $css = PublicInbox::IO::read_all($ro); # indent one level: $css =~ s/^([ \t]*\S)/\t$1/smg; @@ -104,13 +105,13 @@ if (scalar(@ARGV) == 1 && -r __FILE__) { $css =~ s/;/ !important;/sg; $css =~ s/(\w) \}/$1 !important }/msg; - open my $rw, '+<', __FILE__ or die $!; - my $out = do { local $/; <$rw> } or die $!; + open my $rw, '+<', __FILE__; + my $out = PublicInbox::IO::read_all($rw); $css =~ s/; /;\n\t\t/g; $out =~ s/^sub CSS.*^_\n\}/sub CSS () {\n\t<<'_'\n${css}_\n}/sm; seek $rw, 0, 0; - print $rw $out or die $!; - close $rw or die $!; + print $rw $out; + close $rw; } 1; diff --git a/lib/PublicInbox/WWW.pm b/lib/PublicInbox/WWW.pm index 1bc2966d3..32d0410c6 100644 --- a/lib/PublicInbox/WWW.pm +++ b/lib/PublicInbox/WWW.pm @@ -681,8 +681,7 @@ sub get_css ($$$) { stylesheets_prepare($self, defined($inbox) ? '' : '+/'); my $css = $css_map->{$key}; if (!defined($css) && defined($inbox) && $key eq 'userContent') { - my $env = $ctx->{env}; - $css = PublicInbox::UserContent::sample($ctx->{ibx}, $env); + $css = PublicInbox::UserContent::sample($ctx); } defined $css or return r404(); my $h = [ 'Content-Length', length($css), 'Content-Type', 'text/css' ]; diff --git a/lib/PublicInbox/WwwText.pm b/lib/PublicInbox/WwwText.pm index 20b221365..79fe46aab 100644 --- a/lib/PublicInbox/WwwText.pm +++ b/lib/PublicInbox/WwwText.pm @@ -77,9 +77,7 @@ sub get_text { sub _colors_help ($$) { my ($ctx, $txt) = @_; - my $ibx = $ctx->{ibx}; - my $env = $ctx->{env}; - my $base_url = $ibx->base_url($env); + my $base_url = $ctx->{ibx}->base_url($ctx->{env}); $$txt .= "color customization for $base_url\n"; $$txt .= <