word: move inline make scripts to distinct tools
authorMischa POSLAWSKY <perl@shiar.org>
Fri, 3 Nov 2023 00:01:50 +0000 (01:01 +0100)
committerMischa POSLAWSKY <perl@shiar.org>
Sat, 4 Nov 2023 18:10:38 +0000 (19:10 +0100)
Makefile
tools/lastword [new file with mode: 0755]
tools/wordpairs [new file with mode: 0755]

index 1f48304d049013ca134b99c91f42cead1bc99b14..20458be5677899ed862f665e0a4f863cb159ead4 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -80,7 +80,7 @@ data/termcol-xcolor.inc.pl: tools/mktermcol-xcolor data/xcolors/themes
 
 data/wordlist.version.txt: force
        @[ -e $@ ] || date -Is >$@
-       @perl -ni -I. -MShiar_Sheet::DB -E 'say (Shiar_Sheet::DB->connect->select(word => "max(updated)", \["updated>?", $$_])->list or exit 1)' $@ || true
+       tools/lastword $@ || true
 
 data/wordlist.inc.pl: tools/mkwordlist data/wordlist.version.txt
        $(call cmdsave,$<)
@@ -92,7 +92,7 @@ data/%.json: %.inc.pl
        $(call cmdsave,perl -MJSON -E "print JSON->new->utf8->canonical->encode(do \$$ARGV[0])" ./$<)
 
 data/wordpairs.inc.pl: data/wordlist.version.txt
-       @perl -I. -MShiar_Sheet::DB -MData::Dump=pp -E 'say pp(Shiar_Sheet::DB->connect->select("word w JOIN word a ON w.id=a.ref" => "w.id, a.id", {"a.lang"=>undef})->map or exit 1)' >$@
+       tools/wordpairs >$@
 
 .SECONDARY: data/font/%.ttf
 data/font/%.ttf:
diff --git a/tools/lastword b/tools/lastword
new file mode 100755 (executable)
index 0000000..b8e94f9
--- /dev/null
@@ -0,0 +1,9 @@
+#!/usr/bin/env -S perl -ni
+use 5.014;
+use warnings;
+use lib '.';
+use Shiar_Sheet::DB;
+
+my $db = Shiar_Sheet::DB->connect;
+my $query = $db->select(word => 'max(updated)', \['updated > ?', $_]);
+say ($query->list or exit 1);
diff --git a/tools/wordpairs b/tools/wordpairs
new file mode 100755 (executable)
index 0000000..9ba87f4
--- /dev/null
@@ -0,0 +1,13 @@
+#!/usr/bin/env perl
+use 5.014;
+use warnings;
+use lib '.';
+use Shiar_Sheet::DB;
+use Data::Dump 'pp';
+
+my $db = Shiar_Sheet::DB->connect;
+my $query = $db->select(
+       'word w JOIN word a ON w.id = a.ref' => 'w.id, a.id',
+       {'a.lang' => undef}
+);
+say pp($query->map or exit 1);