mason/dhandler: Bring not-found handling into the dhandler.
[bridge-toys] / mason / dhandler
index d7c1da5..59d5e3e 100755 (executable)
        $nrow => 4
 </%args>
 %#
-<%method title>Single hand</%method>
+<%method title>\
+% if ($fail) {
+Not found\
+% } else {
+Single hand\
+% }
+</%method>
+%#
+<%def .not-found>
+<h1>Not found</h1>
+Failed to find &lsquo;<code><% $what |h %></code>&rsquo;.
+% return 404;
+<%args>
+       $what
+</%args>
+</%def>
 %#
 <%once>
        use Deal;
 </%once>
 %#
+<%shared>
+       my $fail = ($m->dhandler_arg ne "");
+</%shared>
+%#
 <%init>
-       unless ($m->dhandler_arg eq "") {
-         $m->clear_buffer;
-         $m->comp("%not-found", what => $m->dhandler_arg);
-       }
+       return $m->comp(".not-found", what => $m->dhandler_arg)
+         if $fail;
 </%init>