#!/usr/bin/perl -w
# Copyright (C) 2012, Guy W. Hulbert.
# License: Public Domain

=head1 NAME

dpkg2ppl - generate perl packlist from dpkg -L output

=cut

use strict;
use vars qw ( $module @tmp $debpkg @out @path %valid_trees );

$module = shift;
defined $module or die "Usage: $0 PERL_MODULE_NAME\n";

(@tmp) = split /::/,$module;
$debpkg = lc join('','lib',join('-',@tmp,'perl'));

open(LIST,"dpkg -L $debpkg|") or die "open dpkg -L \$debpkg: $!";
chomp( @tmp = <LIST> );
close(LIST);

my %valid_trees = ( bin => 'Executables',
		 lib => 'XS Modules',
		 man => 'Documentation',
		 share => 'PP Modules', );

for ( @tmp ) {
    -d $_ and next;
    @path = split /\//;
    $path[1] eq 'usr' or die "Found (usr): $_\n";
    exists $valid_trees{$path[2]} or die "Found (sub): $_\n";
    $path[3] eq 'doc' and next;
    $path[3] eq $debpkg and next;
    push @out,$_;
}

print join("\n",@out,'');
