From: Matt S Trout Date: Fri, 15 Jun 2012 08:54:28 +0000 (+0000) Subject: simple transform X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=483736bb9eab6b22efc73e2085cd525484a714f8;p=scpubgit%2FJSON-Tree-Viewer.git simple transform --- diff --git a/br.pl b/br.pl new file mode 100644 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( + , "\n", + (map {; + ' ', , (map { } @$_), , "\n" + } @rows), +
, $_,
, "\n", + ) + ] ]; +} + +__PACKAGE__->run_if_script;