blib/lib/Code/TidyAll/Plugin/JSON.pm untested

filter: Statementstmt 0.0% 0 / 24 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 33 CC 2 SCAR 11.5
CC
2
Cov
0%
transform_source
6.0
BEGIN
2.0
BEGIN
2.0
CRAP 3.1
1 package Code::TidyAll::Plugin::JSON;
2  
3 use strict;
4 use warnings;
5  
6 use JSON::MaybeXS ();
7 use Specio::Library::Builtins;
8  
9 use Moo;
10  
11 our $VERSION = '0.83';
12  
13 extends 'Code::TidyAll::Plugin';
14  
15 has ascii => (
16 is => 'ro',
17 isa => t('Bool'),
18 default => 0,
19 );
20  
21 sub transform_source {
22 my $self = shift;
23 my $source = shift;
24  
25 my $json = JSON::MaybeXS->new(
26 canonical => 1,
27 pretty => 1,
28 relaxed => 1,
29 utf8 => 1,
30 );
31  
32 $json = $json->ascii if $self->ascii;
33  
34 return $json->encode( $json->decode($source) );
35 }
36  
37 1;
38  
39 # ABSTRACT: Use the JSON::MaybeXS module to tidy JSON documents with tidyall
40  
41 __END__
42  
43 =pod
44  
45 =encoding UTF-8
46  
47 =head1 NAME
48  
49 Code::TidyAll::Plugin::JSON - Use the JSON::MaybeXS module to tidy JSON documents with tidyall
50  
51 =head1 VERSION
52  
53 version 0.83
54  
55 =head1 SYNOPSIS
56  
57 In configuration:
58  
59 [JSON]
60 select = **/*.json
61 ascii = 1
62  
63 =head1 DESCRIPTION
64  
65 Uses L<JSON::MaybeXS> to format JSON files. Files are put into a canonical
66 format with the keys of objects sorted.
67  
68 =head1 CONFIGURATION
69  
70 This plugin accepts the following configuration options:
71  
72 =head2 ascii
73  
74 Escape non-ASCII characters. The output file will be valid ASCII.
75  
76 =head1 SUPPORT
77  
78 Bugs may be submitted at L<https://github.com/houseabsolute/perl-code-tidyall/issues>.
79  
80 =head1 SOURCE
81  
82 The source code repository for Code-TidyAll can be found at L<https://github.com/houseabsolute/perl-code-tidyall>.
83  
84 =head1 AUTHORS
85  
86 =over 4
87  
88 =item *
89  
90 Jonathan Swartz <swartz@pobox.com>
91  
92 =item *
93  
94 Dave Rolsky <autarch@urth.org>
95  
96 =back
97  
98 =head1 COPYRIGHT AND LICENSE
99  
100 This software is copyright (c) 2011 - 2022 by Jonathan Swartz.
101  
102 This is free software; you can redistribute it and/or modify it under
103 the same terms as the Perl 5 programming language system itself.
104  
105 The full text of the license can be found in the
106 F<LICENSE> file included with this distribution.
107  
108 =cut