+sub Data {
+ my ($filename) = @_;
+ my @data = eval {
+ open my $cache, '<:raw', "data/$filename.json"
+ or return do "$filename.inc.pl"; # silent fallback to original code
+ require JSON;
+ local $/; # slurp
+ return JSON::decode_json(readline $cache);
+ };
+ if ($! or $@ or !@data or !$data[0]) {
+ die ['Table data not found', $@ || $!];
+ }
+ if (@data == 1 and ref $data[0] eq 'HASH' and not %{$data[0]}) {
+ die ['Table data missing'];
+ }
+ return wantarray ? @data : $data[0]; # list compatibility like do does
+}
+