From: Robert 'phaylon' Sedlacek Date: Wed, 20 Jun 2012 22:34:04 +0000 (+0000) Subject: handling of non-headered comparisons X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=ac9c8b973ea8b6ba9e8835a246f8a4c31f2059fa;p=scpubgit%2FJSON-Tree-Viewer.git handling of non-headered comparisons --- diff --git a/br.pl b/br.pl index 1181443..efdc3af 100644 --- a/br.pl +++ b/br.pl @@ -75,11 +75,38 @@ sub structure { if ($parts[0] =~ /\+/) { ($parts[0], my @extra) = split /\+/, $parts[0]; my $struct = $self->mangle_structure($self->descend($self->root, @parts)); - return $struct unless $struct->[0]{show_columns}; my $first = shift @parts; my @rest = map [ $_, $self->mangle_structure( $self->descend($self->root, $_, @parts) )->[0] ], @extra; + unless ($struct->[0]{show_columns}) { + my @cols = @{ $struct->[0]{columns} }; + if (@cols == 2) { + my ($key_name, $value_name) = @cols; + my %name; + $name{ $_ }++ + for map $_->{$key_name}, + map @$_, $struct->[0]{data}, map $_->[1]{data}, @rest; + my %value_by_host = (map { + my $host = $_->[0]; + my $data = $_->[1]{data}; + ($host, +{ + map { ($_->{$key_name}, $_->{$value_name}) } @$data, + }); + } [$first, $struct->[0]], @rest); + my @hosts = ($first, @extra); + return [{ + columns => ['key', @hosts], + show_columns => 1, + data => [ map { + my $key = $_; + +{ key => $key, (map { + ($_, $value_by_host{$_}{$key}); + } @hosts)}; + } sort keys %name ], + }]; + } + } my %by_name; my %host_cols; my %complex_cols; @@ -177,7 +204,8 @@ sub descend { my ($self, $target, @path) = @_; return unless $target; if (blessed($target) and $target->isa('IO::All::File')) { - $target = $self->json->decode(scalar $target->all); + my $all = $target->all; + $target = $self->json->decode($all); } return $target unless @path; my $step = shift @path;