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