]> Dogcows Code - chaz/git-codeowners/blob - lib/App/Codeowners/Formatter/JSON.pm
Release App-Codeowners 0.43
[chaz/git-codeowners] / lib / App / Codeowners / Formatter / JSON.pm
1 package App::Codeowners::Formatter::JSON;
2 # ABSTRACT: Format codeowners output as JSON
3
4 =head1 DESCRIPTION
5
6 This is a L<App::Codeowners::Formatter> that formats output using L<JSON::MaybeXS>.
7
8 =cut
9
10 use warnings;
11 use strict;
12
13 our $VERSION = '9999.999'; # VERSION
14
15 use parent 'App::Codeowners::Formatter';
16
17 use App::Codeowners::Util qw(zip);
18
19 =attr format
20
21 If unset (default), the output will be compact. If "pretty", the output will look nicer to humans.
22
23 =cut
24
25 sub finish {
26 my $self = shift;
27 my $results = shift;
28
29 eval { require JSON::MaybeXS } or die "Missing dependency: JSON::MaybeXS\n";
30
31 my %options;
32 $options{pretty} = 1 if lc($self->format) eq 'pretty';
33
34 my $json = JSON::MaybeXS->new(canonical => 1, utf8 => 1, %options);
35
36 my $columns = $self->columns;
37 $results = [map { +{zip @$columns, @$_} } @$results];
38 print { $self->handle } $json->encode($results);
39 }
40
41 1;
This page took 0.049493 seconds and 4 git commands to generate.