#!/usr/bin/perl

# show package provides (+ conflicts/replaces)

use strict;
use warnings;
use AptPkg::Cache;

my $c = AptPkg::Cache->new;

for my $name (@ARGV)
{
    my $pack = $c->{$name}		or next;
    my $pl = $pack->{ProvidesList}	or next;

    my %extra;
    for my $r (@{$pack->{RevDependsList} || []})
    {
	if ($r->{DepType} == AptPkg::Dep::Conflicts or
	    $r->{DepType} == AptPkg::Dep::Replaces)
	{
	    my $k = "$r->{ParentPkg}{Name} $r->{ParentVer}{VerStr}";
	    $extra{$k}{lc $r->{DepType}} = $r->{TargetVer}
	    	? " ($r->{CompTypeDeb} $r->{TargetVer})"
		: '';
	}
    }

    print "$name:\n";
    for my $p (@$pl)
    {
	my $k = "$p->{OwnerPkg}{Name} $p->{OwnerVer}{VerStr}";
	print " * $k";
	my $e = join ' and ', map "$_$extra{$k}{$_}", sort keys %{$extra{$k}};
	print " + $e" if $e;
	print "\n";
    }
}
