{ } jq-lite

Library API contract

On this pageStable public APIInternal implementation packagesConstructor contractrun_query contractCompatibility policyBreaking changesErrorsTesting expectationsVersioning principle
このページの目次安定した公開API内部実装パッケージコンストラクターrun_query互換性の方針破壊的変更エラーテストとバージョン管理

JQ::LiteをPerlライブラリとして使うアプリケーションとCPAN配布物のための後方互換性の契約です。内部実装の発展を許しながら、文書化された公開APIを安全に利用できるようにします。

安定した公開API

2.x系の公開エントリーポイントは以下です。

use JQ::Lite;
my $jq = JQ::Lite->new(%options);
my @results = $jq->run_query($json_text, $query);

明示的に公開APIとして文書化されたものだけが互換性保証の対象です。

パッケージ 状態 保証する内容
JQ::Lite 公開 このLibrary API仕様の対象
JQ::Lite::Error 公開 文書化された例外の基底クラス
JQ::Lite::Error::Input 公開 安定した入力エラー分類
JQ::Lite::Error::Parse 公開 安定したクエリ構文エラー分類
JQ::Lite::Error::Evaluation 公開 安定した評価エラー分類

クエリはJQ::Liteを通して実行してください。エラー階層は機械的なエラー分類に利用できます。

内部実装パッケージ

以下は2.xの実装詳細であり、将来明示的に公開されない限り安定した公開APIには含まれません。

パッケージ 役割 状態
JQ::Lite::Expression 式評価の補助 内部
JQ::Lite::Filters フィルターの振り分けと実装 内部
JQ::Lite::Parser クエリの構文解析 内部
JQ::Lite::Util 共通の実装補助 内部
JQ::Lite::Util::Parsing 構文解析の補助 内部
JQ::Lite::Util::Paths パス操作の補助 内部
JQ::Lite::Util::Transform 変換の補助 内部

インストール済み・読み込み可能という理由だけで、これらに安定したAPIとして依存してはいけません。公開APIが維持される限り、関数、引数、構造、動作はメジャー更新なしに変わり得ます。非公開メソッド、未文書化のフィールドも対象外です。内部APIを公開へ昇格する場合は、利用者向け文書と保証する動作のテストが必要です。

コンストラクター

JQ::Lite->new(%options)はJQ::Liteオブジェクトを返します。

  • raw:適用可能な箇所で生の出力を有効にします。
  • vars:事前定義するjq形式の変数をハッシュ参照で受け取ります。

同じメジャー版の間は、文書化したオプションの名前と意味を非互換に変更・削除しません。既存の呼び出しを変えない新しい省略可能な引数はマイナー版で追加できます。

run_query

$jq->run_query($json_text, $query)は以下の契約に従います。

  • 第1引数はJSONテキスト、第2引数はjqに似たクエリ文字列です。
  • 0個以上の結果をPerlのリストで返します。
  • オブジェクトはハッシュ参照、配列は配列参照です。
  • JSONのスカラーは対応するPerlのスカラー表現で返します。

文書化されたクエリ機能の結果数と順序は観測可能な動作の一部です。同じメジャー版内で非互換に変えません。クエリが未定義または.だけなら、デコードした入力値を返します。

互換性の方針

同じメジャー版の間は、公開パッケージ・メソッド名、引数の意味、返り値、コンストラクターのオプション、エラー分類を維持します。

以前の動作が誤り、安全でない、または文書化された意味論と矛盾する場合は、バグ修正で動作が変わることがあります。下流に影響し得る変更は変更履歴に記載します。既存の動作を変えない機能・オプション・構文・結果型の追加は後方互換です。

破壊的変更

意図的な非互換変更にはメジャーバージョンの更新が必要です。

  • 公開メソッドの削除・改名。
  • 文書化した引数の意味の変更。
  • run_queryのリスト返却契約の変更。
  • 文書化したコンストラクターのオプションの削除。
  • 構造化エラークラス・分類の削除や用途変更。

公開契約を維持した内部整理は破壊的変更ではありません。避けられない変更はChangesに記載し、可能なら移行手順を示します。

エラー

ライブラリの呼び出しはJQ::Lite::Errorを継承する例外を投げることがあります。

クラス category 意味
JQ::Lite::Error::Input input 入力JSONのデコード失敗
JQ::Lite::Error::Parse parse クエリの構文が不正
JQ::Lite::Error::Evaluation evaluation クエリの実行時評価失敗

各オブジェクトは人間向けのmessage、安定した機械向けのcategory、メッセージへの文字列化を提供します。クラス名と分類値は2.xの保証対象ですが、メッセージの厳密な文言は保証対象ではありません。文言を解析して機械的に判断しないでください。

文字列化により、従来の$@を表示・記録するコードでも有用な診断を受け取れます。

テストとバージョン管理

保証する動作は可能な範囲で回帰テストにより保護します。新しい公開APIには引数と返り値のテストが必要です。入力・構文解析・評価の分類と文字列化には専用テストがあります。

利用者がマイナー版の更新だけで動く組み込みを書き直す必要がないことを重視します。公開APIは同じメジャー版で安定させ、意図的な破壊的変更にはメジャー更新を行います。

