]> Sergey Matveev's repositories - public-inbox.git/commitdiff
move JSON module portability into PublicInbox::Config
authorEric Wong <e@80x24.org>
Mon, 23 Nov 2020 07:05:52 +0000 (07:05 +0000)
committerEric Wong <e@80x24.org>
Tue, 24 Nov 2020 05:03:55 +0000 (05:03 +0000)
We'll be using JSON in MiscIdx and MiscSearch, and
PublicInbox::Config seems like an appropriate place to put it.

lib/PublicInbox/Config.pm
lib/PublicInbox/ManifestJsGz.pm

index d2010f7af8f629b896be5c19030ecfc499220334..039eb445f6bbe54daadc977959e1101fae38af3c 100644 (file)
@@ -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;
index 16d2a87c49fd5f902d94218ec54427007161eb38..ab1478afcc38507245a8b41b9ac0ddfcb747d5c9 100644 (file)
@@ -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 {