Bug 25296: Make ->empty work for uninstantiated calls

In OO we would usually instantiate the class and then interact with it
like in:
    my $rs = Koha::Patrons->new;
    $rs->empty;

Koha's practice is to call things like Koha::Patrons->search without
instantiating the Koha::Patrons class. To keep consistency, this patch
instantiates the resultset object on behalf of the caller if required.

To test:
1. Apply the tests patch
2. Run:
   $ kshell
  $k prove t/db_dependent/Koha/Objects.t
=> FAIL: Tests fail because it is expected to have the class
instantiated
3. Apply this patch
4. Repeat 2.
=> SUCCESS: Tests pass, instantiation happens implicitly.
5. Sign off :-D

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
This commit is contained in:
Tomas Cohen Arazi 2020-04-29 09:28:04 -03:00 committed by Martin Renvoize
parent 7acc063709
commit 4805b9b9dd
No known key found for this signature in database
GPG Key ID: 422B469130441A0F
1 changed files with 4 additions and 0 deletions

View File

@ -250,6 +250,10 @@ an iterator).
sub empty {
my ($self) = @_;
unless (ref($self)) {
$self = $self->new;
}
$self->_resultset()->set_cache([]);
return $self;