Same error reporting and possible upcoming extension.
28 files changed:
use Shiar_Sheet::FormatChar;
my $glyphs = Shiar_Sheet::FormatChar->new;
use Shiar_Sheet::FormatChar;
my $glyphs = Shiar_Sheet::FormatChar->new;
-
-my @ops = do 'apl.inc.pl';
-@ops > 1 or Abort("cannot open operator include", 500, $@ // $!);
say "<h1>Browser compatibility</h1>\n";
say "<h1>Browser compatibility</h1>\n";
-my $caniuse = do 'data/browser/support.inc.pl' or die $@ || $!;
+my $caniuse = Data('data/browser/support');
my %CSTATS = (
'n' => 'l1',
my %CSTATS = (
'n' => 'l1',
'Identifier must be alphanumeric name or <q>0</q>.',
]);
}
'Identifier must be alphanumeric name or <q>0</q>.',
]);
}
- $canihas = do "data/browser/usage-$_.inc.pl" or do {
- Alert('Browser usage data not found', $@ || $!);
+ $canihas = eval { Data("data/browser/usage-$_") } or do {
+ Alert('Browser usage data not found', $@);
use Shiar_Sheet::FormatChar;
my $glyphs = Shiar_Sheet::FormatChar->new;
use Shiar_Sheet::FormatChar;
my $glyphs = Shiar_Sheet::FormatChar->new;
-my $groupinfo = do 'data/unicode-cover.inc.pl' or die $@ || $!;
+my $groupinfo = Data('data/unicode-cover');
my @ossel = @{ $groupinfo->{osdefault} };
my @fontlist = map { $_->{file} }
my @ossel = @{ $groupinfo->{osdefault} };
my @fontlist = map { $_->{file} }
my %font;
for my $fontid (@fontlist) {
my %font;
for my $fontid (@fontlist) {
- my ($fontmeta, @fontrange) = do "data/font/$fontid.inc.pl";
+ my ($fontmeta, @fontrange) = eval { Data("data/font/$fontid") };
$fontmeta or next;
$font{$fontid} = {
(map { (-$_ => $fontmeta->{$_}) } keys %{$fontmeta}),
$fontmeta or next;
$font{$fontid} = {
(map { (-$_ => $fontmeta->{$_}) } keys %{$fontmeta}),
my $glyphs = Shiar_Sheet::FormatChar->new;
my @request;
my $glyphs = Shiar_Sheet::FormatChar->new;
my @request;
-my $charsets = do 'charset-encoding.inc.pl'
- or Alert('Encoding metadata could not be read', $@ || $!);
+my $charsets = Data('charset-encoding');
sub tabinput {
# generate character table(s)
sub tabinput {
# generate character table(s)
data => ['data/cli.inc.pl'],
});
data => ['data/cli.inc.pl'],
});
-my $cmd = do 'data/cli.inc.pl'
- or Abort("Error loading program data", 501, $@ // $!);
+my $cmd = Data('data/cli');
raw => '<style>td,th {width:8%} tbody th {white-space:nowrap}</style>',
});
raw => '<style>td,th {width:8%} tbody th {white-space:nowrap}</style>',
});
-my $info = do "codec-$page.inc.pl";
+my $info = Data("codec-$page");
$info and %{$info} > 1
or Abort("Requested codec type <q>$page</q> not available", '404 request not found', $@ // $!);
$info and %{$info} > 1
or Abort("Requested codec type <q>$page</q> not available", '404 request not found', $@ // $!);
$header{'Last-Modified'} = time2str($lastmod);
}
$header{'Last-Modified'} = time2str($lastmod);
}
+sub Data {
+ my ($filename) = @_;
+ my @data = eval {
+ do "$filename.inc.pl";
+ };
+ 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
+}
+
sub Html {
my ($meta) = @_;
sub Html {
my ($meta) = @_;
<h1>ISO-3166-1α2 Country codes</h1>
<:
<h1>ISO-3166-1α2 Country codes</h1>
<:
-my $cc = do 'data/countries.inc.pl';
+my $cc = Data('data/countries');
{
printf '<table class="ccmap">';
{
printf '<table class="ccmap">';
$glyphs->{style} = 'univer';
}
$glyphs->{style} = 'univer';
}
-my $scriptname = do 'writing-script.inc.pl';
+my $scriptname = eval { Data('writing-script') };
$_ = showlink($_, "/latin") for $scriptname->{latn} || ();
$_ = showlink($_, "/latin") for $scriptname->{latn} || ();
-my $table = do "writing-digits.inc.pl";
-Abort("Table data not found", 501, $_) for $@ || $! || ();
+my $table = Data("writing-digits");
sub printtable {
say '<div class=section>', $glyphs->tabletag;
sub printtable {
say '<div class=section>', $glyphs->tabletag;
-my $di = do 'data/digraphs.inc.pl'
- or Abort("Error loading digraphs data", 501, $@ // $!);
+my $di = Data('data/digraphs');
if (exists $get{v}) {
# show characters for inverted mnemonics (vim alternatives)
if (exists $get{v}) {
# show characters for inverted mnemonics (vim alternatives)
([@chars2[0, 1, 3, 4, 6]], [@chars2[2, 5, 7]]);
if ($mode) {
([@chars2[0, 1, 3, 4, 6]], [@chars2[2, 5, 7]]);
if ($mode) {
- my $xorg = do 'data/digraphs-xorg.inc.pl'
- or Abort("Error loading Xorg data", 501, $@ // $!);
+ my $xorg = Data('data/digraphs-xorg');
$_ = [ord $_] for values %{$xorg};
$xorg->{$_}->[2] = # class = compatibility
$di->{$_} ? $di->{$_}->[0] != $xorg->{$_}->[0] ? 'l1' : # conflict
$_ = [ord $_] for values %{$xorg};
$xorg->{$_}->[2] = # class = compatibility
$di->{$_} ? $di->{$_}->[0] != $xorg->{$_}->[0] ? 'l1' : # conflict
say '<div class="section">';
for my $system (qw'gmail msn yahoo') {
say '<div class="section">';
for my $system (qw'gmail msn yahoo') {
- my @info = do "emoji-$system.inc.pl";
- my $meta = shift @info or die $@;
+ my @info = Data("emoji-$system");
+ my $meta = shift @info;
ref $meta eq 'HASH' or Abort("Invalid $system definitions", 404);
my $title = $meta->{name} // $system;
$title = showlink($title, $_) for $meta->{source} || ();
ref $meta eq 'HASH' or Abort("Invalid $system definitions", 404);
my $title = $meta->{name} // $system;
$title = showlink($title, $_) for $meta->{source} || ();
- my ($fontmeta, @cover) = do "data/font/$font.inc.pl";
- $fontmeta or Abort("Unknown font $font", '404 font not found');
+ my ($fontmeta, @cover) = eval { Data("data/font/$font") }
+ or Abort("Unknown font $font", '404 font not found', ref $@ && $@->[1]);
my $map = eval {
$get{map} or return;
my $map = eval {
$get{map} or return;
- my $groupinfo = do 'data/unicode-cover.inc.pl' or die $@ || $!;
+ my $groupinfo = Data('data/unicode-cover');
my ($cat, $name) = split m{/}, $get{map}, 2 or die "invalid map\n";
if (!$name) {
my ($cat, $name) = split m{/}, $get{map}, 2 or die "invalid map\n";
if (!$name) {
-my $cover = do 'data/unicode-cover.inc.pl' or die $@ || $!;
+my $cover = Data('data/unicode-cover');
my @ossel = @{ $cover->{osdefault} };
my @fontlist = map { @{ $cover->{os}->{$_} } } @ossel;
my @ossel = @{ $cover->{osdefault} };
my @fontlist = map { @{ $cover->{os}->{$_} } } @ossel;
<:
use List::Util qw( pairs );
<:
use List::Util qw( pairs );
-my @table = do 'writing-latn.inc.pl';
-if ($! or $@ or !@table) {
- die ["Table data not found", $@ || $!];
-}
-else {
+my @table = Data('writing-latn');
+{
say '<div>';
say '<style>';
for my $row (pairs @table) {
say '<div>';
say '<style>';
for my $row (pairs @table) {
<:
use Shiar_Sheet::Keyboard 2.07;
<:
use Shiar_Sheet::Keyboard 2.07;
-my $info = do 'less.eng.inc.pl' or die $@;
+my $info = Data('less.eng');
my $keys = Shiar_Sheet::Keyboard->new($info);
$keys->map($get{map}) or undef $get{map};
$keys->print_rows($get{rows}, [1,0]);
my $keys = Shiar_Sheet::Keyboard->new($info);
$keys->map($get{map}) or undef $get{map};
$keys->print_rows($get{rows}, [1,0]);
<(common.inc.plp)><:
my $mode = $Request eq 'mpv' ? $Request : 'MPlayer';
<(common.inc.plp)><:
my $mode = $Request eq 'mpv' ? $Request : 'MPlayer';
-my $include = "\L$mode.eng.inc.pl";
+my $include = "\L$mode.eng";
Html({
title => "\L$mode\E cheat sheet",
Html({
title => "\L$mode\E cheat sheet",
'],
stylesheet => [qw( light dark circus mono red )],
keys => 1,
'],
stylesheet => [qw( light dark circus mono red )],
keys => 1,
+ data => ["$include.inc.pl"],
});
say "<h1>$mode cheat sheet</h1>";
say '';
use Shiar_Sheet::Keyboard 2;
});
say "<h1>$mode cheat sheet</h1>";
say '';
use Shiar_Sheet::Keyboard 2;
-my $info = do $include or die $@;
+my $info = Data($include);
my $keys = Shiar_Sheet::Keyboard->new($info);
$keys->map($get{map}) or undef $get{map};
$keys->print_rows($get{rows}, [1,0]);
my $keys = Shiar_Sheet::Keyboard->new($info);
$keys->map($get{map}) or undef $get{map};
$keys->print_rows($get{rows}, [1,0]);
<:
use Shiar_Sheet::Keyboard 2;
<:
use Shiar_Sheet::Keyboard 2;
-my $info = do 'mutt.eng.inc.pl' or die $@;
+my $info = Data('mutt.eng');
my $keys = Shiar_Sheet::Keyboard->new($info);
$keys->map($get{map}) or undef $get{map};
$keys->print_rows($get{rows});
my $keys = Shiar_Sheet::Keyboard->new($info);
$keys->map($get{map}) or undef $get{map};
$keys->print_rows($get{rows});
<:
use Shiar_Sheet::Keyboard 2;
<:
use Shiar_Sheet::Keyboard 2;
-my $info = do 'nethack.eng.inc.pl' or die $@;
+my $info = Data('nethack.eng');
my $keys = Shiar_Sheet::Keyboard->new($info);
$_->{"\e"} = ['me mode'] for values %{ $info->{def} };
# static reset button, even though it's not (officially) in the game
my $keys = Shiar_Sheet::Keyboard->new($info);
$_->{"\e"} = ['me mode'] for values %{ $info->{def} };
# static reset button, even though it's not (officially) in the game
<p>The most significant features introduced for recent versions of the Perl
scripting language.
<:
<p>The most significant features introduced for recent versions of the Perl
scripting language.
<:
-my $info = do 'perl.inc.pl' or die $@ // $!;
+my $info = Data('perl');
say "Depending on desired compatibility you'll want to support a minimum of";
say join(' or ', map {
say "Depending on desired compatibility you'll want to support a minimum of";
say join(' or ', map {
<:
use Shiar_Sheet::Keyboard 2;
<:
use Shiar_Sheet::Keyboard 2;
-my $info = do 'readline.eng.inc.pl' or die $@;
+my $info = Data('readline.eng');
my $keys = Shiar_Sheet::Keyboard->new($info);
$keys->map($get{map}) or undef $get{map};
$keys->print_rows($get{rows} || '^x=213', [4,3,2]);
my $keys = Shiar_Sheet::Keyboard->new($info);
$keys->map($get{map}) or undef $get{map};
$keys->print_rows($get{rows} || '^x=213', [4,3,2]);
}
my %scver = %{$requestver};
}
my %scver = %{$requestver};
-my $datafile = "sc-units-$Request.inc.pl";
+my $datafile = "sc-units-$Request";
Html({
title => "$scver{title} unit cheat sheet",
Html({
title => "$scver{title} unit cheat sheet",
],
stylesheet => [qw( light dark )],
raw => '<link rel="stylesheet" type="text/css" media="all" href="/sc.css?1.2">',
],
stylesheet => [qw( light dark )],
raw => '<link rel="stylesheet" type="text/css" media="all" href="/sc.css?1.2">',
+ data => ["$datafile.inc.pl"],
});
say "<h1>$scver{game} units</h1>\n";
});
say "<h1>$scver{game} units</h1>\n";
-my $units = do $datafile;
-Abort("Cannot open unit data", 501, $_) for $@ || $! || ();
+my $units = Data($datafile);
my $patch = shift @{$units}
or Abort("Cannot open unit data: metadata not found", 501);
my $patch = shift @{$units}
or Abort("Cannot open unit data: metadata not found", 501);
<:
use Shiar_Sheet::Keyboard 2;
<:
use Shiar_Sheet::Keyboard 2;
-my $info = do 'screen.eng.inc.pl' or die $@ // $!;
+my $info = Data('screen.eng');
my $keys = Shiar_Sheet::Keyboard->new($info);
$keys->map($get{map}) or undef $get{map};
$keys->print_rows($get{rows});
my $keys = Shiar_Sheet::Keyboard->new($info);
$keys->map($get{map}) or undef $get{map};
$keys->print_rows($get{rows});
say "<h1>Shell compatibility</h1>\n";
say "<h1>Shell compatibility</h1>\n";
-my $data = do 'shell.inc.pl' or die $@ || $!;
+my $data = Data('shell');
my @agents = keys %{ $data->{agents} };
print '<table class="mapped">';
my @agents = keys %{ $data->{agents} };
print '<table class="mapped">';
use List::Util qw( min max );
use POSIX qw( ceil );
use List::Util qw( min max );
use POSIX qw( ceil );
-my $palettes = do 'termcol.inc.pl';
-Abort("Cannot open palette data", 501, $_) for $@ || $! || ();
+my $palettes = Data('termcol');
sub colcell {
my $name = shift // return "<td>\n";
sub colcell {
my $name = shift // return "<td>\n";
$_ and m{/*+(.+)} and @config = split /[ ]/, $1 for $Request, $get{q};
$_ and m{/*+(.+)} and @config = split /[ ]/, $1 for $Request, $get{q};
-my $tables = do 'unicode-table.inc.pl' or die $@ || $!;
+my $tables = Data('unicode-table');
$glyphs->print(map {
$_ = /(.*)\?(.*)/ ? ($verbose ? $2 : $1) : $_;
$glyphs->print(map {
$_ = /(.*)\?(.*)/ ? ($verbose ? $2 : $1) : $_;
<:
use Shiar_Sheet::Keyboard 2.07;
<:
use Shiar_Sheet::Keyboard 2.07;
-my $info = do 'vi.eng.inc.pl' or die $@;
+my $info = Data('vi.eng');
my $keys = Shiar_Sheet::Keyboard->new($info);
$keys->map($get{map}) or undef $get{map};
$keys->print_rows($get{rows});
my $keys = Shiar_Sheet::Keyboard->new($info);
$keys->map($get{map}) or undef $get{map};
$keys->print_rows($get{rows});
<:
use Shiar_Sheet::Keyboard 2.07;
<:
use Shiar_Sheet::Keyboard 2.07;
-my $info = do 'vimperator.eng.inc.pl' or die $@;
+my $info = Data('vimperator.eng');
my $keys = Shiar_Sheet::Keyboard->new($info);
$keys->map($get{map}) or undef $get{map};
$keys->print_rows($get{rows});
my $keys = Shiar_Sheet::Keyboard->new($info);
$keys->map($get{map}) or undef $get{map};
$keys->print_rows($get{rows});
-my $wordlist = "$wordlistbase.inc.pl";
my $limit = $get{v} // (exists $get{v} ? 5 : 3);
Html({
my $limit = $get{v} // (exists $get{v} ? 5 : 3);
Html({
keywords => [qw'
language
'],
keywords => [qw'
language
'],
+ data => ["$wordlistbase.inc.pl"],
raw => exists $get{q} ? <<'EOT' : undef,
<style>
.gallery figure {
raw => exists $get{q} ? <<'EOT' : undef,
<style>
.gallery figure {
-my $table = do $wordlist or die $@ // $!;
+my $table = Data($wordlistbase);
sub showimg {
my ($id, $name) = @_;
sub showimg {
my ($id, $name) = @_;
$glyphs->{style} = 'univer';
}
$glyphs->{style} = 'univer';
}
-my $scriptname = do 'writing-script.inc.pl';
+my $scriptname = eval { Data('writing-script') }; # optional translations
$_ = showlink($_, "/latin") for $scriptname->{latn} || ();
for (
$_ = showlink($_, "/latin") for $scriptname->{latn} || ();
for (
[brah => 'Brahmi'],
) {
my ($source, $title) = @$_;
[brah => 'Brahmi'],
) {
my ($source, $title) = @$_;
- my @table = do "writing-$source.inc.pl";
- if ($! or $@) {
+ my @table = eval { Data("writing-$source") } or do {
- printf "<p>Table data not found: <em>%s</em>.</p>\n", $@ || $!;
+ printf "<p>%s: <em>%s</em>.</p>\n", @{$@};
$glyphs->print($title => [map {
my $lead = s/^(-)// && $1;
ref $_ eq 'ARRAY' ? @$_ : map { ".>$lead$_" }
$glyphs->print($title => [map {
my $lead = s/^(-)// && $1;
ref $_ eq 'ARRAY' ? @$_ : map { ".>$lead$_" }