]> Dogcows Code - chaz/git-codeowners/blob - lib/App/Codeowners/Formatter/JSON.pm
1ccd4439467a28cc7939171a968726b6c23cdb5e
[chaz/git-codeowners] / lib / App / Codeowners / Formatter / JSON.pm
1 package App::Codeowners::Formatter::JSON;
2 # ABSTRACT: Format codeowners output as JSON
3
4
5 use warnings;
6 use strict;
7
8 our $VERSION = '0.44'; # VERSION
9
10 use parent 'App::Codeowners::Formatter';
11
12 use App::Codeowners::Util qw(zip);
13
14
15 sub finish {
16 my $self = shift;
17 my $results = shift;
18
19 eval { require JSON::MaybeXS } or die "Missing dependency: JSON::MaybeXS\n";
20
21 my %options;
22 $options{pretty} = 1 if lc($self->format) eq 'pretty';
23
24 my $json = JSON::MaybeXS->new(canonical => 1, utf8 => 1, %options);
25
26 my $columns = $self->columns;
27 $results = [map { +{zip @$columns, @$_} } @$results];
28 print { $self->handle } $json->encode($results);
29 }
30
31 1;
32
33 __END__
34
35 =pod
36
37 =encoding UTF-8
38
39 =head1 NAME
40
41 App::Codeowners::Formatter::JSON - Format codeowners output as JSON
42
43 =head1 VERSION
44
45 version 0.44
46
47 =head1 DESCRIPTION
48
49 This is a L<App::Codeowners::Formatter> that formats output using L<JSON::MaybeXS>.
50
51 =head1 ATTRIBUTES
52
53 =head2 format
54
55 If unset (default), the output will be compact. If "pretty", the output will look nicer to humans.
56
57 =head1 BUGS
58
59 Please report any bugs or feature requests on the bugtracker website
60 L<https://github.com/chazmcgarvey/git-codeowners/issues>
61
62 When submitting a bug or request, please include a test-file or a
63 patch to an existing test-file that illustrates the bug or desired
64 feature.
65
66 =head1 AUTHOR
67
68 Charles McGarvey <chazmcgarvey@brokenzipper.com>
69
70 =head1 COPYRIGHT AND LICENSE
71
72 This software is copyright (c) 2019 by Charles McGarvey.
73
74 This is free software; you can redistribute it and/or modify it under
75 the same terms as the Perl 5 programming language system itself.
76
77 =cut
This page took 0.037477 seconds and 3 git commands to generate.