package TB_Temp_Packname;

use Web::Simple;

sub dispatch_request {
  my ($self) = @_;
  sub () {
    response_filter {
      ref($_[0][0]) eq 'HASH' ? $self->render_table($_[0][0]) : $_[0]
    }
  },
  sub (/) {
    return [{
      columns => [ qw(one two three) ],
      data => [
        { one => 1, two => 2, three => 3 }
      ],
    }]
  }
}

sub render_table {
  my ($self, $data) = @_;
  use HTML::Tags;
  my @rows = (
    $data->{columns},
    map [ @{$_}{@{$data->{columns}}} ], @{$data->{data}}
  );
  [ 200, [ 'Content-type' => 'text/html' ], [
    HTML::Tags::to_html_string(
      <table>, "\n",
        (map {;
          '  ', <tr>, (map { <td>, $_, </td> } @$_), </tr>, "\n"
        } @rows),
      </table>, "\n",
    )
  ] ];
}

__PACKAGE__->run_if_script;
