Bugzilla – Attachment 173901 Details for
Bug 30657
Make patron attributes available via Template Toolkit in notices
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 30657: Move to AUTOLOAD
Bug-30657-Move-to-AUTOLOAD.patch (text/plain), 2.76 KB, created by
Martin Renvoize (ashimema)
on 2024-11-04 07:48:43 UTC
(
hide
)
Description:
Bug 30657: Move to AUTOLOAD
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2024-11-04 07:48:43 UTC
Size:
2.76 KB
patch
obsolete
>From 03a6299985bd0ada69f7294e9e7f5242193f70eb Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@ptfs-europe.com> >Date: Thu, 31 Oct 2024 16:34:01 +0000 >Subject: [PATCH] Bug 30657: Move to AUTOLOAD > >--- > Koha/Patron.pm | 57 +++++++++++++++++++++++++++----------------------- > 1 file changed, 31 insertions(+), 26 deletions(-) > >diff --git a/Koha/Patron.pm b/Koha/Patron.pm >index 9072a7b186c..3e56e8911da 100644 >--- a/Koha/Patron.pm >+++ b/Koha/Patron.pm >@@ -108,43 +108,35 @@ Koha::Patron - Koha Patron Object class > > =head2 Class Methods > >-=head3 new, _new_from_dbic, _add_dynamic_methods >+=head3 new > >-These methods are used internally. They dynamically add accessors to Koha::Patron objects resulting from >-calls to ->new, ->find and ->search for any defined extended patron attributes. Said accessors will be named >-after the 'code' of the attribute type and will return either the single value or an array of values for >-attribute types that are repeatable. >+Our methods below include an AUTOLOAD that will dynamically create accessor methods for any >+defined extended patron attributes. > >-=cut >- >-sub new { >- my ( $class, $params ) = @_; >- >- my $self = $class->next::method($params); >- >- $self->_add_dynamic_methods; >+Said accessors will be named after the 'code' of the attribute type and will return either >+the single value or an array of values for attribute types that are repeatable. > >- return $self; >-} >- >-sub _new_from_dbic { >- my $self = shift; >- my ( $source, $data, $prefetch ) = @_; >- >- my $obj = $self->next::method(@_); >+=cut > >- $obj->_add_dynamic_methods; >+our $AUTOLOAD; > >- return $obj; >-} >+# This autoload generates a method for each extended attribute type defined in the system upon the first call >+# for a method matching an attribute type name. >+# >+# TODO: This could be abstracted in the future as a Mixin for extended_attribute, ill_attributes and additional_fields > >-sub _add_dynamic_methods { >- my $self = shift; >+sub AUTOLOAD { >+ my @args = @_; >+ my $self = shift(@args); >+ my $name = $AUTOLOAD; >+ $name =~ s/.*:://; # Remove package name >+ my $found = 0; > > # Fetch attributes dynamically > my $attribute_types = Koha::Patron::Attribute::Types->search(); > while ( my $attr = $attribute_types->next ) { > my $code = $attr->code; >+ $found = 1 if ( $code eq $name ); > > # Dynamically create accessor method > no strict 'refs'; >@@ -170,6 +162,19 @@ sub _add_dynamic_methods { > } > } > } >+ >+ if ($found) { >+ return $self->$name(); >+ } else { >+ my $wt = 'SUPER::' . $name; >+ return $self->$wt(@args); >+ } >+} >+ >+sub new { >+ my ( $class, $params ) = @_; >+ >+ return $class->SUPER::new($params); > } > > =head3 fixup_cardnumber >-- >2.47.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 30657
:
169049
|
169050
|
169056
|
169057
|
173817
|
173818
|
173819
|
173901
|
173902
|
173910
|
173911
|
173912
|
173913
|
173914