A new request with request id 16223 has been created by koha-devel-request@lists.koha-community.org. Short info on the request is :
Title : Koha-devel Digest, Vol 189, Issue 17
Category :
Description : Send Koha-devel mailing list submissions to
koha-devel@lists.koha-community.org
To subscribe or unsubscribe via the World Wide Web, visit
https://lists.koha-community.org/cgi-bin/mailman/listinfo/koha-devel
or, via email, send a message with subject or body 'help' to
koha-devel-request@lists.koha-community.org
You can reach the person managing the list at
koha-devel-owner@lists.koha-community.org
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Koha-devel digest..."
Today's Topics:
1. Re: Perl advice for checking hash content (Jonathan Druart)
----------------------------------------------------------------------
Message: 1
Date: Mon, 30 Aug 2021 11:07:56 +0200
From: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
To: "Victor Grousset/tuxayo" <victor@tuxayo.net>
Cc: koha-devel <koha-devel@lists.koha-community.org>
Subject: Re: [Koha-devel] Perl advice for checking hash content
Message-ID:
<CAJzKNY4z_mwSc2bGgq6Sa55hUujd02BrtV65RHwn-XGoLqV0Pg@mail.gmail.com>
Content-Type: text/plain; charset="UTF-8"
Keep it simple, why not the following?
my $canbe = CanItemBeReserved( $patron->borrowernumber, $itemnumber );
is_deeply(
[$canbe->{status}, $canbe->{limit}]
['tooManyReservesToday', 0],
'Patron cannot reserve if holds_per_day is 0 (i.e. 0 is 0)'
);
Le sam. 28 août 2021 à 09:38, Victor Grousset/tuxayo
<victor@tuxayo.net> a écrit :
>
> Hi :)
>
> For a development, I'm adding additional keys to
> C4::Reserves::CanItemBeReserved returned hash.
>
> But there are a bunch of tests that match the whole return value and
> thus don't expect the new keys in the hash.
>
> Here is the best way so far I've found to adapt it.
>
>
> is_deeply(
> CanItemBeReserved( $patron->borrowernumber, $itemnumber_2 ),
> { status => 'tooManyReservesToday', limit => 0 },
> 'Patron cannot reserve if holds_per_day is 0 (i.e. 0 is 0)'
> );
>
> ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
>
> my @status_and_limit = @{CanItemBeReserved( $patron->borrowernumber,
> $itemnumber_2 )}{"status", "limit"};
> is_deeply(
> \@status_and_limit,
> ['tooManyReservesToday', 0],
> 'Patron cannot reserve if holds_per_day is 0 (i.e. 0 is 0)'
> );
>
>
> How could this be better?
> Since it took me more than two hours only to have something that works
> and without warnings. There are surely other ways to do it™, and
> hopefully a nicer one.
> Most of the time was reading and learning by trial and error about
> referencing and dereferencing and the specifics or Perl hashes and
> array. It's odd to have been working 3.5 years on Koha closer to the
> code than to the librarian stuff and only have to really start learning
> Perl now ^^
> Away, this is why advice is needed to have something that fit the good
> practices :)
>
> Key/Value Hash Slices would allow to not change the expected param of
> is_deeply() but that doesn't really look different for the readability.
> And isn't worth having Koha bump minimal Perl version from 5.14 (2011)
> to 5.20 (2014). Ok it's just for running the tests and not production
> but still. -> very minor or inexistent readability improvement.
> https://perldoc.perl.org/perldata#Key/Value-Hash-Slices
>
> Having two assertions (is() calls) for status and limit would allow a
> simpler syntax but add duplication.
>
>
> Cheers,
>
> --
> Victor Grousset/tuxayo
> _______________________________________________
> Koha-devel mailing list
> Koha-devel@lists.koha-community.org
> https://lists.koha-community.org/cgi-bin/mailman/listinfo/koha-devel
> website : https://www.koha-community.org/
> git : https://git.koha-community.org/
> bugs : https://bugs.koha-community.org/
------------------------------
Subject: Digest Footer
_______________________________________________
Koha-devel mailing list
Koha-devel@lists.koha-community.org
https://lists.koha-community.org/cgi-bin/mailman/listinfo/koha-devel
website : https://www.koha-community.org/
git : https://git.koha-community.org/
bugs : https://bugs.koha-community.org/
------------------------------
End of Koha-devel Digest, Vol 189, Issue 17
*******************************************
NOTE: You are receiving this mail because, the Requester/Technician wanted you to get notified on this request creation.