File Coverage

blib/lib/Slackware/Slackget/SpecialFileContainer.pm
Criterion Covered Total %
statement 6 51 11.7
branch 0 22 0.0
condition 0 9 0.0
subroutine 2 7 28.5
pod 5 5 100.0
total 13 94 13.8


line stmt bran cond sub pod time code
1             package Slackware::Slackget::SpecialFileContainer;
2              
3 2     2   4109 use warnings;
  2         3  
  2         56  
4 2     2   6 use strict;
  2         3  
  2         1123  
5              
6             require Slackware::Slackget::SpecialFiles::PACKAGES ;
7             require Slackware::Slackget::SpecialFiles::FILELIST ;
8             require Slackware::Slackget::SpecialFiles::CHECKSUMS ;
9             require Slackware::Slackget::PackageList;
10             require Slackware::Slackget::Package ;
11              
12             =head1 NAME
13              
14             Slackware::Slackget::SpecialFileContainer - A class to class, sort and compil the PACKAGES.TXT, CHECKSUMS.md5 and FILELIST.TXT
15              
16             =head1 VERSION
17              
18             Version 1.0.0
19              
20             =cut
21              
22             our $VERSION = '1.0.0';
23             our $DEBUG=0;
24              
25             =head1 SYNOPSIS
26              
27             This class is a front-end for the 3 sub-class Slackware::Slackget::SpecialFiles::PACKAGES , Slackware::Slackget::SpecialFiles::CHECKSUMS and Slackware::Slackget::SpecialFiles::FILELIST.
28              
29             Act as a container but also make a treatment (the compilation of the 3 subclasses in one sol object)
30              
31             =head1 CONSTRUCTOR
32              
33             =head2 new
34              
35             take the following arguments :
36              
37             a unique id
38             FILELIST => the FILELIST.TXT filename
39             PACKAGES => the PACKAGES.TXT filename
40             CHECKSUMS => the CHECKSUMS.md5 filename
41             config => a Slackware::Slackget::Config object.
42              
43             use Slackware::Slackget::SpecialFileContainer;
44              
45             my $container = Slackware::Slackget::SpecialFileContainer->new(
46             'slackware',
47             config => $config,
48             FILELIST => /home/packages/update_files/FILELIST.TXT,
49             PACKAGES => /home/packages/update_files/PACKAGES.TXT,
50             CHECKSUMS => /home/packages/update_files/CHECKSUMS.md5
51             );
52              
53             =cut
54              
55             sub new
56             {
57 0     0 1   my ($class,$root,%args) = @_ ;
58 0 0         print "[Slackware::Slackget::SpecialFileContainer] [debug] about to create a new instance\n" if($DEBUG);
59 0 0         return undef unless(defined($root));
60 0           my $self={};
61 0           $self->{ROOT} = $root;
62 0 0 0       unless($args{FILELIST} or $args{PACKAGES} or $args{CHECKSUMS}){
      0        
63 0           warn "[Slackware::Slackget::SpecialFileContainer] Required parameter FILELIST, PACKAGES or CHECKSUMS not found in the contructor\n";
64 0           return undef;
65             }
66 0 0 0       $self->{DATA}->{config} = $args{config} if(defined($args{config}) && ref($args{config}) eq 'Slackware::Slackget::Config');
67 0 0         $self->{DATA}->{FILELIST} = Slackware::Slackget::SpecialFiles::FILELIST->new($args{FILELIST},$self->{DATA}->{config},$root) or return undef;
68 0 0         print "[Slackware::Slackget::SpecialFileContainer] [debug] FILELIST instance : $self->{DATA}->{FILELIST}\n" if($DEBUG);
69 0 0         $self->{DATA}->{PACKAGES} = Slackware::Slackget::SpecialFiles::PACKAGES->new($args{PACKAGES},$self->{DATA}->{config},$root) or return undef;
70 0 0         print "[Slackware::Slackget::SpecialFileContainer] [debug] PACKAGES instance : $self->{DATA}->{PACKAGES}\n" if($DEBUG);
71 0 0         $self->{DATA}->{CHECKSUMS} = Slackware::Slackget::SpecialFiles::CHECKSUMS->new($args{CHECKSUMS},$self->{DATA}->{config},$root) or return undef;
72 0 0         print "[Slackware::Slackget::SpecialFileContainer] [debug] CHECKSUMS instance : $self->{DATA}->{CHECKSUMS}\n" if($DEBUG);
73 0           bless($self);#,$class
74 0           return $self;
75             }
76              
77             =head1 FUNCTIONS
78              
79             =head2 compile
80              
81             Mainly call the compile() method of the special files.
82              
83             $container->compile();
84              
85             =cut
86              
87             sub compile {
88 0     0 1   my $self = shift;
89             # printf("compiling FILELIST...");
90 0           $|++;
91 0           $self->{DATA}->{FILELIST}->compile ;
92             # print "ok\n";
93             # printf("compiling PACKAGES...");
94 0           $self->{DATA}->{PACKAGES}->compile ;
95             # print "ok\n";
96             # printf("compiling CHECKSUMS...");
97 0           $self->{DATA}->{CHECKSUMS}->compile ;
98             # print "ok\n";
99             # printf("merging data...");
100 0           $self->{DATA}->{PACKAGELIST} = undef;
101 0 0         my $packagelist = Slackware::Slackget::PackageList->new('no-root-tag' => 1) or return undef;
102 0           my $r_list = $self->{DATA}->{FILELIST}->get_file_list ;
103 0           foreach my $pkg_name (keys(%{$r_list})){
  0            
104             # print "[DEBUG] Getting info on $pkg_name\n";
105 0           my $r_pack = $self->{DATA}->{PACKAGES}->get_package($pkg_name);
106 0           my $r_chk = $self->{DATA}->{CHECKSUMS}->get_package($pkg_name);
107 0           my $r_list = $self->{DATA}->{FILELIST}->get_package($pkg_name);
108 0           my $pack = new Slackware::Slackget::Package ($pkg_name);
109 0           $pack->merge($r_pack);
110 0           $pack->merge($r_chk);
111 0           $pack->merge($r_list);
112 0           $packagelist->add($pack);
113             # $pack->print_restricted_info ;
114             }
115 0           $packagelist->index_list ;
116 0           $self->{DATA}->{PACKAGELIST} = $packagelist ;
117             # my $total_size = 0;
118             # foreach (@{$packagelist->get_all})
119             # {
120             # $total_size += $_->compressed_size ;
121             # }
122             # print "TOTAL SIZE: $total_size ko\n";
123             ## WARNING: DEBUG ONLY
124             # use Slackware::Slackget::File;
125             #
126             # my $file = new Slackware::Slackget::File ();
127             # $file->Write("debug/specialfilecontainer_$self->{ROOT}.xml",$self->to_XML) ;
128             # $file->Close;
129             # print "ok\n";
130             }
131              
132             =head2 id
133              
134             Return the id of the SpecialFileContainer object id (like: 'slackware', 'linuxpackages', etc.)
135              
136             my $id = $container->id ;
137              
138             =cut
139              
140             sub id {
141 0     0 1   my $self = shift;
142 0           return $self->{ROOT} ;
143             }
144              
145             =head2 to_XML (deprecated)
146              
147             Same as to_xml(), provided for backward compatibility.
148              
149             =cut
150              
151             sub to_XML {
152 0     0 1   return to_xml(@_);
153             }
154              
155             =head2 to_xml
156              
157             return a string XML encoded which represent the compilation of PACKAGES, FILELIST, CHECKSUMS constructor parameters.
158              
159             my $string = $container->to_xml();
160              
161             =cut
162              
163             sub to_xml {
164 0     0 1   my $self = shift;
165 0           my $xml = " <$self->{ROOT}>\n";
166             # print "\t[$self] XMLization of the $self->{DATA}->{PACKAGELIST} packagelist\n";
167 0           $xml .= $self->{DATA}->{PACKAGELIST}->to_XML ;
168 0           $xml .= " </$self->{ROOT}>\n";
169 0           return $xml;
170             }
171              
172             =head1 AUTHOR
173              
174             DUPUIS Arnaud, C<< <a.dupuis@infinityperl.org> >>
175              
176             =head1 BUGS
177              
178             Please report any bugs or feature requests to
179             C<bug-Slackware-Slackget@rt.cpan.org>, or through the web interface at
180             L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Slackware-Slackget>.
181             I will be notified, and then you'll automatically be notified of progress on
182             your bug as I make changes.
183              
184             =head1 SUPPORT
185              
186             You can find documentation for this module with the perldoc command.
187              
188             perldoc Slackware::Slackget::SpecialFileContainer
189              
190              
191             You can also look for information at:
192              
193             =over 4
194              
195             =item * Infinity Perl website
196              
197             L<http://www.infinityperl.org/category/slack-get>
198              
199             =item * slack-get specific website
200              
201             L<http://slackget.infinityperl.org>
202              
203             =item * RT: CPAN's request tracker
204              
205             L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Slackware-Slackget>
206              
207             =item * AnnoCPAN: Annotated CPAN documentation
208              
209             L<http://annocpan.org/dist/Slackware-Slackget>
210              
211             =item * CPAN Ratings
212              
213             L<http://cpanratings.perl.org/d/Slackware-Slackget>
214              
215             =item * Search CPAN
216              
217             L<http://search.cpan.org/dist/Slackware-Slackget>
218              
219             =back
220              
221             =head1 ACKNOWLEDGEMENTS
222              
223             Thanks to Bertrand Dupuis (yes my brother) for his contribution to the documentation.
224              
225             =head1 COPYRIGHT & LICENSE
226              
227             Copyright 2005 DUPUIS Arnaud, All Rights Reserved.
228              
229             This program is free software; you can redistribute it and/or modify it
230             under the same terms as Perl itself.
231              
232             =cut
233              
234             1; # End of Slackware::Slackget::SpecialFileContainer