summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2019-09-17 13:17:11 +0200
committerYorhel <git@yorhel.nl>2019-09-17 13:17:35 +0200
commitb34b37ba5acdf423ab30f4927cbdbbc704e91590 (patch)
tree4eac8e089a6392ab3377fb274992f21b483fb661
parent158825be34b6987c18fcdf80da4d05aee5900be6 (diff)
Make hashes in VNDB::Types immutable + get rid of Tie::IxHash dep
I love it when I can get rid of a dependency! I realized in the process that I had already made Perl 2.24+ a requirement a bit earlier on by using postfix deref. It's a useful feature and 2.24 isn't *that* new, so let's make that official.
-rw-r--r--Dockerfile1
-rw-r--r--README.md3
-rw-r--r--lib/VN3/Types.pm1
-rw-r--r--lib/VNDB/Types.pm19
4 files changed, 16 insertions, 8 deletions
diff --git a/Dockerfile b/Dockerfile
index c844d1b9..9b9dc5d3 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -27,7 +27,6 @@ RUN apt-get install -y tzdata \
libperlio-gzip-perl \
libpq-dev \
libtext-multimarkdown-perl \
- libtie-ixhash-perl \
libxml-parser-perl \
postgresql \
&& cpanm -vn \
diff --git a/README.md b/README.md
index d7493909..4e42b524 100644
--- a/README.md
+++ b/README.md
@@ -46,7 +46,7 @@ Global requirements:
- Linux, or an OS that resembles Linux. Chances are VNDB won't run on Windows.
- PostgreSQL 10 (older versions may work)
-- perl 5.24 recommended, 5.10+ may also work
+- Perl 5.24+
- Elm 0.19
**Perl modules** (core modules are not listed):
@@ -59,7 +59,6 @@ General:
- Image::Magick
- JSON::XS
- PerlIO::gzip
-- Tie::IxHash
util/vndb.pl (the web backend):
- Algorithm::Diff::XS
diff --git a/lib/VN3/Types.pm b/lib/VN3/Types.pm
index 86f6a996..273f8b79 100644
--- a/lib/VN3/Types.pm
+++ b/lib/VN3/Types.pm
@@ -5,7 +5,6 @@ package VN3::Types;
use strict;
use warnings;
use utf8;
-use Tie::IxHash;
use TUWF ':Html5';
use POSIX 'strftime', 'ceil';
use Exporter 'import';
diff --git a/lib/VNDB/Types.pm b/lib/VNDB/Types.pm
index 9bf54822..77271c6f 100644
--- a/lib/VNDB/Types.pm
+++ b/lib/VNDB/Types.pm
@@ -1,15 +1,14 @@
package VNDB::Types;
-use v5.12;
+use v5.24;
no strict 'refs';
use warnings;
use Exporter 'import';
-use Tie::IxHash;
our @EXPORT;
sub hash {
my $name = shift;
- tie $name->%*, 'Tie::IxHash', @_;
+ tie $name->%*, 'VNDB::Types::Hash', @_;
push @EXPORT, "%$name";
}
@@ -121,7 +120,7 @@ hash PRODUCER_RELATION =>
sub => { reverse => 'par', txt => 'Subsidiary' },
par => { reverse => 'sub', txt => 'Parent producer' },
imp => { reverse => 'ipa', txt => 'Imprint' },
- ipa => { reverse => 'imp', txt => 'Parent brand ' };
+ ipa => { reverse => 'imp', txt => 'Parent brand' };
@@ -326,4 +325,16 @@ hash CHAR_ROLE =>
side => { txt => 'Side character', plural => 'Side characters' },
appears => { txt => 'Makes an appearance', plural => 'Make an appearance' };
+
+
+
+# Concise implementation of an immutable hash that remembers key order.
+package VNDB::Types::Hash;
+use v5.24;
+sub TIEHASH { shift; bless [ [ map $_[$_*2], 0..$#_/2 ], +{@_}, 0 ], __PACKAGE__ };
+sub FETCH { $_[0][1]{$_[1]} }
+sub EXISTS { exists $_[0][1]{$_[1]} }
+sub FIRSTKEY { $_[0][2] = 0; &NEXTKEY }
+sub NEXTKEY { $_[0][0][ $_[0][2]++ ] }
+sub SCALAR { scalar $_[0][0]->@* }
1;