Created
October 7, 2009 07:46
-
-
Save lestrrat/203857 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Extermely hackish way to realize case-sensitvie sort | |
# (without having to load a plugin) | |
# note, list.sort("foo") is not supported. | |
sub _build_template { | |
my $code = sub { | |
my ($list, @fields) = @_; | |
return $list unless @$list > 1; # no need to sort 1 item lists | |
return [ | |
@fields # Schwartzian Transform | |
? map { $_->[0] } # for case insensitivity | |
sort { $a->[1] cmp $b->[1] } | |
map { [ $_, Template::VMethods::_list_sort_make_key($_, \@fields) ] } | |
@$list | |
: sort { $a cmp $b } | |
@$list, | |
]; | |
}; | |
my $t = Template->new({ | |
INCLUDE_PATH => 'share/template/pod', | |
}); | |
$t->context->define_vmethod( list => 'sort', $code ); | |
$t; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment