From: Matt S Trout Date: Fri, 15 Jun 2012 10:23:35 +0000 (+0000) Subject: basic structure display X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=a7a7a4b960d599b530856a1499d2aacb414aa9ba;p=scpubgit%2FJSON-Tree-Viewer.git basic structure display --- diff --git a/br.pl b/br.pl index 7751f0f..6ac30cc 100644 --- a/br.pl +++ b/br.pl @@ -31,7 +31,8 @@ sub dispatch_request { sub structure { my ($self, $data) = @_; - if (ref($data) eq 'ARRAY') { + if (ref($data) eq 'HASH') { + $data = [ @{$data}{sort keys %$data} ]; my @cols = sort keys %{$data->[0]}; return [ { columns => \@cols, @@ -44,11 +45,12 @@ sub structure { sub descend { my ($self, $target, @path) = @_; + return $target unless @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); + $self->descend($target->{$step}, @path); } sub render_table { @@ -63,7 +65,9 @@ sub render_table { , , "\n", , "\n", (map {; - ' ', , (map { } @$_), , "\n" + ' ', , + (map { } @$_), + , "\n" } @rows),
, $_,
, $self->render_el($_),
, "\n", , , "\n", @@ -71,4 +75,6 @@ sub render_table { ] ]; } +sub render_el { ref($_[1]) eq 'ARRAY' ? join(', ', @{$_[1]}) : $_[1] } + __PACKAGE__->run_if_script;