Slackget/SpecialFiles/PACKAGES.pm

filter: Statementstmt 23.9% 17 / 71 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 35.7% 5 / 14 Podpod 100% 9 / 9 totaltotal 25.0% 31 / 124 CC 17 SCAR 29.7
CC
17
Cov
18%
get_meta
42.0
new
30.0
compile
20.0
CRAP 19.6
« Slackget/GPG/Signature.pm ↑ Summary Slackget/Date.pm »
1 package Slackware::Slackget::SpecialFiles::PACKAGES;
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::PACKAGES - An interface for the special file PACKAGES.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 PACKAGES.TXT file
25  
26 use Slackware::Slackget::SpecialFiles::PACKAGES;
27  
28 my $pack = Slackware::Slackget::SpecialFiles::PACKAGES->new('PACKAGES.TXT','slackware');
29 ...
30  
31 =head1 WARNINGS
32  
33 All classes from the Slackware::Slackget::SpecialFiles:: namespace need the followings methods :
34  
35 - a contructor new()
36 - a method compil()
37 - a method get_result(), which one can be an alias on another method of the class.
38  
39 Moreover, the get_result() methode need to return a hashref. Keys of this hashref are the filenames.
40  
41 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.
42  
43 =head1 CONSTRUCTOR
44  
45 =head2 new
46  
47 Take a file, a Slackware::Slackget::Config object and an id name :
48  
49 my $pack = Slackware::Slackget::SpecialFiles::PACKAGES->new('PACKAGES.TXT',$config,'slackware');
50  
51 =cut
52  
53 sub new
54 0 ▶{
Subroutine new: not called CC=5 SCAR=34.0
Pod documented
55 0 my ($class,$file,$config,$root) = @_ ;
56 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
57 0 my $self={};
58 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
59 # print "[debug PACKAGES] Loading $file as PACKAGES\n";
60 0 $self->{ROOT} = $root;
61 0 $self->{config}=$config;
62 0 $self->{FILE} = new Slackware::Slackget::File ($file,'file-encoding' => $config->{common}->{'file-encoding'});
63 0 $self->{DATA} = {};
64 0 $self->{METADATA} = {};
65 0 bless($self,$class);
66 0 return $self;
67 }
68  
69  
70 =head1 FUNCTIONS
71  
72 =head2 compile
73  
74 Take no argument, and compile the informations contains in the PACKAGES.TXT file into the internal data structure of slack-get.
75  
76 $pack->compile ;
77  
78 =cut
79  
80 0 ▶sub compile {
Subroutine compile: not called CC=4 SCAR=30.0
Pod documented
81 0 my $self = shift;
82 0 $self->get_meta;
83 0 foreach (@{$self->create_entities}){
84 0 my $pack = new Slackware::Slackget::Package (1);
85 0 ▶ $pack->setValue('package-source',$self->{ROOT}) if($self->{ROOT});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"ROOT"} 0 0 0
86 0 $pack->extract_informations($_);
87 0 $pack->grab_info_from_description ;
88 0 ▶ print STDERR "Error: informations extraction have failed\n" if(!$pack->get_id);
Branch: 1 branch
BranchTrueFalseTotal
unless $pack->get_id 0 0 0
89 # print "PACKAGING of ",$pack->get_id,"\n";$pack->print_full_info;
90 0 $self->{DATA}->{$pack->get_id} = $pack ;
91 }
92 0 $self->{FILE}->Close ;
93 ### DEBUG ONLY
94 # $self->{FILE}->Write("debug/packages_$self->{ROOT}.xml",$self->to_XML);
95 # $self->{FILE}->Close ;
96 }
97  
98 =head2 create_entities
99  
100 This method take the whole file PACKAGES.TXT and split it into entity (one package or meta informations)
101  
102 =cut
103  
104 0 ▶sub create_entities {
Subroutine create_entities: not called CC=4 SCAR=30.0
Pod documented
105 0 my $self = shift;
106 0 my @entities = ();
107 0 my $idx = -1;
108 0 foreach ($self->{FILE}->Get_selection($self->{'starting-position'})){
109 0 ▶ if($_=~ /^PACKAGE NAME:/){
Branch: 1 branch
BranchTrueFalseTotal
if ($_ =~ /^PACKAGE NAME:/) 0 0 0
110 0 $idx++;
111 }
112 0 ▶ next if($_=~ /^\s*(#|\|-*handy-ruler)/i);
Branch: 1 branch
BranchTrueFalseTotal
if $_ =~ /^\s*(#|\|-*handy-ruler)/i 0 0 0
113 0 $entities[$idx] .= $_ ;
114 }
115 0 return \@entities ;
116 }
117  
118 =head2 get_meta
119  
120 This method parse the 10 first lines of the PACKAGES.TXT and extract globals informations. It define the 'starting-position' object tag (this information is only for coders).
121  
122 $pack->get_meta();
123  
124 =cut
125  
126 0 ▶sub get_meta {
Subroutine get_meta: not called CC=6 SCAR=37.4
Pod documented
127 0 my $self = shift;
128 0 my $l = 0;
129 0 foreach ($self->{FILE}->Get_selection(0,15)){
130 0 ▶ if($_=~ /PACKAGES.TXT; (\w+) (\w+) (\d+) ([\d:]+) (\w+) (\d+)/){
Branch: 4 branches
BranchTrueFalseTotal
if ($_ =~ /PACKAGES.TXT; (\w+) (\w+) (\d+) ([\d:]+) (\w+) (\d+)/) { } 0 0 0
elsif ($_ =~ /Total size of all packages \(compressed\):\s+(\d+) MB/) { } 0 0 0
elsif ($_ =~ /Total size of all packages \(uncompressed\):\s+(\d+) MB/) { } 0 0 0
elsif ($_ =~ /^PACKAGE NAME:/) { } 0 0 0
131 0 $self->{METADATA}->{'date'} = new Slackware::Slackget::Date (
132 'day-name' => $1,
133 'day-number' => $3,
134 'month' => $2,
135 'hour' => $4,
136 'year' => $6
137 );
138 }
139 elsif($_=~ /Total size of all packages \(compressed\):\s+(\d+) MB/){
140 0 $self->{METADATA}->{'compressed-size'} = $1;
141 }
142 elsif($_=~ /Total size of all packages \(uncompressed\):\s+(\d+) MB/){
143 0 $self->{METADATA}->{'uncompressed-size'} = $1;
144 }
145 elsif($_=~ /^PACKAGE NAME:/)
146 {
147 0 $self->{'starting-position'}=$l;
148 0 last;
149 }
150 0 $l++;
151 }
152 }
153  
154 =head2 get_result
155  
156 Not yet implemented.
157  
158 =cut
159  
160 0 ▶sub get_result {
Subroutine get_result: not called CC=1 SCAR=6.9
Pod documented
161 0 my $self = shift;
162 }
163  
164 =head2 get_package
165  
166 Return informations relative to a packages as a hashref.
167  
168 my $hashref = $list->get_package($package_name) ;
169  
170 =cut
171  
172 0 ▶sub get_package {
Subroutine get_package: not called CC=1 SCAR=6.9
Pod documented
173 0 my ($self,$pack_name) = @_ ;
174 0 return $self->{DATA}->{$pack_name} ;
175 }
176  
177 =head2 get_date
178  
179 return a Slackware::Slackget::Date object, which is the date of the PACKAGES.TXT
180  
181 my $date = $pack->get_date ;
182  
183 =cut
184  
185 0 ▶sub get_date {
Subroutine get_date: not called CC=1 SCAR=6.9
Pod documented
186 0 my $self = shift;
187 0 return $self->{METADATA}->{'date'} ;
188 }
189  
190 =head2 to_XML (deprecated)
191  
192 Same as to_xml(), provided for backward compatibility.
193  
194 =cut
195  
196 0 ▶sub to_XML {
Subroutine to_XML: not called CC=1 SCAR=6.9
Pod documented
197 0 return to_xml(@_);
198 }
199  
200 =head2 to_xml
201  
202 return the package as an XML encoded string.
203  
204 $xml = $package->to_xml();
205  
206 =cut
207  
208 sub to_xml
209 0 ▶{
Subroutine to_xml: not called CC=2 SCAR=17.9
Pod documented
210 0 my $self = shift;
211 0 my $xml = "<packages>\n";
212 0 foreach (keys(%{$self->{DATA}})){
213 # print "XMLization of $_\n";
214 0 $xml .= $self->{DATA}->{$_}->to_xml ;
215 }
216 0 $xml .= "</packages>\n";
217 0 return $xml;
218 }
219  
220 =head1 AUTHOR
221  
222 DUPUIS Arnaud, C<< <a.dupuis@infinityperl.org> >>
223  
224 =head1 BUGS
225  
226 Please report any bugs or feature requests to
227 C<bug-Slackware-Slackget@rt.cpan.org>, or through the web interface at
228 L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Slackware-Slackget>.
229 I will be notified, and then you'll automatically be notified of progress on
230 your bug as I make changes.
231  
232 =head1 SUPPORT
233  
234 You can find documentation for this module with the perldoc command.
235  
236 perldoc Slackware::Slackget
237  
238  
239 You can also look for information at:
240  
241 =over 4
242  
243 =item * Infinity Perl website
244  
245 L<http://www.infinityperl.org/category/slack-get>
246  
247 =item * slack-get specific website
248  
249 L<http://slackget.infinityperl.org>
250  
251 =item * RT: CPAN's request tracker
252  
253 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Slackware-Slackget>
254  
255 =item * AnnoCPAN: Annotated CPAN documentation
256  
257 L<http://annocpan.org/dist/Slackware-Slackget>
258  
259 =item * CPAN Ratings
260  
261 L<http://cpanratings.perl.org/d/Slackware-Slackget>
262  
263 =item * Search CPAN
264  
265 L<http://search.cpan.org/dist/Slackware-Slackget>
266  
267 =back
268  
269 =head1 ACKNOWLEDGEMENTS
270  
271 Thanks to Bertrand Dupuis (yes my brother) for his contribution to the documentation.
272  
273  
274 =head1 COPYRIGHT & LICENSE
275  
276 Copyright 2005 DUPUIS Arnaud, All Rights Reserved.
277  
278 This program is free software; you can redistribute it and/or modify it
279 under the same terms as Perl itself.
280  
281 =cut
282  
283 2 1; # End of Slackware::Slackget::SpecialFiles::PACKAGES
« Slackget/GPG/Signature.pm ↑ Summary Slackget/Date.pm »