From 3b5f5a74a4278f5ba7ffc0f2f2bed451b92b5b1e Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Fri, 27 May 2022 10:27:03 -0400 Subject: [PATCH] Bug 30861: Add Koha::Object::stash --- Koha/Object.pm | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/Koha/Object.pm b/Koha/Object.pm index ef554d5e56..b314fbdda2 100644 --- a/Koha/Object.pm +++ b/Koha/Object.pm @@ -379,6 +379,33 @@ sub add_message { return $self; } +=head3 $object->stash + +Add the ability to stash things in an object + +$object->stash({ key => $value }); +$object->stash({ key1 => $value1, key2 => $value2 }); + +my $value = $object->stash($key); + +my $stash = $object->stash; + +=cut + +sub stash { + my ( $self, $params ) = @_; + + if ( !$params ) { + return $self->{_stash}; + } + elsif ( ref $params eq 'HASH' ) { + $self->{_stash}->{$_} = $params->{$_} for keys %$params; + } + else { + return $self->{_stash}->{$params}; + } +} + =head3 $object->TO_JSON Returns an unblessed representation of the object, suitable for JSON output. -- 2.32.0 (Apple Git-132)