Fix namespace::clean stub missing get_functions and clean_subroutines#183
Open
dwright wants to merge 1 commit intobscan:mainfrom
Open
Fix namespace::clean stub missing get_functions and clean_subroutines#183dwright wants to merge 1 commit intobscan:mainfrom
dwright wants to merge 1 commit intobscan:mainfrom
Conversation
The namespace::clean stub only provided import() and VERSION, but not get_functions() or clean_subroutines(). Any module that calls namespace::clean->get_functions($package) at file scope (not inside a BEGIN block) would fail with: Can't locate object method "get_functions" via package "namespace::clean" This causes a cascade of BEGIN failed errors through the dependency chain, surfacing as dozens of false Syntax diagnostics in the editor. Fix: add a get_functions stub that reads CODE symbols from the package stash directly, matching the real implementation's return value, and a no-op clean_subroutines stub.
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.
Inquisitor.pm stubs out namespace::clean to prevent it from wiping the symbol table before inspection:
However, the stub only provides import and VERSION. Any module that calls
namespace::clean->get_functions($package)ornamespace::clean->clean_subroutines(...)as a class method at file scope — not inside a BEGIN block — will fail with:This causes a cascade of BEGIN failed errors through the dependency chain, which perlnavigator surfaces as dozens of false Syntax error diagnostics in the editor — one per line of the stack trace — all pointing to line 1 of the file being checked.
Root Cause
The call to
namespace::clean->get_functions(...)at file scope is valid Perl and works at runtime, because namespace::clean loads normally. But under -MInquisitor, the real namespace::clean is blocked from loading, and the stub doesn't provide aget_functionsmethod.Fix
Add a working
get_functionsstub that reads CODE symbols from the package stash directly — matching the real implementation's return value — and a no-opclean_subroutinesstub:*{'namespace::clean::get_functions'} = sub { my ($pragma, $class) = @_; no strict 'refs'; return { map { $_ => \&{"${class}::${_}"} } grep { defined &{"${class}::${_}"} } keys %{"${class}::"} }; }; *{'namespace::clean::clean_subroutines'} = sub { };The
clean_subroutinesstub is a safe no-op since symbol table cleanup is intentionally skipped during inspection anyway.Tests
Added t/02_NamespaceClean.t with a regression test and testWorkspace/MyLib/NamespaceCleanCaller.pm as a fixture that calls
namespace::clean->get_functions(__PACKAGE__)at file scope. All 6 tests pass.