abort messages with http error code
[sheet.git] / chars.plp
index d4cf06beb480889549f60b1c0164ba89bb8d6abe..6605ec8c6d051e492ffdae311600b3dc2727e6f6 100644 (file)
--- a/chars.plp
+++ b/chars.plp
@@ -2,12 +2,12 @@
 
 Html({
        title => 'character support sheet',
-       version => '1.0',
+       version => '1.1',
        keywords => [qw'
                unicode glyph char character reference common ipa symbol sign mark table digraph
        '],
        stylesheet => [qw'light dark mono circus red'],
-       data => [qw( unicode-cover.inc.pl ttfsupport unicode-char.inc.pl )],
+       data => [qw( data/unicode-cover.inc.pl data/font data/unicode-char.inc.pl )],
        raw => <<'EOT',
 <style>
        tbody tr:hover th {
@@ -22,7 +22,7 @@ EOT
 use Shiar_Sheet::FormatChar;
 my $glyphs = Shiar_Sheet::FormatChar->new;
 
-my $groupinfo = do 'unicode-cover.inc.pl' or die $@ || $!;
+my $groupinfo = do 'data/unicode-cover.inc.pl' or die $@ || $!;
 
 my @ossel = @{ $groupinfo->{osdefault} };
 my @fontlist = map { $_->{file} }
@@ -30,7 +30,7 @@ my @fontlist = map { $_->{file} }
 
 my %font;
 for my $fontid (@fontlist) {
-               my ($fontmeta, @fontrange) = do "ttfsupport/$fontid.inc.pl";
+               my ($fontmeta, @fontrange) = do "data/font/$fontid.inc.pl";
                $fontmeta or next;
                $font{$fontid} = {
                        (map { (-$_ => $fontmeta->{$_}) } keys %{$fontmeta}),
@@ -62,8 +62,7 @@ my $query = eval {
 say "<h1>$title</h1>";
 
 if (!$query) {
-       Alert('Unicode group not specified', $@);
-       exit;
+       Abort(["Unicode group not found", $@], '404 no matches');
 };
 
 for ($parent || 'Unicode range') {
@@ -82,15 +81,16 @@ for ($parent || 'Unicode range') {
 my @chars;
 for (map { split /[^\d-]/ } $query) {
        my @range = split /-/, $_, 2;
-       m/^[0-9]+$/ or die "Invalid code point $_ in query $query\n" for @range;
+       m/^[0-9]+$/ or Abort("Invalid code point $_ in query $query", 400)
+               for @range;
        push @chars, chr $_ for $range[0] .. ($range[1] // $range[0]);
 }
 
-@chars or die "No match for query $query\n";
+@chars or Abort("No match for query $query", '404 no results');
 
-@chars <= 1500 or die sprintf(
-       'Too many matches (%d) for query %s'."\n",
-       scalar @chars, $query,
+@chars <= 1500 or Abort(
+       sprintf('Too many matches (%d) for query %s', scalar @chars, $query),
+       '403 not allowed',
 );
 
 # output character list