Acme-POE-Acronym-Generator

 view release on metacpan or  search on metacpan

lib/Acme/POE/Acronym/Generator.pm  view on Meta::CPAN

use warnings;
use Math::Random;

sub new {
  my $package = shift;
  my %opts = @_;
  $opts{lc $_} = delete $opts{$_} for keys %opts;
  $opts{dict} = '/usr/share/dict/words' unless $opts{dict};
  $opts{key} =~ s/[^A-Za-z]//g if $opts{key};
  $opts{key} = lc $opts{key} if $opts{key};
  my $self = bless \%opts, $package;

  $self->{poe} = [ $opts{key}? split( //, $opts{key} ) : qw(p o e) ];
  my $key = join '', @{$self->{poe}};

  if ( $opts{wordlist} and ref $opts{wordlist} eq 'ARRAY' ) {
	for ( @{ $opts{wordlist} } ) {
	   chomp;
	   next unless /^[$key]\w+$/;
	   push @{ $self->{words}->{ substr($_,0,1) } }, $_;
	}



( run in 0.940 second using v1.01-cache-2.11-cpan-de7293f3b23 )