Bug 16699: Remove requirement from borrowernumberQueryParam
[koha.git] / Koha / Plugins.pm
bloba188d7c815a44e4bd9a26efcdc0709aa24f1e62f
1 package Koha::Plugins;
3 # Copyright 2012 Kyle Hall
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
20 use Modern::Perl;
22 use Module::Load::Conditional qw(can_load);
23 use Module::Pluggable search_path => ['Koha::Plugin'], except => qr/::Edifact(|::Line|::Message|::Order|::Segment|::Transport)$/;
25 use C4::Context;
26 use C4::Output;
28 BEGIN {
29 push @INC, C4::Context->config("pluginsdir");
30 pop @INC if $INC[-1] eq '.';
33 =head1 NAME
35 Koha::Plugins - Module for loading and managing plugins.
37 =cut
39 sub new {
40 my ( $class, $args ) = @_;
42 return unless ( C4::Context->config("enable_plugins") || $args->{'enable_plugins'} );
44 $args->{'pluginsdir'} = C4::Context->config("pluginsdir");
46 return bless( $args, $class );
49 =head2 GetPlugins()
51 This will return a list of all the available plugins of the passed type.
53 Usage: my @plugins = C4::Plugins::GetPlugins( $method );
55 At the moment, the available types are 'report', 'tool' and 'to_marc'.
56 =cut
58 sub GetPlugins {
59 my $self = shift;
60 my $method = shift;
62 my @plugin_classes = $self->plugins();
63 my @plugins;
65 foreach my $plugin_class (@plugin_classes) {
66 if ( can_load( modules => { $plugin_class => undef } ) ) {
67 next unless $plugin_class->isa('Koha::Plugins::Base');
69 my $plugin = $plugin_class->new({ enable_plugins => $self->{'enable_plugins'} });
71 if ($method) {
72 if ( $plugin->can($method) ) {
73 push( @plugins, $plugin );
75 } else {
76 push( @plugins, $plugin );
80 return @plugins;
84 __END__
86 =head1 AUTHOR
88 Kyle M Hall <kyle.m.hall@gmail.com>
90 =cut