Bug 13320: Move price calculation from tt to pl
[koha.git] / Koha / Plugins.pm
blob3b31fc5bd9dc97569f036caa690a990a8ec3a7ce
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 under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
10 # version.
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 use Modern::Perl;
22 use Module::Load::Conditional qw(can_load);
23 use Module::Pluggable search_path => ['Koha::Plugin'];
25 use C4::Context;
26 use C4::Output;
28 BEGIN {
29 push @INC, C4::Context->config("pluginsdir");
32 =head1 NAME
34 Koha::Plugins - Module for loading and managing plugins.
36 =cut
38 sub new {
39 my ( $class, $args ) = @_;
41 return unless ( C4::Context->config("enable_plugins") || $args->{'enable_plugins'} );
43 $args->{'pluginsdir'} = C4::Context->config("pluginsdir");
45 return bless( $args, $class );
48 =head2 GetPlugins()
50 This will return a list of all the available plugins of the passed type.
52 Usage: my @plugins = C4::Plugins::GetPlugins( $method );
54 At the moment, the available types are 'report' and 'tool'.
55 =cut
57 sub GetPlugins {
58 my $self = shift;
59 my $method = shift;
61 my @plugin_classes = $self->plugins();
62 my @plugins;
64 foreach my $plugin_class (@plugin_classes) {
65 if ( can_load( modules => { $plugin_class => undef } ) ) {
66 my $plugin = $plugin_class->new({ enable_plugins => $self->{'enable_plugins'} });
68 if ($method) {
69 if ( $plugin->can($method) ) {
70 push( @plugins, $plugin );
72 } else {
73 push( @plugins, $plugin );
77 return @plugins;
81 __END__
83 =head1 AUTHOR
85 Kyle M Hall <kyle.m.hall@gmail.com>
87 =cut