From 4e85fff22acb11ebda31bf76f557fc80e21fc0d2 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Thu, 25 Mar 2021 17:48:28 +0000 Subject: [PATCH] Bug 28031: (follow-up) Cache type instead of passing We should cache the 'type' instead of passing it around. That way we're not changing the signature further for external users of the methods. Signed-off-by: Kyle M Hall --- Koha/Patron/Attribute.pm | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/Koha/Patron/Attribute.pm b/Koha/Patron/Attribute.pm index f0777a6520..1ee4d010e7 100644 --- a/Koha/Patron/Attribute.pm +++ b/Koha/Patron/Attribute.pm @@ -52,10 +52,10 @@ sub store { unless $type; Koha::Exceptions::Patron::Attribute::NonRepeatable->throw( attribute => $self ) - unless $self->repeatable_ok($type); + unless $self->repeatable_ok; Koha::Exceptions::Patron::Attribute::UniqueIDConstraint->throw( attribute => $self ) - unless $self->unique_ok($type); + unless $self->unique_ok; return $self->SUPER::store(); } @@ -72,7 +72,9 @@ sub type { my $self = shift; - return scalar Koha::Patron::Attribute::Types->find( $self->code ); + $self->{_type} ||= Koha::Patron::Attribute::Types->find( $self->code ); + + return $self->{_type}; } =head3 authorised_value @@ -145,7 +147,11 @@ whether storing the current object state would break the repeatable constraint. sub repeatable_ok { - my ( $self, $type ) = @_; + my ( $self ) = @_; + + my $type = $self->type; + Koha::Exceptions::Patron::Attribute::InvalidType->throw( type => $self->code ) + unless $type; my $ok = 1; if ( !$type->repeatable ) { @@ -172,7 +178,11 @@ whether storing the current object state would break the unique constraint. sub unique_ok { - my ( $self, $type ) = @_; + my ( $self ) = @_; + + my $type = $self->type; + Koha::Exceptions::Patron::Attribute::InvalidType->throw( type => $self->code ) + unless $type; my $ok = 1; if ( $type->unique_id ) { -- 2.24.1 (Apple Git-126)