Skip to content

fix: use compile-time mro and block eval for safer module loading#34

Draft
Koan-Bot wants to merge 1 commit into
masterfrom
koan.atoomic/fix-eval-and-require
Draft

fix: use compile-time mro and block eval for safer module loading#34
Koan-Bot wants to merge 1 commit into
masterfrom
koan.atoomic/fix-eval-and-require

Conversation

@Koan-Bot

@Koan-Bot Koan-Bot commented Apr 17, 2026

Copy link
Copy Markdown
Collaborator

What

Two targeted fixes: compile-time mro loading and block eval for role require.

Why

Also noting that #24 (guard key collision) and #26 (rollback duplication) are already fixed on master by commits e15434c and 6b8f5d7 respectively.

How

  • Added use mro (); at module top, removed require mro; from _all_attributes()
  • Replaced 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.t covering: 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

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

simplification: string eval used for require where a block eval suffices optimization: require mro called inside hot-path function on every new()

1 participant