While patching Template::Stash, I noticed some inconsistency in
'sort' virtual methods.


First, the list 'nsort' vmethod performs "Schwartzian Transform
for case insensitivity" - which makes absolutely no sense for
numeric comparison ('<=>') - or have I missed something?


Second, the 'sort' vmethod have the ability to sort by hash field
or even by method call. But I think that an "ideal" 'sort' should
behave just like Stash::get() - i.e. fall back to hash (and array)
elements if method call fails and so on. So the wise solution is
to use existing _dotop code to get "field" value. Currently _dotop
works only as an instance method, but the problem is that we have
no Template::Stash object in virtual method sub and there is no
easy way to reach the stash. Fortunately _dotop could be easily
modified to work as a class method too (there are only few
$self->{ _DEBUG } checks and nothing more) - so this is a possible
solution.


And third - there is case-insensitive sort vmethod for hash
values, which does not use that "Schwartzian Transform". Why don't
add it there?


If you guys (and of course Andy) find this cases reasonable, I can
make patches and tests for this issues.


By the way - what about my 'shuffle' proposal?

-- 
Sergey Martynoff


_______________________________________________
templates mailing list
[email protected]
http://lists.template-toolkit.org/mailman/listinfo/templates

Reply via email to