fix: use compile-time mro and block eval for safer module loading#34
Draft
Koan-Bot wants to merge 1 commit into
Draft
fix: use compile-time mro and block eval for safer module loading#34Koan-Bot wants to merge 1 commit into
Koan-Bot wants to merge 1 commit into
Conversation
Move `require mro` from _all_attributes() hot path to compile-time
`use mro ()` — eliminates per-new() hash lookup overhead.
Replace string eval `eval qq[require $module]` in with() with block
eval `eval { require $file }` — safer, friendlier to static analysis
and coverage tools, with manual ::→/ path conversion for Perl <5.26
compatibility.
17 new tests covering MRO inheritance, block eval role loading,
deeply namespaced roles, error messages, and inline roles.
Closes #22, closes #25
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This was referenced Apr 17, 2026
This was referenced May 3, 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
Two targeted fixes: compile-time
mroloading and block eval for rolerequire.Why
require mrocalled inside hot-path function on everynew()#22:require mrowas called inside_all_attributes()on everynew(). While Perl'srequireshort-circuits via%INC, it still performs a hash lookup per call.use mro ()at compile time eliminates this.requirewhere a block eval suffices #25:eval qq[require $module; 1]used string eval where block eval suffices. Block eval is friendlier to static analysis, coverage tools, and Perl::Critic. Manual::→/path conversion ensures Perl < 5.26 compatibility.Also noting that #24 (guard key collision) and #26 (rollback duplication) are already fixed on master by commits
e15434cand6b8f5d7respectively.How
use mro ();at module top, removedrequire mro;from_all_attributes()eval qq[require $module; 1]with(my $file = "$module.pm") =~ s{::}{/}g; eval { require $file; 1 }Testing
17 new tests in
t/18-eval-and-require.tcovering: MRO inheritance chains, block eval role loading, deeply namespaced roles (Deep::Role::Example), error messages for missing/invalid modules, inline roles, and multiple inheritance.Full test suite passes.
Closes #22, closes #25
🤖 Generated with Claude Code
Quality Report
Changes: 2 files changed, 148 insertions(+), 2 deletions(-)
Code scan: clean
Tests: passed (OK)
Branch hygiene: clean
Generated by Kōan post-mission quality pipeline