Slackget/SpecialFiles/CHECKSUMS.pm

filter: Statementstmt 25.9% 14 / 54 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 36.3% 4 / 11 Podpod 100% 7 / 7 totaltotal 24.5% 25 / 102 CC 15 SCAR 39.3
CC
15
Cov
18%
compile
110.0
new
30.0
to_xml
6.0
CRAP 51.0
« Slackget/MD5.pm ↑ Summary Slackget/Network/Backend/XML.pm »
1 package Slackware::Slackget::SpecialFiles::CHECKSUMS;
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::Package;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 =head1 NAME
10  
11 Slackware::Slackget::SpecialFiles::CHECKSUMS - An interface for the special file CHECKSUMS.md5
12  
13 =head1 VERSION
14  
15 Version 1.0.0
16  
17 =cut
18  
19 2 our $VERSION = '1.0.0';
20  
21 =head1 SYNOPSIS
22  
23 This class contain all methods for the treatment of the CHECKSMUMS.md5 file
24  
25 use Slackware::Slackget::SpecialFiles::CHECKSUMS;
26  
27 my $spec_chk = Slackware::Slackget::SpecialFiles::CHECKSUMS->new('CHECKSUMS.md5','slackware');
28 $spec_chk->compile();
29 my $ref = $spec_chk->get_checksums('glibc-profile-2.3.4-i486-1');
30 print "Checksum for glibc-profile-2.3.4-i486-1.tgz : $ref->{checksum}\n";
31 print "Checksum for glibc-profile-2.3.4-i486-1.tgz.asc : $ref->{'signature-checksum'}\n";
32  
33 =head1 WARNINGS
34  
35 All classes from the Slackware::Slackget::SpecialFiles:: namespace need the followings methods :
36  
37 - a contructor new()
38 - a method compil()
39 - a method get_result(), which one can be an alias on another method of the class.
40  
41 Moreover, the get_result() methode need to return a hashref. Keys of this hashref are the filenames.
42  
43 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.
44  
45 =head1 CONSTRUCTOR
46  
47 =head2 new
48  
49 The constructor take three argument : the file CHECKSUMS.md5 with his all path, a Slackware::Slackget::Config object and an id name.
50  
51 my $spec_chk = Slackware::Slackget::SpecialFiles::CHECKSUMS->new('/home/packages/CHECKSUMS.md5',$config,'slackware');
52  
53 The constructor return undef if the file does not exist.
54  
55 =cut
56  
57 sub new
58 0 ▶{
Subroutine new: not called CC=5 SCAR=34.0
Pod documented
59 0 my ($class,$file,$config,$root) = @_ ;
60 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
61 0 my $self={};
62 0 $self->{ROOT} = $root;
63 0 $self->{config}=$config;
64 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
65 # print "[debug CHECKSUMS] Loading $file as CHECKSUMS\n";
66 0 $self->{FILE} = new Slackware::Slackget::File ($file,'file-encoding' => $config->{common}->{'file-encoding'});
67 0 $self->{DATA} = {};
68 0 bless($self,$class);
69 0 return $self;
70 }
71  
72 =head1 FUNCTIONS
73  
74 =head2 compile
75  
76 This method take no arguments, and extract the list of couple (file/checksum). Those couple are store into an internal data structure.
77  
78 $spec_chk->compile();
79  
80 =cut
81  
82 0 ▶sub compile {
Subroutine compile: not called CC=10 SCAR=47.0
Pod documented
83 0 my $self = shift;
84 0 foreach ($self->{FILE}->Get_file()){
85 0 ▶ if($_=~/^([0-9a-f]*)\s+\.\/(.*)\/([^\/\s\n]*)\.tgz\.asc$/i){
Branch: 2 branches
BranchTrueFalseTotal
if ($_ =~ m[^([0-9a-f]*)\s+\./(.*)/([^/\s\n]*)\.tgz\.asc$]i) { } 0 0 0
elsif ($_ =~ m[^([0-9a-f]*)\s+\./(.*)/([^/\s\n]*)\.tgz$]i) { } 0 0 0
86 0 ▶ next if ($2=~ /source\//);
Branch: 1 branch
BranchTrueFalseTotal
if $2 =~ m[source/] 0 0 0
87 0 ▶ unless(defined($self->{DATA}->{$3})){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"DATA"}{$3}) 0 0 0
88 0 $self->{DATA}->{$3} = new Slackware::Slackget::Package ($3) ;
89 0 ▶ $self->{DATA}->{$3}->setValue('package-source',$self->{ROOT}) if($self->{ROOT});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"ROOT"} 0 0 0
90 0 $self->{DATA}->{$3}->setValue('package-location',$2);
91 }
92 0 $self->{DATA}->{$3}->setValue('signature-checksum',$1);
93 }
94 elsif($_=~/^([0-9a-f]*)\s+\.\/(.*)\/([^\/\s\n]*)\.tgz$/i){
95 0 ▶ next if ($2=~ /source\//);
Branch: 1 branch
BranchTrueFalseTotal
if $2 =~ m[source/] 0 0 0
96 0 ▶ unless(defined($self->{DATA}->{$3})){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"DATA"}{$3}) 0 0 0
97 0 $self->{DATA}->{$3} = new Slackware::Slackget::Package ($3) ;
98 0 ▶ $self->{DATA}->{$3}->setValue('package-source',$self->{ROOT}) if($self->{ROOT});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"ROOT"} 0 0 0
99 0 $self->{DATA}->{$3}->setValue('package-location',$2);
100 }
101 # $self->{DATA}->{$3}->{checksum} = $1;
102 0 $self->{DATA}->{$3}->setValue('checksum',$1);
103 }
104 }
105 0 $self->{FILE}->Close();
106 ### DEBUG ONLY
107 # $self->{FILE}->Write("debug/checksums_$self->{ROOT}.xml",$self->to_XML);
108 # $self->{FILE}->Close ;
109 }
110  
111 =head2 get_checksums
112  
113 This method return a Slackware::Slackget::Package object containing 2 keys : checksum and signature-checksum, wich are respectively the file checksum and the GnuPG signature (.asc) checksum. The object can contain more inforations (like the package-source and package-location). This method is the same that get_package().
114  
115 my $ref = $spec_chk->get_checksums($package_name) ;
116  
117 This method return undef if $package_name doesn't exist in the data structure.
118  
119 =cut
120  
121 0 ▶sub get_checksums {
Subroutine get_checksums: not called CC=1 SCAR=6.9
Pod documented
122 0 my ($self,$package) = @_;
123 0 return $self->{DATA}->{$package};
124 }
125  
126 =head2 get_package
127  
128 Return informations relative to a packages as a Slackware::Slackget::Package object.
129  
130 my $package_object = $spec_chk->get_package($package_name) ;
131  
132 =cut
133  
134 0 ▶sub get_package {
Subroutine get_package: not called CC=1 SCAR=6.9
Pod documented
135 0 my ($self,$pack_name) = @_ ;
136 0 return $self->{DATA}->{$pack_name} ;
137 }
138  
139 =head2 get_result
140  
141 Alias for get_checksums()
142  
143 =cut
144  
145 0 ▶sub get_result {
Subroutine get_result: not called CC=1 SCAR=6.9
Pod documented
146 0 my $self = shift;
147 0 return $self->get_checksums(@_);
148 }
149  
150 =head2 to_XML (deprecated)
151  
152 Same as to_xml(), provided for backward compatibility.
153  
154 =cut
155  
156 0 ▶sub to_XML {
Subroutine to_XML: not called CC=1 SCAR=6.9
Pod documented
157 0 return to_xml(@_);
158 }
159  
160 =head2 to_xml
161  
162 Translate the internale data structure into a single XML string.
163  
164 WARNING: this method is for debug ONLY, YOU NEVER HAVE TO CALL IT IN NORMAL USE.
165  
166 =cut
167  
168 0 ▶sub to_xml {
Subroutine to_xml: not called CC=2 SCAR=17.9
Pod documented
169 0 my $self = shift;
170 0 my $xml = "<checksums>\n";
171 0 foreach (keys(%{$self->{DATA}})){
172 0 $xml.=$self->{DATA}->{$_}->to_xml ;
173 }
174 0 $xml .= "</checksums>\n";
175 0 return $xml;
176 }
177  
178 =head1 AUTHOR
179  
180 DUPUIS Arnaud, C<< <a.dupuis@infinityperl.org> >>
181  
182 =head1 BUGS
183  
184 Please report any bugs or feature requests to
185 C<bug-Slackware-Slackget@rt.cpan.org>, or through the web interface at
186 L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Slackware-Slackget>.
187 I will be notified, and then you'll automatically be notified of progress on
188 your bug as I make changes.
189  
190 =head1 SUPPORT
191  
192 You can find documentation for this module with the perldoc command.
193  
194 perldoc Slackware::Slackget
195  
196  
197 You can also look for information at:
198  
199 =over 4
200  
201 =item * Infinity Perl website
202  
203 L<http://www.infinityperl.org/category/slack-get>
204  
205 =item * slack-get specific website
206  
207 L<http://slackget.infinityperl.org>
208  
209 =item * RT: CPAN's request tracker
210  
211 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Slackware-Slackget>
212  
213 =item * AnnoCPAN: Annotated CPAN documentation
214  
215 L<http://annocpan.org/dist/Slackware-Slackget>
216  
217 =item * CPAN Ratings
218  
219 L<http://cpanratings.perl.org/d/Slackware-Slackget>
220  
221 =item * Search CPAN
222  
223 L<http://search.cpan.org/dist/Slackware-Slackget>
224  
225 =back
226  
227 =head1 ACKNOWLEDGEMENTS
228  
229 Thanks to Bertrand Dupuis (yes my brother) for his contribution to the documentation.
230  
231  
232 =head1 COPYRIGHT & LICENSE
233  
234 Copyright 2005 DUPUIS Arnaud, All Rights Reserved.
235  
236 This program is free software; you can redistribute it and/or modify it
237 under the same terms as Perl itself.
238  
239 =cut
240  
241 2 1; # End of Slackware::Slackget::SpecialFiles::CHECKSUMS
« Slackget/MD5.pm ↑ Summary Slackget/Network/Backend/XML.pm »