lib/Debian/ModuleList.pm

filter: Statementstmt 31.8% 14 / 44 Branchbran 0.0% 0 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 80.0% 4 / 5 Podpod 0.0% 0 / 1 totaltotal 30.0% 18 / 60 CC 8 SCAR 38.8
CC
8
Cov
26%
list_modules
72.0
BEGIN
1.0
BEGIN
1.0
CRAP 48.3
↑ Summary script/list-debian-modules.pl »
1 package Debian::ModuleList;
2  
3 1 ▶use IPC::Open3;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use File::Temp qw/tempdir/;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use IO::All;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 our $VERSION = '0.01';
9  
10 0 ▶sub list_modules {
Subroutine list_modules: not called CC=8 SCAR=42.8
Pod undocumented
11 0 ▶ die("apt-file is not installed") if ( !-x "/usr/bin/apt-file" );
Branch: 1 branch
BranchTrueFalseTotal
unless -x "/usr/bin/apt-file" 0 0 0
12  
13 0 my $out;
14 0 my $dir = tempdir( CLEANUP => 1 );
15 0 my $sources = File::Spec->catfile( $dir, "sources.list" );
16 0 "deb http://ftp.us.debian.org/debian/ sid main contrib non-free\n" >
17 io($sources);
18 0 system( "apt-file", "-c", $dir, "-s", $sources, "update" );
19 0 my $pid = open3(
20 undef, $out, undef, "apt-file", "-c", $dir,
21 "-s", $sources, "-x", "search", '.*\.pm$'
22 );
23 0 my @array;
24 0 ▶ push @array, $_ while (<$out>);
Branch: 1 branch
BranchTrueFalseTotal
defined($_ = readline $out) and do { push @array, $_ } 0 0 0
25 0 waitpid( $pid, 0 );
26  
27 0 foreach (@array) {
28 0 chomp $_;
29 0 my $index = index( $_, ": " );
30 0 my ( $package, $file );
31 0 $package = substr( $_, 0, $index );
32 0 $file = substr( $_, $index + 2 );
33 0 my $matching = "";
34 0 foreach (@INC) {
35 0 ▶ $_ .= "/" if ( !( $_ =~ /\/$/ ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $_ =~ m[/$] 0 0 0
36 0 ▶ $matching = $_ if ( substr( $file, 0, length($_) ) eq $_ );
Branch: 1 branch
BranchTrueFalseTotal
if substr($file, 0, length $_) eq $_ 0 0 0
37 }
38 0 ▶ next if ( !length($matching) );
Branch: 1 branch
BranchTrueFalseTotal
unless length $matching 0 0 0
39 0 my $module = $file;
40 0 $module =~ s/$matching//;
41 0 $module =~ s/\.pm$//;
42 0 $module =~ s/\//::/g;
43 0 push @list, $module;
44  
45 # print "Package: " . $package . "\n";
46 # print "Module: " . $module . "\n";
47 }
48  
49 0 my %hash;
50 0 @hash{@list} = ();
51 0 @list = sort keys %hash;
52  
53 0 return @list;
54  
55 }
56  
57 =head1 NAME
58  
59 Debian::ModuleList - list the modules in Debian
60  
61 =head1 DESCRIPTION
62  
63 This requires apt-file to be installed.
64  
65 use Debian::ModuleList;
66 my @list = Debian::ModuleList::list_modules();
67 =cut
68  
69 1 1;
↑ Summary script/list-debian-modules.pl »