App-Greple-wordle
view release on metacpan or search on metacpan
lib/App/Greple/wordle.pm view on Meta::CPAN
package App::Greple::wordle;
use v5.14;
use warnings;
use utf8;
our $VERSION = "0.13";
use Data::Dumper;
use List::Util qw(shuffle max);
use Try::Tiny;
use Getopt::EX::Colormap qw(colorize ansi_code);
use Text::VisualWidth::PP 0.05 'vwidth';
use App::Greple::wordle::game;
use App::Greple::wordle::util qw();
use Getopt::EX::Hashed; {
Getopt::EX::Hashed->configure( DEFAULT => [ is => 'rw' ] );
has data => ' =s ' , default => 'ORIGINAL' ;
has answer => ' =s ' , default => $ENV{WORDLE_ANSWER} ;
has index => ' n =i ' , default => $ENV{WORDLE_INDEX} ;
has trial => ' x =i ' , default => 6 ;
has total => ' =i ' , default => 30 ;
has random => ' ! ' , default => 0 ;
has series => ' s =i ' , default => 1 ;
has compat => ' ' , action => sub { $_->series = 0 } ;
has keymap => ' ! ' , default => 1 ;
has result => ' ! ' , default => 1 ;
has correct => ' =s ' , default => "\N{U+1F389}" ; # PARTY POPPER
has wrong => ' =s ' , default => "\N{U+1F4A5}" ; # COLLISION SYMBOL
has debug => ' ! ' ;
}
no Getopt::EX::Hashed;
sub parseopt {
my $app = shift;
my $argv = shift;
use Getopt::Long qw(GetOptionsFromArray Configure);
Configure qw(bundling no_getopt_compat pass_through);
$app->getopt($argv) || die "Option parse error.\n";
$app;
}
sub _days {
use Date::Calc qw(Delta_Days);
my($mday, $mon, $year, $yday) = (localtime(time))[3,4,5,7];
Delta_Days(2021, 6, 19, $year + 1900, $mon + 1, $mday);
}
my(@word_all, %word_all, @word_hidden);
sub setup {
my $app = shift;
my $pkg = __PACKAGE__ . '::' . uc($app->data);
eval "use $pkg";
if ($@) {
die "$app->{data}: no such data set\n" if $@ =~ /Can't locate/;
die $@;
} else {
no strict 'refs';
@word_all = @{"$pkg\::WORDS"};
@word_hidden = @{"$pkg\::HIDDEN"};
}
$word_all{$_} = 1 for @word_all;
for ($app->index) {
$_ = int rand @word_hidden if $app->random;
$_ //= _days;
$_ += _days if /^[-+]/;
}
if (my $answer = $app->answer) {
$app->index = undef;
( run in 1.000 second using v1.01-cache-2.11-cpan-92ad3014f07 )