perf(perl): Lazy eval perl (#2189)

* perf(perl): evaluate version lazily

* fix(perl): update format string; update tests

* refact(perl): run rustfmt

Co-authored-by: Moritz Vetter <mv@3yourmind.com>
This commit is contained in:
Moritz Vetter 2021-01-22 18:07:03 +01:00 committed by GitHub
parent d10a83ce6b
commit 16b8cbfdb8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 30 deletions

View File

@ -1930,8 +1930,8 @@ 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. |
| ---------- | ------------------------------------ | ----------------------------------------------------- |
| `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. |

View File

@ -15,7 +15,7 @@ impl<'a> RootModuleConfig<'a> for PerlConfig<'a> {
PerlConfig {
symbol: "🐪 ",
style: "149 bold",
format: "via [$symbol$version]($style) ",
format: "via [$symbol($version )]($style)",
disabled: false,
}
}

View File

@ -29,8 +29,6 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
return None;
}
let perl_version = utils::exec_cmd("perl", &["-e", "printf q#%vd#,$^V;"])?.stdout;
let mut module = context.new_module("perl");
let config: PerlConfig = PerlConfig::try_load(module.config);
@ -45,7 +43,11 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
_ => None,
})
.map(|variable| match variable {
"version" => Some(Ok(format!("v{}", &perl_version))),
"version" => {
let perl_version =
utils::exec_cmd("perl", &["-e", "printf q#%vd#,$^V;"])?.stdout;
Some(Ok(format!("v{}", perl_version)))
}
_ => None,
})
.parse(None)