/usr/share/doc/libapt-pkg-perl/examples/apt-cache is in libapt-pkg-perl 0.1.33build1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 | #!/usr/bin/perl
#
# Example: demonstrate accessing the package cache
#
# Usage: apt-cache PACKAGE
#
use AptPkg::Config '$_config';
use AptPkg::System '$_system';
use AptPkg::Cache;
(my $self = $0) =~ s#.*/##;
# initialise the global config object with the default values and
# setup the $_system object
$_config->init;
$_system = $_config->system;
# suppress cache building messages
$_config->{quiet} = 2;
# set up the cache
my $cache = AptPkg::Cache->new;
my $policy = $cache->policy;
die "Usage: $self PACKAGE ...\n" unless @ARGV;
for my $pack (@ARGV)
{
my $p = $cache->{$pack};
unless ($p)
{
warn "$self: don't know anything about package `$pack'\n";
next;
}
print "Package: $pack\n";
for my $field (qw/Section SelectedState InstState CurrentState Flags/)
{
print "$field: $p->{$field}\n" if $p->{$field};
}
print "CurrentVer: $p->{CurrentVer}{VerStr}\n" if $p->{CurrentVer};
if (my $c = $policy->candidate($p))
{
print "CandidateVer: ", $c->{VerStr}, "\n";
}
my $prio = $policy->priority($p);
my $pin_ver;
if ($prio and my $v = $policy->match($p))
{
$pin_ver = $v->{VerStr};
}
if (my $available = $p->{VersionList})
{
print "VersionList:\n";
my $i = 0;
for my $v (@$available)
{
print " [$i] $v->{VerStr}";
print " (prio $prio)" if $prio and $pin_ver eq $v->{VerStr};
print "\n";
for my $f (map $_->{File}, @{$v->{FileList}})
{
printf " * %s (prio %d)\n", $f->{FileName},
$policy->priority($f);
}
for my $field (qw/MultiArch Arch Priority/)
{
print " $field: $v->{$field}\n" if $v->{$field};
}
if (my $deps = $v->{DependsList})
{
my $type = '';
my $delim = '';
for my $d (@$deps)
{
if ($d->{DepType} ne $type)
{
print "\n" if $type;
$type = $d->{DepType};
print " $type: ";
}
else
{
print $delim;
}
$delim = ($d->{CompType} & AptPkg::Dep::Or) ? ' | ' : ', ';
print $d->{TargetPkg}{ShortName};
print " ($d->{CompTypeDeb} $d->{TargetVer})"
if $d->{TargetVer};
}
print "\n";
}
if (my $p = $v->{ProvidesList})
{
print ' Provides: ', (join ', ', map $_->{Name}, @$p),
"\n";
}
$i++;
}
}
if (my $revdeps = $p->{RevDependsList})
{
print "RevDependsList:";
my $parent = '';
my $type = '';
for my $r (@$revdeps)
{
my $new_parent = "$r->{ParentPkg}{ShortName} $r->{ParentVer}{VerStr}";
unless ($new_parent eq $parent)
{
$parent = $new_parent;
$type = '';
}
if ($r->{DepType} ne $type)
{
printf "\n %-30s", $type ? '' : $parent;
$type = $r->{DepType};
print " $type: ";
}
else
{
print ', ';
}
print $r->{TargetPkg}{ShortName};
print " ($r->{CompTypeDeb} $r->{TargetVer})" if $r->{TargetVer};
}
print "\n";
}
if (my $provides = $p->{ProvidesList})
{
print 'ProvidesList: ', (join ', ',
map "$_->{OwnerPkg}{ShortName} $_->{OwnerVer}{VerStr}", @$provides),
"\n";
}
print "\n";
}
1;
|