Skip to main content

parse_module_import_head

Function parse_module_import_head 

Source
pub fn parse_module_import_head(line: &str) -> Option<ModuleImportHead<'_>>
Expand description

Parse the leading import token of a single Perl source line.

Returns None when the line does not start with use or require (after leading whitespace) or when no token is present after the keyword.

For require "file.pm" and require 'file.pm' forms, the surrounding quotes are stripped and the inner path is returned as token.

ยงExamples

use perl_module_import::{ModuleImportKind, parse_module_import_head};

let parsed = parse_module_import_head("use Foo::Bar;");
assert_eq!(parsed.map(|head| head.kind), Some(ModuleImportKind::Use));
assert_eq!(parsed.map(|head| head.token), Some("Foo::Bar"));

let parsed = parse_module_import_head("use parent 'Foo::Bar';");
assert_eq!(parsed.map(|head| head.kind), Some(ModuleImportKind::UseParent));
assert_eq!(parsed.map(|head| head.token), Some("parent"));