From 292daf16743e94e342288b76625733408b5c3fb5 Mon Sep 17 00:00:00 2001 From: John Doe Date: Fri, 2 Jul 2021 19:19:38 +0000 Subject: [PATCH] use Module-Pluggable as Plugin infrastructure https://bugs.koha-community.org/show_bug.cgi?id=28655 --- Koha/Object.pm | 9 +++++++-- Koha/ObjectHooks.pm | 15 +++++++++------ Koha/ObjectHooks/Plugin/FixupCardnumber.pm | 12 ++++++++++++ 3 files changed, 28 insertions(+), 8 deletions(-) create mode 100644 Koha/ObjectHooks/Plugin/FixupCardnumber.pm diff --git a/Koha/Object.pm b/Koha/Object.pm index ad74affcc4..9c2973eeaa 100644 --- a/Koha/Object.pm +++ b/Koha/Object.pm @@ -106,8 +106,13 @@ sub _new_from_dbic { croak( "DBIC result _type " . ref( $self->{_result} ) . " isn't of the _type " . $class->_type() ) unless ref( $self->{_result} ) eq "Koha::Schema::Result::" . $class->_type(); - eval "require Koha::ObjectHooks"; - + use Koha::ObjectHooks; + my $ok = Koha::ObjectHooks->new(); + my @plugins = $ok->plugins(); + foreach my $plugin (@plugins) { + $plugin->run(); + } + bless( $self, $class ); } diff --git a/Koha/ObjectHooks.pm b/Koha/ObjectHooks.pm index 05aa99dcc9..aa905b69de 100644 --- a/Koha/ObjectHooks.pm +++ b/Koha/ObjectHooks.pm @@ -1,10 +1,13 @@ package Koha::ObjectHooks; +use Module::Pluggable search_path => ['Koha::ObjectHooks::Plugin'], + require => 1; -use Hook::LexWrap; - -wrap 'Koha::Patron::fixup_cardnumber', post => - sub { my ( $self ) = @_; - $self->cardnumber( sprintf("LB%07d", $self->cardnumber)); - }; +sub new + { + my $class = shift; + my $self = bless {}, $class; + return $self; + } 1; + diff --git a/Koha/ObjectHooks/Plugin/FixupCardnumber.pm b/Koha/ObjectHooks/Plugin/FixupCardnumber.pm new file mode 100644 index 0000000000..4bf9a66819 --- /dev/null +++ b/Koha/ObjectHooks/Plugin/FixupCardnumber.pm @@ -0,0 +1,12 @@ +package Koha::ObjectHooks::Plugin::FixupCardnumber; + +use Hook::LexWrap; + +sub run { + wrap 'Koha::Patron::fixup_cardnumber', post => + sub { my ( $self ) = @_; + $self->cardnumber( sprintf("LB%07d", $self->cardnumber)); + }; +} + +1; -- 2.20.1