lib/OODoc/Export/JSON.pm

filter: Statementstmt 62.0% 18 / 29 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 62.5% 5 / 8 Podpod 100% 3 / 3 totaltotal 49.0% 26 / 53 CC 6 SCAR 25.6
CC
6
Cov
45%
write
30.0
boolean
6.0
new
2.0
CRAP 13.0
« lib/OODoc/Text/Option.pm ↑ Summary lib/OODoc/Text/Structure.pm »
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
BranchTrueFalseTotal
$_[1] ? : 0 0 0
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
BranchTrueFalseTotal
if ($output eq '-') { } 0 0 0
40 0 { $fh = \*STDOUT;
41 }
42 else
43 0 ▶ { open $fh, '>:encoding(UTF-8)', $output
Branch: 1 branch
BranchTrueFalseTotal
open $fh, ">:encoding(UTF-8)", $output or &fault(&__x("cannot write output to {file}", "file", $output)) 0 0 0
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
BranchTrueFalseTotal
$output eq "-" or $fh->close or &fault(&__x("write errors to {file}", "file", $output)) 0 0 0
Condition0%0/3
$output eq "-" or $fh->close
l!l&&r!l&&!r
000
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
ABresult
1X1
011
000
51 or fault __x"write errors to {file}", file => $output;
52 }
53  
54 1 1;
« lib/OODoc/Text/Option.pm ↑ Summary lib/OODoc/Text/Structure.pm »