Slackget/SpecialFiles/FILELIST.pm

filter: Statementstmt 26.1% 17 / 65 Branchbran 0.0% 0 / 18 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 33.3% 5 / 15 Podpod 100% 10 / 10 totaltotal 27.1% 32 / 118 CC 14 SCAR 33.1
CC
14
Cov
19%
compile
72.0
new
30.0
to_xml
6.0
CRAP 27.4
« Slackget/Network/Connection/FILE.pm ↑ Summary Slackget/PkgTools.pm »
1 package Slackware::Slackget::SpecialFiles::FILELIST;
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  
6 2 ▶use Slackware::Slackget::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use Slackware::Slackget::Date;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use Slackware::Slackget::Package;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 =head1 NAME
11  
12 Slackware::Slackget::SpecialFiles::FILELIST - An interface for the special file FILELIST.TXT
13  
14 =head1 VERSION
15  
16 Version 1.0.0
17  
18 =cut
19  
20 2 our $VERSION = '1.0.0';
21  
22 =head1 SYNOPSIS
23  
24 This class contain all methods for the treatment of the FILELIST.TXT file
25  
26 use Slackware::Slackget::SpecialFiles::FILELIST;
27  
28 my $spec_file = Slackware::Slackget::SpecialFiles::FILELIST->new('FILELIST.TXT');
29 $spec_file->compil();
30 my $ref = $spec_file->get_file_list() ;
31  
32 This class care about package-namespace, which is the root set of a package (slackware, extra or pasture for packages from Slackware)
33  
34 =head1 WARNINGS
35  
36 All classes from the Slackware::Slackget::SpecialFiles:: namespace need the followings methods :
37  
38 - a contructor new()
39 - a method compil()
40 - a method get_result(), which one can be an alias on another method of the class.
41  
42 Moreover, the get_result() methode need to return a hashref. Keys of this hashref are the filenames.
43  
44 Classes from ths namespace represent an abstraction of the special file they can manage so informations stored in the returned hashref must have a direct link with this special file.
45  
46 =head1 CONSTRUCTOR
47  
48 =head2 new
49  
50 Take a file, a Slackware::Slackget::Config object and an id name :
51  
52 my $spec_chk = Slackware::Slackget::SpecialFiles::CHECKSUMS->new('/home/packages/FILELIST.TXT',$config,'slackware');
53  
54 The constructor return undef if the file does not exist.
55  
56 =cut
57  
58 sub new
59 0 ▶{
Subroutine new: not called CC=5 SCAR=34.0
Pod documented
60 0 my ($class,$file,$config,$root) = @_ ;
61 0 ▶ return undef if(!defined($config) && ref($config) ne 'Slackware::Slackget::Config') ;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $config and ref $config ne "Slackware::Slackget::Config" 0 0 0
Condition0%0/3
not defined $config and ref $config ne "Slackware::Slackget::Config"
!ll&&!rl&&r
000
MC/DC0%0/2
not defined $config and ref $config ne "Slackware::Slackget::Config"
not defined $config ref $config ne "Slackware::Slackget::Config"
Truth table0%0/3
not(A) and B
A= not defined $configB= ref $config ne "Slackware::Slackget::Config"
ABresult
0X0
100
111
62 0 my $self={};
63 0 $self->{ROOT} = $root;
64 0 $self->{config}=$config;
65 0 ▶ return undef unless(defined($file) && -e $file);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $file and -e $file 0 0 0
Condition0%0/3
defined $file and -e $file
!ll&&!rl&&r
000
MC/DC0%0/2
defined $file and -e $file
defined $file -e $file
Truth table0%0/3
A and B
A= defined $fileB= -e $file
ABresult
0X0
100
111
66 # print "[debug FILELIST] Loading $file as FILELIST\n";
67 0 $self->{FILE} = new Slackware::Slackget::File ($file,'file-encoding' => $config->{common}->{'file-encoding'});
68 0 $self->{DATA} = {};
69 0 bless($self,$class);
70 0 return $self;
71 }
72  
73 =head1 FUNCTIONS
74  
75 =head2 compile
76  
77 This method take no arguments, and extract the list of couple (file/package-namespace). Those couple are store into an internal data structure.
78  
79 $list->compile();
80  
81 =cut
82  
83 0 ▶sub compile {
Subroutine compile: not called CC=8 SCAR=42.8
Pod documented
84 0 my $self = shift;
85 0 ▶ if($self->{FILE}->Get_line(0)=~ /(\w+) (\w+) (\d+) ([\d:]+) \w+ (\d+)/) # match a date like : Tue Apr 5 12:56:29 PDT 2005
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"FILE"}->Get_line(0) =~ /(\w+) (\w+) (\d+) ([\d:]+) \w+ (\d+)/) 0 0 0
86 {
87 0 $self->{METADATA}->{'date'} = new Slackware::Slackget::Date (
88 'day-name' => $1,
89 'day-number' => $3,
90 'month' => $2,
91 'hour' => $4,
92 'year' => $6
93
94 );
95 }
96 0 foreach ($self->{FILE}->Get_file()){
97 0 chomp;
98 0 ▶ next if($_=~ /\.asc\s*\n*$/i);
Branch: 1 branch
BranchTrueFalseTotal
if $_ =~ /\.asc\s*\n*$/i 0 0 0
99
100 0 ▶ if(my @m=$_=~/^([^\s]+)\s+(\d+)\s+(\w+)\s+(\w+)\s+(\d+)\s+(\d+)-(\d+)-(\d+)\s+(\d+):(\d+)\s+\.\/(.*)\/(.*)\.tgz\s*\n*$/gi){#(\d+)-(\d+)-(\d+)\s+(\d+):(\d+)\s+\.\/(.*)\/([^\/\s\n]*)\.tgz
Branch: 2 branches
BranchTrueFalseTotal
if (my(@m) = $_ =~ m[^([^\s]+)\s+(\d+)\s+(\w+)\s+(\w+)\s+(\d+)\s+(\d+)-(\d+)-(\d+)\s+(\d+):(\d+)\s+\./(.*)/(.*)\.tgz\s*\n*$]gi) { } 0 0 0
elsif ($_ =~ /\.tgz/i) { } 0 0 0
101 # 1 2 3 4 5 6 7 8 9 10 11 12
102 0 $m[10].='/'; # a fucking bad hack :(
103 0 ▶ next if ($m[10]=~ /(source|src)\//);
Branch: 1 branch
BranchTrueFalseTotal
if $m[10] =~ m[(source|src)/] 0 0 0
104 # print "matching $m[11] : \n\t",join ' ; ',@m,"\n\n";
105 0 $self->{DATA}->{$m[11]} = new Slackware::Slackget::Package ( $m[11] );
106 0 ▶ $self->{DATA}->{$m[11]}->setValue('package-source',$self->{ROOT}) if($self->{ROOT});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"ROOT"} 0 0 0
107 0 $self->{DATA}->{$m[11]}->setValue('package-location',$m[10]);
108 0 $self->{DATA}->{$m[11]}->setValue('compressed-size',int($m[4]/1024));
109 0 $self->{DATA}->{$m[11]}->setValue('package-date',new Slackware::Slackget::Date (
110 'year' => $m[5],
111 'month-number' => $m[6],
112 'day-number' => $m[7],
113 'hour' => $m[8].':'.$m[9].':00'
114 ));
115 # $self->{FILE}->Write("packages/$m[11]_$self->{ROOT}.xml",$self->{DATA}->{$m[11]}->to_XML);
116 # print "\nPAUSE\n";<STDIN>;
117 }
118 elsif($_=~/\.tgz/i){
119 0 warn "Skipping $_ even if it's a .tgz (source: $self->{ROOT})\n";
120 }
121 }
122 0 $self->{FILE}->Close();
123
124 # DEBUG ONLY
125 # unlink("filelist_$self->{ROOT}.xml") if(-e "filelist_$self->{ROOT}.xml");
126 # print "saving filelist_$self->{ROOT}.xml\n";
127 # $self->{FILE}->Write("debug/filelist_$self->{ROOT}.xml",$self->to_XML);
128 # $self->{FILE}->Close();
129 }
130  
131 =head2 get_file_list
132  
133 Return a hashref build on this model
134  
135 $ref = {
136 filename => Slackware::Slackget::Package
137 }
138  
139 my $ref = $list->get_file_list ;
140  
141 =cut
142  
143 0 ▶sub get_file_list {
Subroutine get_file_list: not called CC=1 SCAR=6.9
Pod documented
144 0 my $self = shift;
145 0 return $self->{DATA} ;
146 }
147  
148 =head2 get_package
149  
150 Return informations relative to a packages as a hashref.
151  
152 my $hashref = $list->get_package($package_name) ;
153  
154 =cut
155  
156 0 ▶sub get_package {
Subroutine get_package: not called CC=1 SCAR=6.9
Pod documented
157 0 my ($self,$pack_name) = @_ ;
158 0 return $self->{DATA}->{$pack_name} ;
159 }
160  
161 =head2 get_result
162  
163 Alias for get_file_list().
164  
165 =cut
166  
167 0 ▶sub get_result {
Subroutine get_result: not called CC=1 SCAR=6.9
Pod documented
168 0 my $self = shift;
169 0 return $self->get_file_list();
170 }
171  
172 =head2 get_date
173  
174 return a Slackware::Slackget::Date object, which is the date of the FILELIST.TXT
175  
176 my $date = $list->get_date ;
177  
178 =cut
179  
180 0 ▶sub get_date {
Subroutine get_date: not called CC=1 SCAR=6.9
Pod documented
181 0 my $self = shift;
182 0 return $self->{METADATA}->{'date'} ;
183 }
184  
185 =head2 to_XML (deprecated)
186  
187 Same as to_xml(), provided for backward compatibility.
188  
189 =cut
190  
191 0 ▶sub to_XML {
Subroutine to_XML: not called CC=1 SCAR=6.9
Pod documented
192 0 return to_xml(@_);
193 }
194  
195 =head2 to_xml
196  
197 return a string containing all packages name carriage return separated.
198  
199 WARNING: ONLY FOR DEBUG
200  
201 my $string = $list->to_xml();
202  
203 =cut
204  
205 0 ▶sub to_xml {
Subroutine to_xml: not called CC=2 SCAR=17.9
Pod documented
206 0 my $self = shift;
207 0 my $xml = "<filelist>\n";
208 0 foreach (keys(%{$self->{DATA}})){
209 0 $xml .= $self->{DATA}->{$_}->to_XML ;
210 }
211 0 $xml .= "</filelist>\n";
212 0 return $xml;
213 }
214  
215 =head2 meta_to_XML (deprecated)
216  
217 Same as meta_to_xml(), provided for backward compatibility.
218  
219 =cut
220  
221 0 ▶sub meta_to_XML {
Subroutine meta_to_XML: not called CC=1 SCAR=6.9
Pod documented
222 0 return meta_to_xml(@_);
223 }
224  
225 =head2 meta_to_xml
226  
227 Return an XML encoded string which represent the meta informations of the FILELIST.TXT file.
228  
229 my $xml_string = $list->meta_to_xml ;
230  
231 =cut
232  
233 sub meta_to_xml
234 0 ▶{
Subroutine meta_to_xml: not called CC=2 SCAR=17.9
Pod documented
235 0 my $self = shift;
236 0 my $xml = "\t<filelist>\n";
237 0 ▶ $xml .= "\t\t".$self->get_date()->to_XML()."\n" if(defined($self->get_date));
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->get_date 0 0 0
238 0 $xml = "\t</filelist>\n";
239 0 return $xml;
240 }
241  
242 =head1 AUTHOR
243  
244 DUPUIS Arnaud, C<< <a.dupuis@infinityperl.org> >>
245  
246 =head1 BUGS
247  
248 Please report any bugs or feature requests to
249 C<bug-Slackware-Slackget@rt.cpan.org>, or through the web interface at
250 L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Slackware-Slackget>.
251 I will be notified, and then you'll automatically be notified of progress on
252 your bug as I make changes.
253  
254 =head1 SUPPORT
255  
256 You can find documentation for this module with the perldoc command.
257  
258 perldoc Slackware::Slackget
259  
260  
261 You can also look for information at:
262  
263 =over 4
264  
265 =item * Infinity Perl website
266  
267 L<http://www.infinityperl.org/category/slack-get>
268  
269 =item * slack-get specific website
270  
271 L<http://slackget.infinityperl.org>
272  
273 =item * RT: CPAN's request tracker
274  
275 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Slackware-Slackget>
276  
277 =item * AnnoCPAN: Annotated CPAN documentation
278  
279 L<http://annocpan.org/dist/Slackware-Slackget>
280  
281 =item * CPAN Ratings
282  
283 L<http://cpanratings.perl.org/d/Slackware-Slackget>
284  
285 =item * Search CPAN
286  
287 L<http://search.cpan.org/dist/Slackware-Slackget>
288  
289 =back
290  
291 =head1 ACKNOWLEDGEMENTS
292  
293 Thanks to Bertrand Dupuis (yes my brother) for his contribution to the documentation.
294  
295  
296 =head1 COPYRIGHT & LICENSE
297  
298 Copyright 2005 DUPUIS Arnaud, All Rights Reserved.
299  
300 This program is free software; you can redistribute it and/or modify it
301 under the same terms as Perl itself.
302  
303 =cut
304  
305 2 1; # End of Slackware::Slackget::SpecialFiles::FILELIST
« Slackget/Network/Connection/FILE.pm ↑ Summary Slackget/PkgTools.pm »