line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::CPAN::Meta::JSON; |
2
|
|
|
|
|
|
|
|
3
|
8
|
|
|
8
|
|
187365
|
use warnings; |
|
8
|
|
|
|
|
19
|
|
|
8
|
|
|
|
|
394
|
|
4
|
8
|
|
|
8
|
|
45
|
use strict; |
|
8
|
|
|
|
|
14
|
|
|
8
|
|
|
|
|
414
|
|
5
|
|
|
|
|
|
|
|
6
|
8
|
|
|
8
|
|
41
|
use vars qw($VERSION); |
|
8
|
|
|
|
|
19
|
|
|
8
|
|
|
|
|
626
|
|
7
|
|
|
|
|
|
|
$VERSION = '0.15'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
#---------------------------------------------------------------------------- |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 NAME |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
Test::CPAN::Meta::JSON - Validate a META.json file within a CPAN distribution. |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 SYNOPSIS |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
There are two forms this module can be used. |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
The first is a standalone test of your distribution's META.json file: |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
use Test::More; |
22
|
|
|
|
|
|
|
eval "use Test::CPAN::Meta::JSON"; |
23
|
|
|
|
|
|
|
plan skip_all => "Test::CPAN::Meta::JSON required for testing META.json" if $@; |
24
|
|
|
|
|
|
|
meta_json_ok(); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
Note that you may provide an optional label/comment/message/etc to the |
27
|
|
|
|
|
|
|
function, or one will be created automatically. |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
The second form allows you to test other META.json files, or specify a specific |
30
|
|
|
|
|
|
|
version you wish to test against: |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
use Test::More test => 6; |
33
|
|
|
|
|
|
|
use Test::CPAN::Meta::JSON; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
# specify a file and specification version |
36
|
|
|
|
|
|
|
meta_spec_ok('META.json','1.3',$msg); |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
# specify the specification version to validate the local META.json |
39
|
|
|
|
|
|
|
meta_spec_ok(undef,'1.3',$msg); |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
# specify a file, where the specification version is deduced |
42
|
|
|
|
|
|
|
# from the file itself |
43
|
|
|
|
|
|
|
meta_spec_ok('META.json',undef,$msg); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
Note that this form requires you to specify the number of tests you will be |
46
|
|
|
|
|
|
|
running in your test script. Also note that each 'meta_spec_ok' is actually 2 |
47
|
|
|
|
|
|
|
tests under the hood. |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
Also note that the version you are testing against, is the version of the |
50
|
|
|
|
|
|
|
META.yml specification, which forms the basis for the contents of a META.json |
51
|
|
|
|
|
|
|
file. |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
L |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=head1 DESCRIPTION |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
This module was written to ensure that a META.json file, provided with a |
58
|
|
|
|
|
|
|
standard distribution uploaded to CPAN, meets the specifications that are |
59
|
|
|
|
|
|
|
slowly being introduced to module uploads, via the use of package makers and |
60
|
|
|
|
|
|
|
installers such as L, L and |
61
|
|
|
|
|
|
|
L. |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
See L for further details of the CPAN Meta Specification. |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head1 ABSTRACT |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
A test module to validate a CPAN META.json file. |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=cut |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
#---------------------------------------------------------------------------- |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
############################################################################# |
74
|
|
|
|
|
|
|
#Library Modules # |
75
|
|
|
|
|
|
|
############################################################################# |
76
|
|
|
|
|
|
|
|
77
|
8
|
|
|
8
|
|
7682
|
use IO::File; |
|
8
|
|
|
|
|
102339
|
|
|
8
|
|
|
|
|
1355
|
|
78
|
8
|
|
|
8
|
|
22938
|
use JSON; |
|
8
|
|
|
|
|
126688
|
|
|
8
|
|
|
|
|
50
|
|
79
|
8
|
|
|
8
|
|
2780
|
use Test::Builder; |
|
8
|
|
|
|
|
11153
|
|
|
8
|
|
|
|
|
192
|
|
80
|
8
|
|
|
8
|
|
16620
|
use Test::CPAN::Meta::JSON::Version; |
|
8
|
|
|
|
|
26
|
|
|
8
|
|
|
|
|
713
|
|
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
#---------------------------------------------------------------------------- |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
my $Test = Test::Builder->new(); |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub import { |
87
|
8
|
|
|
8
|
|
130
|
my $self = shift; |
88
|
8
|
|
|
|
|
23
|
my $caller = caller; |
89
|
8
|
|
|
8
|
|
80
|
no strict 'refs'; |
|
8
|
|
|
|
|
13
|
|
|
8
|
|
|
|
|
4298
|
|
90
|
8
|
|
|
|
|
18
|
*{$caller.'::meta_json_ok'} = \&meta_json_ok; |
|
8
|
|
|
|
|
50
|
|
91
|
8
|
|
|
|
|
16
|
*{$caller.'::meta_spec_ok'} = \&meta_spec_ok; |
|
8
|
|
|
|
|
88
|
|
92
|
|
|
|
|
|
|
|
93
|
8
|
|
|
|
|
45
|
$Test->exported_to($caller); |
94
|
8
|
|
|
|
|
96
|
$Test->plan(@_); |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
############################################################################# |
98
|
|
|
|
|
|
|
#Interface Functions # |
99
|
|
|
|
|
|
|
############################################################################# |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head1 FUNCTIONS |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=over |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=item * meta_json_ok([$msg]) |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
Basic META.json wrapper around meta_spec_ok. |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
Returns a hash reference to the contents of the parsed META.json |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=cut |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub meta_json_ok { |
114
|
1
|
|
|
1
|
1
|
16
|
$Test->plan( tests => 2 ); |
115
|
1
|
|
|
|
|
3465
|
return meta_spec_ok(undef,undef,@_); |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=item * meta_spec_ok($file, $version [,$msg]) |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
Validates the named file against the given specification version. Both $file |
121
|
|
|
|
|
|
|
and $version can be undefined. |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
Returns a hash reference to the contents of the given file, after it has been |
124
|
|
|
|
|
|
|
parsed. |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=back |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=cut |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
sub meta_spec_ok { |
131
|
10
|
|
|
10
|
1
|
5420
|
my ($file, $vers, $msg) = @_; |
132
|
10
|
|
100
|
|
|
38
|
$file ||= 'META.json'; |
133
|
|
|
|
|
|
|
|
134
|
10
|
100
|
|
|
|
29
|
unless($msg) { |
135
|
8
|
|
|
|
|
16
|
$msg = "$file meets the designated specification"; |
136
|
8
|
100
|
|
|
|
33
|
$msg .= " ($vers)" if($vers); |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
10
|
|
|
|
|
27
|
my $data = _readdata($file); |
140
|
|
|
|
|
|
|
|
141
|
10
|
50
|
|
|
|
30
|
unless($data) { |
142
|
0
|
|
|
|
|
0
|
$Test->ok(0,"$file contains valid JSON"); |
143
|
0
|
|
|
|
|
0
|
$Test->ok(0,$msg); |
144
|
0
|
|
|
|
|
0
|
return; |
145
|
|
|
|
|
|
|
} else { |
146
|
10
|
|
|
|
|
60
|
$Test->ok(1,"$file contains valid JSON"); |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
|
149
|
10
|
|
|
|
|
3855
|
my %hash; |
150
|
10
|
100
|
|
|
|
36
|
$hash{spec} = $vers if($vers); |
151
|
10
|
|
|
|
|
21
|
$hash{data} = $data; |
152
|
|
|
|
|
|
|
|
153
|
10
|
|
|
|
|
86
|
my $spec = Test::CPAN::Meta::JSON::Version->new(%hash); |
154
|
10
|
100
|
|
|
|
39
|
if(my $result = $spec->parse()) { |
155
|
2
|
|
|
|
|
8
|
$Test->ok(0,$msg); |
156
|
2
|
|
|
|
|
997
|
$Test->diag(" ERR: $_") for($spec->errors); |
157
|
|
|
|
|
|
|
} else { |
158
|
8
|
|
|
|
|
28
|
$Test->ok(1,$msg); |
159
|
|
|
|
|
|
|
} |
160
|
|
|
|
|
|
|
|
161
|
10
|
|
|
|
|
2788
|
return $data; |
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
sub _readdata { |
165
|
10
|
|
|
10
|
|
15
|
my $file = shift; |
166
|
10
|
|
|
|
|
15
|
my $data; |
167
|
10
|
50
|
|
|
|
71
|
my $fh = IO::File->new($file,'r') or die "Cannot open file [$file]: $!"; |
168
|
10
|
|
|
|
|
1317
|
while(<$fh>) { $data .= $_ } |
|
496
|
|
|
|
|
1054
|
|
169
|
10
|
|
|
|
|
60
|
$fh->close; |
170
|
10
|
|
|
|
|
481
|
return decode_json($data); |
171
|
|
|
|
|
|
|
} |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
q( Currently Listening To: Paul Menel - "Little Gorgeous Fool" from 'Three Sides To Every Story'); |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
__END__ |