Slackget/PackageList.pm

filter: Statementstmt 17.1% 12 / 70 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 22.2% 2 / 9 Podpod 100% 6 / 6 totaltotal 21.2% 20 / 94 CC 10 SCAR 26.8
CC
10
Cov
16%
fill_from_xml
30.0
new
20.0
index_list
6.0
CRAP 14.6
« Slackget/Date.pm ↑ Summary Slackget/Network/Backend/TEST.pm »
1 package Slackware::Slackget::PackageList;
2  
3 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 3 require Slackware::Slackget::Package;
7 3 require Slackware::Slackget::List ;
8 3 require Slackware::Slackget::Date ;
9  
10 =head1 NAME
11  
12 Slackware::Slackget::PackageList - This class is a container of Slackware::Slackget::Package object
13  
14 =head1 VERSION
15  
16 Version 1.0.0
17  
18 =cut
19  
20 3 our $VERSION = '1.0.0';
21 3 our @ISA = qw( Slackware::Slackget::List );
22  
23 =head1 SYNOPSIS
24  
25 This class is a container of Slackware::Slackget::Package object, and allow you to perform some operations on this packages list. As the Package's list class, it is a slack-get's internal representation of data.
26  
27 use Slackware::Slackget::PackageList;
28  
29 my $packagelist = Slackware::Slackget::PackageList->new();
30 $packagelist->add($package);
31 $packagelist->get($index);
32 my $package = $packagelist->Shift();
33  
34  
35 =head1 CONSTRUCTOR
36  
37 =head2 new
38  
39 This class constructor don't take any parameters to works properly, but you can eventually disable the root tag <packagelist> by using 'no-root-tag' => 1, and modify the default encoding (utf8) by passing an 'encoding' => <your encoding> parameter. Thoses options are only related to the export functions.
40  
41 my $PackageList = new Slackware::Slackget::PackageList ();
42 my $PackageList = new Slackware::Slackget::PackageList ('no-root-tag' => 1);
43  
44 =cut
45  
46 sub new
47 0 ▶{
Subroutine new: not called CC=4 SCAR=30.0
Pod documented
48 0 my ($class,%args) = @_ ;
49 0 my $encoding = 'utf8';
50 0 ▶ if(defined($args{'encoding'}) && $args{'encoding'} !~ /^\s*$/)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{"encoding"} and not $args{"encoding"} =~ /^\s*$/) 0 0 0
Condition0%0/3
defined $args{"encoding"} and not $args{"encoding"} =~ /^\s*$/
!ll&&!rl&&r
000
MC/DC0%0/2
defined $args{"encoding"} and not $args{"encoding"} =~ /^\s*$/
defined $args{"encoding"} not $args{"encoding"} =~ /^\s*$/
Truth table0%0/3
A and not(B)
A= defined $args{"encoding"}B= not $args{"encoding"} =~ /^\s*$/
ABresult
0X0
100
111
51 {
52 0 $encoding = $args{'encoding'} ;
53 0 delete($args{'encoding'}) ;
54 }
55 0 my $self={list_type => 'Slackware::Slackget::Package','root-tag' => 'package-list',ENCODING => $encoding};
56 0 foreach (keys(%args))
57 {
58 0 $self->{$_} = $args{$_};
59 }
60 0 bless($self,$class);
61 0 return $self;
62 }
63  
64 =head1 FUNCTIONS
65  
66 This class inheritate from Slackware::Slackget::List (L<Slackware::Slackget::List>), so you may want read the Slackware::Slackget::List documentation for the supported methods of this class.
67  
68 The present documentation present only methods that differs from the Slackware::Slackget::List class.
69  
70 =cut
71  
72 =head2 fill_from_xml
73  
74 Fill the Slackware::Slackget::PackageList from the XML data passed as argument.
75  
76 $packagelist->fill_from_xml(
77 '<choice action="installpkg">
78 <package id="gcc-objc-3.3.4-i486-1">
79 <date hour="12:32:00" day-number="12" month-number="06" year="2004" />
80 <compressed-size>1395</compressed-size>
81 <location>./slackware/d</location>
82 <package-source>slackware</package-source>
83 <version>3.3.4</version>
84 <name>gcc-objc</name>
85 <uncompressed-size>3250</uncompressed-size>
86 <description>gcc-objc (Objective-C support for GCC)
87 Objective-C support for the GNU Compiler Collection.
88 This package contains those parts of the compiler collection needed to
89 compile code written in Objective-C. Objective-C was originally
90 developed to add object-oriented extensions to the C language, and is
91 best known as the native language of the NeXT computer.
92
93 </description>
94 <signature-checksum>565a10ce130b4287acf188a6c303a1a4</signature-checksum>
95 <checksum>23bae31e3ffde5e7f44617bbdc7eb860</checksum>
96 <architecture>i486</architecture>
97 <package-location>slackware/d/</package-location>
98 <package-version>1</package-version>
99 <referer>gcc-objc</referer>
100 </package>
101
102 <package id="gcc-objc-3.4.3-i486-1">
103 <date hour="18:24:00" day-number="21" month-number="12" year="2004" />
104 <compressed-size>1589</compressed-size>
105 <package-source>slackware</package-source>
106 <version>3.4.3</version>
107 <name>gcc-objc</name>
108 <signature-checksum>1027468ed0d63fcdd584f74d2696bf99</signature-checksum>
109 <architecture>i486</architecture>
110 <checksum>5e659a567d944d6824f423d65e4f940f</checksum>
111 <package-location>testing/packages/gcc-3.4.3/</package-location>
112 <package-version>1</package-version>
113 <referer>gcc-objc</referer>
114 </package>
115 </choice>'
116 );
117  
118 =cut
119  
120 sub fill_from_xml
121 0 ▶{
Subroutine fill_from_xml: not called CC=5 SCAR=34.0
Pod documented
122 0 my ($self,@xml) = @_ ;
123 0 my $xml = '';
124 0 foreach (@xml)
125 {
126 0 $xml .= $_ ;
127 }
128 0 require XML::Simple ;
129 0 $XML::Simple::PREFERRED_PARSER='XML::Parser' ;
130 0 my $xml_in = XML::Simple::XMLin($xml,KeyAttr => {'package' => 'id'});
131 # use Data::Dumper ;
132 # print Data::Dumper::Dumper($xml_in);
133 0 foreach my $pack_name (keys(%{$xml_in->{'package'}})){
134 0 my $package = new Slackware::Slackget::Package ($pack_name);
135 0 foreach my $key (keys(%{$xml_in->{'package'}->{$pack_name}})){
136 0 ▶ if($key eq 'date')
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq 'date') { } 0 0 0
137 {
138 0 $package->setValue($key,Slackware::Slackget::Date->new(%{$xml_in->{'package'}->{$pack_name}->{$key}}));
139 }
140 else
141 {
142 0 $package->setValue($key,$xml_in->{'package'}->{$pack_name}->{$key}) ;
143 }
144
145 }
146 0 $self->add($package);
147 }
148 }
149  
150 =head2 Sort
151  
152 Apply the Perl built-in function sort() on the PackageList. This method return nothing.
153  
154 $list->Sort() ;
155  
156 =cut
157  
158 sub Sort
159 0 ▶{
Subroutine Sort: not called CC=1 SCAR=6.9
Pod documented
160 0 my $self = shift ;
161 0 $self->{LIST} = [ sort {$a->{ROOT} cmp $b->{ROOT} } @{ $self->{LIST} } ] ;
162 }
163  
164 =head2 index_list
165  
166 Create an index on the PackageList. This index don't take many memory but speed a lot search, especially when you already have the package id !
167  
168 The index is build with the Package ID.
169  
170 =cut
171  
172 sub index_list
173 0 ▶{
Subroutine index_list: not called CC=2 SCAR=17.9
Pod documented
174 0 my $self = shift ;
175 0 $self->{INDEX} = {} ;
176 0 foreach my $pkg (@{$self->{LIST}})
177 {
178 # print "[Slackware::Slackget::PackageList] indexing package: ",$pkg->get_id(),"\n";
179 0 $self->{INDEX}->{$pkg->get_id()} = $pkg ;
180 }
181 0 return 1;
182 }
183  
184 =head2 get_indexed
185  
186 Return a package, as well as Get() do but use the index to return it quickly. You must provide a package ID to this method.
187  
188 my $pkg = $list->get_indexed($qlistviewitem->text(5)) ;
189  
190 =cut
191  
192 sub get_indexed
193 0 ▶{
Subroutine get_indexed: not called CC=1 SCAR=6.9
Pod documented
194 0 my ($self, $id) = @_ ;
195 0 return $self->{INDEX}->{$id} ;
196 }
197  
198 =head2 get_indexes
199  
200 Return the list of all indexes
201  
202 my @indexes = $list->get_indexes() ;
203  
204 =cut
205  
206 sub get_indexes
207 0 ▶{
Subroutine get_indexes: not called CC=1 SCAR=6.9
Pod documented
208 0 my ($self, $id) = @_ ;
209 0 return keys(%{$self->{INDEX}}) ;
210 }
211  
212 0 ▶sub __to_string {
Subroutine __to_string: not called CC=2 SCAR=17.9
213 0 my $self = shift ;
214 # PACKAGES.TXT; Tue Aug 26 23:19:17 CEST 2008
215 #
216 # This file provides details on the packages found on this site
217 # Total size of all packages (compressed) : 4002 MB
218 # Total size of all packages (uncompressed) : 10091 MB
219 0 my $now_string = localtime;
220 0 my $text = "PACKAGES.TXT; $now_string\n\nThis file provides details on the packages found on this site\n";
221 0 my $tsc = 0; # total size compressed
222 0 my $tsu = 0; # total size uncompressed
223 0 my $tmp_text = '';
224 0 foreach (@{$self->{LIST}}){
225 0 $tmp_text .= $_->to_string()."\n";
226 0 $tsc += $_->compressed_size();
227 0 $tsu += $_->uncompressed_size();
228 }
229 0 $tmp_text =~ s/\n{3,}/\n\n/g;
230 0 $tsc = int( $tsc / 1024 );
231 0 $tsu = int( $tsu / 1024 );
232 0 $text .= "Total size of all packages (compressed) : $tsc MB\nTotal size of all packages (uncompressed) : $tsu MB\n\n";
233 0 $text .= "$tmp_text\n";
234 }
235  
236 =head1 AUTHOR
237  
238 DUPUIS Arnaud, C<< <a.dupuis@infinityperl.org> >>
239  
240 =head1 BUGS
241  
242 Please report any bugs or feature requests to
243 C<bug-slackget10@rt.cpan.org>, or through the web interface at
244 L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=slackget10>.
245 I will be notified, and then you'll automatically be notified of progress on
246 your bug as I make changes.
247  
248 =head1 BUGS
249  
250 Please report any bugs or feature requests to
251 C<bug-Slackware-Slackget@rt.cpan.org>, or through the web interface at
252 L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Slackware-Slackget>.
253 I will be notified, and then you'll automatically be notified of progress on
254 your bug as I make changes.
255  
256 =head1 SUPPORT
257  
258 You can find documentation for this module with the perldoc command.
259  
260 perldoc Slackware::Slackget
261  
262  
263 You can also look for information at:
264  
265 =over 4
266  
267 =item * Infinity Perl website
268  
269 L<http://www.infinityperl.org/category/slack-get>
270  
271 =item * slack-get specific website
272  
273 L<http://slackget.infinityperl.org>
274  
275 =item * RT: CPAN's request tracker
276  
277 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Slackware-Slackget>
278  
279 =item * AnnoCPAN: Annotated CPAN documentation
280  
281 L<http://annocpan.org/dist/Slackware-Slackget>
282  
283 =item * CPAN Ratings
284  
285 L<http://cpanratings.perl.org/d/Slackware-Slackget>
286  
287 =item * Search CPAN
288  
289 L<http://search.cpan.org/dist/Slackware-Slackget>
290  
291 =back
292  
293 =head1 ACKNOWLEDGEMENTS
294  
295 Thanks to Bertrand Dupuis (yes my brother) for his contribution to the documentation.
296  
297 =head1 SEE ALSO
298  
299 =head1 COPYRIGHT & LICENSE
300  
301 Copyright 2005 DUPUIS Arnaud, All Rights Reserved.
302  
303 This program is free software; you can redistribute it and/or modify it
304 under the same terms as Perl itself.
305  
306 =cut
307  
308 3 1; # End of Slackware::Slackget::PackageList
« Slackget/Date.pm ↑ Summary Slackget/Network/Backend/TEST.pm »