diff options
author | jluehrs2 <jluehrs2@uiuc.edu> | 2008-01-31 20:01:49 -0500 |
---|---|---|
committer | jluehrs2 <jluehrs2@uiuc.edu> | 2008-01-31 20:01:49 -0500 |
commit | 39968282dd9dc5f9276f8fea507ce4d306c46e1d (patch) | |
tree | aba484e2bb7a1f6de1f035bd1b29094694103de6 /lib/Games | |
parent | cf852c833582af1fe915c8a846568316d2e45ac6 (diff) | |
download | games-word-39968282dd9dc5f9276f8fea507ce4d306c46e1d.tar.gz games-word-39968282dd9dc5f9276f8fea507ce4d306c46e1d.zip |
implement internal functions for iterating over the word list
Diffstat (limited to 'lib/Games')
-rw-r--r-- | lib/Games/Word/Wordlist.pm | 24 |
1 files changed, 24 insertions, 0 deletions
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 - ??? |