| 1 | package PICA::Writer::JSON; | ||||||||||
| 2 | 16 | ▶ | use v5.14.1; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | |||||||||||
| 4 | 16 | our $VERSION = '2.12'; | |||||||||
| 5 | |||||||||||
| 6 | 16 | ▶ | use Scalar::Util qw(reftype); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 16 | ▶ | use JSON::PP; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 16 | ▶ | use PICA::Data; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 16 | ▶ | use parent 'PICA::Writer::Base'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | 2 | ▶ | sub write_record { | ||||||||
|
Subroutine
write_record: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||
| 13 | 2 | my ($self, $record) = @_; | |||||||||
| 14 | |||||||||||
| 15 | 2 | my $json = $self->{json}; | |||||||||
| 16 | 2 | ▶ | unless ($json) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 17 | 2 | $json = JSON::PP->new(%$self); | |||||||||
| 18 | $json->$_($self->{$_}) | ||||||||||
| 19 | 2 | for grep {exists $self->{$_}} | |||||||||
| 20 | qw(pretty ascii latin1 utf8 indent space_before space_after canonical); | ||||||||||
| 21 | 2 | $self->{json} = $json; | |||||||||
| 22 | } | ||||||||||
| 23 | |||||||||||
| 24 | 2 | print {$self->{fh}} $json->encode(PICA::Data::TO_JSON($record)); | |||||||||
| 25 | 2 | ▶ | print {$self->{fh}} "\n" unless $json->get_indent; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 26 | } | ||||||||||
| 27 | |||||||||||
| 28 | 16 | 1; | |||||||||
| 29 | __END__ | ||||||||||