Man Linux: Main Page and Category List


       Cache::Apt::Lookup - Cache handler for apt-cross and related tools


       Extensively modified portion of NorthernCross using only the Config and
       Cache modules and exposing the package details using a dedicated

       Includes code from apt-rdepends to get the Depends info efficiently.


        use Cache::Apt::Lookup;
        use Cache::Apt::Config;
        use Cache::Apt::Package;
        use Debian::DpkgCross;   # for check_arch
        use Data::Dumper;

        my $verbose = 0;    # usually read a command line option to set an integer
        my $arch = "arm";   # usually read a command line string parameter for this.
        my $suite = "unstable";  # or use &get_suite();
        &set_verbose ($verbose);
        &check_arch($arch) if (defined ($arch));

        my $config = &init_cache($verbose);

Copyright and Licence

        Copyright (C) 2006, 2007  Neil Williams <>

        Copyright (c) 2006, 2007  Alexander Shishkin <>

        Copyright (C) 2002-2005  Simon Law <>

        This package is free software; you can redistribute it and/or modify
        it under the terms of the GNU General Public License as published by
        the Free Software Foundation; either version 3 of the License, or
        (at your option) any later version.

        This program is distributed in the hope that it will be useful,
        but WITHOUT ANY WARRANTY; without even the implied warranty of
        GNU General Public License for more details.

        You should have received a copy of the GNU General Public License
        along with this program.  If not, see <>.

compare (A, B)

       Direct link to the apt perl binding for version comparison.

       Compare package version A with B, returning a negative value if A is an
       earlier version than B, zero if the same or a positive value if A is


       Alternative function that initialises a copy of the host cache in the
       apt-cross directory to provide data on cross packages available for

       If $verbose >=4, the full Apt configuration is dumped to STDOUT before
       the call returns.

       The cache lists are not removed when switching from one architecture to

       Remember which cache has been initialised! Queries are made against
       whichever cache was initialised most recently.


       Loads the currently configured cache into memory.

       Accepts a verbosity level to support debugging modes.

       If $verbose >=4, the full Apt configuration is dumped to STDOUT before
       the call returns.


       Completely clears the current config in preparation for a new set of
       &check_cache_arch, &set_suite and &init_cache;


       Look up a package name in the source cache and return the raw apt-pkg-
       perl data or undef on error.


       Look up a package name in the Packages cache and return the raw apt-
       pkg-perl data or undef on error.


       Expects an AptCrossPackage and populates that variable with the
       dependency information for that package using the current cache
       configuration. Returns an array of AptCrossDependency instances
       suitable to be dropped into the AptCrossPackage::Depends variable.


       Provides an iterator over all package names.

       Example: (listing of all unique package names)

        my $iter = &lookup();
        my $pkg;
        my @package_names = ();
        my %hash = ();
        my $c = 0;

        do {
               $pkg = $iter->next;
               $hash{$pkg}++ if ($pkg);
        } while ($pkg);

        @package_names = sort (keys %hash);
        foreach my $p (@package_names)
               print "$p ";

        print "\nTotal of $c package names\n";


       Override the default apt_cross_dir with a specified directory that must
       already exist. This directory is also expected to contain any
       sources.list files that your script will later specify to Config.


       Sets and returns the location of ~/.apt-cross or uses .apt-cross if no
       home could be found. Note that when running under sudo (e.g. in a
       chroot) $home will be the home directory of the SUDO_USER within the

       If cachedir has been set and is usable, returns $cachedir.


       Replacement for get_aptcross_dir to distance the modules from the apt-
       cross package. get_aptcross_dir may be removed in future versions so
       use this function to get the location of the cache.


       Return the current verbosity setting.


       Used by scripts to pass a command-line verbose level to the module to
       be used to create debugging output to the console.

        0 == quiet
        1 == normal
        2 == add some progress output or user-level messages.
        3 == add debug messages to level 2.
        4 == add detailed configuration dumps to level 3.


       Supports the apt-cross -m option by adding a specific mirror to the
       sources for the currently configured cache. An update will be needed to
       load the cache data from the mirror.


       Removes the timestamp file for the current user-specific cache and
       forces an update of the apt cache. Supports the apt-cross -u command.


       Non-intrusive way to ensure the user-specific cache for the current
       configuration is up to date without force. If the cache has been
       updated within the last 24hrs, no update is performed.


       Init function for the ~/.apt-cross directory that prepares a directory
       tree suitable for each suite and architecture combination.  Copies your
       apt sources for use with the cross caches and manages the timestamp
       file to ensure the configured cache is up to date using update_sources.


       Actually performs the apt-get update for the currently configured
       cache. Called by setup_config, force_update and check_update.


       Update the user-specific apt-cross cache using the current
       configuration. Errors are directed to /dev/null because switching
       architectures and configurations can cause misleading and unnecessary
       error messages from apt.


       Collates your various apt sources into one array that can be used to
       provide sources for your cross caches.


       Retrieves the ProvidesList for the specified package.

       The AptPkg bindings index the ProvidesList under what is provided, not
       what the specified package provides, so this routine iterates over the
       cache and creates a suitable index. Subsequent queries are made against
       the new hash.

       e.g. When querying apt-cache, you may expect to see:
        $ apt-cache show cdebconf | grep Provides
        Provides: debconf-2.0

       However, in the AptPkg bindings, this relationship is indexed under
       debconf-2.0, not under cdebconf. i.e.
        $cache->{"debconf-2.0"}{ProvidesList}[0]{Name} eq "cdebconf" actually
       returns true when Cache::Apt::Lookup expects:
        $cache->{"cdebconf"}{ProvidesList}[0]{Name} eq "debconf-2.0" to be

       Returns a comma-separated list of packages that are provided by the
       specified package or undef.


       Calculates the Packages file for the requested suite and architecture
       and uses that to update the multiarch lists. Warns if the calculated
       file does not exist - in which case, use the "--suite" or "-S" options
       to apt-cross to explicitly state which suite to use. (This can happen
       if you use codenames in your /etc/apt/sources.list rather than suite
       names (sid instead of unstable). Apart from sid, the mapping from a
       codename to a suite name changes with each release and this module does
       not attempt to keep up with these changes.

       Once found, the routine checks for
       /usr/share/apt-cross/ and passes the Packages file
       to it.