Skip to content

Instantly share code, notes, and snippets.

@lestrrat
Created October 7, 2009 07:46
Show Gist options
  • Save lestrrat/203857 to your computer and use it in GitHub Desktop.
Save lestrrat/203857 to your computer and use it in GitHub Desktop.
# 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