From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id F3FF41FA17 for ; Mon, 23 Nov 2020 07:06:02 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 02/12] move JSON module portability into PublicInbox::Config Date: Mon, 23 Nov 2020 07:05:52 +0000 Message-Id: <20201123070602.9698-3-e@80x24.org> In-Reply-To: <20201123070602.9698-1-e@80x24.org> References: <20201123070602.9698-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: We'll be using JSON in MiscIdx and MiscSearch, and PublicInbox::Config seems like an appropriate place to put it. --- lib/PublicInbox/Config.pm | 12 ++++++++++++ lib/PublicInbox/ManifestJsGz.pm | 8 ++------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/lib/PublicInbox/Config.pm b/lib/PublicInbox/Config.pm index d2010f7a..039eb445 100644 --- a/lib/PublicInbox/Config.pm +++ b/lib/PublicInbox/Config.pm @@ -488,4 +488,16 @@ sub urlmatch { } } +sub json { + state $json; + $json //= do { + for my $mod (qw(Cpanel::JSON::XS JSON::MaybeXS JSON JSON::PP)) { + eval "require $mod" or next; + # ->ascii encodes non-ASCII to "\uXXXX" + $json = $mod->new->ascii(1) and last; + } + $json; + }; +} + 1; diff --git a/lib/PublicInbox/ManifestJsGz.pm b/lib/PublicInbox/ManifestJsGz.pm index 16d2a87c..ab1478af 100644 --- a/lib/PublicInbox/ManifestJsGz.pm +++ b/lib/PublicInbox/ManifestJsGz.pm @@ -10,17 +10,13 @@ use Digest::SHA (); use File::Spec (); use bytes (); # length use PublicInbox::Inbox; +use PublicInbox::Config; use PublicInbox::Git; use IO::Compress::Gzip qw(gzip); use HTTP::Date qw(time2str); *try_cat = \&PublicInbox::Inbox::try_cat; -our $json; -for my $mod (qw(Cpanel::JSON::XS JSON::MaybeXS JSON JSON::PP)) { - eval "require $mod" or next; - # ->ascii encodes non-ASCII to "\uXXXX" - $json = $mod->new->ascii(1) and last; -} +our $json = PublicInbox::Config::json(); # called by WwwListing sub url_regexp {