summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordakkar <dakkar@thenautilus.net>2010-12-02 20:53:29 +0000
committerdakkar <dakkar@thenautilus.net>2010-12-02 20:53:29 +0000
commitbdb7d68f2a6d7f87b719f13a01069b94367d370e (patch)
treee5689145a93c1043ebd39fd6f13b5c2df76ce53c
parentmutable objects, all status in attributes (diff)
downloadqr-builder-bdb7d68f2a6d7f87b719f13a01069b94367d370e.tar.gz
qr-builder-bdb7d68f2a6d7f87b719f13a01069b94367d370e.tar.bz2
qr-builder-bdb7d68f2a6d7f87b719f13a01069b94367d370e.zip
modifiable 'length' function
-rw-r--r--lib/GridFiller/Chooser.pm7
-rw-r--r--lib/GridFiller/Chooser/Random.pm2
-rw-r--r--lib/GridFiller/Chooser/Smarter.pm2
3 files changed, 9 insertions, 2 deletions
diff --git a/lib/GridFiller/Chooser.pm b/lib/GridFiller/Chooser.pm
index 66e13b9..6feb429 100644
--- a/lib/GridFiller/Chooser.pm
+++ b/lib/GridFiller/Chooser.pm
@@ -3,6 +3,7 @@ use Moose;
use namespace::autoclean;
use GridFiller::Status;
use GridFiller::Constants ':all';
+use MooseX::Types::Moose qw(CodeRef);
use Carp;
with 'MooseX::Log::Log4perl';
@@ -16,6 +17,12 @@ has status => (
},
);
+has length => (
+ isa => CodeRef,
+ is => 'rw',
+ default => sub { sub {length shift} },
+);
+
sub find_place_for {
croak "unimplemented";
}
diff --git a/lib/GridFiller/Chooser/Random.pm b/lib/GridFiller/Chooser/Random.pm
index 7b86d55..7fefbf6 100644
--- a/lib/GridFiller/Chooser/Random.pm
+++ b/lib/GridFiller/Chooser/Random.pm
@@ -11,7 +11,7 @@ sub find_place_for {
my $dir = int(rand(2)) ? $HORIZONTAL : $VERTICAL;
- my $length = length $word;
+ my $length = $self->length->($word);
my @ret;
diff --git a/lib/GridFiller/Chooser/Smarter.pm b/lib/GridFiller/Chooser/Smarter.pm
index 814e930..fd21dae 100644
--- a/lib/GridFiller/Chooser/Smarter.pm
+++ b/lib/GridFiller/Chooser/Smarter.pm
@@ -14,7 +14,7 @@ sub maxfirst {
sub find_place_for {
my ($self,$word) = @_;
- my $length = length $word;
+ my $length = $self->length->($word);
my @candidates;