X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=lib%2FApp%2FCodeowners%2FFormatter%2FJSON.pm;fp=lib%2FApp%2FCodeowners%2FFormatter%2FJSON.pm;h=2ead10c728a2a98c303bd2fce481ae55e4694071;hb=3a345750fddc777385eacb334ea011f9327b774e;hp=0000000000000000000000000000000000000000;hpb=0047d0a57e8ffe0d7cfde415fa6f50dae30201d1;p=chaz%2Fgit-codeowners diff --git a/lib/App/Codeowners/Formatter/JSON.pm b/lib/App/Codeowners/Formatter/JSON.pm new file mode 100644 index 0000000..2ead10c --- /dev/null +++ b/lib/App/Codeowners/Formatter/JSON.pm @@ -0,0 +1,77 @@ +package App::Codeowners::Formatter::JSON; +# ABSTRACT: Format codeowners output as JSON + + +use warnings; +use strict; + +our $VERSION = '0.42'; # VERSION + +use parent 'App::Codeowners::Formatter'; + +use App::Codeowners::Util qw(zip); + + +sub finish { + my $self = shift; + my $results = shift; + + eval { require JSON::MaybeXS } or die "Missing dependency: JSON::MaybeXS\n"; + + my %options; + $options{pretty} = 1 if lc($self->format) eq 'pretty'; + + my $json = JSON::MaybeXS->new(canonical => 1, utf8 => 1, %options); + + my $columns = $self->columns; + $results = [map { +{zip @$columns, @$_} } @$results]; + print { $self->handle } $json->encode($results); +} + +1; + +__END__ + +=pod + +=encoding UTF-8 + +=head1 NAME + +App::Codeowners::Formatter::JSON - Format codeowners output as JSON + +=head1 VERSION + +version 0.42 + +=head1 DESCRIPTION + +This is a L that formats output using L. + +=head1 ATTRIBUTES + +=head2 format + +If unset (default), the output will be compact. If "pretty", the output will look nicer to humans. + +=head1 BUGS + +Please report any bugs or feature requests on the bugtracker website +L + +When submitting a bug or request, please include a test-file or a +patch to an existing test-file that illustrates the bug or desired +feature. + +=head1 AUTHOR + +Charles McGarvey + +=head1 COPYRIGHT AND LICENSE + +This software is copyright (c) 2019 by Charles McGarvey. + +This is free software; you can redistribute it and/or modify it under +the same terms as the Perl 5 programming language system itself. + +=cut