blib/lib/FreeBSD/Ports/INDEXhash.pm

filter: Statementstmt 17.4% 15 / 86 Branchbran 0.0% 0 / 28 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 75.0% 3 / 4 Podpod 100% 1 / 1 totaltotal 15.9% 19 / 119 CC 15 SCAR 53.0
CC
15
Cov
13%
INDEXhash
240.0
BEGIN
1.0
BEGIN
1.0
CRAP 200.2
↑ Summary
1 package FreeBSD::Ports::INDEXhash;
2  
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 vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 require Exporter;
7  
8 2 @EXPORT_OK = qw(INDEXhash);
9 2 @ISA = qw(Exporter);
10 2 @EXPORT = ();
11  
12 =head1 NAME
13  
14 FreeBSD::Ports::INDEXhash - Generates a hash out of the FreeBSD Ports index file.
15  
16 =head1 VERSION
17  
18 Version 1.2.2
19  
20 =cut
21  
22 2 our $VERSION = '1.2.2';
23  
24  
25 =head1 SYNOPSIS
26  
27 use FreeBSD::Ports::INDEXhash qw/INDEXhash/;
28  
29 my %hash=INDEXhash();
30  
31 while(my ($name, $port) = each %hash){
32 print "Name: ".$name."\n".
33 "Info: ".$port->{info}."\n".
34 "Prefix: ".$port->{prefix}."\n".
35 "Maintainer: ".$port->{maintainer}."\n".
36 "WWW: ".$port->{www}."\n".
37 "Categories: ".join(" ", @{$port->{categories}})."\n".
38 "E-deps: ".join(" ", @{$port->{Edeps}})."\n".
39 "B-deps: ".join(" ", @{$port->{Bdeps}})."\n".
40 "P-deps: ".join(" ", @{$port->{Pdeps}})."\n".
41 "R-deps: ".join(" ", @{$port->{Rdeps}})."\n".
42 "F-deps: ".join(" ", @{$port->{Fdeps}})."\n".
43 "\n";
44  
45 $keysInt++;
46 };
47  
48  
49 =head1 EXPORT
50  
51 INDEXhash
52  
53 =head1 FUNCTIONS
54  
55 =head2 INDEXhash
56  
57 This parses the FreeBSD ports index file and a hash of it. Upon error it returns undef.
58  
59 If a path to it is not passed to this function, it chooses the file automatically. The
60 PORTSDIR enviromental varaiable is respected if using automatically.
61  
62 =cut
63  
64 0 ▶sub INDEXhash {
Subroutine INDEXhash: not called CC=15 SCAR=54.8
Pod documented
65 0 my $index=$_[0];
66
67 0 ▶ if(!defined($index)){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $index) 0 0 0
68 0 ▶ if(!defined($ENV{PORTSDIR})){
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $ENV{'PORTSDIR'}) { } 0 0 0
69 0 $index="/usr/ports/INDEX-";
70  
71 }else{
72 0 $index=$ENV{PORTSDIR}."/INDEX-";
73 };
74  
75 0 my $fbsdversion=`uname -r`;
76 0 chomp($fbsdversion);
77 0 $fbsdversion =~ s/\..+// ;
78 0 $index=$index.$fbsdversion;
79  
80 0 ▶ if (! -f $index) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-f $index) 0 0 0
81 0 ▶ if(!defined($ENV{PORTSDIR})){
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $ENV{'PORTSDIR'}) { } 0 0 0
82 0 $index="/usr/ports/INDEX";
83
84 }else{
85 0 $index=$ENV{PORTSDIR}."/INDEX";
86 };
87 }
88  
89 };
90  
91 #error out if the it is not a file
92 0 ▶ if(! -f $index){
Branch: 1 branch
BranchTrueFalseTotal
unless (-f $index) 0 0 0
93 0 return undef;
94 };
95
96 #read the index file
97 0 ▶ if(!open(INDEXFILE, $index)){
Branch: 1 branch
BranchTrueFalseTotal
unless (open INDEXFILE, $index) 0 0 0
98 0 return undef;
99 };
100 0 my @rawindex=<INDEXFILE>;
101 0 close(INDEXFILE);
102
103 0 my %hash=(orginsN2D=>{}, originsD2N=>{});
104
105 0 my $rawindexInt=0;
106 0 ▶ while(defined($rawindex[$rawindexInt])){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $rawindex[$rawindexInt]) 0 0 0
107 0 my @linesplit=split(/\|/, $rawindex[$rawindexInt]);
108  
109 0 $hash{$linesplit[0]}={path=>$linesplit[1],
110 prefix=>$linesplit[2],
111 info=>$linesplit[3],
112 maintainer=>$linesplit[5],
113 www=>$linesplit[9],
114 Bdeps=>[],
115 Rdeps=>[],
116 Edeps=>[],
117 Pdeps=>[],
118 Fdeps=>[],
119 categories=>[]
120 };
121  
122 #builds the origin mappings
123 0 $hash{originsN2D}{$linesplit[0]}=$linesplit[1];
124 0 $hash{originsD2N}{$linesplit[1]}=$linesplit[0];
125 #builds the short origin mappings
126 0 $hash{soriginsN2D}{$linesplit[0]}=$linesplit[1];
127 0 $hash{soriginsN2D}{$linesplit[0]}=~s/\/usr\/ports\///;
128 0 ▶ if (defined($ENV{PORTSDIR})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ENV{"PORTSDIR"}) 0 0 0
129 0 $hash{soriginsN2D}{$linesplit[0]}=~s/$ENV{PORTSDIR}//;
130 0 $hash{soriginsN2D}{$linesplit[0]}=~s/^\///;
131 }
132 0 $hash{soriginsD2N}{$hash{soriginsN2D}{$linesplit[0]}}=$linesplit[0];
133  
134 0 my $depsInt=0;
135 0 chomp($linesplit[12]);
136 0 my @Fdeps=split(/ /, $linesplit[12]);
137 0 ▶ while(defined($Fdeps[$depsInt])){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $Fdeps[$depsInt]) 0 0 0
138 0 push(@{$hash{$linesplit[0]}{Fdeps}}, $Fdeps[$depsInt]);
139
140 0 $depsInt++;
141 };
142  
143  
144 0 $depsInt=0;
145 0 my @Pdeps=split(/ /, $linesplit[11]);
146 0 ▶ while(defined($Pdeps[$depsInt])){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $Pdeps[$depsInt]) 0 0 0
147 0 push(@{$hash{$linesplit[0]}{Pdeps}}, $Pdeps[$depsInt]);
148  
149 0 $depsInt++;
150 };
151  
152 0 $depsInt=0;
153 0 my @Edeps=split(/ /, $linesplit[10]);
154 0 ▶ while(defined($Edeps[$depsInt])){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $Edeps[$depsInt]) 0 0 0
155 0 push(@{$hash{$linesplit[0]}{Edeps}}, $Edeps[$depsInt]);
156  
157 0 $depsInt++;
158 };
159  
160 0 $depsInt=0;
161 0 my @Rdeps=split(/ /, $linesplit[8]);
162 0 ▶ while(defined($Rdeps[$depsInt])){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $Rdeps[$depsInt]) 0 0 0
163 0 push(@{$hash{$linesplit[0]}{Rdeps}}, $Rdeps[$depsInt]);
164  
165 0 $depsInt++;
166 };
167  
168 0 $depsInt=0;
169 0 my @Bdeps=split(/ /, $linesplit[7]);
170 0 ▶ while(defined($Bdeps[$depsInt])){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $Bdeps[$depsInt]) 0 0 0
171 0 push(@{$hash{$linesplit[0]}{Bdeps}}, $Bdeps[$depsInt]);
172  
173 0 $depsInt++;
174 };
175  
176 0 $depsInt=0;
177 0 my @categories=split(/ /, $linesplit[6]);
178 0 ▶ while(defined($categories[$depsInt])){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $categories[$depsInt]) 0 0 0
179 0 push(@{$hash{$linesplit[0]}{categories}}, $categories[$depsInt]);
180  
181 0 $depsInt++;
182 };
183  
184 0 $rawindexInt++;
185 };
186
187 0 return %hash;
188 };
189  
190 =head1 HASH FORMAT
191  
192 Each entry, minus 'originsN2D' and 'originsD2N'.
193  
194 =head2 ports hash
195  
196 =head3 info
197  
198 This is a short description of the port.
199  
200 =head3 prefix
201  
202 This is the install prefix the port will try to use.
203  
204 =head3 maintainer
205  
206 This is the email address for the port's maintainer.
207  
208 =head3 www
209  
210 This is the web site of a port inquestion.
211  
212 =head3 Edeps
213  
214 This is the extract depends of a port. This is a array.
215  
216 =head3 Bdeps
217  
218 This is the build depends for the port. This is a array.
219  
220 =head3 Pdeps
221  
222 This is the package depends for a port. This is a array.
223  
224 =head3 Rdeps
225  
226 This is the run depends of a port. This is a array.
227  
228 =head3 Fdeps
229  
230 This is the fetch depends of a port. This is a array.
231  
232 =head3 categories
233  
234 This is all the categories a specific port falls under. This is a array.
235  
236 =head2 originsN2D
237  
238 This contains a mapping of port names to the directory they are in.
239  
240 =head2 originsD2N
241  
242 This contains a mapping of directories to port names.
243  
244 =head2 soriginsD2N
245  
246 This is the same as 'originsD2N', but does not everything prior to
247 the ports directory is removed. This is to make it easy for matching
248 packages to ports.
249  
250 =head2 originsN2D
251  
252  
253 This is the same as 'originsN2D', but does not everything prior to
254 the ports directory is removed.
255  
256 =head1 AUTHOR
257  
258 Zane C. Bowers, C<< <vvelox at vvelox.net> >>
259  
260 =head1 BUGS
261  
262 Please report any bugs or feature requests to C<bug-freebsd-ports-indexhash at rt.cpan.org>, or through
263 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=FreeBSD-Ports-INDEXhash>. I will be notified, and then you'll
264 automatically be notified of progress on your bug as I make changes.
265  
266  
267  
268  
269 =head1 SUPPORT
270  
271 You can find documentation for this module with the perldoc command.
272  
273 perldoc FreeBSD::Ports::INDEXhash
274  
275  
276 You can also look for information at:
277  
278 =over 4
279  
280 =item * RT: CPAN's request tracker
281  
282 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=FreeBSD-Ports-INDEXhash>
283  
284 =item * AnnoCPAN: Annotated CPAN documentation
285  
286 L<http://annocpan.org/dist/FreeBSD-Ports-INDEXhash>
287  
288 =item * CPAN Ratings
289  
290 L<http://cpanratings.perl.org/d/FreeBSD-Ports-INDEXhash>
291  
292 =item * Search CPAN
293  
294 L<http://search.cpan.org/dist/FreeBSD-Ports-INDEXhash>
295  
296 =back
297  
298  
299 =head1 ACKNOWLEDGEMENTS
300  
301 kevin brintnall <kbrint@rufus.net> for pointing out how useful the each function is.
302  
303 Yen-Ming Lee <leeym@freebsd.org> for pointing out the issue with Fdeps always being defined due to a new line on the end of it.
304  
305 =head1 COPYRIGHT & LICENSE
306  
307 Copyright 2008 Zane C. Bowers, all rights reserved.
308  
309 This program is free software; you can redistribute it and/or modify it
310 under the same terms as Perl itself.
311  
312  
313 =cut
314  
315 2 1; # End of FreeBSD::Ports::INDEXhash
↑ Summary