blib/lib/Module/MetaInfo/DirTree.pm

filter: Statementstmt 100% 71 / 71 Branchbran 81.5% 31 / 38 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 12 / 12 Podpod 0.0% 0 / 1 totaltotal 93.4% 114 / 122 CC 21 SCAR 16.9
CC
21
Cov
94%
AUTOLOAD
9.2
_search_config_file
7.0
_read_file
5.0
CRAP 5.4
« blib/lib/Module/MetaInfo/_Extractor.pm ↑ Summary
1 package Module::MetaInfo::DirTree;
2 2 $VERSION = "0.01";
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use Symbol;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use Module::MetaInfo::_Extractor;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 2 ▶use vars qw(@ISA $AUTOLOAD);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 2 @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</pck/i>.
28  
29 Within that directory all names starting with C<opt_> are reserved for
30 subdirectories for use for meta information which overrides the
31 default in special circumstances. E.g. C<opt_rpm> 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<pkg-data-XXX/description> 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<PkgData> directory in the base
93 directory of the perl module. Calling the <add_option> function will
94 mean that the directory C<PkgData/opt_ARG> directory will be checked
95 where ARG is the argument to C<add_option>. Option directories are
96 checked before the main package directory.
97  
98 Calling the C<add_data_dir> function will cause the
99 C<ARG/package_name> 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 12 ▶sub _check_data_version {
Subroutine _check_data_version: called CC=1 SCAR=0.0
118 12 return 1;
119 }
120  
121 5 ▶sub _read_file {
Subroutine _read_file: called CC=5 SCAR=16.2
122 5 my $self=shift;
123 5 my $filepath=shift;
124 5 my $fh = Symbol::gensym();
125 5 ▶ open ($fh, $filepath) || die "Failed to open file " .
Branch: 1 branch
BranchTrueFalseTotal
open $fh, $filepath or die 'Failed to open file ' . $filepath . ": $!" 5 0 5
126 $filepath . ": $!";
127 print STDERR "Reading ". $filepath ."\n"
128 5 ▶ if ${$self->{'_verbose'}};
Branch: 1 branch
BranchTrueFalseTotal
if ${$self->{"_verbose"};} 2 3 5
129 5 my $returnme="";
130 5 ▶ while (<$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $fh)) 25 5 30
131 25 $returnme .= $_;
132 }
133 5 ▶ close($fh) or die "Failed to close " . $filepath . ": $!";
Branch: 1 branch
BranchTrueFalseTotal
close $fh or die 'Failed to close ' . $filepath . ": $!" 5 0 5
134 5 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 12 ▶sub _search_path {
Subroutine _search_path: called CC=1 SCAR=0.0
155 12 my $self=shift;
156 12 return ${$self->{"_scratch_dir"}} .'/'. $self->{distname}
157 12 .'/'. $self->{package_name} .'/'. "PkgData";
158 }
159  
160 12 ▶sub _search_config_file {
Subroutine _search_config_file: called CC=7 SCAR=19.5
161 12 my $self=shift;
162 12 my $filename=shift;
163  
164 12 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 print STDERR "searching for $filename\n"
170 12 ▶ if ${$self->{'_verbose'}};
Branch: 1 branch
BranchTrueFalseTotal
if ${$self->{"_verbose"};} 4 8 12
171  
172 12 foreach my $dir ( $self->_search_path() ) {
173 12 _check_data_version($dir);
174 print STDERR "Checking for $filename in given data directory\n"
175 12 ▶ if ${$self->{'_verbose'}};
Branch: 1 branch
BranchTrueFalseTotal
if ${$self->{"_verbose"};} 4 8 12
176 12 my $file = $dir . '/' . $filename;
177 12 ▶ $returnme = $self->_read_file($file) if -e $file;
Branch: 1 branch
BranchTrueFalseTotal
if -e $file 5 7 12
178 12 ▶ return $returnme if defined $returnme;
Branch: 1 branch
BranchTrueFalseTotal
if defined $returnme 5 7 12
179 }
180 print STDERR "Couldn't find a data file named $filename anywhere\n"
181 7 ▶ if ${$self->{'_verbose'}};
Branch: 1 branch
BranchTrueFalseTotal
if ${$self->{"_verbose"};} 2 5 7
182 7 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 2 my %meta_infos = ( "description" => 1, "doc_files" => 2 );
189  
190 17 ▶sub AUTOLOAD {
Subroutine AUTOLOAD: called CC=9 SCAR=22.2
191 17 (my $sub = $AUTOLOAD) =~ s/.*:://;
192 17 ▶ $sub =~ m/^DESTROY$/ && return;
Branch: 1 branch
BranchTrueFalseTotal
$sub =~ /^DESTROY$/ and return 5 12 17
193 12 my $self=shift;
194 12 ▶ croak "Function call into Module::MetaInfo wasn't a method call"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 0 12 12
195 unless ref $self;
196 print STDERR "In autoload with sub $sub\n"
197 12 ▶ if ${$self->{'_verbose'}};
Branch: 1 branch
BranchTrueFalseTotal
if ${$self->{"_verbose"};} 4 8 12
198 12 my $return=undef;
199 12 my $meta_sub=$meta_infos{$sub};
200 12 ▶ croak "meta information function $sub undefined" unless $meta_infos{$sub};
Branch: 1 branch
BranchTrueFalseTotal
unless $meta_infos{$sub} 0 12 12
201
202 12 ▶ $meta_sub == 1 && return $self->_search_config_file($sub);
Branch: 1 branch
BranchTrueFalseTotal
$meta_sub == 1 and return $self->_search_config_file($sub) 7 5 12
203 5 ▶ $meta_sub == 2 && do {
Branch: 1 branch
BranchTrueFalseTotal
$meta_sub == 2 and do { my $file = $self->_search_config_file($sub); return undef unless defined $file; my(@elts) = grep(/\S/, split(/\s+/, $file, 0)); return wantarray ? @elts : \@elts } 5 0 5
204 5 my $file=$self->_search_config_file($sub);
205 5 ▶ return undef unless defined $file;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $file 2 3 5
206 3 my @elts=grep ( /\S/, split /\s+/, $file);
207 3 ▶ return wantarray ? @elts : \@elts;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 3 3
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 10 ▶sub can {
Subroutine can: called CC=3 SCAR=11.0
Pod undocumented
217 10 my $self=shift;
218 10 my $func=shift;
219 10 my $can = $self->SUPER::can($func);
220  
221 10 ▶ return $can if defined $can;
Branch: 1 branch
BranchTrueFalseTotal
if defined $can 0 10 10
222  
223 10 ▶ return 1 if $meta_infos{$func};
Branch: 1 branch
BranchTrueFalseTotal
if $meta_infos{$func} 8 2 10
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
« blib/lib/Module/MetaInfo/_Extractor.pm ↑ Summary