From df994ac3d3d733ffe29062c1c4b76f98cae69c8b Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Wed, 22 Apr 2020 08:27:22 -0400 Subject: [PATCH] Bug 24631: Remove the need to 'require' the plugin path --- Koha/Plugins.pm | 20 ++++++++++++-------- cpanfile | 1 + 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/Koha/Plugins.pm b/Koha/Plugins.pm index 4fc8fb0c47..11e60984d4 100644 --- a/Koha/Plugins.pm +++ b/Koha/Plugins.pm @@ -20,6 +20,7 @@ package Koha::Plugins; use Modern::Perl; use Class::Inspector; +use File::Find::Rule; use List::MoreUtils qw(any); use Module::Load qw(load); use Module::Load::Conditional qw(can_load); @@ -30,9 +31,11 @@ use C4::Context; use C4::Output; use Koha::Plugins::Methods; +our @pluginsdir; + BEGIN { my $pluginsdir = C4::Context->config("pluginsdir"); - my @pluginsdir = ref($pluginsdir) eq 'ARRAY' ? @$pluginsdir : $pluginsdir; + @pluginsdir = ref($pluginsdir) eq 'ARRAY' ? @$pluginsdir : $pluginsdir; push( @INC, @pluginsdir ); pop @INC if $INC[-1] eq '.'; } @@ -128,21 +131,22 @@ sub GetPluginsMetadata { } )->_resultset->get_column('plugin_class'); + my @metafiles = File::Find::Rule->file()->name('META.yml')->in( @pluginsdir ); + my @plugins; while ( my $plugin_class = $plugin_classes->next ) { my $plugin_path = $plugin_class; $plugin_path =~ s/::/\//g; # Take class name, transform :: to / to get path + my $yaml_to_find = "$plugin_path/META.yml"; $plugin_path =~ s/$/.pm/; # Add .pm to the end - require $plugin_path; # Require the plugin to have it's path listed in INC - $plugin_path = - $INC{$plugin_path}; # Get the full true path to the plugin from INC - my $meta_yaml = "$plugin_path/META.yml"; - my $plugin_metadata; + # Find the full path to the file, it's somewhere in the list of metafiles we found when this module as loaded + my ( $meta_yaml ) = grep { $yaml_to_find eq substr( $_, -length($yaml_to_find) ) } @metafiles; - if ( -r $meta_yaml ) { + my $plugin_metadata; + if ( -r $meta_yaml ) { # If the metafile exists and is readable, use it $plugin_metadata = YAML::LoadFile($meta_yaml); - } else { + } else { # Fall back to loading the plugin to get the metadata if there is no META.yml file to read load $plugin_class; my $plugin = $plugin_class->new({ enable_plugins => $self->{'enable_plugins'} diff --git a/cpanfile b/cpanfile index f7d69c3f84..048d8d9620 100644 --- a/cpanfile +++ b/cpanfile @@ -39,6 +39,7 @@ requires 'Email::Date', '1.103'; requires 'Email::MessageID', '1.406'; requires 'Email::Valid', '0.190'; requires 'Exception::Class', '1.38'; +requires 'File::Find::Rule', '0.34'; requires 'File::Slurp', '9999.13'; requires 'Font::TTF', '0.45'; requires 'GD', '2.39'; -- 2.24.2 (Apple Git-127)