From: Matt S Trout Date: Fri, 15 Jun 2012 14:47:53 +0000 (+0000) Subject: name field first, don't implode on complex data values X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=b5f74ce308a520257388a7b5c0bcbca6b253098a;p=scpubgit%2FJSON-Tree-Viewer.git name field first, don't implode on complex data values --- diff --git a/br.pl b/br.pl index 0bb29b6..3bb6466 100644 --- a/br.pl +++ b/br.pl @@ -14,7 +14,7 @@ sub _build_root { } sub _build_json { - JSON->new->relaxed + JSON->new->relaxed->pretty } sub dispatch_request { @@ -41,8 +41,10 @@ sub structure { $tmp{join '|', keys %$_} = 1 for values %$data; if (keys %tmp == 1) { $data->{$_}->{name} ||= $_ for keys %$data; + my @cols = grep $_ ne 'name', sort keys %{(values %$data)[0]}; + unshift @cols, 'name'; return { - columns => [ sort keys %{(values %$data)[0]} ], + columns => \@cols, show_columns => 1, data => [ @{$data}{sort keys %$data} ], } @@ -113,9 +115,13 @@ sub render_el { return join(', ', @$part); } if (ref($part) eq 'HASH') { - return $self->link_to($whole->{key}); + if ($whole->{key}) { + return $self->link_to($whole->{key}) + } + $part = '(complex)'; } - return $part; + use HTML::Tags; + return $part =~ /\n/ ? (
, $part, 
) : $part; } __PACKAGE__->run_if_script;