#!/opt/perl/bin/perl
use AnyEvent;
use BS::HTTPD;
use BS::HTTPD::Appgets;
use CGI qw/escapeHTML/;

my $cvar = AnyEvent->condvar;

my $httpd = BS::HTTPD->new (port => 9090);

my @list = qw/Apples <this> Other things/;

$httpd->reg_cb (
   _ => sub {
      my ($httpd, $req) = @_;
      set_request ($req);

      o "<html><body><h1>Editable list:</h1>";

      my $new_element;
      form {
         entry (\$new_element);
         o '<input type="submit" value="append"/>'
      } sub {
         push @list, $new_element;
      };

      o "<ul>";
      for my $cur (sort @list) {
         my $c = $cur;
         my $lnk = $req->link ("[delete]", sub { @list = grep { $c ne $_ } @list; });
         o "<li>".escapeHTML ($c)." ".$lnk."</li>";
      }
      o "</ul>";

      o "</body></html>";

      $req->respond;
   }
);

$cvar->wait;
