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