use std::path::{Path, PathBuf};
use crate::path::module_name_to_path;
use perl_parser_core::path_security::validate_workspace_path;
#[must_use]
pub fn resolve_module_path(
root: &Path,
module_name: &str,
include_paths: &[String],
) -> Option<PathBuf> {
let relative_path = module_name_to_path(module_name);
for base in include_paths {
let base_path = Path::new(base);
let candidate = if base_path.is_absolute() {
base_path.join(&relative_path)
} else if base == "." {
root.join(&relative_path)
} else {
root.join(base).join(&relative_path)
};
if !base_path.is_absolute() && validate_workspace_path(&candidate, root).is_err() {
continue;
}
if candidate.exists() {
return Some(candidate);
}
}
Some(root.join("lib").join(relative_path))
}