simple transform
Matt S Trout [Fri, 15 Jun 2012 08:54:28 +0000 (08:54 +0000)]
br.pl [new file with mode: 0644]

diff --git a/br.pl b/br.pl
new file mode 100644 (file)
index 0000000..604dc59
--- /dev/null
+++ b/br.pl
@@ -0,0 +1,40 @@
+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;