From: Matt S Trout Date: Fri, 15 Jun 2012 10:18:50 +0000 (+0000) Subject: show dwarn X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=scpubgit%2FJSON-Tree-Viewer.git;a=commitdiff_plain;h=56168e973d365077e81882cd958f7695aa830686 show dwarn --- diff --git a/br.pl b/br.pl index 604dc59..7751f0f 100644 --- a/br.pl +++ b/br.pl @@ -1,6 +1,21 @@ package TB_Temp_Packname; use Web::Simple; +use Scalar::Util qw(blessed); +use IO::All; +use JSON; + +has root => (is => 'lazy'); + +has json => (is => 'lazy'); + +sub _build_root { + io->dir("/home/matthewt/tmp/introspection-data/host/services-dev/stable/node/host/") +} + +sub _build_json { + JSON->new->relaxed +} sub dispatch_request { my ($self) = @_; @@ -9,14 +24,31 @@ sub dispatch_request { 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 (/**/) { + $self->structure($self->descend($self->root, split '/', $_[1])); + }, +} + +sub structure { + my ($self, $data) = @_; + if (ref($data) eq 'ARRAY') { + my @cols = sort keys %{$data->[0]}; + return [ { + columns => \@cols, + data => $data, + } ]; + } else { + die "Confused by $data"; + } +} + +sub descend { + my ($self, $target, @path) = @_; + my $step = shift @path; + if (blessed($target) and $target->isa('IO::All::File')) { + $target = $self->json->decode(scalar $target->all); } + $self->descend(::Dwarn($target->{$step}), @path); } sub render_table { @@ -28,11 +60,13 @@ sub render_table { ); [ 200, [ 'Content-type' => 'text/html' ], [ HTML::Tags::to_html_string( + , , "\n", , "\n", (map {; ' ', , (map { } @$_), , "\n" } @rows),
, $_,
, "\n", + , , "\n", ) ] ]; }