« blib/lib/Perinci/CmdLine/Plugin/Run/Completion.pm
↑ Summary
blib/lib/Perinci/CmdLine/PluginBase.pm »
| 1 | package Perinci::CmdLine::Plugin::Plugin::Disable; | ||||||||||
| 2 | |||||||||||
| 3 | # put pragmas + Log::ger here | ||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 1 | ▶ | use parent 'Perinci::CmdLine::PluginBase'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 1 | ▶ | use Log::ger; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | # put other modules alphabetically here | ||||||||||
| 10 | |||||||||||
| 11 | # put global variables alphabetically here | ||||||||||
| 12 | 1 | our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY | |||||||||
| 13 | 1 | our $DATE = '2023-11-23'; # DATE | |||||||||
| 14 | 1 | our $DIST = 'Perinci-CmdLine-Lite'; # DIST | |||||||||
| 15 | 1 | our $VERSION = '1.929'; # VERSION | |||||||||
| 16 | |||||||||||
| 17 | 0 | ▶ | sub meta { | ||||||||
|
Subroutine
meta: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 18 | return { | ||||||||||
| 19 | 0 | summary => 'Prevent the loading (activation) of other plugins', | |||||||||
| 20 | conf => { | ||||||||||
| 21 | plugins => { | ||||||||||
| 22 | summary => 'List of plugin names or regexes', | ||||||||||
| 23 | description => <<'_', | ||||||||||
| 24 | |||||||||||
| 25 | Plugins should be an array of plugin names or regexes, e.g.: | ||||||||||
| 26 | |||||||||||
| 27 | ['Foo', 'Bar', qr/baz/] | ||||||||||
| 28 | |||||||||||
| 29 | To make it easier to specify via environment variable (PERINCI_CMDLINE_PLUGINS), | ||||||||||
| 30 | a semicolon-separated string is also accepted. A regex should be enclosed in | ||||||||||
| 31 | "/.../". For example: | ||||||||||
| 32 | |||||||||||
| 33 | Foo;Bar;/baz/ | ||||||||||
| 34 | |||||||||||
| 35 | _ | ||||||||||
| 36 | schema => ['any*', of=>[ | ||||||||||
| 37 | 'str*', | ||||||||||
| 38 | ['array*', of=>['any*', of=>['str*', 're*']]], | ||||||||||
| 39 | ]], | ||||||||||
| 40 | req => 1, | ||||||||||
| 41 | }, | ||||||||||
| 42 | }, | ||||||||||
| 43 | tags => ['category:plugin'], | ||||||||||
| 44 | }; | ||||||||||
| 45 | } | ||||||||||
| 46 | |||||||||||
| 47 | 0 | ▶ | sub new { | ||||||||
|
Subroutine
new: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||
| 48 | 0 | my ($class, %args) = (shift, @_); | |||||||||
| 49 | 0 | ▶ | $args{plugins} or die "Please specify plugins to disable"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 50 | 0 | ▶ | unless (ref $args{plugins} eq 'ARRAY') { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 51 | $args{plugins} = | ||||||||||
| 52 | 0 | ▶ | [map { m!\A/(.*)/\z! ? qr/$1/ : $_ } split /;/, $args{plugins}]; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 53 | } | ||||||||||
| 54 | 0 | $class->SUPER::new(%args); | |||||||||
| 55 | } | ||||||||||
| 56 | |||||||||||
| 57 | 0 | ▶ | sub before_activate_plugin { | ||||||||
|
Subroutine
before_activate_plugin: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||
| 58 | 0 | my ($self, $r) = @_; | |||||||||
| 59 | |||||||||||
| 60 | 0 | for my $el (@{ $self->{plugins} }) { | |||||||||
| 61 | 0 | ▶ | if (ref $el eq 'Regexp') { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 62 | 0 | ▶ | next unless $r->{plugin_name} =~ $el; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 63 | } else { | ||||||||||
| 64 | 0 | ▶ | next unless $r->{plugin_name} eq $el; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 65 | } | ||||||||||
| 66 | 0 | log_info "[pericmd Plugin::Disable] Disabling loading of Perinci::CmdLine plugin '$r->{plugin_name}'"; | |||||||||
| 67 | 0 | return [601, "Cancel"]; | |||||||||
| 68 | } | ||||||||||
| 69 | 0 | [200, "OK"]; | |||||||||
| 70 | } | ||||||||||
| 71 | |||||||||||
| 72 | 1 | 1; | |||||||||
| 73 | # ABSTRACT: Prevent the loading (activation) of other plugins | ||||||||||
| 74 | |||||||||||
| 75 | __END__ | ||||||||||