Skip to content

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

Open
toddr-bot wants to merge 4 commits intoabw:masterfrom
toddr-bot:koan.toddr.bot/fix-provider-inc-manipulation
Open

fix: use do() instead of require() for compiled templates (GH #177)#367
toddr-bot wants to merge 4 commits intoabw:masterfrom
toddr-bot: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

@atoomic atoomic marked this pull request as ready for review April 4, 2026 23:45
Copy link
Copy Markdown
Collaborator

@atoomic atoomic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need some extra work, view comment about eval block

# Unlike require(), do() doesn't consult or modify %INC,
# so we avoid the previous hack of deleting %INC entries
# to force reloads (see GH #177).
my $compiled = do $fpath;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should still preserve the eval block as $@ is used the line just after

@atoomic
Copy link
Copy Markdown
Collaborator

atoomic commented Apr 4, 2026

@toddr-bot rebase and view comment from #367 (comment)

toddr-bot and others added 2 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 abw#79.

Closes abw#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

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

Branch koan.toddr.bot/fix-provider-inc-manipulation rebased onto master and force-pushed.

Diff: 1 file changed, 7 insertions(+), 18 deletions(-)

Review feedback was analyzed and applied.

Changes

  • 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.

Actions

  • Already-solved check: skipped (JSON parse error)
  • Resolved merge conflicts (1 round(s))
  • Rebased koan.toddr.bot/fix-provider-inc-manipulation onto upstream/master
  • Applied review feedback
  • Force-pushed koan.toddr.bot/fix-provider-inc-manipulation to origin
  • CI check enqueued (async)

CI

CI will be checked asynchronously.


Automated by Kōan

@toddr-bot toddr-bot force-pushed the koan.toddr.bot/fix-provider-inc-manipulation branch from 7935f9e to a40172a Compare April 5, 2026 01:04
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

2 participants