| 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.85'; | ||
| 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__ |