pub fn current_package_at(ast: &Node, offset: usize) -> &strExpand description
Determines the current package context at the given offset.
Scans the AST backwards from the offset to find the most recent package declaration, providing proper context for symbol resolution in Perl’s package-based namespace system.
§Arguments
ast- Root AST node to search withinoffset- Byte offset in the source document
§Returns
Package name as string slice, defaults to “main” if no package found
§Performance
- Search time: O(n) worst case, O(log n) typical
- Memory: Returns borrowed string slice (zero-copy)
- Caching: Results suitable for per-request caching
§Perl Parsing Context
Perl package semantics:
package Foo;declarations change current namespace- Scope continues until next package declaration or EOF
- Default package is “main” when no explicit declaration
- Package names follow Perl identifier rules (
::-separated)
§Examples
ⓘ
use perl_parser::declaration::current_package_at;
use perl_parser::ast::Node;
let ast = Node::new_root();
let pkg = current_package_at(&ast, 100);
println!("Current package: {}", pkg);