simple transform
[scpubgit/JSON-Tree-Viewer.git] / br.pl
CommitLineData
483736bb 1package TB_Temp_Packname;
2
3use Web::Simple;
4
5sub dispatch_request {
6 my ($self) = @_;
7 sub () {
8 response_filter {
9 ref($_[0][0]) eq 'HASH' ? $self->render_table($_[0][0]) : $_[0]
10 }
11 },
12 sub (/) {
13 return [{
14 columns => [ qw(one two three) ],
15 data => [
16 { one => 1, two => 2, three => 3 }
17 ],
18 }]
19 }
20}
21
22sub render_table {
23 my ($self, $data) = @_;
24 use HTML::Tags;
25 my @rows = (
26 $data->{columns},
27 map [ @{$_}{@{$data->{columns}}} ], @{$data->{data}}
28 );
29 [ 200, [ 'Content-type' => 'text/html' ], [
30 HTML::Tags::to_html_string(
31 <table>, "\n",
32 (map {;
33 ' ', <tr>, (map { <td>, $_, </td> } @$_), </tr>, "\n"
34 } @rows),
35 </table>, "\n",
36 )
37 ] ];
38}
39
40__PACKAGE__->run_if_script;