From f4de351e41495f4820ef974f3e278370681fe7ff 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. --- 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 a8dcd64b92..70103769e3 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.20.1