File Coverage

blib/lib/Debian/ModuleList.pm
Criterion Covered Total %
statement 12 42 28.5
branch 0 8 0.0
condition n/a
subroutine 4 5 80.0
pod 0 1 0.0
total 16 56 28.5


line stmt bran cond sub pod time code
1             package Debian::ModuleList;
2              
3 1     1   35464 use IPC::Open3;
  1         5457  
  1         60  
4 1     1   1442 use File::Temp qw/tempdir/;
  1         24829  
  1         81  
5 1     1   10 use File::Spec;
  1         8  
  1         22  
6 1     1   981 use IO::All;
  1         13782  
  1         12  
7              
8             our $VERSION = '0.01';
9              
10             sub list_modules {
11 0 0   0 0   die("apt-file is not installed") if ( !-x "/usr/bin/apt-file" );
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>);
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 0         $_ .= "/" if ( !( $_ =~ /\/$/ ) );
36 0 0         $matching = $_ if ( substr( $file, 0, length($_) ) eq $_ );
37             }
38 0 0         next if ( !length($matching) );
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;