diff --git a/docs/config/README.md b/docs/config/README.md index 7104d1d57..05ad449f8 100644 --- a/docs/config/README.md +++ b/docs/config/README.md @@ -1966,7 +1966,7 @@ format = "via [🎁 $version](208 bold) " ## Perl The `perl` module shows the currently installed version of Perl. -The module will be shown if any of the following conditions are met: +By default the module will be shown if any of the following conditions are met: - The current directory contains a `Makefile.PL` or `Build.PL` file - The current directory contains a `cpanfile` or `cpanfile.snapshot` file @@ -1976,12 +1976,15 @@ The module will be shown if any of the following conditions are met: ### Options -| Option | Default | Description | -| ---------- | ------------------------------------ | ----------------------------------------------------- | -| `format` | `"via [$symbol($version )]($style)"` | The format string for the module. | -| `symbol` | `"🐪 "` | The symbol used before displaying the version of Perl | -| `style` | `"bold 149"` | The style for the module. | -| `disabled` | `false` | Disables the `perl` module. | +| Option | Default | Description | +| -------------------- | ------------------------------------ | ----------------------------------------------------- | +| `format` | `"via [$symbol($version )]($style)"` | The format string for the module. | +| `symbol` | `"🐪 "` | The symbol used before displaying the version of Perl | +| `detect_extensions` | `["pl", "pm", "pod"]` | Which extensions should trigger this moudle. | +| `detect_files` | `["Makefile.PL", "Build.PL", "cpanfile", "cpanfile.snapshot", "META.json", "META.yml", ".perl-version"]` | Which filenames should trigger this module. | +| `detect_folders` | `[]` | Which folders should trigger this module. | +| `style` | `"bold 149"` | The style for the module. | +| `disabled` | `false` | Disables the `perl` module. | ### Variables diff --git a/src/configs/perl.rs b/src/configs/perl.rs index cd86461e7..b670afdf9 100644 --- a/src/configs/perl.rs +++ b/src/configs/perl.rs @@ -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![], } } } diff --git a/src/modules/perl.rs b/src/modules/perl.rs index a307e287c..735860fca 100644 --- a/src/modules/perl.rs +++ b/src/modules/perl.rs @@ -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> { + 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 {