line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Config::Any::JSON; |
2
|
|
|
|
|
|
|
|
3
|
5
|
|
|
5
|
|
4698
|
use strict; |
|
5
|
|
|
|
|
11
|
|
|
5
|
|
|
|
|
121
|
|
4
|
5
|
|
|
5
|
|
23
|
use warnings; |
|
5
|
|
|
|
|
8
|
|
|
5
|
|
|
|
|
123
|
|
5
|
|
|
|
|
|
|
|
6
|
5
|
|
|
5
|
|
22
|
use base 'Config::Any::Base'; |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
1832
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 NAME |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
Config::Any::JSON - Load JSON config files |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 DESCRIPTION |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
Loads JSON files. Example: |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
{ |
17
|
|
|
|
|
|
|
"name": "TestApp", |
18
|
|
|
|
|
|
|
"Controller::Foo": { |
19
|
|
|
|
|
|
|
"foo": "bar" |
20
|
|
|
|
|
|
|
}, |
21
|
|
|
|
|
|
|
"Model::Baz": { |
22
|
|
|
|
|
|
|
"qux": "xyzzy" |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head1 METHODS |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=head2 extensions( ) |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
return an array of valid extensions (C, C). |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=cut |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub extensions { |
35
|
10
|
|
|
10
|
1
|
31
|
return qw( json jsn ); |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=head2 load( $file ) |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
Attempts to load C<$file> as a JSON file. |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=cut |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub load { |
45
|
5
|
|
|
5
|
1
|
1739
|
my $class = shift; |
46
|
5
|
|
|
|
|
12
|
my $file = shift; |
47
|
|
|
|
|
|
|
|
48
|
5
|
50
|
|
|
|
230
|
open( my $fh, '<', $file ) or die $!; |
49
|
5
|
|
|
|
|
38
|
binmode $fh; |
50
|
5
|
|
|
|
|
10
|
my $content = do { local $/; <$fh> }; |
|
5
|
|
|
|
|
25
|
|
|
5
|
|
|
|
|
91
|
|
51
|
5
|
|
|
|
|
39
|
close $fh; |
52
|
|
|
|
|
|
|
|
53
|
5
|
50
|
|
|
|
13
|
if ( eval { require Cpanel::JSON::XS } ) { |
|
5
|
0
|
|
|
|
2594
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
54
|
5
|
|
|
|
|
8319
|
my $decoder = Cpanel::JSON::XS->new->utf8->relaxed; |
55
|
5
|
|
|
|
|
132
|
return $decoder->decode( $content ); |
56
|
|
|
|
|
|
|
} |
57
|
0
|
|
|
|
|
0
|
elsif ( eval { require JSON::MaybeXS } ) { |
58
|
0
|
|
|
|
|
0
|
my $decoder = JSON::MaybeXS::JSON()->new->utf8->relaxed; |
59
|
0
|
|
|
|
|
0
|
return $decoder->decode( $content ); |
60
|
|
|
|
|
|
|
} |
61
|
0
|
|
|
|
|
0
|
elsif ( eval { require JSON::DWIW } ) { |
62
|
0
|
|
|
|
|
0
|
my $decoder = JSON::DWIW->new; |
63
|
0
|
|
|
|
|
0
|
my ( $data, $error ) = $decoder->from_json( $content ); |
64
|
0
|
0
|
|
|
|
0
|
die $error if $error; |
65
|
0
|
|
|
|
|
0
|
return $data; |
66
|
|
|
|
|
|
|
} |
67
|
0
|
|
|
|
|
0
|
elsif ( eval { require JSON::XS } ) { |
68
|
0
|
|
|
|
|
0
|
my $decoder = JSON::XS->new->utf8->relaxed; |
69
|
0
|
|
|
|
|
0
|
return $decoder->decode( $content ); |
70
|
|
|
|
|
|
|
} |
71
|
0
|
|
|
|
|
0
|
elsif ( eval { require JSON::Syck } ) { |
72
|
0
|
|
|
|
|
0
|
require Encode; |
73
|
0
|
|
|
|
|
0
|
return JSON::Syck::Load( Encode::decode('UTF-8', $content ) ); |
74
|
|
|
|
|
|
|
} |
75
|
0
|
|
|
|
|
0
|
elsif ( eval { require JSON::PP; JSON::PP->VERSION( 2 ); } ) { |
|
0
|
|
|
|
|
0
|
|
76
|
0
|
|
|
|
|
0
|
my $decoder = JSON::PP->new->utf8->relaxed; |
77
|
0
|
|
|
|
|
0
|
return $decoder->decode( $content ); |
78
|
|
|
|
|
|
|
} |
79
|
0
|
|
|
|
|
0
|
require JSON; |
80
|
0
|
0
|
|
|
|
0
|
if ( eval { JSON->VERSION( 2 ) } ) { |
|
0
|
|
|
|
|
0
|
|
81
|
0
|
|
|
|
|
0
|
return JSON::decode_json( $content ); |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
else { |
84
|
0
|
|
|
|
|
0
|
return JSON::jsonToObj( $content ); |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=head2 requires_any_of( ) |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
Specifies that this modules requires one of, L, L, |
91
|
|
|
|
|
|
|
L or L in order to work. |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=cut |
94
|
|
|
|
|
|
|
|
95
|
5
|
|
|
5
|
1
|
28
|
sub requires_any_of { 'JSON::DWIW', 'JSON::XS', 'JSON::Syck', 'JSON::PP', 'JSON' } |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head1 AUTHOR |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
Brian Cassidy |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
Copyright 2006-2016 by Brian Cassidy |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
106
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head1 SEE ALSO |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=over 4 |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=item * L |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=item * L |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=item * L |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=item * L |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=item * L |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=item * L |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=item * L |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=item * L |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=back |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=cut |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
1; |