Bug 18179: Forbid list context calls for Koha::Objects->find
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Tue, 18 Apr 2017 16:49:18 +0000 (13:49 -0300)
committerKyle M Hall <kyle@bywatersolutions.com>
Fri, 28 Apr 2017 10:48:30 +0000 (06:48 -0400)
commita1fcf1818c8d9f23d9c870e93c41c67a27faf603
tree65106989d3afdd68c8ae7be3c75688e9f9993c32
parent21bddb399d7f88a33c6dff474d07190a09e627dc
Bug 18179: Forbid list context calls for Koha::Objects->find

Reading https://perlmaven.com/how-to-return-undef-from-a-function
this sound like the more correct behaviour.

Considering:
$template->param(
    stuff => Koha::Stuffs->find( $id ),
    foo   => 1,
);
without this patch, if the $id does not represent any rows in the DB,
stuff will be assigned to 'foo' and $foo will be undef in the template.
That can lead to very bad side-effects.

With this patch we make sure that it will never happen again.

Test plan:
  prove t/db_dependent/Koha/Objects.t
should return green

Signed-off-by: Marc VĂ©ron <veron@veron.ch>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Koha/Objects.pm
t/db_dependent/Koha/Objects.t