# different files, but same package
# require them here to avoid dependencies
use URPM::Build;
use URPM::Resolve;
use URPM::Signature;
our @ISA = qw(DynaLoader);
our $VERSION = '1.11';
URPM->bootstrap($VERSION);
sub new {
my ($class, %options) = @_;
my $self = bless {
depslist => [],
provides => {},
}, $class;
$self->{nofatal} = 1 if $options{nofatal};
$self;
}
sub set_nofatal { $_[0]->{nofatal} = $_[1] }
sub search {
my ($urpm, $name, %options) = @_;
my $best;
#- tries other alternative if no strict searching.
unless ($options{strict_name}) {
if ($name =~ /^(.*)-([^\-]*)-([^\-]*)\.([^\.\-]*)$/) {
foreach (keys %{$urpm->{provides}{$1} || {}}) {
my $pkg = $urpm->{depslist}[$_];
$pkg->fullname eq $name and return $pkg;
}
}
unless ($options{strict_fullname}) {
if ($name =~ /^(.*)-([^\-]*)-([^\-]*)$/) {
foreach (keys %{$urpm->{provides}{$1} || {}}) {
my $pkg = $urpm->{depslist}[$_];
my ($n, $v, $r, $a) = $pkg->fullname;
$options{src} && $a eq 'src' || $pkg->is_arch_compat or next;
"$n-$v-$r" eq $name or next;
!$best || $pkg->compare_pkg($best) > 0 and $best = $pkg;
}
$best and return $best;
}
if ($name =~ /^(.*)-([^\-]*)$/) {
foreach (keys %{$urpm->{provides}{$1} || {}}) {
my $pkg = $urpm->{depslist}[$_];
my ($n, $v, undef, $a) = $pkg->fullname;
$options{src} && $a eq 'src' || $pkg->is_arch_compat or next;
"$n-$v" eq $name or next;
!$best || $pkg->compare_pkg($best) > 0 and $best = $pkg;
}
$best and return $best;
}
}
}
unless ($options{strict_fullname}) {
foreach (keys %{$urpm->{provides}{$name} || {}}) {
my $pkg = $urpm->{depslist}[$_];
my ($n, undef, undef, $a) = $pkg->fullname;
$options{src} && $a eq 'src' || $pkg->is_arch_compat or next;
$n eq $name or next;
!$best || $pkg->compare_pkg($best) > 0 and $best = $pkg;
}
}
return $best;
}
#- Olivier Thauvin:
#- Returns @$listid, $start .. $end or the whole deplist id
#- according to the given args
sub build_listid {
my ($urpm, $start, $end, $listid) = @_;
package URPM::Package;
our @ISA = qw(); # help perl_checker
package URPM::Transaction;
our @ISA = qw(); # help perl_checker
package URPM::DB;
our @ISA = qw(); # help perl_checker
1;
__END__
=head1 NAME
URPM - Perl module to manipulate RPM files
=head1 SYNOPSIS
use URPM;
# using the local RPM database
my $db = URPM::DB::open();
$db->traverse(sub {
my ($package) = @_; # this is a URPM::Package object
print $package->filename, "\n";
# ...
});
# loading and parsing a synthesis file
my $urpm = new URPM;
$urpm->parse_synthesis("synthesis.sample.cz");
$urpm->traverse(sub {
# retrieve all packages from the dependency list
# ...
});
=head1 DESCRIPTION
The URPM module allows you to manipulate RPM files, RPM header files and
hdlist files and manage them in memory. It is notably used by the B<urpmi>
utility. It provides four classes : C<URPM>, C<URPM::DB>, C<URPM::Package>,
and C<URPM::Transaction>.
=head2 The URPM class
=over 4
=item new()
The constructor creates a new, empty URPM object. It's a blessed hash that
contains two fields:
B<depslist> is an arrayref containing the list of depending packages (which are
C<URPM::Package> objects).
B<provides> is an hashref containing as keys the list of items provided by the
URPM object.
If the constructor is called with the arguments C<< nofatal => 1 >>, various
fatal error messages are suppressed (file not found in parse_hdlist() and
parse_synthesis()).
=item read_config_files()
Force the re-reading of the RPM configuration files.
=item list_rpm_tag()
Return a hash containing the key/id values of known rpm tags
This utility function compares two version ranges, in order to calculate
dependencies properly. The ranges have roughly the form
[<|<=|==|=>|>] [epoch:]version[-release]
where epoch, version and release are RPM-style version numbers.
If the optional parameter $nopromoteepoch is true, and if the 2nd range has no
epoch while the first one has one, then the 2nd range is assumed to have an
epoch == 0.
=item $urpm->parse_synthesis($file, [ callback => sub {...} ])
This method gets the B<depslist> and the B<provides> from a synthesis file
and adds them to the URPM object.
=item $urpm->parse_hdlist($file, %options)
This method loads rpm informations from rpm B<headers> contained in an hdlist
file and adds them to the URPM object. Allowed options are
$tag may be one of C<name>, C<whatprovides>, C<whatrequires>, C<whatconflicts>,
C<group>, C<triggeredby>, or C<path>.
$names is a reference to an array, holding the acceptable values of the said
tag for the searched variables.
Then, $callback is called for each matching package in the depslist.
Returns a new C<URPM::DB> object pointing on the local RPM database.
$prefix defaults to C<""> and indicates the RPM DB root directory prefix if
any. (See the B<--root> option to rpm(1)).
$write_perm is a boolean that defaults to false, and that indicates whether
the RPM DB should be open in read/write mode.
=item rebuild($prefix)
Rebuilds the RPM database (like C<rpm --rebuilddb>). $prefix defaults to C<"">.
=item $db->traverse($callback)
Executes the specified callback (a code reference) for each package
in the DB, passing a C<URPM::Package> object as argument the callback.
=item $db->traverse_tag($tag,$names,$callback)
$tag may be one of C<name>, C<whatprovides>, C<whatrequires>, C<whatconflicts>,
C<group>, C<triggeredby>, or C<path>.
$names is a reference to an array, holding the acceptable values of the said
tag for the searched variables.
Then, $callback is called for each matching package in the DB.
=item $db->create_transaction($prefix)
Creates and returns a new transaction (an C<URPM::Transaction> object) on the
specified DB. For $prefix, cf L<open>.
=back
=head2 The URPM::Package class
Most methods of C<URPM::Package> are accessors for the various properties
of an RPM package.
Returns a 4 element list: name, version, release and architecture in an array context.
Returns a string NAME-VERSION-RELEASE.ARCH in scalar context.
=item $package->get_tag($tagid)
Returns an array containing values of $tagid. $tagid is the numerical value of
rpm tags. See rpmlib.h.
=item $package->queryformat($format)
Querying the package like rpm --queryformat do.
The function calls directly the rpmlib, then use header informations, so it
silently failed if you use synthesis instead of hdlist/rpm/header files or rpmdb.
=item $package->get_tag_modifiers($tagid)
Return an array of human readable view of tag values. $tagid is the numerical value of rpm tags.