feat: override IO::File::open for mocked file compatibility#220
Draft
Koan-Bot wants to merge 2 commits intocpanel:masterfrom
Draft
feat: override IO::File::open for mocked file compatibility#220Koan-Bot wants to merge 2 commits intocpanel:masterfrom
Koan-Bot wants to merge 2 commits intocpanel:masterfrom
Conversation
Contributor
Author
Rebase: feat: override IO::File::open for mocked file compatibilityBranch Actions
Automated by Kōan |
4816643 to
0c75b5c
Compare
0c75b5c to
ac7e277
Compare
Contributor
Author
a7a17e4 to
1e5285f
Compare
IO::File::open() uses CORE::open internally, which bypasses CORE::GLOBAL::open and makes IO::File->new() ignore mocked files. Fix: replace IO::File::open with a wrapper that checks if the target file is mocked. If mocked, tie the existing IO::File glob directly (avoiding the need to create a new handle). If not mocked, fall through to the original IO::File::open via goto. This follows the same pattern as the Cwd::abs_path override (PR cpanel#211) — intercept at the namespace level when C/XS code bypasses CORE::GLOBAL. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
When _io_file_open_override passed numeric modes to sysopen(), __sysopen replaced $_[0] with a new IO::File glob — but the original IO::File glob held by the caller was never updated. For mocked files, convert sysopen flags to string modes and use _io_file_mock_open which ties the existing glob in place. Only fall through to real sysopen for non-mocked files. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1e5285f to
24f4723
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.
What
Override
IO::File::openso thatIO::File->new($mocked_file)works correctly with mocked files.Why
IO::File::open()usesCORE::openinternally, which bypassesCORE::GLOBAL::open. This means any module usingIO::File(e.g. Config::MySQL::Reader via Mixin::Linewise::Readers) would silently ignore mocked files — reading from the real filesystem or failing.Fixes #39.
How
IO::File::openand replace with_io_file_open_override%files_being_mocked_io_file_mock_opengoto &$_orig_io_file_openpasses through to the originalCORE::GLOBAL::sysopen), so those are just forwardedSame pattern as the
Cwd::abs_pathoverride (PR #211) — intercept at the namespace level when internal code bypassesCORE::GLOBAL.Testing
t/io_file_compat.t: 13 test groups coveringIO::File->newwith read/write/append/r+ modes, 2-arg embedded mode,$fh->open()method,getline(), sysopen numeric modes, and non-existent mock files.🤖 Generated with Claude Code