ALPM - XS module, OO wrapper of libalpm, Archlinux's packaging system
use ALPM ( root => '/', dbpath => '/var/lib/pacman/', cachedirs => [ '/var/cache/pacman/pkg' ], logfile => '/var/log/pacman.log', xfercommand => '/usr/bin/wget --passive-ftp -c -O %o %u' ); # It's easier just to load a configuration file: use ALPM qw(/etc/pacman.conf); # My new favorite way to get/set options. A tied hash. (TMTOWTDI) my %alpm; tie %alpm, 'ALPM'; $alpm{root} = '/'; printf "Root Dir = %s\n", $alpm{root}; my ($root, $dbpath, $cachedir) = @alpm{qw/root dbpath cachedir/}; # Callback options... $alpm{logcb} = sub { my ($msg, $lvl) = @_; print "[$lvl] $msg\n" }; # Querying databases & packages my $localdb = ALPM->local_db; my $pkg = $localdb->get_pkg('perl'); # Lots of different ways to get package attributes... my $attribs_ref = $pkg->get_attribs_ref; my $name = $pkg->get_name; my ($size, $isize) = $pkg->get_attribs('size', 'isize'); print "$name $attribs_ref->{version} $attribs_ref->{arch} $size/$isize"; my $syncdb = ALPM->register_db( 'extra', 'ftp://ftp.archlinux.org/$repo/os/i686' ); my $perlpkgs = $syncdb->search('perl'); printf "%d perl packages found.\n", scalar @{$perlpkgs}; # Transactions my $trans = ALPM->transaction( type => 'upgrade' ); $trans->add( 'perl', 'perl-alpm', 'pacman' ); #$trans->prepare; (unnecessary, commit does it if needed) $trans->commit; $trans = undef; # to force releasing, not required though
Archlinux uses a package manager called pacman. Pacman internally uses the alpm library for handling its database of packages. This module is an attempt at creating a perlish object-oriented interface to the libalpm C library.
None.
Because all alpm functions have been converted to class methods, classes, and object methods, nothing is exported.
There are a few different options you can specify after use ALPM. These help to set configuration options for ALPM. These options are global for everyone who is using the module. You can specify either:
use ALPM
ALPM has a number of options corresponding to the alpm_option_get_... and alpm_option_set... C functions in the library. Options which take multiple values (hint: they have a plural name) expect an array reference as an argument. Similarly the same options return multiple values as an array reference.
alpm_option_get_...
alpm_option_set...
* = the option is set with (and returns) an arrayref + = the option is boolean and is either 0 or 1
Callbacks can only be set to code references.
The log message and level are passed to the provided code ref as arguments. level can be: error, warning, debug, function, or unknown
The filename, bytes transfered, and bytes total are passed to the provided code ref as arguments.
The total number of bytes downloaded so far is passed to the provided code ref as the only argument.
ALPM has all its package specific and database specific functions inside the package and database classes as methods. Everything else is accessed through class methods to ALPM.
As far as I can tell you cannot run multiple instances of libalpm. Class methods help remind you of this. The class method notation also helps to differentiate between globally affecting ALPM functions and package or database-specific functions.
Params : Pass set_options a hash or hashref to set many options at once. Returns : 1
Usage : ALPM->set_opt( 'root', '/' ); Params : An option name and new option value. Returns : 1
Usage : my %alpm_opts = ALPM->get_options(); my ($root, $dbpath) = ALPM->get_options( 'root', 'dbpath' ); Params : * When no params are given, returns a hash of all options. * Otherwise, return a list of option values in the same order as the parameters. Notes : Unset options are undefined. Returns : A hashref or list.
Usage : my $root = ALPM->get_opt('root'); Params : An option name. Returns : The given option's value or undef if it is unset.
Usage : my $localdb = ALPM->register_db; my $syncdb = ALPM->register_db( 'core' => 'ftp://ftp.archlinux.org/$repo/os/i686' ); Params : No parameters will return the local database. Two parameters will register a sync database: 1) The name of the repository to connect to. 2) The URL to the repository's online files. Like with pacman's mirrorlist config file, $repo will be replaced with the repository name (argument 1) ... use single quotes! Precond : You must set options before using register_db. Throws : An 'ALPM DB Error: ...' message is croaked on errors. Returns : An ALPM::DB object.
See ALPM::DB
Returns : The local system database as an ALPM::DB object. Precond : You must set certain options first. This is what is called by register_db without arguments.
Usage : my $comm_db = ALPM->get_repo_db('community'); Params : The name of a repository. Returns : An ALPM::DB object matching the repo name.
Usage : my $pkgfile = ALPM->load_pkgfile('perl-alpm-0.2.pkg.tar.gz'); Params : The path to a package tarball. Returns : An ALPM::Package object.
See ALPM::Package
Usage : ALPM->load_config('/etc/pacman.conf'); Params : The path to a pacman.conf configuration file. Returns : 1
Usage : my $t = ALPM->transaction( type => 'sync', flags => qw/ nodeps / ); Purpose : Initializes a transaction Params : A hash of the transaction settings type => A string, can be upgrade, remove, removeupgrade, or sync. flags => A list of strings, valid flags are: nodeps, force, nosave, cascade, recurse, dbonly, alldeps, dlonly, noscriptlet, noconflicts, printuris, needed, allexplicit, unneeded, recurseall event => A coderef, used as an event callback. When an event occurs, the coderef is passed a hashref representing the event. Events are explained in detail in the ALPM::Transaction document. Throws : An 'ALPM Error: ...' is thrown if a transaction is already active. Returns : An ALPM::Transaction object.
See ALPM::Transaction
Global ALPM errors are thrown with croak. The error messages match the errors that the C library provides. These errors are prefixed with ALPM Error: . Errors that occur when using a ALPM::DB object are prefixed with ALPM DB Error: .
croak
ALPM Error:
ALPM DB Error:
TODO: List of error messages.
TODO: Common error messages and how to fix them.
ALPM::DB, ALPM::Package, ALPM::Transaction
http://code.toofishes.net/cgit/ - GIT repository for pacman/libalpm
http://code.toofishes.net/pacman/doc/ - libalpm doxygen docs
libalpm(8) (pretty sparse)
pacman(8)
Justin Davis, <jrcd83 at gmail dot com>
<jrcd83 at gmail dot com>
Copyright (C) 2009 by Justin Davis
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.10.0 or, at your option, any later version of Perl 5 you may have available.
To install ALPM, copy and paste the appropriate command in to your terminal.
cpanm
cpanm ALPM
CPAN shell
perl -MCPAN -e shell install ALPM
For more information on module installation, please visit the detailed CPAN module installation guide.