Skip to content

feat: add text/binary options to stat_as_* for -T/-B mock support#107

Draft
Koan-Bot wants to merge 2 commits into
cpan-authors:mainfrom
Koan-Bot:koan.atoomic/feat-stat-text-binary-options
Draft

feat: add text/binary options to stat_as_* for -T/-B mock support#107
Koan-Bot wants to merge 2 commits into
cpan-authors:mainfrom
Koan-Bot:koan.atoomic/feat-stat-text-binary-options

Conversation

@Koan-Bot
Copy link
Copy Markdown
Contributor

@Koan-Bot Koan-Bot commented May 11, 2026

What

Add text and binary options to stat_as_* helpers so -T and -B return correct results when using mock_all_from_stat().

Why

Documented limitation: -T and -B rely on content heuristics that can't work for mocked files that don't exist on disk. Users had to mock these operators separately from their stat callback, fragmenting the mock setup. This feature lets users declare text/binary intent inline.

How

  • _stat_for() extracts text/binary options before the stat array is built and sets a package-level metadata variable
  • _check_from_stat() saves/restores this metadata (re-entrancy safe) and passes it to the -T/-B dispatch handlers
  • When metadata is present, handlers return directly; when absent, they fall back to Perl's heuristic (backward compatible)
  • Specifying one option infers the other (complementary)

Testing

  • 9 subtests covering: text files, binary files, explicit false values, directories, fallback behavior, non-existent files, mixed files, and stacked operators
  • Full test suite passes (65 test files)

🤖 Generated with Claude Code


Quality Report

Changes: 2 files changed, 221 insertions(+), 5 deletions(-)

Code scan: clean

Tests: passed (0 Tests)

Branch hygiene: clean

Generated by Kōan post-mission quality pipeline

Koan-Bot and others added 2 commits May 11, 2026 04:31
…port

When using mock_all_from_stat(), -T and -B checks rely on Perl's
content-based heuristic which cannot work for files that don't exist
on disk. This adds text/binary options to all stat_as_* helpers so
users can control -T/-B results declaratively:

    return stat_as_file( size => 100, text => 1 );    # -T true, -B false
    return stat_as_file( size => 200, binary => 1 );  # -T false, -B true

Specifying one option infers the other (they are complementary).
When neither is given, behavior is unchanged (falls back to heuristic).

Implementation uses a save/restore pattern for the metadata side-channel,
consistent with existing re-entrancy handling in _check_from_stat.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Older perldocker/perl-tester images (5.10-5.22) no longer ship cpm
pre-installed, causing CI failures on all PR branches. Fall back to
cpanm --installdeps when cpm is not found.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

1 participant