line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::Smoke::Util::LoadAJSON; |
2
|
9
|
|
|
9
|
|
117262
|
use warnings; |
|
9
|
|
|
|
|
29
|
|
|
9
|
|
|
|
|
295
|
|
3
|
9
|
|
|
9
|
|
56
|
use strict; |
|
9
|
|
|
|
|
25
|
|
|
9
|
|
|
|
|
357
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 NAME |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
Test::Smoke::Util::LoadAJSON - A JSON:PP/JSON::XS Factory Class |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 SYNOPSIS |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
use Test::Smoke::Util::LoadAJSON; |
14
|
|
|
|
|
|
|
my $json = Test::Smoke::Util::LoadAJSON->new->utf8->pretty->encode(\%data); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 DESCRIPTION |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
This is purely a fallback factory class that helps keep our code clean. |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
This is for people with a clean perl 5.14+ install that have L but not |
21
|
|
|
|
|
|
|
JSON. Also people that installed L on a pre-5.14 system. |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
Also checks for C<$ENV{PERL_JSON_BACKEND}> to force either of the two. |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=cut |
26
|
|
|
|
|
|
|
|
27
|
9
|
|
|
9
|
|
55
|
use Exporter 'import'; |
|
9
|
|
|
|
|
27
|
|
|
9
|
|
|
|
|
404
|
|
28
|
|
|
|
|
|
|
our @EXPORT = qw/encode_json decode_json/; |
29
|
|
|
|
|
|
|
|
30
|
9
|
|
|
9
|
|
62
|
no warnings 'redefine'; |
|
9
|
|
|
|
|
19
|
|
|
9
|
|
|
|
|
958
|
|
31
|
|
|
|
|
|
|
my $json_base_class; |
32
|
|
|
|
|
|
|
sub import { |
33
|
17
|
|
|
17
|
|
14451
|
my ($class) = @_; |
34
|
17
|
|
|
|
|
49
|
$json_base_class = $class->find_base_class; |
35
|
|
|
|
|
|
|
|
36
|
17
|
50
|
|
|
|
75
|
die "Could not find a supported JSON implementation.\n" |
37
|
|
|
|
|
|
|
if !$json_base_class; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
{ |
40
|
9
|
|
|
9
|
|
60
|
no warnings 'redefine', 'once'; |
|
9
|
|
|
|
|
22
|
|
|
9
|
|
|
|
|
2257
|
|
|
17
|
|
|
|
|
30
|
|
41
|
17
|
|
|
|
|
48
|
*encode_json = \&{$json_base_class."::encode_json"}; |
|
17
|
|
|
|
|
69
|
|
42
|
17
|
|
|
|
|
38
|
*decode_json = \&{$json_base_class."::decode_json"}; |
|
17
|
|
|
|
|
58
|
|
43
|
|
|
|
|
|
|
} |
44
|
17
|
|
|
|
|
3986
|
goto &Exporter::import; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=head2 my $class = Test::Smoke::Util::LoadAJSON->find_base_class() |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
On success returns one of: B, B |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
Returns undef on failure. |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=cut |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub find_base_class { |
56
|
|
|
|
|
|
|
my @backends = $ENV{PERL_JSON_BACKEND} |
57
|
|
|
|
|
|
|
? ($ENV{PERL_JSON_BACKEND}) |
58
|
17
|
50
|
|
17
|
1
|
98
|
: qw/JSON::PP JSON::XS/; |
59
|
17
|
|
|
|
|
46
|
for my $try_class (@backends) { |
60
|
9
|
|
|
9
|
|
6700
|
eval "use $try_class"; |
|
9
|
|
|
5
|
|
119615
|
|
|
9
|
|
|
4
|
|
419
|
|
|
5
|
|
|
|
|
97
|
|
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
176
|
|
|
4
|
|
|
|
|
471
|
|
|
4
|
|
|
|
|
40
|
|
|
4
|
|
|
|
|
140
|
|
|
18
|
|
|
|
|
1252
|
|
61
|
18
|
100
|
|
|
|
129
|
next if $@; |
62
|
17
|
|
|
|
|
70
|
return $try_class; |
63
|
0
|
|
|
|
|
0
|
last; |
64
|
|
|
|
|
|
|
} |
65
|
0
|
|
|
|
|
0
|
return; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=head2 my $obj = Test::Smoke::Util::LoadAJSON->new() |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
If a base class is found, will return an instantiated object. |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
This will die() if no base class could be found. |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=cut |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub new { |
77
|
4
|
|
|
4
|
1
|
46
|
my $class = shift; |
78
|
4
|
|
|
|
|
23
|
return $json_base_class->new(@_); |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
1; |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head1 COPYRIGHT |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
(c) 2014, All rights reserved. |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
* Abe Timmerman |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
90
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
See: |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=over 4 |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=item * L |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=item * L |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=back |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful, |
103
|
|
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
104
|
|
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=cut |