fix: support multiple file handles to the same mocked file (#27)#202
Open
Koan-Bot wants to merge 1 commit intocpanel:masterfrom
Open
fix: support multiple file handles to the same mocked file (#27)#202Koan-Bot wants to merge 1 commit intocpanel:masterfrom
Koan-Bot wants to merge 1 commit intocpanel:masterfrom
Conversation
f83c57e to
00ac6a1
Compare
Replace single 'fh' tracking with 'fhs' array of weak references, allowing multiple independent handles (each with its own tell position) to be open on the same mocked file simultaneously. - MockFile.pm: _fh_to_file scans fhs array, __open/__sysopen push to it - FileHandle.pm: CLOSE removes only the specific handle via tied identity - New test t/multi_handle.t covers dual read, read+write, sysopen cases - Updated t/readline.t for new fhs structure Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
00ac6a1 to
3e255b8
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #27 — allows opening multiple independent file handles to the same mocked file.
Problem
The
%files_being_mockedhash tracked a singlefhper mocked path. Opening a second handle to the same file overwrote the first, and closing any handle cleared tracking entirely.Solution
{'fh'}with{'fhs'}arrayref of weak referencesopen/sysopenpushes to the array instead of overwritingCLOSEremoves only the specific handle (matched by tied object identity)_fh_to_file()scans all entries, cleaning dead weakrefs during traversalopendir/closedir) are unchanged — they use a separate patternTest plan
t/multi_handle.twith 4 test groups:t/readline.tassertion for newfhsstructure🤖 Generated with Claude Code