fix: restrict Subs style to package-local subs only#193
Merged
toddr merged 1 commit intocpan-authors:mainfrom Mar 22, 2026
Merged
Conversation
The Subs style used UNIVERSAL::can() to look up handlers, which walks
the inheritance tree. This means XML element names could dispatch to
inherited methods (e.g. a base class's connect() or cleanup()), even
though the documentation says "a sub by that name in the package
specified by the Pkg option".
Replace can() with direct symbol table lookup (defined &{"Pkg::tag"})
so only subs actually defined in the target package are called. This
matches the documented behavior and prevents unintended method dispatch
through UNIVERSAL or parent classes.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
toddr
approved these changes
Mar 22, 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
Restrict the Subs style to only dispatch to subs defined directly in the target package, not inherited methods.
Why
The Subs style used
UNIVERSAL::can()to find handlers, which walks the entire inheritance tree. This means XML element names like<connect/>or<cleanup/>could invoke inherited base class methods — a behavior inconsistent with the documentation ("a sub by that name in the package specified by the Pkg option") and potentially dangerous if the package inherits from a class with side-effectful methods.How
Replaced
$expat->{Pkg}->can($tag)with a direct symbol table check:defined &{"Pkg::$tag"}. This only finds subs actually defined in the package, matching the documented contract. Applied to both Start and End handlers.Testing
t/subs_inherited.twith 4 tests covering:isa,can,VERSION) are not triggeredtag_) also uses direct lookup🤖 Generated with Claude Code