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;
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;