Honor PERL_JSON_BACKEND=JSON::XS through the bundled compatibility shim

Offen
#2,114 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Anfängerfreundlichkeit
58/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
json, perl
Bereich
backend

Rechercherichtung

Start with src/main/perl/lib/JSON.pm and the existing adapter in src/main/perl/lib/JSON/XS.pm; compare how the dispatcher handles PERL_JSON_BACKEND with how the adapter reports its backend and native XS status. Add the project owned regression described in the acceptance criteria, first checking its expected behavior with system Perl. Run it on both JVM and interpreter backends, then verify the default and JSON::backportPP selections and the CPAN distribution test.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

area:backend area:cpan-port bug

Summary

The bundled JSON dispatcher ignores PERL_JSON_BACKEND=JSON::XS. It always loads JSON::PP unless the value is exactly JSON::backportPP, and JSON->backend consequently reports JSON::PP. This makes CPAN distributions that explicitly request the XS-compatible backend fail even though PerlOnJava already ships a JSON::XS compatibility module backed by the bundled pure-Perl JSON implementation.

Reproduction

With PERL_JSON_BACKEND=JSON::XS, run:

./jperl -e 'require JSON; print JSON->backend, "\n"'
./jperl --interpreter -e 'require JSON; print JSON->backend, "\n"'

Both currently print JSON::PP. The same selection occurs when the variable is set inside a test's BEGIN block before use JSON.

This was observed in CPAN random run 20261118-104825-43075 for Data-Compare-Plugins-JSON 1.04. t/05-compare-json-uses-xs.t sets PERL_JSON_BACKEND=JSON::XS, loads JSON::XS and JSON, then expects JSON->backend to be an isa JSON::XS. The PerlOnJava run reports JSON::PP and fails that assertion (1 of 75 tests; 1 of 11 test programs). The run used JSON 4.11, JSON::XS 4.04 and JSON::PP 4.18. The complete unmodified distribution suite passed under system Perl (11 files, 75 tests); the focused test also passed with the distribution and dependency library paths active.

Root cause and existing support

src/main/perl/lib/JSON.pm loads JSON::PP for every backend value other than JSON::backportPP, initializes $Backend / $BackendModule to JSON::PP, and leaves $BackendModuleXS undefined. Separately, src/main/perl/lib/JSON/XS.pm already exposes a JSON::XS-compatible API by delegating to Cpanel::JSON::XS, which uses the JSON::PP stack. The compatibility adapter is therefore present, but JSON never selects it when the caller requests JSON::XS.

The fix should connect the dispatcher to this existing adapter (or a small JSON::Backend::XS wrapper over it) when PERL_JSON_BACKEND=JSON::XS. It should preserve the distinction between selecting an XS-compatible API and actually running native XS: do not claim a native XS implementation is loaded. Keep the default PP selection and the JSON::backportPP behavior intact.

Acceptance criteria

  • Add a project-owned regression for setting PERL_JSON_BACKEND=JSON::XS before loading JSON; validate the test's expected behavior with system Perl first.
  • On both JVM and interpreter backends, the requested JSON::XS adapter is selected and JSON->backend satisfies isa JSON::XS.
  • The selected adapter continues to encode/decode through the bundled PP implementation and retains the existing JSON::XS API behavior; native XS status is reported accurately.
  • Default backend selection and PERL_JSON_BACKEND=JSON::backportPP remain unchanged.
  • Data-Compare-Plugins-JSON 1.04's unmodified t/05-compare-json-uses-xs.t and full suite pass through the normal PerlOnJava CPAN dependency overlay.

Related work

The existing JSON::XS shim is documented in docs/reference/xs-compatibility.md and implemented in src/main/perl/lib/JSON/XS.pm. Issue #1148 covers JSON::Parse loading without XS and is a separate problem. Issue #2097 concerns adding JSON::SL support; it may share JSON infrastructure, but does not cover backend selection.

Vorherrschende Sprache
Perl
Sterne
67
Forks
8
Ø Merge
5 Std. 12 Min.
Gemergte PRs (30 T.)
131

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus fglock/PerlOnJava

Alle Issues in fglock/PerlOnJava

Ähnliche Issues

Weitere Issues zu Perl

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.