[Koha-bugs] [Bug 19605] ILL backends should be pluggable through regular Koha plugins

bugzilla-daemon at bugs.koha-community.org bugzilla-daemon at bugs.koha-community.org
Mon Feb 12 18:47:23 CET 2024


https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19605

--- Comment #15 from Tomás Cohen Arazi <tomascohen at gmail.com> ---
I been looking at the PluginBackend implementation, and got a bit confused
about this:

sub new_backend {
    my ( $class, $params ) = @_;

    my $self = {};

    $self->{_logger} = $params->{logger} if ( $params->{logger} );
    $self->{_config} = $params->{config} if ( $params->{config} );

    bless( $self, $class );

    return $self;
}


It seems to me that in this particular implementation, as we already have a
plugin instance in this context:

+    my $backend_plugin = $self->get_backend_plugin($backend_name);
+    if ($backend_plugin) {
+
+        # New way of loading backends: Through plugins
+        my $backend_plugin_class = $backend_plugin->{class};
+
+        $self->{_my_backend} = $backend_plugin_class->new_backend(

it doesn't make sense to instantiate the plugin again. Thus, the PluginBackend
implementation could just be:

sub new_backend {
    my ($self,$params) = @_;

    $self->{_logger} = $params->{logger} if ( $params->{logger} );
    $self->{_config} = $params->{config} if ( $params->{config} );

    return $self;
}

I would rather rename the method to `get_ill_backend`, and leave the plugin
authors the decision on what to return (the name change is a matter of taste,
but I think `ill` needs to be part of the method name).

In my case, I would love to be able to (say) have my own class for the backend,
so  my implementation would be written like this:

sub get_ill_backend {
    my ($self,$params) = @_;

    require INNReach::ILL::Backend;

    return INNReach::ILL::Backend->new({
        plugin => $self,
        logger => $params->{logger}
    });
}

-- 
You are receiving this mail because:
You are watching all bug changes.


More information about the Koha-bugs mailing list