File Coverage

blib/lib/App/Codeowners/Formatter/JSON.pm
Criterion Covered Total %
statement 24 24 100.0
branch 2 4 50.0
condition n/a
subroutine 5 5 100.0
pod 1 1 100.0
total 32 34 94.1


line stmt bran cond sub pod time code
1             package App::Codeowners::Formatter::JSON;
2             # ABSTRACT: Format codeowners output as JSON
3              
4              
5 1     1   969 use warnings;
  1         5  
  1         89  
6 1     1   9 use strict;
  1         10  
  1         80  
7              
8             our $VERSION = '0.51'; # VERSION
9              
10 1     1   19 use parent 'App::Codeowners::Formatter';
  1         2  
  1         30  
11              
12 1     1   162 use App::Codeowners::Util qw(zip);
  1         8  
  1         325  
13              
14              
15             sub finish {
16 1     1 1 7 my $self = shift;
17 1         8 my $results = shift;
18              
19 1 50       7 eval { require JSON::MaybeXS } or die "Missing dependency: JSON::MaybeXS\n";
  1         16  
20              
21 1         3 my %options;
22 1 50       24 $options{pretty} = 1 if lc($self->format) eq 'pretty';
23              
24 1         24 my $json = JSON::MaybeXS->new(canonical => 1, %options);
25              
26 1         56 my $columns = $self->columns;
27 1         3 $results = [map { +{zip @$columns, @$_} } @$results];
  3         25  
28 1         5 print { $self->handle } $json->encode($results);
  1         31  
29             }
30              
31             1;
32              
33             __END__