Packaged/Generate.pm

filter: Statementstmt 32.0% 41 / 128 Branchbran 0.0% 0 / 38 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 54.1% 13 / 24 Podpod 100% 2 / 2 totaltotal 28.4% 56 / 197 CC 31 SCAR 33.0
CC
31
Cov
24%
_fetch_gentoo
72.0
_fetch_debian
56.0
_fetch_mandrake
30.0
CRAP 27.2
↑ Summary Packaged.pm »
1 package Module::Packaged::Generate;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use App::Cache;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use IO::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Compress::Zlib;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use IO::String;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use IO::Zlib;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use File::Spec::Functions qw(catdir catfile tmpdir);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use LWP::Simple qw(mirror);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Parse::CPAN::Packages;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Parse::Debian::Packages;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Sort::Versions;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Storable qw(store retrieve);
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use base 'Class::Accessor::Chained::Fast';
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 __PACKAGE__->mk_accessors(qw(cache data));
16  
17 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
Pod documented
18 0 my $class = shift;
19 0 my $self = {};
20 0 bless $self, $class;
21  
22 0 $self->cache(App::Cache->new({ ttl => 60 * 60 }));
23  
24 $self->{data} = $self->cache->get_code(
25 "data",
26 0 ▶ sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
27 0 $self->_fetch_cpan;
28 0 $self->_fetch_debian;
29 0 $self->_fetch_fedora;
30 0 $self->_fetch_freebsd;
31 0 $self->_fetch_gentoo;
32 0 $self->_fetch_mandrake;
33 0 $self->_fetch_openbsd;
34 0 $self->_fetch_suse;
35 0 $self->{data};
36 }
37 0 );
38  
39 0 return $self;
40 }
41  
42 0 ▶sub _fetch_cpan {
Subroutine _fetch_cpan: not called CC=2 SCAR=17.9
43 0 my $self = shift;
44 0 my $details =
45 $self->cache->get_url(
46 "http://www.cpan.org/modules/02packages.details.txt.gz",
47 "02packages.gz");
48  
49 0 $details = Compress::Zlib::memGunzip($details);
50  
51 0 my $p = Parse::CPAN::Packages->new($details);
52  
53 0 foreach my $dist ($p->latest_distributions) {
54 0 $self->{data}->{ $dist->dist }->{cpan} = $dist->version;
55 }
56 }
57  
58 0 ▶sub _fetch_gentoo {
Subroutine _fetch_gentoo: not called CC=8 SCAR=42.8
59 0 my $self = shift;
60  
61 0 my $file =
62 $self->cache->get_url("http://www.gentoo.org/dyn/gentoo_pkglist_x86.txt",
63 "gentoo.html");
64 0 $file =~ s{</a></td>\n}{</a></td>}g;
65  
66 0 my @dists = keys %{ $self->{data} };
67  
68 0 foreach my $line (split "\n", $file) {
69 0 ▶ next unless ($line =~ m/dev-perl/);
Branch: 1 branch
BranchTrueFalseTotal
unless $line =~ /dev-perl/ 0 0 0
70 0 my $dist;
71 0 $line =~ s/\.ebuild//g;
72 0 my ($package, $version, $trash) = split(' ', $line);
73 0 ▶ next unless $package;
Branch: 1 branch
BranchTrueFalseTotal
unless $package 0 0 0
74  
75 # Let's try to find a cpan dist that matches the package name
76 0 ▶ if (exists $self->{data}->{$package}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{'data'}{$package}) { } 0 0 0
77 0 $dist = $package;
78 } else {
79 0 foreach my $d (@dists) {
80 0 ▶ if (lc $d eq lc $package) {
Branch: 1 branch
BranchTrueFalseTotal
if (lc $d eq lc $package) 0 0 0
81 0 $dist = $d;
82 0 last;
83 }
84 }
85 }
86  
87 0 ▶ if ($dist) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dist) { } 0 0 0
88 0 $self->{data}->{$dist}->{gentoo} = $version;
89 } else {
90  
91 # I should probably care about these and fix them
92 # warn "Could not find $package: $version\n";
93 }
94 }
95 }
96  
97 0 ▶sub _fetch_fedora {
Subroutine _fetch_fedora: not called CC=4 SCAR=30.0
98 0 my $self = shift;
99 0 my $file =
100 $self->cache->get_url("http://fedora.redhat.com/docs/package-list/fc2/",
101 "fedora.html");
102 0 foreach my $line (split "\n", $file) {
103 0 ▶ next unless $line =~ /^perl-/;
Branch: 1 branch
BranchTrueFalseTotal
unless $line =~ /^perl-/ 0 0 0
104 0 my ($dist, $version) =
105 $line =~ m{perl-(.*?)</td><td class="column-2">(.*?)</td>};
106  
107 # only populate if CPAN already has
108 $self->{data}{$dist}{fedora} = $version
109 0 ▶ if $self->{data}{$dist};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"data"}{$dist} 0 0 0
110 }
111 }
112  
113 0 ▶sub _fetch_suse {
Subroutine _fetch_suse: not called CC=4 SCAR=30.0
114 0 my $self = shift;
115 0 my $file = $self->cache->get_url(
116 "http://www.novell.com/products/linuxpackages/suselinux/index_all.html",
117 "suse.html"
118 );
119  
120 0 foreach my $line (split "\n", $file) {
121  
122 # <a href="perl-dbi.html">perl-DBI 1.43 </a> (The Perl Database Interface)
123 0 my ($dist, $version) = $line =~ m{">perl-(.*?) (.*?) </a>};
124 0 ▶ next unless $dist;
Branch: 1 branch
BranchTrueFalseTotal
unless $dist 0 0 0
125  
126 # only populate if CPAN already has
127 $self->{data}{$dist}{suse} = $version
128 0 ▶ if $self->{data}{$dist};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"data"}{$dist} 0 0 0
129 }
130 }
131  
132 0 ▶sub _fetch_mandrake {
Subroutine _fetch_mandrake: not called CC=5 SCAR=34.0
133 0 my $self = shift;
134 0 my $file1 = $self->cache->get_url(
135 "http://distro.ibiblio.org/pub/linux/distributions/mandriva/MandrivaLinux/official/10.2/i586/media/media_info/synthesis.hdlist_main.cz",
136 "mandrake1.html"
137 );
138 0 my $file2 = $self->cache->get_url(
139 "http://distro.ibiblio.org/pub/linux/distributions/mandriva/MandrivaLinux/official/10.2/i586/media/media_info/synthesis.hdlist_contrib.cz",
140 "mandrake2.html"
141 );
142  
143 0 foreach my $file ($file1, $file2) {
144 0 $file = Compress::Zlib::memGunzip($file);
145 0 foreach my $line (split / /, $file) {
146  
147 # @info@perl-DBI-1.43-2mdk.i586@0@1371700@Development/Perl
148 next
149 0 ▶ unless my ($dist, $version) =
Branch: 1 branch
BranchTrueFalseTotal
unless () = $line =~ /\@info\@perl-(.*)-(.*?)-\d+mdk/ 0 0 0
150 $line =~ m{\@info\@perl-(.*)-(.*?)-\d+mdk};
151  
152 # only populate if CPAN already has
153 $self->{data}{$dist}{mandrake} = $version
154 0 ▶ if $self->{data}{$dist};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"data"}{$dist} 0 0 0
155 }
156 }
157 }
158  
159 0 ▶sub _fetch_freebsd {
Subroutine _fetch_freebsd: not called CC=4 SCAR=30.0
160 0 my $self = shift;
161 0 my $file = $self->cache->get_url("http://www.freebsd.org/ports/perl5.html",
162 "freebsd.html");
163  
164 #<DT><B><A NAME="p5-DBI-1.37"></A><A HREF="http://www.FreeBSD.org/cgi/cvsweb.cgi/ports/databases/p5-DBI-137">p5-DBI-1.37</A></B> </DT>
165 0 for my $package ($file =~ m/A NAME="p5-(.*?)"/g) {
166 0 ▶ my ($dist, $version) = $package =~ /^(.*?)-(\d.*)$/ or next;
Branch: 1 branch
BranchTrueFalseTotal
() = $package =~ /^(.*?)-(\d.*)$/ or next 0 0 0
167  
168 # tidy up the oddness FreeBSD versions
169 0 $version =~ s/_\d$//;
170  
171 # only populate if CPAN already has
172 $self->{data}{$dist}{freebsd} = $version
173 0 ▶ if $self->{data}{$dist};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"data"}{$dist} 0 0 0
174 }
175 }
176  
177 0 ▶sub _fetch_debian {
Subroutine _fetch_debian: not called CC=7 SCAR=40.3
178 0 my $self = shift;
179  
180 0 my %dists = map { lc $_ => $_ } keys %{ $self->{data} };
181 0 for my $dist (qw( stable testing unstable )) {
182 0 my $data =
183 $self->cache->get_url(
184 "http://ftp.debian.org/dists/$dist/main/binary-i386/Packages.gz",
185 "debian-$dist-Packages.gz");
186 0 $data = Compress::Zlib::memGunzip($data);
187  
188 0 my $fh = IO::String->new($data);
189 0 my $debthing = Parse::Debian::Packages->new($fh);
190 0 ▶ while (my %package = $debthing->next) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(%package) = $debthing->next) 0 0 0
191 next
192 unless $package{Package} =~ /^lib(.*?)-perl$/
193 0 ▶ || $package{Package} =~ /^perl-(tk)$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $package{"Package"} =~ /^lib(.*?)-perl$/ or $package{"Package"} =~ /^perl-(tk)$/ 0 0 0
Condition0%0/3
$package{"Package"} =~ /^lib(.*?)-perl$/ or $package{"Package"} =~ /^perl-(tk)$/
l!l&&r!l&&!r
000
MC/DC0%0/2
$package{"Package"} =~ /^lib(.*?)-perl$/ or $package{"Package"} =~ /^perl-(tk)$/
$package{"Package"} =~ /^lib(.*?)-perl$/ $package{"Package"} =~ /^perl-(tk)$/
Truth table0%0/3
A or B
A= $package{"Package"} =~ /^lib(.*?)-perl$/B= $package{"Package"} =~ /^perl-(tk)$/
ABresult
1X1
011
000
194 0 ▶ my $dist = $dists{$1} or next;
Branch: 1 branch
BranchTrueFalseTotal
my $dist = $dists{$1} or next 0 0 0
195  
196 # don't care about the debian version
197 0 my ($version) = $package{Version} =~ /^(.*?)-/;
198 $self->{data}{$dist}{debian} = $version
199 0 ▶ if $self->{data}{$dist};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"data"}{$dist} 0 0 0
200 }
201 }
202 }
203  
204 0 ▶sub _fetch_openbsd {
Subroutine _fetch_openbsd: not called CC=4 SCAR=30.0
205 0 my $self = shift;
206 0 my $file =
207 $self->cache->get_url("http://www.openbsd.org/3.6_packages/i386.html",
208 "openbsd.html");
209  
210 0 for my $package ($file =~ m/href=i386\/p5-(.*?)\.tgz-long/g) {
211 0 ▶ my ($dist, $version) = $package =~ /^(.*?)-(\d.*)$/ or next;
Branch: 1 branch
BranchTrueFalseTotal
() = $package =~ /^(.*?)-(\d.*)$/ or next 0 0 0
212  
213 # only populate if CPAN already has
214 $self->{data}{$dist}{openbsd} = $version
215 0 ▶ if $self->{data}{$dist};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"data"}{$dist} 0 0 0
216 }
217 }
218  
219 0 ▶sub check {
Subroutine check: not called CC=1 SCAR=6.9
Pod documented
220 0 my ($self, $dist) = @_;
221  
222 0 return $self->{data}->{$dist};
223 }
224  
225 1 1;
226  
227 __END__
↑ Summary Packaged.pm »