| 1 | # This code is part of Perl distribution OODoc version 3.05. | ||||||||||||||||||||||||||||
| 2 | # The POD got stripped from this file by OODoc version 3.05. | ||||||||||||||||||||||||||||
| 3 | # For contributors see file ChangeLog. | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | # This software is copyright (c) 2003-2025 by Mark Overmeer. | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | # This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||
| 8 | # the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||
| 9 | # SPDX-License-Identifier: Artistic-1.0-Perl OR GPL-1.0-or-later | ||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | package OODoc::Export::JSON;{ | ||||||||||||||||||||||||||||
| 13 | 1 | our $VERSION = '3.05'; | |||||||||||||||||||||||||||
| 14 | } | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 1 | ▶ | use parent 'OODoc::Export'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 1 | ▶ | use Log::Report 'oodoc'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 1 | ▶ | use JSON (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | #-------------------- | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 0 | ▶ | sub new(%) { my $class = shift; $class->SUPER::new(serializer => 'json', @_) } | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | #-------------------- | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | # Bleh: JSON has real true and false booleans :-( | ||||||||||||||||||||||||||||
| 32 | 0 | ▶ | sub boolean($) { $_[1] ? $JSON::true : $JSON::false } | ||||||||||||||||||||||||||
|
Subroutine
boolean: not called CC=2 SCAR=17.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | sub write($$%) | ||||||||||||||||||||||||||||
| 36 | 0 | ▶ | { my ($self, $output, $data, %args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
write: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 0 | my $fh; | |||||||||||||||||||||||||||
| 39 | 0 | ▶ | if($output eq '-') | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 40 | 0 | { $fh = \*STDOUT; | |||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | else | ||||||||||||||||||||||||||||
| 43 | 0 | ▶ | { open $fh, '>:encoding(UTF-8)', $output | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 44 | or fault __x"cannot write output to {file}", file => $output; | ||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 0 | my $json = JSON->new->pretty($args{pretty_print}); | |||||||||||||||||||||||||||
| 48 | 0 | $fh->print($json->encode($data)); | |||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 0 | ▶ | $output eq '-' || $fh->close | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$output eq "-" or $fh->close
MC/DC0%0/2
$output eq "-" or $fh->close
$output eq "-"
$fh->close
Truth table0%0/3
A or B
A= $output eq "-"B= $fh->close
| |||||||||||||||||||||||||||||
| 51 | or fault __x"write errors to {file}", file => $output; | ||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 1 | 1; | |||||||||||||||||||||||||||