line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::CPAN::Meta::JSON; |
2
|
|
|
|
|
|
|
|
3
|
8
|
|
|
8
|
|
97635
|
use warnings; |
|
8
|
|
|
|
|
15
|
|
|
8
|
|
|
|
|
291
|
|
4
|
8
|
|
|
8
|
|
35
|
use strict; |
|
8
|
|
|
|
|
11
|
|
|
8
|
|
|
|
|
259
|
|
5
|
|
|
|
|
|
|
|
6
|
8
|
|
|
8
|
|
32
|
use vars qw($VERSION); |
|
8
|
|
|
|
|
12
|
|
|
8
|
|
|
|
|
602
|
|
7
|
|
|
|
|
|
|
$VERSION = '0.16'; |
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
|
|
3734
|
use IO::File; |
|
8
|
|
|
|
|
57935
|
|
|
8
|
|
|
|
|
1047
|
|
78
|
8
|
|
|
8
|
|
5053
|
use JSON; |
|
8
|
|
|
|
|
77082
|
|
|
8
|
|
|
|
|
43
|
|
79
|
8
|
|
|
8
|
|
1972
|
use Test::Builder; |
|
8
|
|
|
|
|
11492
|
|
|
8
|
|
|
|
|
154
|
|
80
|
8
|
|
|
8
|
|
4264
|
use Test::CPAN::Meta::JSON::Version; |
|
8
|
|
|
|
|
23
|
|
|
8
|
|
|
|
|
645
|
|
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
#---------------------------------------------------------------------------- |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
my $Test = Test::Builder->new(); |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub import { |
87
|
8
|
|
|
8
|
|
114
|
my $self = shift; |
88
|
8
|
|
|
|
|
20
|
my $caller = caller; |
89
|
8
|
|
|
8
|
|
55
|
no strict 'refs'; |
|
8
|
|
|
|
|
10
|
|
|
8
|
|
|
|
|
3283
|
|
90
|
8
|
|
|
|
|
18
|
*{$caller.'::meta_json_ok'} = \&meta_json_ok; |
|
8
|
|
|
|
|
51
|
|
91
|
8
|
|
|
|
|
23
|
*{$caller.'::meta_spec_ok'} = \&meta_spec_ok; |
|
8
|
|
|
|
|
53
|
|
92
|
|
|
|
|
|
|
|
93
|
8
|
|
|
|
|
37
|
$Test->exported_to($caller); |
94
|
8
|
|
|
|
|
93
|
$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
|
17
|
$Test->plan( tests => 2 ); |
115
|
1
|
|
|
|
|
122
|
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
|
2909
|
my ($file, $vers, $msg) = @_; |
132
|
10
|
|
100
|
|
|
32
|
$file ||= 'META.json'; |
133
|
|
|
|
|
|
|
|
134
|
10
|
100
|
|
|
|
21
|
unless($msg) { |
135
|
8
|
|
|
|
|
14
|
$msg = "$file meets the designated specification"; |
136
|
8
|
100
|
|
|
|
24
|
$msg .= " ($vers)" if($vers); |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
10
|
|
|
|
|
20
|
my $data = _readdata($file); |
140
|
|
|
|
|
|
|
|
141
|
10
|
50
|
|
|
|
25
|
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
|
|
|
|
|
48
|
$Test->ok(1,"$file contains valid JSON"); |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
|
149
|
10
|
|
|
|
|
2270
|
my %hash; |
150
|
10
|
100
|
|
|
|
30
|
$hash{spec} = $vers if($vers); |
151
|
10
|
|
|
|
|
13
|
$hash{data} = $data; |
152
|
|
|
|
|
|
|
|
153
|
10
|
|
|
|
|
67
|
my $spec = Test::CPAN::Meta::JSON::Version->new(%hash); |
154
|
10
|
100
|
|
|
|
29
|
if(my $result = $spec->parse()) { |
155
|
2
|
|
|
|
|
6
|
$Test->ok(0,$msg); |
156
|
2
|
|
|
|
|
721
|
$Test->diag(" ERR: $_") for($spec->errors); |
157
|
|
|
|
|
|
|
} else { |
158
|
8
|
|
|
|
|
23
|
$Test->ok(1,$msg); |
159
|
|
|
|
|
|
|
} |
160
|
|
|
|
|
|
|
|
161
|
10
|
|
|
|
|
1900
|
return $data; |
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
sub _readdata { |
165
|
10
|
|
|
10
|
|
12
|
my $file = shift; |
166
|
10
|
|
|
|
|
10
|
my $data; |
167
|
10
|
50
|
|
|
|
55
|
my $fh = IO::File->new($file,'r') or die "Cannot open file [$file]: $!"; |
168
|
10
|
|
|
|
|
985
|
while(<$fh>) { $data .= $_ } |
|
500
|
|
|
|
|
738
|
|
169
|
10
|
|
|
|
|
48
|
$fh->close; |
170
|
10
|
|
|
|
|
327
|
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__ |