Hi community, I've been on a mindblowing search on a template error :D I was thinking that "loop.count" was wrong for testing if loop is not empty, the method is "loop.size". See doc http://template-toolkit.org/docs/manual/Directives.html#section_FOREACH Looks like we use both actually :
git grep 'IF.*\.count ' origin/master | wc -l 602 git grep 'IF.*\.size ' origin/master | wc -l 1636
So using count seems to work because it starts with 1. But in my opinion it is a wrong call. We can see for example : <a href="#images">Images ([% localimages.count || 0 | html %])</a> This is wrong no ? Should be create a coding guideline ? -- Fridolin SOMERS <fridolin.somers@biblibre.com> Software and system maintainer 🦄 BibLibre, France
You should grep "loop.count", not ".count" Most of the count you have with your regex is coming from koha_objects->count Le ven. 7 mai 2021 à 09:17, Fridolin SOMERS <fridolin.somers@biblibre.com> a écrit :
Hi community,
I've been on a mindblowing search on a template error :D
I was thinking that "loop.count" was wrong for testing if loop is not empty, the method is "loop.size".
See doc http://template-toolkit.org/docs/manual/Directives.html#section_FOREACH
Looks like we use both actually :
git grep 'IF.*\.count ' origin/master | wc -l 602 git grep 'IF.*\.size ' origin/master | wc -l 1636
So using count seems to work because it starts with 1. But in my opinion it is a wrong call.
We can see for example : <a href="#images">Images ([% localimages.count || 0 | html %])</a> This is wrong no ?
Should be create a coding guideline ?
-- Fridolin SOMERS <fridolin.somers@biblibre.com> Software and system maintainer 🦄 BibLibre, France _______________________________________________ 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/
I was going to say… I’d never even heard of the “count” call in TT. Looking at http://template-toolkit.org/docs/manual/VMethods.html, it’s not a method for a data structure. Looking at http://template-toolkit.org/docs/manual/Directives.html#section_FOREACH, it’s only a method of the “loop” variable. grep -R "loop\.count" * | wc -l 86 What’s the actual problem being observed? David Cook Software Engineer Prosentient Systems Suite 7.03 6a Glen St Milsons Point NSW 2061 Australia Office: 02 9212 0899 Online: 02 8005 0595 From: Koha-devel <koha-devel-bounces@lists.koha-community.org> On Behalf Of Jonathan Druart Sent: Friday, 7 May 2021 5:58 PM To: Fridolin SOMERS <fridolin.somers@biblibre.com> Cc: koha-devel <koha-devel@lists.koha-community.org> Subject: Re: [Koha-devel] TT loop count VS size You should grep "loop.count", not ".count" Most of the count you have with your regex is coming from koha_objects->count Le ven. 7 mai 2021 à 09:17, Fridolin SOMERS <fridolin.somers@biblibre.com <mailto:fridolin.somers@biblibre.com> > a écrit : Hi community, I've been on a mindblowing search on a template error :D I was thinking that "loop.count" was wrong for testing if loop is not empty, the method is "loop.size". See doc http://template-toolkit.org/docs/manual/Directives.html#section_FOREACH Looks like we use both actually :
git grep 'IF.*\.count ' origin/master | wc -l 602 git grep 'IF.*\.size ' origin/master | wc -l 1636
So using count seems to work because it starts with 1. But in my opinion it is a wrong call. We can see for example : <a href="#images">Images ([% localimages.count || 0 | html %])</a> This is wrong no ? Should be create a coding guideline ? -- Fridolin SOMERS <fridolin.somers@biblibre.com <mailto:fridolin.somers@biblibre.com> > Software and system maintainer 🦄 BibLibre, France _______________________________________________ Koha-devel mailing list Koha-devel@lists.koha-community.org <mailto: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/
That's because .count is a Koha::Objects method. El dom., 9 may. 2021 20:50, <dcook@prosentient.com.au> escribiĂł:
I was going to say… I’d never even heard of the “count” call in TT. Looking at http://template-toolkit.org/docs/manual/VMethods.html, it’s not a method for a data structure. Looking at http://template-toolkit.org/docs/manual/Directives.html#section_FOREACH, it’s only a method of the “loop” variable.
grep -R "loop\.count" * | wc -l
86
What’s the actual problem being observed?
David Cook
Software Engineer
Prosentient Systems
Suite 7.03
6a Glen St
Milsons Point NSW 2061
Australia
Office: 02 9212 0899
Online: 02 8005 0595
*From:* Koha-devel <koha-devel-bounces@lists.koha-community.org> *On Behalf Of *Jonathan Druart *Sent:* Friday, 7 May 2021 5:58 PM *To:* Fridolin SOMERS <fridolin.somers@biblibre.com> *Cc:* koha-devel <koha-devel@lists.koha-community.org> *Subject:* Re: [Koha-devel] TT loop count VS size
You should grep "loop.count", not ".count"
Most of the count you have with your regex is coming from koha_objects->count
Le ven. 7 mai 2021 à 09:17, Fridolin SOMERS <fridolin.somers@biblibre.com> a écrit :
Hi community,
I've been on a mindblowing search on a template error :D
I was thinking that "loop.count" was wrong for testing if loop is not empty, the method is "loop.size".
See doc http://template-toolkit.org/docs/manual/Directives.html#section_FOREACH
Looks like we use both actually :
git grep 'IF.*\.count ' origin/master | wc -l 602 git grep 'IF.*\.size ' origin/master | wc -l 1636
So using count seems to work because it starts with 1. But in my opinion it is a wrong call.
We can see for example : <a href="#images">Images ([% localimages.count || 0 | html %])</a> This is wrong no ?
Should be create a coding guideline ?
-- Fridolin SOMERS <fridolin.somers@biblibre.com> Software and system maintainer 🦄 BibLibre, France _______________________________________________ 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/
_______________________________________________ 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/
I know that .count is an object method, but I don’t understand the problem that Fridolin is having. I don’t see any problem at this point. David Cook Software Engineer Prosentient Systems Suite 7.03 6a Glen St Milsons Point NSW 2061 Australia Office: 02 9212 0899 Online: 02 8005 0595 From: Tomas Cohen Arazi <tomascohen@gmail.com> Sent: Monday, 10 May 2021 11:14 AM To: David Cook <dcook@prosentient.com.au> Cc: Jonathan Druart <jonathan.druart@bugs.koha-community.org>; Fridolin SOMERS <fridolin.somers@biblibre.com>; koha-devel <koha-devel@lists.koha-community.org> Subject: Re: [Koha-devel] TT loop count VS size That's because .count is a Koha::Objects method. El dom., 9 may. 2021 20:50, <dcook@prosentient.com.au <mailto:dcook@prosentient.com.au> > escribió: I was going to say… I’d never even heard of the “count” call in TT. Looking at http://template-toolkit.org/docs/manual/VMethods.html, it’s not a method for a data structure. Looking at http://template-toolkit.org/docs/manual/Directives.html#section_FOREACH, it’s only a method of the “loop” variable. grep -R "loop\.count" * | wc -l 86 What’s the actual problem being observed? David Cook Software Engineer Prosentient Systems Suite 7.03 6a Glen St Milsons Point NSW 2061 Australia Office: 02 9212 0899 Online: 02 8005 0595 From: Koha-devel <koha-devel-bounces@lists.koha-community.org <mailto:koha-devel-bounces@lists.koha-community.org> > On Behalf Of Jonathan Druart Sent: Friday, 7 May 2021 5:58 PM To: Fridolin SOMERS <fridolin.somers@biblibre.com <mailto:fridolin.somers@biblibre.com> > Cc: koha-devel <koha-devel@lists.koha-community.org <mailto:koha-devel@lists.koha-community.org> > Subject: Re: [Koha-devel] TT loop count VS size You should grep "loop.count", not ".count" Most of the count you have with your regex is coming from koha_objects->count Le ven. 7 mai 2021 à 09:17, Fridolin SOMERS <fridolin.somers@biblibre.com <mailto:fridolin.somers@biblibre.com> > a écrit : Hi community, I've been on a mindblowing search on a template error :D I was thinking that "loop.count" was wrong for testing if loop is not empty, the method is "loop.size". See doc http://template-toolkit.org/docs/manual/Directives.html#section_FOREACH Looks like we use both actually :
git grep 'IF.*\.count ' origin/master | wc -l 602 git grep 'IF.*\.size ' origin/master | wc -l 1636
So using count seems to work because it starts with 1. But in my opinion it is a wrong call. We can see for example : <a href="#images">Images ([% localimages.count || 0 | html %])</a> This is wrong no ? Should be create a coding guideline ? -- Fridolin SOMERS <fridolin.somers@biblibre.com> Software and system maintainer 🦄 BibLibre, France _______________________________________________ Koha-devel mailing list Koha-devel@lists.koha-community.org <mailto: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/ _______________________________________________ Koha-devel mailing list Koha-devel@lists.koha-community.org <mailto: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/
Ahhh my bad. So VAR.size is when VAR is an array. VAR.count is allow when VAR is a Koha::Objects, in perl called with ->count. Forget my warning ;) Best regards, Le 10/05/2021 à 04:20, dcook@prosentient.com.au a écrit :
I know that .count is an object method, but I don’t understand the problem that Fridolin is having. I don’t see any problem at this point.
David Cook
Software Engineer
Prosentient Systems
Suite 7.03
6a Glen St
Milsons Point NSW 2061
Australia
Office: 02 9212 0899
Online: 02 8005 0595
*From:*Tomas Cohen Arazi <tomascohen@gmail.com> *Sent:* Monday, 10 May 2021 11:14 AM *To:* David Cook <dcook@prosentient.com.au> *Cc:* Jonathan Druart <jonathan.druart@bugs.koha-community.org>; Fridolin SOMERS <fridolin.somers@biblibre.com>; koha-devel <koha-devel@lists.koha-community.org> *Subject:* Re: [Koha-devel] TT loop count VS size
That's because .count is a Koha::Objects method.
El dom., 9 may. 2021 20:50, <dcook@prosentient.com.au <mailto:dcook@prosentient.com.au>> escribiĂł:
I was going to say… I’d never even heard of the “count” call in TT. Looking at http://template-toolkit.org/docs/manual/VMethods.html <http://template-toolkit.org/docs/manual/VMethods.html>, it’s not a method for a data structure. Looking at http://template-toolkit.org/docs/manual/Directives.html#section_FOREACH <http://template-toolkit.org/docs/manual/Directives.html#section_FOREACH>, it’s only a method of the “loop” variable.
grep -R "loop\.count" *Â Â | wc -l
86
What’s the actual problem being observed?
David Cook
Software Engineer
Prosentient Systems
Suite 7.03
6a Glen St
Milsons Point NSW 2061
Australia
Office: 02 9212 0899
Online: 02 8005 0595
*From:*Koha-devel <koha-devel-bounces@lists.koha-community.org <mailto:koha-devel-bounces@lists.koha-community.org>> *On Behalf Of *Jonathan Druart *Sent:* Friday, 7 May 2021 5:58 PM *To:* Fridolin SOMERS <fridolin.somers@biblibre.com <mailto:fridolin.somers@biblibre.com>> *Cc:* koha-devel <koha-devel@lists.koha-community.org <mailto:koha-devel@lists.koha-community.org>> *Subject:* Re: [Koha-devel] TT loop count VS size
You should grep "loop.count", not ".count"
Most of the count you have with your regex is coming from koha_objects->count
Le ven. 7 mai 2021 à  09:17, Fridolin SOMERS <fridolin.somers@biblibre.com <mailto:fridolin.somers@biblibre.com>> a écrit :
Hi community,
I've been on a mindblowing search on a template error :D
I was thinking that "loop.count" was wrong for testing if loop is not empty, the method is "loop.size".
See doc http://template-toolkit.org/docs/manual/Directives.html#section_FOREACH <http://template-toolkit.org/docs/manual/Directives.html#section_FOREACH>
Looks like we use both actually : Â > git grep 'IF.*\.count ' origin/master | wc -l 602 Â > git grep 'IF.*\.size ' origin/master | wc -l 1636
So using count seems to work because it starts with 1. But in my opinion it is a wrong call.
We can see for example : Â <a href="#images">Images ([% localimages.count || 0 | html %])</a> This is wrong no ?
Should be create a coding guideline ?
-- Fridolin SOMERS <fridolin.somers@biblibre.com <mailto:fridolin.somers@biblibre.com>> Software and system maintainer 🦄 BibLibre, France _______________________________________________ Koha-devel mailing list Koha-devel@lists.koha-community.org <mailto:Koha-devel@lists.koha-community.org> https://lists.koha-community.org/cgi-bin/mailman/listinfo/koha-devel <https://lists.koha-community.org/cgi-bin/mailman/listinfo/koha-devel> website : https://www.koha-community.org/ <https://www.koha-community.org/> git : https://git.koha-community.org/ <https://git.koha-community.org/> bugs : https://bugs.koha-community.org/ <https://bugs.koha-community.org/>
_______________________________________________ Koha-devel mailing list Koha-devel@lists.koha-community.org <mailto:Koha-devel@lists.koha-community.org> https://lists.koha-community.org/cgi-bin/mailman/listinfo/koha-devel <https://lists.koha-community.org/cgi-bin/mailman/listinfo/koha-devel> website : https://www.koha-community.org/ <https://www.koha-community.org/> git : https://git.koha-community.org/ <https://git.koha-community.org/> bugs : https://bugs.koha-community.org/ <https://bugs.koha-community.org/>
-- Fridolin SOMERS <fridolin.somers@biblibre.com> Software and system maintainer 🦄 BibLibre, France
participants (4)
-
dcookďĽ prosentient.com.au -
Fridolin SOMERS -
Jonathan Druart -
Tomas Cohen Arazi