line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Module::MetaInfo::DirTree; |
2
|
|
|
|
|
|
|
$VERSION = "0.01"; |
3
|
2
|
|
|
2
|
|
761
|
use warnings; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
63
|
|
4
|
2
|
|
|
2
|
|
10
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
63
|
|
5
|
2
|
|
|
2
|
|
9
|
use Carp; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
159
|
|
6
|
2
|
|
|
2
|
|
1008
|
use Symbol; |
|
2
|
|
|
|
|
1011
|
|
|
2
|
|
|
|
|
124
|
|
7
|
2
|
|
|
2
|
|
517
|
use Module::MetaInfo::_Extractor; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
51
|
|
8
|
|
|
|
|
|
|
|
9
|
2
|
|
|
2
|
|
9
|
use vars qw(@ISA $AUTOLOAD); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
1843
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
@ISA= qw(Module::MetaInfo::_Extractor); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 NAME |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
DirTree - get metainfo from a directory in a the perl module |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 DESCRIPTION |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
This is a (experimental) module designed to get meta information from |
21
|
|
|
|
|
|
|
a special directory which is kept inside the perl-module. |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head1 DIRECTORY NAME |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
The main directory for meta data is PkgData. This name is chosen |
26
|
|
|
|
|
|
|
because within the CPAN collection distributed by RedHat none of the |
27
|
|
|
|
|
|
|
existing modules had any files matching C. |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
Within that directory all names starting with C are reserved for |
30
|
|
|
|
|
|
|
subdirectories for use for meta information which overrides the |
31
|
|
|
|
|
|
|
default in special circumstances. E.g. C is for data which |
32
|
|
|
|
|
|
|
should be different specifically for rpm. |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=head1 DIRECTORY FORMAT |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
The directory contains files which contain the meta information. The |
37
|
|
|
|
|
|
|
files each have their own format. |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=head2 summary |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
This should contain a one line summary of what the module is for. |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head2 description |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
This contains the description of the module. This should be a few |
46
|
|
|
|
|
|
|
lines of text which explain what the module does. At present this |
47
|
|
|
|
|
|
|
should be in plain text format (ASCII - no internationalisation !??!). |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
A typical maximum length would be about 20-30 lines. |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head2 doc |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
This will contain a list of documentation file names, one per line. |
54
|
|
|
|
|
|
|
The names can refer to individual files or whole directories. They |
55
|
|
|
|
|
|
|
are relative to the top level directory of the perl module. |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head2 BuildMe.PL |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
This file contains a perl script for building the meta information. |
60
|
|
|
|
|
|
|
This script will be run with the current directory the main directory |
61
|
|
|
|
|
|
|
of the distribution |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
Avoid using this script |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head2 override directory |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
In order to provide your own descriptions of certain RPMs, you can put |
68
|
|
|
|
|
|
|
a file with the name of the module into a specified directory. This |
69
|
|
|
|
|
|
|
will then be used in the description field exactly as it is. This |
70
|
|
|
|
|
|
|
file will override all other possibilities since we assume that the |
71
|
|
|
|
|
|
|
package builder could delete the override file if wanted. Where there |
72
|
|
|
|
|
|
|
turns out to be an C as well as a description we |
73
|
|
|
|
|
|
|
give a warning. |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head2 rpm specific build scripts |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
build.sh install.sh clean.sh pre.sh post.sh preun.sh postun.sh |
78
|
|
|
|
|
|
|
verify.sh |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
These give direct access to the various RPM scripts of (almost)the |
81
|
|
|
|
|
|
|
same names. The text included is copied verbatim into the spec file. |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
The prep and build scripts are run after makerpm's normal options. |
84
|
|
|
|
|
|
|
The clean script is run before hand (whilst the build directory is |
85
|
|
|
|
|
|
|
still there) install script is run after deleting the previous build |
86
|
|
|
|
|
|
|
root, but before running the normal install options. This means that |
87
|
|
|
|
|
|
|
you have to create your own directories. |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head1 SEARCH PATH |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
The default search path is only the C directory in the base |
93
|
|
|
|
|
|
|
directory of the perl module. Calling the function will |
94
|
|
|
|
|
|
|
mean that the directory C directory will be checked |
95
|
|
|
|
|
|
|
where ARG is the argument to C. Option directories are |
96
|
|
|
|
|
|
|
checked before the main package directory. |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
Calling the C function will cause the |
99
|
|
|
|
|
|
|
C directory to be searched. |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
Each directory on the path is checked in turn. |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head1 RULES FOR CREATING META INFO FILES |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
When creating a metainfo file, the general rule is to always create |
106
|
|
|
|
|
|
|
the file in the generic (top level) directory. The opt directories |
107
|
|
|
|
|
|
|
should only be used for special cases. |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=cut |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=head2 $self->_read_file() |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
Given a filename this simply returns the contents. |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=cut |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
sub _check_data_version { |
118
|
12
|
|
|
12
|
|
21
|
return 1; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub _read_file { |
122
|
6
|
|
|
6
|
|
21
|
my $self=shift; |
123
|
6
|
|
|
|
|
214
|
my $filepath=shift; |
124
|
6
|
|
|
|
|
45
|
my $fh = Symbol::gensym(); |
125
|
6
|
50
|
|
|
|
606
|
open ($fh, $filepath) || die "Failed to open file " . |
126
|
|
|
|
|
|
|
$filepath . ": $!"; |
127
|
6
|
|
|
|
|
39
|
print STDERR "Reading ". $filepath ."\n" |
128
|
6
|
100
|
|
|
|
18
|
if ${$self->{'_verbose'}}; |
129
|
6
|
|
|
|
|
20
|
my $returnme=""; |
130
|
6
|
|
|
|
|
3195
|
while (<$fh>) { |
131
|
33
|
|
|
|
|
562
|
$returnme .= $_; |
132
|
|
|
|
|
|
|
} |
133
|
6
|
50
|
|
|
|
131
|
close($fh) or die "Failed to close " . $filepath . ": $!"; |
134
|
6
|
|
|
|
|
31
|
return $returnme; |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=head2 $self->_search_config_file() |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
this finds the correct configuration file for a given name by |
141
|
|
|
|
|
|
|
searching through the path of different directories where it could be |
142
|
|
|
|
|
|
|
then calling _read_file() to read the file and returns the contents of |
143
|
|
|
|
|
|
|
the file. |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=cut |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
#search |
148
|
|
|
|
|
|
|
# |
149
|
|
|
|
|
|
|
#This function takes a filename and returns the entire contents of |
150
|
|
|
|
|
|
|
#that file from the override directory or the module directory. |
151
|
|
|
|
|
|
|
# |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
sub _search_path { |
155
|
12
|
|
|
12
|
|
65
|
my $self=shift; |
156
|
12
|
|
|
|
|
17
|
return ${$self->{"_scratch_dir"}} .'/'. $self->{distname} |
|
12
|
|
|
|
|
90
|
|
157
|
|
|
|
|
|
|
.'/'. $self->{package_name} .'/'. "PkgData"; |
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
sub _search_config_file { |
161
|
12
|
|
|
12
|
|
24
|
my $self=shift; |
162
|
12
|
|
|
|
|
36
|
my $filename=shift; |
163
|
|
|
|
|
|
|
|
164
|
12
|
|
|
|
|
53
|
my $returnme=undef; |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
# my $user_file = $self->{"user-data-dir"} . "/" . $filename; |
167
|
|
|
|
|
|
|
# my $pkg_own_file = $self->{"perl-data-dir"} . "/" . $filename; |
168
|
|
|
|
|
|
|
|
169
|
12
|
|
|
|
|
72
|
print STDERR "searching for $filename\n" |
170
|
12
|
100
|
|
|
|
19
|
if ${$self->{'_verbose'}}; |
171
|
|
|
|
|
|
|
|
172
|
12
|
|
|
|
|
58
|
foreach my $dir ( $self->_search_path() ) { |
173
|
12
|
|
|
|
|
40
|
_check_data_version($dir); |
174
|
12
|
|
|
|
|
58
|
print STDERR "Checking for $filename in given data directory\n" |
175
|
12
|
100
|
|
|
|
14
|
if ${$self->{'_verbose'}}; |
176
|
12
|
|
|
|
|
35
|
my $file = $dir . '/' . $filename; |
177
|
12
|
100
|
|
|
|
1053
|
$returnme = $self->_read_file($file) if -e $file; |
178
|
12
|
100
|
|
|
|
76
|
return $returnme if defined $returnme; |
179
|
|
|
|
|
|
|
} |
180
|
6
|
|
|
|
|
34
|
print STDERR "Couldn't find a data file named $filename anywhere\n" |
181
|
6
|
100
|
|
|
|
15
|
if ${$self->{'_verbose'}}; |
182
|
6
|
|
|
|
|
25
|
return undef; |
183
|
|
|
|
|
|
|
} |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
#1 for whole file returns |
186
|
|
|
|
|
|
|
#2 for white space separated array returns - may become line separated |
187
|
|
|
|
|
|
|
# commented array returns.. |
188
|
|
|
|
|
|
|
my %meta_infos = ( "description" => 1, "doc_files" => 2 ); |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
sub AUTOLOAD { |
191
|
12
|
|
|
12
|
|
258
|
(my $sub = $AUTOLOAD) =~ s/.*:://; |
192
|
12
|
50
|
|
|
|
51
|
$sub =~ m/^DESTROY$/ && return; |
193
|
12
|
|
|
|
|
18
|
my $self=shift; |
194
|
12
|
50
|
|
|
|
39
|
croak "Function call into Module::MetaInfo wasn't a method call" |
195
|
|
|
|
|
|
|
unless ref $self; |
196
|
12
|
|
|
|
|
199
|
print STDERR "In autoload with sub $sub\n" |
197
|
12
|
100
|
|
|
|
24
|
if ${$self->{'_verbose'}}; |
198
|
12
|
|
|
|
|
22
|
my $return=undef; |
199
|
12
|
|
|
|
|
26
|
my $meta_sub=$meta_infos{$sub}; |
200
|
12
|
50
|
|
|
|
35
|
croak "meta information function $sub undefined" unless $meta_infos{$sub}; |
201
|
|
|
|
|
|
|
|
202
|
12
|
100
|
|
|
|
60
|
$meta_sub == 1 && return $self->_search_config_file($sub); |
203
|
5
|
50
|
|
|
|
46
|
$meta_sub == 2 && do { |
204
|
5
|
|
|
|
|
16
|
my $file=$self->_search_config_file($sub); |
205
|
5
|
100
|
|
|
|
34
|
return undef unless defined $file; |
206
|
3
|
|
|
|
|
46
|
my @elts=grep ( /\S/, split /\s+/, $file); |
207
|
3
|
50
|
|
|
|
24
|
return wantarray ? @elts : \@elts; |
208
|
|
|
|
|
|
|
} |
209
|
|
|
|
|
|
|
} |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
# can here returns 1 if the function is defined. This isn't exactly |
212
|
|
|
|
|
|
|
# what can should do since it should return a function reference. We |
213
|
|
|
|
|
|
|
# could define can to create make a little closeure which then calls the |
214
|
|
|
|
|
|
|
# correct function. Later dude... |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
sub can { |
217
|
10
|
|
|
10
|
0
|
15
|
my $self=shift; |
218
|
10
|
|
|
|
|
18
|
my $func=shift; |
219
|
10
|
|
|
|
|
78
|
my $can = $self->SUPER::can($func); |
220
|
|
|
|
|
|
|
|
221
|
10
|
50
|
|
|
|
42
|
return $can if defined $can; |
222
|
|
|
|
|
|
|
|
223
|
10
|
100
|
|
|
|
58
|
return 1 if $meta_infos{$func}; |
224
|
|
|
|
|
|
|
} |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
=head1 COPYRIGHT |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
You may distribute under the terms of either the GNU General |
229
|
|
|
|
|
|
|
Public License or the Artistic License, as specified in the |
230
|
|
|
|
|
|
|
Perl README. |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
=cut |