<(common.inc.plp)><: Html({ title => 'words cheat sheet admin', version => '1.0', nocache => 1, }); use List::Util qw( pairs pairkeys ); my $db = eval { my @dbinfo = ( 'DBI:Pg:dbname=sheet;host=localhost', 'sheetadmin', 'fairuse', ) or die "database not configured\n"; require DBIx::Simple; DBIx::Simple->new(@dbinfo[0..2], { RaiseError => 1, pg_enable_utf8 => 1, }); } or Abort('Database error', 501, $@); my @wordcols = ( form => 'Translation', ref => 'Reference', cat => 'Category', lang => 'Language', source => 'Image URL', thumb => 'Convert options', wptitle => 'Wikipedia', ); my $find = $Request ? {id => $Request} : undef; my $row; if ($ENV{REQUEST_METHOD} eq 'POST') { $row = {%post{ pairkeys @wordcols }}; $_ = length ? $_ : undef for values %{$row}; eval { my %res = (returning => $Request ? '*' : 'lang, cat'); my $query = $find ? $db->update(word => $row, $find, \%res) : $db->insert(word => $row, \%res); $row = $query->hash; } or Alert("Entry could not be saved", $@); } elsif ($find) { $row = $db->select(word => '*', $find)->hash or Abort("Word not found", 404); } my $title = $find ? "entry #$Request" : 'new entry'; :>

Words <:= $title :>

<: for my $col (pairs @wordcols) { printf '
' . '
', $col->key, $col->value, $row->{$col->key} // ''; say '
'; } :>