Skip to content
This repository has been archived by the owner on Oct 11, 2021. It is now read-only.

Commit

Permalink
Support 'shuffle' option
Browse files Browse the repository at this point in the history
  • Loading branch information
markpasc committed Sep 4, 2008
1 parent e357232 commit 1ca907d
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions plugins/Order/lib/Order/Plugin.pm
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,22 @@ sub tag_order {
: 'descend'
;

my @objs = $args->{natural}
? sort {
$a->[0] =~ m{ \A [+-]? \d+ }xms && $b->[0] =~ m{ \A [+-]? \d+ }xms
? $a->[0] <=> $b->[0]
: lc $a->[0] cmp lc $b->[0]
} @items
: sort { lc $a->[0] cmp lc $b->[0] } @items
;
my @objs;
if ($args->{natural}) {
@objs = sort {
$a->[0] =~ m{ \A [+-]? \d+ }xms && $b->[0] =~ m{ \A [+-]? \d+ }xms
? $a->[0] <=> $b->[0]
: lc $a->[0] cmp lc $b->[0]
} @items;
}
elsif ($args->{shuffle}) {
require List::Util;
@objs = List::Util::shuffle(@items);
}
else {
@objs = sort { lc $a->[0] cmp lc $b->[0] } @items;
}

@objs = map { $_->[1] } @objs;
@objs = reverse @objs if $order eq 'descend';

Expand Down

0 comments on commit 1ca907d

Please sign in to comment.