line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::RPM::Spec::License; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
78082
|
use strict; |
|
2
|
|
|
|
|
11
|
|
|
2
|
|
|
|
|
58
|
|
4
|
2
|
|
|
2
|
|
12
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
48
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
987
|
use English; |
|
2
|
|
|
|
|
7301
|
|
|
2
|
|
|
|
|
12
|
|
7
|
2
|
|
|
2
|
|
3416
|
use Error::Pure qw(err); |
|
2
|
|
|
|
|
14854
|
|
|
2
|
|
|
|
|
45
|
|
8
|
2
|
|
|
2
|
|
1168
|
use File::Find::Rule; |
|
2
|
|
|
|
|
16643
|
|
|
2
|
|
|
|
|
16
|
|
9
|
2
|
|
|
2
|
|
4208
|
use Getopt::Std; |
|
2
|
|
|
|
|
112
|
|
|
2
|
|
|
|
|
126
|
|
10
|
2
|
|
|
2
|
|
892
|
use Parse::RPM::Spec; |
|
2
|
|
|
|
|
1253599
|
|
|
2
|
|
|
|
|
1233
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = 0.01; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
$| = 1; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# Constructor. |
17
|
|
|
|
|
|
|
sub new { |
18
|
0
|
|
|
0
|
1
|
|
my ($class, @params) = @_; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
# Create object. |
21
|
0
|
|
|
|
|
|
my $self = bless {}, $class; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
# Object. |
24
|
0
|
|
|
|
|
|
return $self; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# Run. |
28
|
|
|
|
|
|
|
sub run { |
29
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# Process arguments. |
32
|
0
|
|
|
|
|
|
$self->{'_opts'} = { |
33
|
|
|
|
|
|
|
'f' => 0, |
34
|
|
|
|
|
|
|
'g' => '*', |
35
|
|
|
|
|
|
|
'h' => 0, |
36
|
|
|
|
|
|
|
's' => 0, |
37
|
|
|
|
|
|
|
}; |
38
|
0
|
0
|
0
|
|
|
|
if (! getopts('fg:hs', $self->{'_opts'}) || $self->{'_opts'}->{'h'}) { |
39
|
0
|
|
|
|
|
|
print STDERR "Usage: $0 [-f] [-g file_glog] [-h] [-s] [--version] [file_or_dir]\n"; |
40
|
0
|
|
|
|
|
|
print STDERR "\t-f\t\tPrint spec file name.\n"; |
41
|
0
|
|
|
|
|
|
print STDERR "\t-g file_glob\tFile glob (default is * = *.spec).\n"; |
42
|
0
|
|
|
|
|
|
print STDERR "\t-h\t\tPrint help.\n"; |
43
|
0
|
|
|
|
|
|
print STDERR "\t-s\t\tSkip errors.\n"; |
44
|
0
|
|
|
|
|
|
print STDERR "\t--version\tPrint version.\n"; |
45
|
0
|
|
|
|
|
|
print STDERR "\tfile_or_dir\tFile or directory to check license in spec ". |
46
|
|
|
|
|
|
|
"files (default is actual directory)\n"; |
47
|
0
|
|
|
|
|
|
return 1; |
48
|
|
|
|
|
|
|
} |
49
|
0
|
|
0
|
|
|
|
$self->{'_file_or_dir'} = shift @ARGV || '.'; |
50
|
|
|
|
|
|
|
|
51
|
0
|
0
|
|
|
|
|
if (-f $self->{'_file_or_dir'}) { |
|
|
0
|
|
|
|
|
|
52
|
0
|
|
|
|
|
|
$self->_process_spec_file($self->{'_file_or_dir'}); |
53
|
|
|
|
|
|
|
} elsif (-d $self->{'_file_or_dir'}) { |
54
|
0
|
|
|
|
|
|
foreach my $spec_file (File::Find::Rule->file |
55
|
|
|
|
|
|
|
->name($self->{'_opts'}->{'g'}.'.spec')->in($self->{'_file_or_dir'})) { |
56
|
|
|
|
|
|
|
|
57
|
0
|
|
|
|
|
|
$self->_process_spec_file($spec_file); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
} else { |
60
|
|
|
|
|
|
|
err 'Cannot process file or dir.', |
61
|
0
|
|
|
|
|
|
'Input', $self->{'_file_or_dir'}, |
62
|
|
|
|
|
|
|
; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
|
return 0; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub _process_spec_file { |
69
|
0
|
|
|
0
|
|
|
my ($self, $spec_file) = @_; |
70
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
my $rpm_spec = eval { |
72
|
0
|
|
|
|
|
|
Parse::RPM::Spec->new({'file' => $spec_file}); |
73
|
|
|
|
|
|
|
}; |
74
|
0
|
0
|
|
|
|
|
if ($EVAL_ERROR) { |
75
|
0
|
0
|
|
|
|
|
if (! $self->{'_opts'}->{'s'}) { |
76
|
0
|
|
|
|
|
|
err "Failing of '$spec_file'.", |
77
|
|
|
|
|
|
|
'Error', $EVAL_ERROR, |
78
|
|
|
|
|
|
|
; |
79
|
|
|
|
|
|
|
} else { |
80
|
0
|
|
|
|
|
|
print STDERR "Skip spec file '$spec_file' (error).\n"; |
81
|
0
|
|
|
|
|
|
return; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
} |
84
|
0
|
0
|
|
|
|
|
if (defined $rpm_spec->license) { |
85
|
0
|
0
|
|
|
|
|
if ($self->{'_opts'}->{'f'}) { |
86
|
0
|
|
|
|
|
|
print $spec_file.': '; |
87
|
|
|
|
|
|
|
} |
88
|
0
|
|
|
|
|
|
print $rpm_spec->license."\n"; |
89
|
|
|
|
|
|
|
} else { |
90
|
0
|
|
|
|
|
|
print STDERR "Skip spec file '$spec_file' (no license).\n"; |
91
|
0
|
|
|
|
|
|
return; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
0
|
|
|
|
|
|
return; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
1; |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
__END__ |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=pod |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=encoding utf8 |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=head1 NAME |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
App::RPM::Spec::License - Base class for rpm-spec-license tool. |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head1 SYNOPSIS |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
use App::RPM::Spec::License; |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
my $app = App::RPM::Spec::License->new; |
115
|
|
|
|
|
|
|
my $exit_code = $app->run; |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=head1 METHODS |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head2 C<new> |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
my $app = App::RPM::Spec::License->new; |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
Constructor. |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
Returns instance of object. |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head2 C<run> |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
my $exit_code = $app->run; |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
Run. |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
Returns 1 for error, 0 for success. |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=head1 EXAMPLE |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=for comment filename=print_license.pl |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
use strict; |
140
|
|
|
|
|
|
|
use warnings; |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
use App::RPM::Spec::License; |
143
|
|
|
|
|
|
|
use File::Temp; |
144
|
|
|
|
|
|
|
use File::Spec::Functions qw(catfile); |
145
|
|
|
|
|
|
|
use IO::Barf qw(barf); |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
# Temp dir. |
148
|
|
|
|
|
|
|
my $temp_dir = File::Temp->newdir; |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
barf(catfile($temp_dir, 'ex1.spec'), <<'END'); |
151
|
|
|
|
|
|
|
License: BSD |
152
|
|
|
|
|
|
|
END |
153
|
|
|
|
|
|
|
barf(catfile($temp_dir, 'ex2.spec'), <<'END'); |
154
|
|
|
|
|
|
|
License: MIT |
155
|
|
|
|
|
|
|
END |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
# Arguments. |
158
|
|
|
|
|
|
|
@ARGV = ( |
159
|
|
|
|
|
|
|
$temp_dir, |
160
|
|
|
|
|
|
|
); |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
# Run. |
163
|
|
|
|
|
|
|
exit App::RPM::Spec::License->new->run; |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
# Output: |
166
|
|
|
|
|
|
|
# BSD |
167
|
|
|
|
|
|
|
# MIT |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=head1 DEPENDENCIES |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
L<English>, |
172
|
|
|
|
|
|
|
L<Error::Pure>, |
173
|
|
|
|
|
|
|
L<File::Find::Rule>, |
174
|
|
|
|
|
|
|
L<Getopt::Std>. |
175
|
|
|
|
|
|
|
L<Parse::RPM::Spec>, |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=head1 REPOSITORY |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
L<https://github.com/michal-josef-spacek/App-RPM-Spec-License> |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=head1 AUTHOR |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
Michal Josef Špaček L<mailto:skim@cpan.org> |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
L<http://skim.cz> |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
© 2023 Michal Josef Špaček |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
BSD 2-Clause License |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=head1 VERSION |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
0.01 |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
=cut |