|
Lines 45-62
sub new {
Link Here
|
| 45 |
return bless( $args, $class ); |
45 |
return bless( $args, $class ); |
| 46 |
} |
46 |
} |
| 47 |
|
47 |
|
| 48 |
=head2 GetPlugins() |
48 |
=head2 GetPlugins |
| 49 |
|
49 |
|
| 50 |
This will return a list of all the available plugins of the passed type. |
50 |
This will return a list of all available plugins, optionally limited by |
|
|
51 |
method or metadata value. |
| 51 |
|
52 |
|
| 52 |
Usage: my @plugins = C4::Plugins::GetPlugins( $method ); |
53 |
my @plugins = C4::Plugins::GetPlugins({ |
|
|
54 |
method => 'some_method', |
| 55 |
metadata => { some_key => 'some_value' }, |
| 56 |
}); |
| 57 |
|
| 58 |
The method and metadata parameters are optional. |
| 59 |
Available methods currently are: 'report', 'tool', 'to_marc', 'edifact'. |
| 60 |
If you pass multiple keys in the metadata hash, all keys must match. |
| 53 |
|
61 |
|
| 54 |
At the moment, the available types are 'report', 'tool' and 'to_marc'. |
|
|
| 55 |
=cut |
62 |
=cut |
| 56 |
|
63 |
|
| 57 |
sub GetPlugins { |
64 |
sub GetPlugins { |
| 58 |
my $self = shift; |
65 |
my ( $self, $params ) = @_; |
| 59 |
my $method = shift; |
66 |
my $method = $params->{method}; |
|
|
67 |
my $req_metadata = $params->{metadata} // {}; |
| 60 |
|
68 |
|
| 61 |
my @plugin_classes = $self->plugins(); |
69 |
my @plugin_classes = $self->plugins(); |
| 62 |
my @plugins; |
70 |
my @plugins; |
|
Lines 67-79
sub GetPlugins {
Link Here
|
| 67 |
|
75 |
|
| 68 |
my $plugin = $plugin_class->new({ enable_plugins => $self->{'enable_plugins'} }); |
76 |
my $plugin = $plugin_class->new({ enable_plugins => $self->{'enable_plugins'} }); |
| 69 |
|
77 |
|
| 70 |
if ($method) { |
78 |
# Limit results by method or metadata |
| 71 |
if ( $plugin->can($method) ) { |
79 |
my $ok = 1; |
| 72 |
push( @plugins, $plugin ); |
80 |
next if $method && !$plugin->can($method); |
|
|
81 |
my $plugin_metadata = $plugin->get_metadata; |
| 82 |
foreach my $key ( keys %$req_metadata ) { |
| 83 |
if( !$plugin_metadata->{$key} || |
| 84 |
$plugin_metadata->{$key} ne $req_metadata->{$key} ) { |
| 85 |
$ok = 0; |
| 86 |
last; |
| 73 |
} |
87 |
} |
| 74 |
} else { |
|
|
| 75 |
push( @plugins, $plugin ); |
| 76 |
} |
88 |
} |
|
|
89 |
push( @plugins, $plugin ) if $ok; |
| 77 |
} |
90 |
} |
| 78 |
} |
91 |
} |
| 79 |
return @plugins; |
92 |
return @plugins; |