[Koha-bugs] [Bug 19809] Koha::Objects::find calls do not need to be forbidden in list context
bugzilla-daemon at bugs.koha-community.org
bugzilla-daemon at bugs.koha-community.org
Fri Jun 8 09:55:47 CEST 2018
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19809
--- Comment #5 from Julian Maurice <julian.maurice at biblibre.com> ---
(In reply to Marcel de Rooy from comment #4)
> My first feeling is that if we allow list context, we should return an empty
> list instead of undef. It would fix your if( @a ) test since @a==0.
This doesn't need to be fixed. Empty list and undef both evaluate to a false
value in this context.
> But what would pop up again? Constructions like the one in Objects.t:
> my $patrons = {
> foo => Koha::Patrons->find('foo'),
> bar => 'baz',
> };
> This would generate "Odd number of elements in anonymous hash" warnings and
> mixup of hash keys and values. So we should have to add scalars again in the
> parameter hashes.
I believe that is the main reason why calls in list context were forbidden in
the first place. But this problem disappear if 'find' returns undef instead of
an empty list.
> So the question actually becomes: Where do we want to add scalars?
Nowhere! Because we don't need to :-)
IMO 'find' is a method that should return one, only one, and always one result.
And this should not depend on the calling context.
--
You are receiving this mail because:
You are watching all bug changes.
More information about the Koha-bugs
mailing list