This document defines the backward-compatibility contract for applications and CPAN distributions that use JQ::Lite as a Perl library.

The goal is to make it safe for downstream code to depend on the documented public API while still allowing JQ::Lite internals to evolve.

Stable public API

For the 2.x series, the supported public library entry point is:

use JQ::Lite;

my $jq = JQ::Lite->new(%options);
my @results = $jq->run_query($json_text, $query);

Only APIs explicitly documented as public are covered by the compatibility guarantees in this document.

Public packages

Package Status Compatibility
JQ::Lite Public Covered by this Library API contract
JQ::Lite::Error Public Base class for documented Library API exceptions
JQ::Lite::Error::Input Public Stable input-error category
JQ::Lite::Error::Parse Public Stable query-parse-error category
JQ::Lite::Error::Evaluation Public Stable evaluation-error category

Downstream distributions should use JQ::Lite as the query entry point. The documented JQ::Lite::Error hierarchy may be used for machine-readable error classification.

Internal implementation packages

The following installed packages are implementation details in the 2.x series and are not part of the stable public API unless a future release explicitly documents otherwise:

Package Role Status
JQ::Lite::Expression Expression evaluation helpers Internal
JQ::Lite::Filters Filter dispatch and implementation Internal
JQ::Lite::Parser Query parsing Internal
JQ::Lite::Util Shared implementation utilities Internal
JQ::Lite::Util::Parsing Parsing helpers Internal
JQ::Lite::Util::Paths Path helpers Internal
JQ::Lite::Util::Transform Transformation helpers Internal

Downstream code must not rely on these packages as compatibility-stable APIs merely because they are installed or loadable. Their functions, signatures, package structure, and behavior may change during refactoring without a major version bump, provided the documented JQ::Lite public API remains compatible.

Private methods, undocumented object fields, and other implementation details are likewise outside the compatibility contract.

If an internal package is promoted to public API in the future, that status must be stated explicitly in user-facing documentation and accompanied by tests for its promised behavior.

Constructor contract

JQ::Lite->new(%options) returns a JQ::Lite object.

The currently documented constructor options are:

  • raw — enables raw-output behavior where applicable.
  • vars — accepts a hash reference of predeclared jq-style variables.

Within a major release series, documented option names and their meanings will not be removed or changed incompatibly.

New optional constructor arguments may be added in minor releases when they do not alter the behavior of existing calls.

run_query contract

$jq->run_query($json_text, $query):

  • accepts JSON text as its first argument;
  • accepts a jq-like query string as its second argument;
  • returns zero or more results as a Perl list;
  • represents object results as hash references and array results as array references;
  • returns scalar JSON values as the corresponding Perl scalar representation.

The number and ordering of results are part of the observable behavior of a documented query feature and will not be changed incompatibly within the same major release series.

A query that is undefined or consists only of . returns the decoded input value.

Compatibility policy

Within a major release series, JQ::Lite will preserve compatibility for the documented Library API in the following areas:

  • public package and method names;
  • documented argument meanings;
  • documented return-value semantics;
  • documented constructor options;
  • documented error classes/categories and their meanings.

Bug fixes may change behavior when the previous behavior was incorrect, unsafe, or inconsistent with documented jq-lite semantics. Such changes should be called out in the changelog when they may affect downstream callers.

Adding new methods, options, supported jq syntax, or result types that do not change existing documented behavior is considered backward compatible.

Breaking changes

A deliberate incompatible change to this stable Library API requires a major version bump.

Examples include:

  • removing or renaming a documented public method;
  • changing the meaning of an existing documented argument;
  • changing run_query from list-returning semantics to a different return contract;
  • removing a documented constructor option;
  • removing or repurposing a documented structured error class/category.

Internal package refactoring is not a breaking Library API change when the documented JQ::Lite public contract remains intact.

When a breaking change is unavoidable, it should be documented in Changes together with a migration path where practical.

Errors

Library calls may throw objects derived from JQ::Lite::Error. The documented categories are:

Class category Meaning
JQ::Lite::Error::Input input The JSON input supplied to the Library API could not be decoded
JQ::Lite::Error::Parse parse The jq-lite query is syntactically malformed
JQ::Lite::Error::Evaluation evaluation Query evaluation failed at runtime

Each documented error object provides:

  • message — a human-readable diagnostic;
  • category — a stable machine-readable category;
  • stringification to the human-readable message.

The class names and category values above are part of the 2.x Library API compatibility contract. Exact human-readable message wording is not a compatibility contract and downstream code should not parse it for machine-readable decisions.

Stringification deliberately preserves the traditional $@ usage pattern so existing callers that log or display an exception continue to receive a useful diagnostic.

Testing expectations

Behavior covered by this contract should be protected by regression tests where practical. New stable public APIs should include tests for their documented argument and return-value semantics.

The test suite includes dedicated Library API error tests covering the documented input, parse, and evaluation categories and message stringification behavior.

Versioning principle

The Library API follows the same general stability principle as the CLI contract: downstream users should not need to rewrite working integrations because of a minor release.

In short:

Documented public Library API behavior is stable within a major release series; intentional breaking changes require a major version bump.