line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::Software::License; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
89618
|
use 5.008004; |
|
2
|
|
|
|
|
9
|
|
|
2
|
|
|
|
|
165
|
|
4
|
2
|
|
|
2
|
|
13
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
66
|
|
5
|
2
|
|
|
2
|
|
10
|
use strict; |
|
2
|
|
|
|
|
14
|
|
|
2
|
|
|
|
|
77
|
|
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
1860
|
use version; |
|
2
|
|
|
|
|
4787
|
|
|
2
|
|
|
|
|
13
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.002000'; |
9
|
2
|
|
|
2
|
|
1212
|
use English qw( -no_match_vars ); |
|
2
|
|
|
|
|
4837
|
|
|
2
|
|
|
|
|
20
|
|
10
|
|
|
|
|
|
|
local $OUTPUT_AUTOFLUSH = 1; |
11
|
|
|
|
|
|
|
|
12
|
2
|
|
|
2
|
|
3084
|
use parent 0.228 qw(Exporter); |
|
2
|
|
|
|
|
690
|
|
|
2
|
|
|
|
|
16
|
|
13
|
2
|
|
|
2
|
|
2142
|
use Software::LicenseUtils 0.103007; |
|
2
|
|
|
|
|
279179
|
|
|
2
|
|
|
|
|
73
|
|
14
|
2
|
|
|
2
|
|
1913
|
use File::Slurp; |
|
2
|
|
|
|
|
25610
|
|
|
2
|
|
|
|
|
208
|
|
15
|
2
|
|
|
2
|
|
2432
|
use File::Find::Rule (); |
|
2
|
|
|
|
|
18501
|
|
|
2
|
|
|
|
|
52
|
|
16
|
2
|
|
|
2
|
|
2180
|
use File::Find::Rule::Perl (); |
|
2
|
|
|
|
|
8326
|
|
|
2
|
|
|
|
|
53
|
|
17
|
2
|
|
|
2
|
|
8284
|
use Try::Tiny; |
|
2
|
|
|
|
|
3485
|
|
|
2
|
|
|
|
|
146
|
|
18
|
2
|
|
|
2
|
|
13
|
use Parse::CPAN::Meta 1.4409; |
|
2
|
|
|
|
|
42
|
|
|
2
|
|
|
|
|
112
|
|
19
|
|
|
|
|
|
|
|
20
|
2
|
|
|
2
|
|
8
|
use constant {FFR => 'File::Find::Rule', TRUE => 1, FALSE => 0, EMPTY => -1}; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
138
|
|
21
|
|
|
|
|
|
|
|
22
|
2
|
|
|
2
|
|
18
|
use Test::Builder 1.001002; |
|
2
|
|
|
|
|
38
|
|
|
2
|
|
|
|
|
2929
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
@Test::Software::License::EXPORT = qw( |
25
|
|
|
|
|
|
|
all_software_license_ok |
26
|
|
|
|
|
|
|
); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
my $passed_a_test = FALSE; |
29
|
|
|
|
|
|
|
my $meta_author = FALSE; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
####### |
32
|
|
|
|
|
|
|
# import |
33
|
|
|
|
|
|
|
####### |
34
|
|
|
|
|
|
|
sub import { |
35
|
2
|
|
|
2
|
|
46
|
my ($self, @args) = @_; |
36
|
2
|
|
|
|
|
5
|
my $pack = caller; |
37
|
2
|
|
|
|
|
20
|
my $test = Test::Builder->new; |
38
|
|
|
|
|
|
|
|
39
|
2
|
|
|
|
|
25
|
$test->exported_to($pack); |
40
|
2
|
|
|
|
|
25
|
$test->plan(@args); |
41
|
|
|
|
|
|
|
|
42
|
2
|
|
|
|
|
285
|
$self->export_to_level(1, $self, @Test::Software::License::EXPORT); |
43
|
2
|
|
|
|
|
25
|
return 1; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
####### |
47
|
|
|
|
|
|
|
# all_software_license_ok |
48
|
|
|
|
|
|
|
####### |
49
|
|
|
|
|
|
|
sub all_software_license_ok { |
50
|
0
|
0
|
|
0
|
1
|
|
my $options = shift if ref $_[0] eq 'HASH'; |
51
|
0
|
|
0
|
|
|
|
$options ||= {strict => FALSE, diag => FALSE}; |
52
|
0
|
|
|
|
|
|
my $test = Test::Builder->new; |
53
|
0
|
|
|
|
|
|
_from_perlscript_ok($options); |
54
|
0
|
|
|
|
|
|
_from_perlmodule_ok($options); |
55
|
0
|
|
|
|
|
|
_from_metayml_ok($options); |
56
|
0
|
|
|
|
|
|
_from_metajson_ok($options); |
57
|
0
|
|
|
|
|
|
_check_for_license_file($options); |
58
|
|
|
|
|
|
|
|
59
|
0
|
0
|
|
|
|
|
if (not $options->{strict}) { |
60
|
0
|
|
|
|
|
|
$test->ok($passed_a_test, |
61
|
|
|
|
|
|
|
'This distribution appears to have a valid License'); |
62
|
|
|
|
|
|
|
} |
63
|
0
|
|
|
|
|
|
return; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
####### |
67
|
|
|
|
|
|
|
# _from_perlmodule_ok |
68
|
|
|
|
|
|
|
####### |
69
|
|
|
|
|
|
|
sub _from_perlmodule_ok { |
70
|
0
|
|
|
0
|
|
|
my $options = shift; |
71
|
0
|
|
|
|
|
|
my $test = Test::Builder->new; |
72
|
0
|
|
|
|
|
|
my @files = FFR->perl_module->in('lib'); |
73
|
|
|
|
|
|
|
|
74
|
0
|
0
|
|
|
|
|
if ($#files == EMPTY) { |
75
|
0
|
|
|
|
|
|
$test->skip('no perl_module found in lib'); |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
else { |
78
|
0
|
0
|
|
|
|
|
if ($options->{diag}) { |
79
|
0
|
|
|
|
|
|
my $found_perl_modules = $#files + 1; |
80
|
0
|
|
|
|
|
|
$test->ok($files[0], |
81
|
|
|
|
|
|
|
'found (' . $found_perl_modules . ') perl modules to test'); |
82
|
|
|
|
|
|
|
} |
83
|
0
|
|
|
|
|
|
_guess_license($options, \@files); |
84
|
|
|
|
|
|
|
} |
85
|
0
|
|
|
|
|
|
return; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
####### |
89
|
|
|
|
|
|
|
# _from_perlscript_ok |
90
|
|
|
|
|
|
|
####### |
91
|
|
|
|
|
|
|
sub _from_perlscript_ok { |
92
|
0
|
|
|
0
|
|
|
my $options = shift; |
93
|
0
|
|
|
|
|
|
my $test = Test::Builder->new; |
94
|
|
|
|
|
|
|
|
95
|
0
|
|
|
|
|
|
my @dirs = qw( script bin ); |
96
|
0
|
|
|
|
|
|
foreach my $dir (@dirs) { |
97
|
0
|
|
|
|
|
|
my @files = FFR->perl_script->in($dir); |
98
|
0
|
0
|
|
|
|
|
if ($#files == EMPTY) { |
99
|
0
|
|
|
|
|
|
$test->skip('no perl_scripts found in ' . $dir); |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
else { |
102
|
0
|
0
|
|
|
|
|
if (not $options->{diag}) { |
103
|
0
|
|
|
|
|
|
my $found_perl_scripts = $#files + 1; |
104
|
0
|
|
|
|
|
|
$test->ok($files[0], |
105
|
|
|
|
|
|
|
"found ($found_perl_scripts) perl script to test in $dir"); |
106
|
|
|
|
|
|
|
} |
107
|
0
|
|
|
|
|
|
_guess_license($options, \@files); |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
} |
110
|
0
|
|
|
|
|
|
return; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
####### |
114
|
|
|
|
|
|
|
# composed method test for license |
115
|
|
|
|
|
|
|
####### |
116
|
|
|
|
|
|
|
sub _guess_license { |
117
|
0
|
|
|
0
|
|
|
my $options = shift; |
118
|
0
|
|
|
|
|
|
my $files_ref = shift; |
119
|
0
|
|
|
|
|
|
my $test = Test::Builder->new; |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
try { |
122
|
0
|
|
|
0
|
|
|
foreach my $file (@{$files_ref}) { |
|
0
|
|
|
|
|
|
|
123
|
0
|
|
|
|
|
|
my $ps_text = read_file($file); |
124
|
0
|
|
|
|
|
|
my @guesses = Software::LicenseUtils->guess_license_from_pod($ps_text); |
125
|
0
|
0
|
|
|
|
|
if ($options->{strict}) { |
126
|
0
|
|
|
|
|
|
$test->ok($guesses[0], "$file -> @guesses"); |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
else { |
129
|
0
|
0
|
|
|
|
|
if ($#guesses >= 0) { |
130
|
0
|
|
|
|
|
|
$test->ok(1, "$file -> @guesses"); |
131
|
0
|
|
|
|
|
|
$passed_a_test = TRUE; |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
else { |
134
|
0
|
|
|
|
|
|
$test->skip('no licence found in ' . $file); |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
} |
138
|
0
|
|
|
|
|
|
}; |
139
|
0
|
|
|
|
|
|
return; |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
####### |
143
|
|
|
|
|
|
|
# _from_metayml_ok |
144
|
|
|
|
|
|
|
####### |
145
|
|
|
|
|
|
|
sub _from_metayml_ok { |
146
|
0
|
|
|
0
|
|
|
my $options = shift; |
147
|
0
|
|
|
|
|
|
my $test = Test::Builder->new; |
148
|
|
|
|
|
|
|
|
149
|
0
|
0
|
|
|
|
|
if (-e 'META.yml') { |
150
|
|
|
|
|
|
|
try { |
151
|
0
|
|
|
0
|
|
|
my $meta_yml = Parse::CPAN::Meta->load_file('META.yml'); |
152
|
0
|
|
|
|
|
|
$meta_author = $meta_yml->{author}[0]; |
153
|
|
|
|
|
|
|
|
154
|
0
|
|
|
|
|
|
my @guess_yml = _hack_guess_license_from_meta($meta_yml->{license}); |
155
|
0
|
0
|
|
|
|
|
if ($options->{strict}) { |
156
|
0
|
|
|
|
|
|
$test->ok($guess_yml[0], "META.yml -> @guess_yml"); |
157
|
|
|
|
|
|
|
} |
158
|
|
|
|
|
|
|
else { |
159
|
0
|
0
|
|
|
|
|
if (@guess_yml) { |
160
|
0
|
|
|
|
|
|
$test->ok(1, "META.yml -> @guess_yml"); |
161
|
0
|
|
|
|
|
|
$passed_a_test = TRUE; |
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
else { |
164
|
0
|
|
|
|
|
|
$test->ok(0, 'META.yml -> license unknown'); |
165
|
0
|
|
|
|
|
|
$passed_a_test = FALSE; |
166
|
|
|
|
|
|
|
} |
167
|
|
|
|
|
|
|
} |
168
|
0
|
|
|
|
|
|
}; |
169
|
|
|
|
|
|
|
} |
170
|
|
|
|
|
|
|
else { |
171
|
0
|
|
|
|
|
|
$test->skip('no META.yml found'); |
172
|
|
|
|
|
|
|
} |
173
|
0
|
|
|
|
|
|
return; |
174
|
|
|
|
|
|
|
} |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
####### |
177
|
|
|
|
|
|
|
# _from_metajson_ok |
178
|
|
|
|
|
|
|
####### |
179
|
|
|
|
|
|
|
sub _from_metajson_ok { |
180
|
0
|
|
|
0
|
|
|
my $options = shift; |
181
|
0
|
|
|
|
|
|
my $test = Test::Builder->new; |
182
|
|
|
|
|
|
|
|
183
|
0
|
0
|
|
|
|
|
if (-e 'META.json') { |
184
|
|
|
|
|
|
|
try { |
185
|
0
|
|
|
0
|
|
|
my $meta_json = Parse::CPAN::Meta->load_file('META.json'); |
186
|
0
|
|
|
|
|
|
$meta_author = $meta_json->{author}[0]; |
187
|
|
|
|
|
|
|
|
188
|
0
|
|
|
|
|
|
foreach my $json_license (@{$meta_json->{license}}) { |
|
0
|
|
|
|
|
|
|
189
|
0
|
|
|
|
|
|
my @guess_json = _hack_guess_license_from_meta($json_license); |
190
|
0
|
0
|
|
|
|
|
if ($options->{strict}) { |
191
|
0
|
|
|
|
|
|
$test->ok($guess_json[0], "META.json -> @guess_json"); |
192
|
|
|
|
|
|
|
} |
193
|
|
|
|
|
|
|
else { |
194
|
0
|
0
|
|
|
|
|
if (@guess_json) { |
195
|
0
|
|
|
|
|
|
$test->ok(1, "META.json -> @guess_json"); |
196
|
0
|
|
|
|
|
|
$passed_a_test = TRUE; |
197
|
|
|
|
|
|
|
} |
198
|
|
|
|
|
|
|
else { |
199
|
0
|
|
|
|
|
|
$test->ok(0, 'META.json -> license unknown'); |
200
|
0
|
|
|
|
|
|
$passed_a_test = FALSE; |
201
|
|
|
|
|
|
|
} |
202
|
|
|
|
|
|
|
} |
203
|
|
|
|
|
|
|
} |
204
|
0
|
|
|
|
|
|
}; |
205
|
|
|
|
|
|
|
} |
206
|
|
|
|
|
|
|
else { |
207
|
0
|
|
|
|
|
|
$test->skip('no META.json found'); |
208
|
|
|
|
|
|
|
} |
209
|
0
|
|
|
|
|
|
return; |
210
|
|
|
|
|
|
|
} |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
####### |
213
|
|
|
|
|
|
|
# _check_for_license_file |
214
|
|
|
|
|
|
|
####### |
215
|
|
|
|
|
|
|
sub _check_for_license_file { |
216
|
0
|
|
|
0
|
|
|
my $options = shift; |
217
|
0
|
|
|
|
|
|
my $test = Test::Builder->new; |
218
|
|
|
|
|
|
|
|
219
|
0
|
0
|
|
|
|
|
if ($options->{strict}) { |
220
|
0
|
|
|
|
|
|
$test->ok(-e 'LICENSE', 'LICENSE file found'); |
221
|
0
|
|
|
|
|
|
my $license_file = read_file('LICENSE'); |
222
|
0
|
|
|
|
|
|
$test->like($license_file, qr/$meta_author/, 'LICENSE file contains META Author'); |
223
|
|
|
|
|
|
|
} |
224
|
|
|
|
|
|
|
else { |
225
|
0
|
0
|
|
|
|
|
if (-e 'LICENSE') { |
226
|
0
|
|
|
|
|
|
$test->ok(1, 'LICENSE file found'); |
227
|
|
|
|
|
|
|
} |
228
|
|
|
|
|
|
|
else { |
229
|
0
|
|
|
|
|
|
$test->skip('no LICENSE file found'); |
230
|
|
|
|
|
|
|
} |
231
|
|
|
|
|
|
|
} |
232
|
0
|
|
|
|
|
|
return; |
233
|
|
|
|
|
|
|
} |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
####### |
236
|
|
|
|
|
|
|
## hack to support meta license strings |
237
|
|
|
|
|
|
|
####### |
238
|
|
|
|
|
|
|
sub _hack_guess_license_from_meta { |
239
|
0
|
|
|
0
|
|
|
my $license_str = shift; |
240
|
0
|
|
|
|
|
|
my @guess; |
241
|
|
|
|
|
|
|
try { |
242
|
0
|
|
|
0
|
|
|
my $hack = 'license : ' . $license_str; |
243
|
0
|
|
|
|
|
|
@guess = Software::LicenseUtils->guess_license_from_meta($hack); |
244
|
0
|
|
|
|
|
|
}; |
245
|
0
|
|
|
|
|
|
return @guess; |
246
|
|
|
|
|
|
|
} |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
1; |
250
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
__END__ |