pub fn file_path_to_module_name(file_path: &str) -> StringExpand description
Convert a filesystem source path into a likely module name.
This is intended for file-rename workflows where a concrete source path needs to map back to the module import name. It follows these rules:
- Strip
.pmor.plsuffix - If a
lib/segment exists, use everything after the lastlib/ - Otherwise, fall back to the file stem
ยงExamples
use perl_module_path::file_path_to_module_name;
assert_eq!(file_path_to_module_name("/workspace/lib/Foo/Bar.pm"), "Foo::Bar");
assert_eq!(file_path_to_module_name("/workspace/script.pl"), "script");
assert_eq!(file_path_to_module_name(r"C:\workspace\lib\Foo\Bar.pm"), "Foo::Bar");