line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::Smoke::Util::LoadAJSON; |
2
|
9
|
|
|
9
|
|
96653
|
use warnings; |
|
9
|
|
|
|
|
24
|
|
|
9
|
|
|
|
|
245
|
|
3
|
9
|
|
|
9
|
|
41
|
use strict; |
|
9
|
|
|
|
|
14
|
|
|
9
|
|
|
|
|
299
|
|
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
|
|
40
|
use Exporter 'import'; |
|
9
|
|
|
|
|
17
|
|
|
9
|
|
|
|
|
323
|
|
28
|
|
|
|
|
|
|
our @EXPORT = qw/encode_json decode_json/; |
29
|
|
|
|
|
|
|
|
30
|
9
|
|
|
9
|
|
47
|
no warnings 'redefine'; |
|
9
|
|
|
|
|
16
|
|
|
9
|
|
|
|
|
811
|
|
31
|
|
|
|
|
|
|
my $json_base_class; |
32
|
|
|
|
|
|
|
sub import { |
33
|
17
|
|
|
17
|
|
11678
|
my ($class) = @_; |
34
|
17
|
|
|
|
|
49
|
$json_base_class = $class->find_base_class; |
35
|
|
|
|
|
|
|
|
36
|
17
|
50
|
|
|
|
59
|
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
|
|
|
|
|
12
|
|
|
9
|
|
|
|
|
1855
|
|
|
17
|
|
|
|
|
34
|
|
41
|
17
|
|
|
|
|
27
|
*encode_json = \&{$json_base_class."::encode_json"}; |
|
17
|
|
|
|
|
61
|
|
42
|
17
|
|
|
|
|
29
|
*decode_json = \&{$json_base_class."::decode_json"}; |
|
17
|
|
|
|
|
61
|
|
43
|
|
|
|
|
|
|
} |
44
|
17
|
|
|
|
|
3269
|
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
|
69
|
: qw/JSON::PP JSON::XS/; |
59
|
17
|
|
|
|
|
38
|
for my $try_class (@backends) { |
60
|
9
|
|
|
9
|
|
4950
|
eval "use $try_class"; |
|
9
|
|
|
5
|
|
95387
|
|
|
9
|
|
|
4
|
|
410
|
|
|
5
|
|
|
|
|
72
|
|
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
161
|
|
|
4
|
|
|
|
|
368
|
|
|
4
|
|
|
|
|
35
|
|
|
4
|
|
|
|
|
118
|
|
|
18
|
|
|
|
|
1024
|
|
61
|
18
|
100
|
|
|
|
90
|
next if $@; |
62
|
17
|
|
|
|
|
61
|
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
|
34
|
my $class = shift; |
78
|
4
|
|
|
|
|
30
|
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 |