| 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
| |||||||||||
| 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
| |||||||||||
| 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__ | ||||||||||