|
Line 0
Link Here
|
| 0 |
- |
1 |
package Koha::Object::Mixin::ExtendedAttributes; |
|
|
2 |
|
| 3 |
# Copyright 2024 PTFS Europe Ltd |
| 4 |
# |
| 5 |
# This file is part of Koha. |
| 6 |
# |
| 7 |
# Koha is free software; you can redistribute it and/or modify it |
| 8 |
# under the terms of the GNU General Public License as published by |
| 9 |
# the Free Software Foundation; either version 3 of the License, or |
| 10 |
# (at your option) any later version. |
| 11 |
# |
| 12 |
# Koha is distributed in the hope that it will be useful, but |
| 13 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
# GNU General Public License for more details. |
| 16 |
# |
| 17 |
# You should have received a copy of the GNU General Public License |
| 18 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
| 19 |
|
| 20 |
use Modern::Perl; |
| 21 |
|
| 22 |
=head1 NAME |
| 23 |
|
| 24 |
Koha::Object::Mixin::ExtendedAttributes |
| 25 |
|
| 26 |
=head2 Class methods |
| 27 |
|
| 28 |
|
| 29 |
=head3 AUTOLOAD |
| 30 |
|
| 31 |
=cut |
| 32 |
|
| 33 |
our $AUTOLOAD; |
| 34 |
|
| 35 |
# This class is not yet utilized, but we'll need it if we ever want to support this sort of syntax: |
| 36 |
# ill_request->extended_attributes_author; and get the 'author' extended_attributes from the ill_request |
| 37 |
# TODO: This needs to be abstracted in the future, currently only considering ILL |
| 38 |
|
| 39 |
sub AUTOLOAD { |
| 40 |
my ($self) = @_; |
| 41 |
|
| 42 |
my $name = $AUTOLOAD; |
| 43 |
$name =~ s/.*:://; # Remove package name |
| 44 |
|
| 45 |
if ( $name =~ /^extended_attributes_(\w+)$/ ) { |
| 46 |
my $type = $1; |
| 47 |
|
| 48 |
# Define the method dynamically |
| 49 |
no strict 'refs'; |
| 50 |
*{$AUTOLOAD} = sub { |
| 51 |
my ($self) = @_; |
| 52 |
my $relation = 'extended_attributes_' . $type; |
| 53 |
my $rs = $self->_result->$relation; |
| 54 |
return Koha::ILL::Request::Attributes->_new_from_dbic($rs)->search; |
| 55 |
}; |
| 56 |
|
| 57 |
# Call the newly defined method |
| 58 |
return $self->$name(); |
| 59 |
} |
| 60 |
my $wt = 'SUPER::' . $name; |
| 61 |
return $self->$wt; |
| 62 |
} |
| 63 |
|
| 64 |
1; |