From 1bf6a647f43224e8a00c83861c5bc5ee8886d28f Mon Sep 17 00:00:00 2001
From: Mark Hofstetter <mark@hofstetter.at>
Date: Fri, 2 Jul 2021 09:17:04 +0200
Subject: [PATCH] THIS IS NOT A BUGFIX JUST A PROVE OF CONCEPT

just run

t/patron-object-hook.t

and see what happens

to make this work properly something like

https://metacpan.org/pod/Module::Pluggable

should be used to find & include the plugins

Signed-off-by: Mark Hofstetter <mark@hofstetter.at>

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

https://bugs.koha-community.org/show_bug.cgi?id=28655
---
 Koha/Object.pm         |  3 ++-
 Koha/ObjectHooks.pm    | 10 ++++++++++
 t/patron-object-hook.t | 32 ++++++++++++++++++++++++++++++++
 3 files changed, 44 insertions(+), 1 deletion(-)
 create mode 100644 Koha/ObjectHooks.pm
 create mode 100755 t/patron-object-hook.t

diff --git a/Koha/Object.pm b/Koha/Object.pm
index 806d42d1aa..ad74affcc4 100644
--- a/Koha/Object.pm
+++ b/Koha/Object.pm
@@ -106,8 +106,9 @@ 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();
 
-    bless( $self, $class );
+    eval "require Koha::ObjectHooks";
 
+    bless( $self, $class );
 }
 
 =head3 $object->store();
diff --git a/Koha/ObjectHooks.pm b/Koha/ObjectHooks.pm
new file mode 100644
index 0000000000..05aa99dcc9
--- /dev/null
+++ b/Koha/ObjectHooks.pm
@@ -0,0 +1,10 @@
+package Koha::ObjectHooks;
+
+use Hook::LexWrap;
+
+wrap 'Koha::Patron::fixup_cardnumber', post =>
+    sub { my ( $self ) = @_;
+          $self->cardnumber( sprintf("LB%07d",  $self->cardnumber));
+    };
+
+1;
diff --git a/t/patron-object-hook.t b/t/patron-object-hook.t
new file mode 100755
index 0000000000..5c091885d4
--- /dev/null
+++ b/t/patron-object-hook.t
@@ -0,0 +1,32 @@
+#!/usr/bin/perl
+
+# This file is part of Koha.
+#
+# Koha is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# Koha is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Koha; if not, see <http://www.gnu.org/licenses>.
+
+
+use Modern::Perl;
+use Koha::Patrons;
+
+use Test::More tests => 1;
+
+
+my $borrowernumber = 1;
+
+my $patron = Koha::Patrons->find( $borrowernumber );
+
+$patron->fixup_cardnumber();
+
+printf ("%s \n", $patron->cardnumber);
+like($patron->cardnumber, qr/LB\d+/, 'cardnumber is prefixed by LB');
-- 
2.20.1