From: Matt S Trout Date: Fri, 15 Jun 2012 11:39:45 +0000 (+0000) Subject: non terrible table browsing X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=a6694990cb6556bfcd42988e88e9e5fe5b8f46d4;p=scpubgit%2FJSON-Tree-Viewer.git non terrible table browsing --- diff --git a/br.pl b/br.pl index 8f7a436..0bb29b6 100644 --- a/br.pl +++ b/br.pl @@ -35,6 +35,19 @@ sub dispatch_request { sub structure { my ($self, $data) = @_; if (ref($data) eq 'HASH') { + if (keys %$data > 1 + and values %$data == grep ref($_) eq 'HASH', values %$data) { + my %tmp; + $tmp{join '|', keys %$_} = 1 for values %$data; + if (keys %tmp == 1) { + $data->{$_}->{name} ||= $_ for keys %$data; + return { + columns => [ sort keys %{(values %$data)[0]} ], + show_columns => 1, + data => [ @{$data}{sort keys %$data} ], + } + } + } return { columns => [ 'key', 'value' ], data => [ map +{ key => $_, value => $data->{$_} }, sort keys %$data ],