From bdb7d68f2a6d7f87b719f13a01069b94367d370e Mon Sep 17 00:00:00 2001 From: dakkar Date: Thu, 2 Dec 2010 20:53:29 +0000 Subject: modifiable 'length' function --- lib/GridFiller/Chooser.pm | 7 +++++++ lib/GridFiller/Chooser/Random.pm | 2 +- lib/GridFiller/Chooser/Smarter.pm | 2 +- 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; -- cgit v1.2.3