Skip to content

feat: add file_passthrough() for strict-mode-compatible real FS access#280

Draft
Koan-Bot wants to merge 1 commit intocpanel:masterfrom
atoomic:koan.atoomic/file-passthrough
Draft

feat: add file_passthrough() for strict-mode-compatible real FS access#280
Koan-Bot wants to merge 1 commit intocpanel:masterfrom
atoomic:koan.atoomic/file-passthrough

Conversation

@Koan-Bot
Copy link
Contributor

@Koan-Bot Koan-Bot commented Mar 3, 2026

Summary

  • Adds Test::MockFile->file_passthrough($path) which registers a path with strict mode but delegates all I/O to the real filesystem
  • Solves the DBD::SQLite / DBI compatibility issue where XS-based modules perform C-level I/O that bypasses Perl's overrides

Why

When using Test::MockFile in strict mode, XS modules like DBD::SQLite that use C-level file operations (not Perl's open) fail because strict mode blocks access to unmocked paths. file_passthrough adds a strict rule allowing all operations on the given path while intentionally NOT registering it in %files_being_mocked, so all overrides fall through to CORE::*.

How

  • file_passthrough($path) creates a strict-mode rule (allow-all for exact path) and returns a blessed object
  • The object is NOT in %files_being_mocked, so _mock_stat, __open, etc. all fall through to real filesystem
  • On DESTROY, the strict rule is removed but the real file is NOT deleted

Testing

  • 5 subtests in t/file_passthrough.t: object creation, real FS delegation (write/read/stat/unlink), coexistence with regular mocks, scope cleanup, input validation

Closes #91

🤖 Generated with Claude Code

…em access

Adds Test::MockFile->file_passthrough($path) which registers a path
with strict mode but delegates all I/O to the real filesystem. This
allows XS-based modules like DBD::SQLite that perform C-level I/O to
create and use files while Perl-level checks (-f, stat, open) remain
consistent under strict mode.

The passthrough object adds a strict rule (allow-all for the path) and
intentionally does NOT register in %files_being_mocked, so all
overrides fall through to CORE::*. On scope exit (DESTROY), the strict
rule is removed but the real file is not deleted.

Closes cpanel#91

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

Development

Successfully merging this pull request may close these issues.

Test::MockFile & DBD::SQLite

1 participant