Skip to content

fix: use do() instead of require() for compiled templates (GH #177)#427

Open
toddr-bot wants to merge 4 commits into
mainfrom
koan.toddr.bot/fix-provider-inc-manipulation
Open

fix: use do() instead of require() for compiled templates (GH #177)#427
toddr-bot wants to merge 4 commits into
mainfrom
koan.toddr.bot/fix-provider-inc-manipulation

Conversation

@toddr-bot

Copy link
Copy Markdown
Contributor

What

Replace delete $INC{...}; require ... with do ... in Provider::_load_compiled().

Why

The compiled template loader manipulated %INC (a global interpreter hash) to force reloads — deleting entries before require to prevent the "already loaded" shortcut. This is a well-known antipattern that can interfere with other modules tracking loaded files. Issue #177 (opened by toddr) proposed switching to do(), which was the original approach in #79 but deferred at the time.

How

do $file executes the file and returns the last expression, just like require, but doesn't consult or modify %INC. This is a one-line behavioral change — the $@ error handling remains identical. Updated comments to reflect the new approach.

Testing

Full test suite passes (3170 tests across 116 files), including all 6 compile test files (t/compile1.t through t/compile6.t, 81 compile-specific tests).

Closes #177

🤖 Generated with Claude Code

toddr-bot and others added 4 commits April 5, 2026 01:03
Replace the delete-$INC-then-require hack with do(), which doesn't
consult or modify %INC in the first place. This eliminates the need
to manipulate global interpreter state just to reload compiled
templates, as originally proposed in GH #79.

Closes #177

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Restored the `eval { }` block around the `do $fpath` call, per @atoomic's review: `$@` is checked immediately after to detect load errors, so the `eval` block is needed to ensure `$@` reflects errors from this specific `do` call rather than stale errors from earlier code.
@toddr-bot

Copy link
Copy Markdown
Contributor Author

Recreated from #367 (auto-closed when the toddr-bot fork was removed). Original branch is now hosted on this repo.

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.

Stop removing entries from %INC to load code

1 participant