summaryrefslogtreecommitdiff
path: root/lib/GridFiller/Status.pm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/GridFiller/Status.pm')
-rw-r--r--lib/GridFiller/Status.pm18
1 files changed, 14 insertions, 4 deletions
diff --git a/lib/GridFiller/Status.pm b/lib/GridFiller/Status.pm
index 4f55c6f..b14f870 100644
--- a/lib/GridFiller/Status.pm
+++ b/lib/GridFiller/Status.pm
@@ -6,6 +6,7 @@ use List::MoreUtils qw(uniq);
use GridFiller::Types qw(WordListT GridStatusT);
use GridFiller::Constants ':all';
use Carp;
+use feature 'switch';
with 'MooseX::Log::Log4perl';
@@ -30,7 +31,7 @@ around BUILDARGS => sub {
my ($orig, $class, $args, @rest) = @_;
if (exists $args->{words} && exists $args->{grid}) {
- $args->{words_to_use} = _munge_words_to_use(delete $args->{words});
+ $args->{words_to_use} = _munge_words_to_use(delete $args->{words},$args);
$args->{grid_status} = _munge_grid_status(delete $args->{grid});
}
@@ -38,13 +39,22 @@ around BUILDARGS => sub {
};
sub _munge_words_to_use {
- my $words=shift;
+ my ($words,$args) = @_;
# clone initial word list
- return [ shuffle uniq @$words ];
+
+ my $mode = delete $args->{mode} || 'random';
+
+ given ($mode) {
+ when ('random') { return [ shuffle uniq @$words ] }
+ when ('given') { return [ uniq @$words ] }
+ when ('longest') { return [ sort {length($b) <=> length($a)} uniq @$words ] }
+ when ('shortest') { return [ sort {length($a) <=> length($b)} uniq @$words ] }
+ default { croak "Unknown mode $mode" }
+ }
}
sub _munge_grid_status {
- my $grid=shift;
+ my ($grid) = @_;
return [
map {
[