lib/Stepford/Grapher/Renderer/Json.pm

filter: Statementstmt 100% 30 / 30 Branchbran 50.0% 2 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod 100% 1 / 1 totaltotal 95.2% 40 / 42 CC 3 SCAR 5.2
CC
3
Cov
94%
render
3.1
BEGIN
1.0
BEGIN
1.0
CRAP 1.7
« script/graph-stepford.pl ↑ Summary lib/Stepford/Grapher/CommandLine.pm »
1 package Stepford::Grapher::Renderer::Json;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use autodie;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶use JSON::PP qw( encode_json );
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 our $VERSION = '1.01';
13  
14 1 with(
15 'Stepford::Grapher::Role::Renderer',
16 );
17  
18 1 has output => (
19 is => 'ro',
20 isa => 'Str',
21 );
22  
23 1 ▶sub render {
Subroutine render: called CC=3 SCAR=11.2
Pod documented
24 1 my $self = shift;
25 1 my $data = shift;
26  
27 1 my $fh = \*STDOUT;
28 1 ▶ if ( defined $self->output ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->output) 1 0 1
29  
30 # open as raw because encode_json produces bytes not chars
31 1 open $fh, '>:raw', $self->output;
32 }
33  
34 1 ▶ print $fh encode_json($data)
Branch: 1 branch
BranchTrueFalseTotal
print $fh &encode_json($data) or die "Problem printing JSON: $!" 1 0 1
35 or die "Problem printing JSON: $!";
36 1 return;
37 }
38  
39 1 __PACKAGE__->meta->make_immutable;
40 1 1;
41  
42 # ABSTRACT: Render to a JSON data structure
43  
44 __END__
« script/graph-stepford.pl ↑ Summary lib/Stepford/Grapher/CommandLine.pm »