File Coverage

blib/lib/Data/Clean/FromJSON.pm
Criterion Covered Total %
statement 19 19 100.0
branch n/a
condition 3 6 50.0
subroutine 6 6 100.0
pod 2 2 100.0
total 30 33 90.9


line stmt bran cond sub pod time code
1             package Data::Clean::FromJSON;
2              
3             our $DATE = '2019-08-08'; # DATE
4             our $VERSION = '0.392'; # VERSION
5              
6 1     1   415 use 5.010001;
  1         7  
7 1     1   4 use strict;
  1         1  
  1         23  
8 1     1   5 use warnings;
  1         1  
  1         21  
9              
10 1     1   353 use parent qw(Data::Clean);
  1         254  
  1         4  
11              
12             sub new {
13 1     1 1 3 my ($class, %opts) = @_;
14 1   50     8 $opts{"JSON::PP::Boolean"} //= ['one_or_zero'];
15 1   50     6 $opts{"JSON::XS::Boolean"} //= ['one_or_zero']; # this does not exist though
16 1   50     5 $opts{"Cpanel::JSON::XS::Boolean"} //= ['one_or_zero']; # this does not exist though
17              
18 1         10 $class->SUPER::new(%opts);
19             }
20              
21             sub get_cleanser {
22 1     1 1 102 my $class = shift;
23 1         4 state $singleton = $class->new;
24 1         1680 $singleton;
25             }
26              
27             1;
28             # ABSTRACT: Clean data from JSON decoder
29              
30             __END__
31              
32             =pod
33              
34             =encoding UTF-8
35              
36             =head1 NAME
37              
38             Data::Clean::FromJSON - Clean data from JSON decoder
39              
40             =head1 VERSION
41              
42             This document describes version 0.392 of Data::Clean::FromJSON (from Perl distribution Data-Clean-ForJSON), released on 2019-08-08.
43              
44             =head1 SYNOPSIS
45              
46             use Data::Clean::FromJSON;
47             use JSON;
48             my $cleanser = Data::Clean::FromJSON->get_cleanser;
49             my $data = JSON->new->decode('[true]'); # -> [bless(do{\(my $o=1)},"JSON::XS::Boolean")]
50             my $cleaned = $cleanser->clean_in_place($data); # -> [1]
51              
52             =head1 DESCRIPTION
53              
54             This class can convert L<JSON::PP::Boolean> (or C<JSON::XS::Boolean>) objects to
55             1/0 values.
56              
57             =head1 METHODS
58              
59             =head2 CLASS->get_cleanser => $obj
60              
61             Return a singleton instance, with default options. Use C<new()> if you want to
62             customize options.
63              
64             =head2 CLASS->new() => $obj
65              
66             =head2 $obj->clean_in_place($data) => $cleaned
67              
68             Clean $data. Modify data in-place.
69              
70             =head2 $obj->clone_and_clean($data) => $cleaned
71              
72             Clean $data. Clone $data first.
73              
74             =head1 FAQ
75              
76             =head2 Why am I getting 'Modification of a read-only value attempted at lib/Data/Clean.pm line xxx'?
77              
78             [2013-10-15 ] This is also from Data::Clone::clone() when it encounters
79             JSON::{PP,XS}::Boolean objects. You can use clean_in_place() instead of
80             clone_and_clean(), or clone your data using other cloner like L<Sereal>.
81              
82             =head1 ENVIRONMENT
83              
84             LOG_CLEANSER_CODE
85              
86             =head1 HOMEPAGE
87              
88             Please visit the project's homepage at L<https://metacpan.org/release/Data-Clean-ForJSON>.
89              
90             =head1 SOURCE
91              
92             Source repository is at L<https://github.com/perlancar/perl-Data-Clean-ForJSON>.
93              
94             =head1 BUGS
95              
96             Please report any bugs or feature requests on the bugtracker website L<https://rt.cpan.org/Public/Dist/Display.html?Name=Data-Clean-ForJSON>
97              
98             When submitting a bug or request, please include a test-file or a
99             patch to an existing test-file that illustrates the bug or desired
100             feature.
101              
102             =head1 AUTHOR
103              
104             perlancar <perlancar@cpan.org>
105              
106             =head1 COPYRIGHT AND LICENSE
107              
108             This software is copyright (c) 2019, 2018, 2017, 2016, 2015, 2014, 2013, 2012 by perlancar@cpan.org.
109              
110             This is free software; you can redistribute it and/or modify it under
111             the same terms as the Perl 5 programming language system itself.
112              
113             =cut