Skip to content

fix: eliminate -B double-dispatch through mock system#91

Draft
Koan-Bot wants to merge 1 commit intocpan-authors:mainfrom
Koan-Bot:koan.atoomic/fix-B-double-dispatch
Draft

fix: eliminate -B double-dispatch through mock system#91
Koan-Bot wants to merge 1 commit intocpan-authors:mainfrom
Koan-Bot:koan.atoomic/fix-B-double-dispatch

Conversation

@Koan-Bot
Copy link
Copy Markdown
Contributor

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

What

Fix the -B handler in _check_from_stat to avoid re-entering the mock system.

Why

The -B handler called -d $f_or_fh to check if the target is a directory. Since -d is also mocked under mock_all_from_stat, this triggered a full second round-trip through the mock dispatch — calling the user's stat callback again. This is wasteful and risks inconsistency if the callback has side effects or returns different results on subsequent calls.

Additionally, -B and -T were using lstat instead of stat, which is incorrect — both operators follow symlinks in Perl.

How

  • Replace -d $f_or_fh with an inline mode-bit check (_S_IFMT mask against S_IFDIR) on the already-cached @stat array — zero mock re-entry.
  • Add B and T to the $can_use_stat character class so the stat cache (not lstat) is used, matching Perl's symlink-following semantics.

Testing

  • New t/B-no-double-dispatch.t verifies the stat callback is called exactly once per -B check (regular file, directory, non-existent file).
  • Full test suite passes.

🤖 Generated with Claude Code


Quality Report

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

Code scan: clean

Tests: passed (0 Tests)

Branch hygiene: clean

Generated by Kōan post-mission quality pipeline

The -B handler in _check_from_stat called `-d $f_or_fh` to check for
directories, which re-entered the mock system and triggered a redundant
second call to the user's stat callback. Replace with an inline mode-bit
check on the already-cached @stat array.

Also add B and T to the $can_use_stat set so they use stat (not lstat),
matching Perl's symlink-following behavior for these operators.

Co-Authored-By: Claude <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