Make pqd --output json have flags to enable sorted keys and prettyfied JSON

This commit is contained in:
Brian Fraser fraserb@gmail.com
2013-01-24 12:00:48 -03:00
parent b21baeb5d8
commit d1bdd4d80c
5 changed files with 596 additions and 6 deletions

View File

@@ -7977,7 +7977,7 @@ sub _d {
{
package JSONReportFormatter;
use Mo;
use JSON;
use JSON ();
use List::Util qw(sum);
@@ -7985,8 +7985,22 @@ use Transformers qw(make_checksum parse_timestamp);
use constant PTDEBUG => $ENV{PTDEBUG} || 0;
our $pretty_json = undef;
our $sorted_json = undef;
extends qw(QueryReportFormatter);
has _json => (
is => 'ro',
init_arg => undef,
builder => '_build_json',
handles => { encode_json => 'encode' },
);
sub _build_json {
return JSON->new->utf8->pretty($pretty_json)->canonical($sorted_json);
}
override [qw(rusage date hostname files header profile prepared)] => sub {
return;
};
@@ -8062,7 +8076,7 @@ override query_report => sub {
};
}
return encode_json(\@queries) . "\n";
return $self->encode_json(\@queries) . "\n";
};
1;