From: Jan "Yenya" Kasprzak Date: Wed, 21 Dec 2022 07:46:47 +0000 (+0100) Subject: Infrastructure mods X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?p=aoc.git;a=commitdiff_plain;h=073fe39005345f037e5fdcd48e1586f61eb29d11 Infrastructure mods --- diff --git a/lib/Y/AoC/Task.pm b/lib/Y/AoC/Task.pm index bab6d93..ec7c4a2 100644 --- a/lib/Y/AoC/Task.pm +++ b/lib/Y/AoC/Task.pm @@ -3,6 +3,8 @@ package Y::AoC::Task; use v5.36; use Exporter ('import'); +use IO::Handle; + our @EXPORT = qw(t asay bsay); use Y::AoC qw(red white grey yellow day year); @@ -20,10 +22,13 @@ $SIG{__WARN__} = sub($msg) { say STDERR $msg; }; +STDOUT->autoflush(1); +STDERR->autoflush(1); + our $in_test; sub t($subtest = ()) { $subtest //= ''; - $ARGV[0] =~ s/in\.txt/test$subtest.txt/; + $ARGV[0] =~ s/in\.txt/test$subtest.txt/ if defined $ARGV[0]; $in_test = 1; } @@ -91,12 +96,3 @@ sub try_submit($part, @msg) { } 1; -__END__ -package Y::AoC::UA; - -sub new($class, $year, $day) { - eval 'require -} - -sub get($ua) { -1; diff --git a/lib/Y/AoC/UA.pm b/lib/Y/AoC/UA.pm index ecee1b0..7258324 100644 --- a/lib/Y/AoC/UA.pm +++ b/lib/Y/AoC/UA.pm @@ -19,7 +19,7 @@ sub request($url, $args) { $cachefile = $cache_dir . '/' . $args->{cache_to}; $cache = Mojo::File->new("$cachefile"); - if ($args->{max_age}) { + if (defined $args->{max_age}) { $cache->remove if $cache->stat && time - $cache->stat->mtime @@ -29,7 +29,9 @@ sub request($url, $args) { if ($cache->stat) { say "\n", white('cached'), " response from $cachefile"; - return Mojo::DOM->new($cache->slurp); + return $args->{body} + ? $cache->slurp + : Mojo::DOM->new($cache->slurp); } }