@@ -, +, @@ --- 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 --- a/Koha/Object.pm +++ a/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 ); } --- a/Koha/ObjectHooks.pm +++ a/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; + --- a/Koha/ObjectHooks/Plugin/FixupCardnumber.pm +++ a/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; --