From 39968282dd9dc5f9276f8fea507ce4d306c46e1d Mon Sep 17 00:00:00 2001 From: jluehrs2 Date: Thu, 31 Jan 2008 20:01:49 -0500 Subject: implement internal functions for iterating over the word list --- lib/Games/Word/Wordlist.pm | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/lib/Games/Word/Wordlist.pm b/lib/Games/Word/Wordlist.pm index 405cda6..399aff4 100644 --- a/lib/Games/Word/Wordlist.pm +++ b/lib/Games/Word/Wordlist.pm @@ -81,6 +81,30 @@ sub is_word { return $self->_is_word_nocache(@_); } +sub _each_word_cache { + my $self = shift; + my $code = shift; + &$code($_) for @{ $self->{word_list} }; +} + +sub _each_word_nocache { + my $self = shift; + my $code = shift; + + open my $fh, '<', $self->{file} + or die "Couldn't open word list: $self->{file}"; + while (<$fh>) { + chomp; + &$code($_); + } +} + +sub _each_word { + my $self = shift; + return $self->_each_word_cache(@_) if $self->{cache}; + return $self->_each_word_nocache(@_); +} + =head1 NAME Games::Word::Wordlist - ??? -- cgit v1.2.3-54-g00ecf