Skip Menu |

This queue is for tickets about the Template-Toolkit CPAN distribution.

Report information
The Basics
Id: 40637
Status: resolved
Worked: 30 min
Priority: 0/
Queue: Template-Toolkit

People
Owner: Nobody in particular
Requestors: rod.taylor [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: List Sorts to take more than one column
Allow list sorts to take more than one column. This enables this construct to function as expected: hashlist.sort('foo', 'bar', ...); Patch in attached file.
Subject: template_toolkit_vmethods.patch
*** VMethods.pm.orig Mon Nov 3 14:29:08 2008 --- VMethods.pm Mon Nov 3 15:03:14 2008 *************** *** 451,472 **** sub list_sort { no warnings; ! my ($list, $field) = @_; return $list unless @$list > 1; # no need to sort 1 item lists ! return [ ! $field # Schwartzian Transform ! ? map { $_->[0] } # for case insensitivity ! sort { $a->[1] cmp $b->[1] } ! map { [ $_, lc(ref($_) eq 'HASH' ! ? $_->{ $field } : ! UNIVERSAL::can($_, $field) ! ? $_->$field() : $_) ] } ! @$list ! : map { $_->[0] } sort { $a->[1] cmp $b->[1] } map { [ $_, lc $_ ] } ! @$list, ! ]; } sub list_nsort { --- 451,485 ---- sub list_sort { no warnings; ! my ($list, @fields) = @_; return $list unless @$list > 1; # no need to sort 1 item lists ! ! if (@fields >= 1) { ! return [ map { $_->[0] } # for case insensitivity ! sort {$a->[1] cmp $b->[1] } ! map { [ $_, list_sort_make_key($_, \@fields)]} ! @$list]; ! } ! else { ! return [map { $_->[0] } # Schwartzian transform for case insensitivity sort { $a->[1] cmp $b->[1] } map { [ $_, lc $_ ] } ! @$list] ! } ! } ! ! sub list_sort_make_key { ! my ($listItem, $fields) = @_; ! ! my @keyComponents; ! if (ref($listItem) eq 'HASH') { ! @keyComponents = map {$listItem->{ $_ }} @$fields; ! } ! else { ! @keyComponents = map {UNIVERSAL::can($listItem, $_) ? $listItem->$_() : $listItem} @$fields; ! } ! ! return lc(join('zzz', @keyComponents)); } sub list_nsort {
Patch applied, with a bit of minor reworking. http://template-toolkit.org/svnweb/Template2/revision?rev=1245 Thanks Rod Andy
Patch applied, with a bit of minor reworking. http://template-toolkit.org/svnweb/Template2/revision?rev=1245 Thanks Rod Andy