harden(core/options): use package Pod::Simple::Search than legacy Pod::Find (#2775)

This commit is contained in:
qgarnier 2021-05-07 10:33:52 +02:00 committed by GitHub
parent bd06401e7d
commit 0e46dcdfef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 42 additions and 11 deletions

View File

@ -21,7 +21,6 @@
package centreon::plugins::options;
use Pod::Usage;
use Pod::Find qw(pod_where);
use strict;
use warnings;
@ -32,6 +31,7 @@ sub new {
my $self = {};
bless $self, $class;
$self->{pod_where_loaded} = 0;
$self->{sanity} = 0;
$self->{options_stored} = {};
$self->{options} = {};
@ -76,14 +76,16 @@ sub display_help {
my $stdout;
foreach (@{$self->{pod_package}}) {
my $where = $self->pod_where(package => $_->{package});
{
local *STDOUT;
open STDOUT, '>', \$stdout;
my $where = pod_where({-inc => 1}, $_->{package});
pod2usage(-exitval => 'NOEXIT', -input => $where,
-verbose => 99,
-sections => $_->{sections}) if (defined($where));
pod2usage(
-exitval => 'NOEXIT', -input => $where,
-verbose => 99,
-sections => $_->{sections}
) if (defined($where));
}
$self->{output}->add_option_msg(long_msg => $stdout) if (defined($stdout));
@ -151,6 +153,34 @@ sub parse_options {
$SIG{__WARN__} = $save_warn_handler if ($self->{sanity} == 1);
}
sub pod_where {
my ($self, %options) = @_;
if ($self->{pod_where_loaded} == 0) {
$self->{pod_where_loaded} = 1;
my ($code) = centreon::plugins::misc::mymodule_load(
module => 'Pod::Find',
no_quit => 1
);
if ($code) {
$code = centreon::plugins::misc::mymodule_load(
module => 'Pod::Simple::Search',
no_quit => 1
);
die "Cannot load module 'Pod::Simple::Search'" if ($code);
$self->{pod_where_loaded} = 2;
$self->{pod_simple_search} = Pod::Simple::Search->new();
$self->{pod_simple_search}->inc(1);
}
}
if ($self->{pod_where_loaded} == 1) {
return Pod::Find::pod_where({-inc => 1}, $options{package});
}
return $self->{pod_simple_search}->find($options{package});
}
sub get_option {
my ($self, %options) = @_;

View File

@ -25,7 +25,6 @@ use warnings;
use centreon::plugins::output;
use centreon::plugins::misc;
use Pod::Usage;
use Pod::Find qw(pod_where);
my %handlers = (DIE => {}, ALRM => {});
@ -164,7 +163,7 @@ sub display_local_help {
open STDOUT, '>', \$stdout;
if ($alternative_fatpacker == 0) {
pod2usage(-exitval => 'NOEXIT', -input => pod_where({-inc => 1}, __PACKAGE__));
pod2usage(-exitval => 'NOEXIT', -input => $self->{options}->pod_where(package => __PACKAGE__));
} else {
my $pp = __PACKAGE__ . '.pm';
$pp =~ s{::}{/}g;
@ -418,8 +417,10 @@ sub run {
$self->check_relaunch();
(undef, $self->{plugin}) =
centreon::plugins::misc::mymodule_load(output => $self->{output}, module => $self->{plugin},
error_msg => 'Cannot load module --plugin.');
centreon::plugins::misc::mymodule_load(
output => $self->{output}, module => $self->{plugin},
error_msg => 'Cannot load module --plugin.'
);
my $plugin = $self->{plugin}->new(options => $self->{options}, output => $self->{output});
$plugin->init(
help => $self->{help},