4 title => 'words cheat sheet admin',
9 use List::Util qw( pairs pairkeys );
13 'DBI:Pg:dbname=sheet;host=localhost', 'sheetadmin', 'fairuse',
14 ) or die "database not configured\n";
16 DBIx::Simple->new(@dbinfo[0..2], {
20 } or Abort('Database error', 501, $@);
23 form => 'Translation',
27 source => 'Image URL',
28 thumb => 'Convert options',
29 wptitle => 'Wikipedia',
31 my $find = $Request ? {id => $Request} : undef;
34 if ($ENV{REQUEST_METHOD} eq 'POST') {
35 $row = {%post{ pairkeys @wordcols }};
36 $_ = length ? $_ : undef for values %{$row};
38 my %res = (returning => $Request ? '*' : 'lang, cat');
39 my $query = $find ? $db->update(word => $row, $find, \%res) :
40 $db->insert(word => $row, \%res);
42 } or Alert("Entry could not be saved", $@);
45 $row = $db->select(word => '*', $find)->hash
46 or Abort("Word not found", 404);
49 my $title = $find ? "entry <small>#$Request</small>" : 'new entry';
51 <h1>Words <:= $title :></h1>
53 <form action="" method="post">
57 for my $col (pairs @wordcols) {
58 printf '<dt><label for="%s">%s</label></dt>'
59 . '<dd><input id="%1$s" name="%1$s" value="%s" />',
60 $col->key, $col->value, $row->{$col->key} // '';
65 <p><input type="submit" value="Save" /></p>