blib/lib/App/karr/Role/Output.pm

filter: Statementstmt 70.5% 12 / 17 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 60.0% 3 / 5 Podpod 100% 2 / 2 totaltotal 60.7% 17 / 28 CC 3 SCAR 17.7
CC
3
Cov
57%
print_json_results
12.0
print_json
2.0
BEGIN
1.0
CRAP 5.9
« blib/lib/App/karr/Role/ClaimDefault.pm ↑ Summary blib/lib/App/karr/Error.pm »
1 # ABSTRACT: Role providing common output format options
2  
3 package App::karr::Role::Output;
4 3 our $VERSION = '0.602';
5 3 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use MooX::Options;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 # Loaded without importing: a Moo::Role composes every sub in this package into
8 # its consumers, so an imported json_encode would become a method on every
9 # command class.
10 3 ▶use App::karr::Encoding ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12  
13 3 option json => (
14 is => 'ro',
15 doc => 'JSON output',
16 );
17  
18 # Characters out, not octets: STDOUT carries the CLI's :encoding(UTF-8) layer
19 # (App::karr::Encoding::enable_std_utf8), so encoding here as well would give an
20 # agent double-encoded JSON -- the machine-readable half of ticket #53.
21 0 ▶sub print_json {
Subroutine print_json: not called CC=1 SCAR=6.9
Pod documented
22 0 my ($self, $data) = @_;
23 0 print App::karr::Encoding::json_encode($data) . "\n";
24 }
25  
26  
27  
28 0 ▶sub print_json_results {
Subroutine print_json_results: not called CC=3 SCAR=24.8
Pod documented
29 0 my ($self, @results) = @_;
30 0 ▶ return unless $self->json;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->json 0 0 0
31 0 ▶ $self->print_json(@results == 1 ? $results[0] : \@results);
Branch: 1 branch
BranchTrueFalseTotal
@results == 1 ? : 0 0 0
32 }
33  
34 3 1;
35  
36 __END__
« blib/lib/App/karr/Role/ClaimDefault.pm ↑ Summary blib/lib/App/karr/Error.pm »