Skip to content

refactor: use JSON::MaybeXS for broader compatibility#26

Closed
Koan-Bot wants to merge 1 commit into
masterfrom
koan.atoomic/json-maybexs
Closed

refactor: use JSON::MaybeXS for broader compatibility#26
Koan-Bot wants to merge 1 commit into
masterfrom
koan.atoomic/json-maybexs

Conversation

@Koan-Bot

@Koan-Bot Koan-Bot commented Apr 16, 2026

Copy link
Copy Markdown
Collaborator

What

Swap the runtime dependency from JSON::XS (XS, C toolchain required) to JSON::MaybeXS, which picks the best available backend at runtime.

Why

Closes #23. JSON::XS requires a C compiler and dev headers to install, which blocks use in locked-down containers and minimal Docker images. JSON::MaybeXS transparently prefers Cpanel::JSON::XSJSON::XSJSON::PP (core since 5.14), so:

  • Users who already have an XS backend see zero behavior change
  • Environments without a C toolchain now install cleanly

How

  • lib/Slack/WebHook.pm: use JSON::XS ()use JSON::MaybeXS (), JSON::XS->newJSON::MaybeXS->new
  • dist.ini and cpanfile: runtime requires swapped accordingly
  • t/hooks.t: test imports swapped so the suite exercises the chosen backend (no separate JSON::XS test-only dep needed)

The _build_json constructor chain (->new->utf8(0)->pretty(1)) is identical — JSON::MaybeXS exposes the same API.

Testing

  • prove -Ilib t/hooks.t → 48/48 pass locally (Cpanel::JSON::XS backend selected)
  • No behavior change for users with an XS backend installed

Notes

This touches lib/Slack/WebHook.pm and t/hooks.t, which will lightly conflict with PR #20 (JSON payload refactor). Conflict is trivial: both touch the use line and one test decode call — resolution is "take both". Whichever merges first, the other rebases in ~2 lines.


Quality Report

Changes: 4 files changed, 7 insertions(+), 7 deletions(-)

Code scan: clean

Tests: passed (OK)

Branch hygiene: clean

Generated by Kōan post-mission quality pipeline

Swap the hard dependency on JSON::XS (XS module, needs C toolchain) for
JSON::MaybeXS, which transparently selects the best available backend:
Cpanel::JSON::XS, JSON::XS, or JSON::PP (core since 5.14).

Users with JSON::XS installed see zero behavior change. Environments
without a C compiler now work out of the box with the pure-Perl fallback.

The _build_json method keeps the same constructor chain — JSON::MaybeXS
exposes the same ->new->utf8(0)->pretty(1) API.

Closes #23.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@Koan-Bot

Koan-Bot commented May 1, 2026

Copy link
Copy Markdown
Collaborator Author

Superseded by #29 which consolidates this change (JSON::MaybeXS) with the Encode removal and JSON post refactor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Replace JSON::XS with JSON::MaybeXS for broader compatibility

1 participant