feat(perl): Configure when the module is shown (#2355)

This makes it possible to configure when the perl module is shown
based on the contents of a directory. This should make it possible to
be a lot more granular when configuring the module.
This commit is contained in:
Shu Kutsuzawa
2021-02-22 03:51:36 +09:00
committed by GitHub
parent e73581ddf0
commit 51f752f6b0
3 changed files with 29 additions and 25 deletions
+14
View File
@@ -8,6 +8,9 @@ pub struct PerlConfig<'a> {
pub style: &'a str,
pub format: &'a str,
pub disabled: bool,
pub detect_extensions: Vec<&'a str>,
pub detect_files: Vec<&'a str>,
pub detect_folders: Vec<&'a str>,
}
impl<'a> RootModuleConfig<'a> for PerlConfig<'a> {
@@ -17,6 +20,17 @@ impl<'a> RootModuleConfig<'a> for PerlConfig<'a> {
style: "149 bold",
format: "via [$symbol($version )]($style)",
disabled: false,
detect_extensions: vec!["pl", "pm", "pod"],
detect_files: vec![
"Makefile.PL",
"Build.PL",
"cpanfile",
"cpanfile.snapshot",
"META.json",
"META.yml",
".perl-version",
],
detect_folders: vec![],
}
}
}
+5 -18
View File
@@ -4,33 +4,20 @@ use crate::configs::perl::PerlConfig;
use crate::formatter::StringFormatter;
/// Creates a module with the current perl version
///
/// Will display the perl version if any of the following criteria are met:
/// - Current directory contains a `.pl`, `.pm` or a `.pod` file
/// - Current directory contains a "Makefile.PL", "Build.PL", "cpanfile", "cpanfile.snapshot",
/// "META.json", "META.yml", or ".perl-version" file
pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
let mut module = context.new_module("perl");
let config: PerlConfig = PerlConfig::try_load(module.config);
let is_perl_project = context
.try_begin_scan()?
.set_files(&[
"Makefile.PL",
"Build.PL",
"cpanfile",
"cpanfile.snapshot",
"META.json",
"META.yml",
".perl-version",
])
.set_extensions(&["pl", "pm", "pod"])
.set_extensions(&config.detect_extensions)
.set_files(&config.detect_files)
.set_folders(&config.detect_folders)
.is_match();
if !is_perl_project {
return None;
}
let mut module = context.new_module("perl");
let config: PerlConfig = PerlConfig::try_load(module.config);
let parsed = StringFormatter::new(config.format).and_then(|formatter| {
formatter
.map_meta(|var, _| match var {