refactor: reduce duplication in MockFile.pm#284
Open
Koan-Bot wants to merge 1 commit intocpanel:masterfrom
Open
refactor: reduce duplication in MockFile.pm#284Koan-Bot wants to merge 1 commit intocpanel:masterfrom
Koan-Bot wants to merge 1 commit intocpanel:masterfrom
Conversation
Extract _default_mock_attrs() and _new_nonexistent_file_mock() to centralize mock object construction defaults that were duplicated across new(), _create_file_through_broken_symlink(), and _maybe_autovivify(). Changes to defaults now only need to happen in one place. Add _maybe_throw_autodie() helper that combines the check-and-throw pattern (_throw_autodie + _caller_has_autodie_for) into a single call, reducing 50 two-line boilerplate patterns to one-liners. Remove dead $set_error variable in __chown — it was declared but never set to true, so the conditional guards were always no-ops. Fix CAEATS typo in POD (now CAVEATS). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
atoomic
approved these changes
Mar 12, 2026
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
Extract shared patterns and remove dead code in
lib/Test/MockFile.pmto improve maintainability.Why
The 4188-line main module had three identical mock-construction blocks (20+ lines each) and 50 instances of a two-line autodie check-and-throw pattern. Any change to mock defaults required synchronizing three locations — a maintenance trap. The review also found a dead variable and a POD typo.
How
_default_mock_attrs(): centralizes the default attribute hash used bynew(),_create_file_through_broken_symlink(), and_maybe_autovivify()._new_nonexistent_file_mock($path): shared constructor for the two internal sites that create placeholder mocks (broken-symlink targets and autovivified files). Reduces 40 lines to 2 call sites._maybe_throw_autodie($func, @args): combines_caller_has_autodie_for()+_throw_autodie()into a single call, replacing 50 two-line patterns.$set_errorvariable in__chown(declared but never set).CAEATS→CAVEATStypo in POD.Skipped extracting the CORE::open fallback dispatch —
@_aliasing constraints prevent clean extraction (documented in project learnings).Testing
Full local test suite: 86 files, 1457 tests — all pass.
Net change: -23 lines (110 insertions, 133 deletions).
🤖 Generated with Claude Code