From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.2 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 6F7541F5CE; Thu, 26 Sep 2024 00:55:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1727312106; bh=iH4DNwWkS9pfnukvpmCdiX/B2BIQjmIoxFzeHsx9n9c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WezM5nZZdFne5A4k0jTThemSN0MGnkkVhJ4yqkrM9q+py80qQNOtOHDFAfmErSuBv cQUdtGW7mIe+BYWsrbLcC5gRbde6dAwGxgvciqga1F+yxji5XWCukNHzN1ViRm1R5x wM3EPOfLxZxn7S+u386+Lu8OzYJdhJRioAXB2UwQ= From: Eric Wong To: meta@public-inbox.org Cc: "Robin H. Johnson" Subject: [PATCH 1/5] user_content: simplify internal API and use v5.12 Date: Thu, 26 Sep 2024 00:55:01 +0000 Message-ID: <20240926005506.3703216-2-e@80x24.org> In-Reply-To: <20240926005506.3703216-1-e@80x24.org> References: <20240926005506.3703216-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: 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. --- lib/PublicInbox/UserContent.pm | 27 ++++++++++++++------------- lib/PublicInbox/WWW.pm | 3 +-- lib/PublicInbox/WwwText.pm | 6 ++---- 3 files changed, 17 insertions(+), 19 deletions(-) diff --git a/lib/PublicInbox/UserContent.pm b/lib/PublicInbox/UserContent.pm index f28610f7..9dacfa0b 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 1bc2966d..32d0410c 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 20b22136..79fe46aa 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 .= <