From c3843b6756eef8581dac8b06516d0521276a8373 Mon Sep 17 00:00:00 2001 From: Pedro Amorim Date: Fri, 19 Jul 2024 15:49:18 +0000 Subject: [PATCH] Bug 37389: Move AUTOLOAD out of ILL::Request into Mixin This AUTOLOAD is not being used, but we're keeping this as also being a result of this work if we ever want to support the following syntax in the code: ill_request->extended_attributes_author; # and get the 'author' extended_attribute for the ill_request --- Koha/ILL/Request.pm | 31 ------------ Koha/Object/Mixin/ExtendedAttributes.pm | 64 +++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 31 deletions(-) create mode 100644 Koha/Object/Mixin/ExtendedAttributes.pm diff --git a/Koha/ILL/Request.pm b/Koha/ILL/Request.pm index d8b669fe95..9f6d8bdeba 100644 --- a/Koha/ILL/Request.pm +++ b/Koha/ILL/Request.pm @@ -2220,37 +2220,6 @@ sub get_staff_table_actions { return $ill_table_actions; } -=head3 AUTOLOAD - -=cut - -our $AUTOLOAD; - -sub AUTOLOAD { - my ($self) = @_; - - my $name = $AUTOLOAD; - $name =~ s/.*:://; # Remove package name - - if ( $name =~ /^extended_attributes_(\w+)$/ ) { - my $type = $1; - - # Define the method dynamically - no strict 'refs'; - *{$AUTOLOAD} = sub { - my ($self) = @_; - my $relation = 'extended_attributes_' . $type; - my $rs = $self->_result->$relation; - return Koha::ILL::Request::Attributes->_new_from_dbic($rs)->search; - }; - - # Call the newly defined method - return $self->$name(); - } - my $wt = 'SUPER::'.$name; - return $self->$wt; -} - sub get_column(){ my ($self, $column_name) = @_; return $self->_result->get_column($column_name); diff --git a/Koha/Object/Mixin/ExtendedAttributes.pm b/Koha/Object/Mixin/ExtendedAttributes.pm new file mode 100644 index 0000000000..bb32429055 --- /dev/null +++ b/Koha/Object/Mixin/ExtendedAttributes.pm @@ -0,0 +1,64 @@ +package Koha::Object::Mixin::ExtendedAttributes; + +# Copyright 2024 PTFS Europe Ltd +# +# 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 . + +use Modern::Perl; + +=head1 NAME + +Koha::Object::Mixin::ExtendedAttributes + +=head2 Class methods + + +=head3 AUTOLOAD + +=cut + +our $AUTOLOAD; + +# This class is not yet utilized, but we'll need it if we ever want to support this sort of syntax: +# ill_request->extended_attributes_author; and get the 'author' extended_attributes from the ill_request +# TODO: This needs to be abstracted in the future, currently only considering ILL + +sub AUTOLOAD { + my ($self) = @_; + + my $name = $AUTOLOAD; + $name =~ s/.*:://; # Remove package name + + if ( $name =~ /^extended_attributes_(\w+)$/ ) { + my $type = $1; + + # Define the method dynamically + no strict 'refs'; + *{$AUTOLOAD} = sub { + my ($self) = @_; + my $relation = 'extended_attributes_' . $type; + my $rs = $self->_result->$relation; + return Koha::ILL::Request::Attributes->_new_from_dbic($rs)->search; + }; + + # Call the newly defined method + return $self->$name(); + } + my $wt = 'SUPER::' . $name; + return $self->$wt; +} + +1; \ No newline at end of file -- 2.34.1