ALPM::Package - ALPM package class.


ALPM documentation Contained in the ALPM distribution.

Index


Code Index:

NAME

Top

ALPM::Package - ALPM package class.

SYNOPSIS

Top

  use ALPM qw( /etc/pacman.conf );
  my $perlpkg = ALPM->localdb->find('perl');

  # TMTOWTDI!

  my $name = $perlpkg->name();
  print "$name rocks!\n";

  my %attrs = $perlpkg->attribs();
  print "$attrs{name} rocks!\n";

  my $attrs_ref = $perlpkg->attribs_ref();
  print "attrs_ref->{name} rocks!\n";

  # Dependencies are given as arrayrefs of hashrefs (AoH):
  print "$name depends on:\n";
  for my $dep ( @{ $perlpkg->depends() } ) {
      my @words = @{$dep}{'name', 'mod', 'ver'};
      print "  @words\n";
  }

  # Others lists are arrayrefs of scalars:
  print "$name owns files:\n";
  print "  $_\n" foreach ( @{ $perlpkg->files } );

DESCRIPTION

Top

This class is a wrapper for all of the alpm_pkg_... C library functions of libalpm. You retrieve the package from the database and you can then access its attributes. Attributes are like ALPM's options. There are many different ways to access them. You cannot modify a package.

ATTRIBUTES

Top

There are three basic ways to access an attribute. You can use the accessor method that is specific to an attribute, you can use the attr method, or you can use the attribs method.

Attribute Accessors

The accessors are named (almost) exactly the same as the alpm_pkg_get... functions. They are easy to use if you only want a few attributes.

I have removed the get_ prefix on the accessors. This is because you can't really set anything so you should know it's a get anyways.

* filename
* name
* version
* desc
* url
* builddate
* installdate
* packager
* md5sum
* arch
* size
* isize
* reason
* licenses
* groups
* depends
* optdepends
* conflicts
* provides
* deltas
* replaces
* files
* backup
* has_scriptlet
* download_size
* changelog
* requiredby

Attributes with plural names return an arrayref of strings.

Dependency Lists

depends is different because it returns an arrayref of hashrefs (an AoH). The hash has the following key-value pairs:

  |---------+----------------------------------------|
  | Key     | Value                                  |
  |---------+----------------------------------------|
  | name    | Package name of the dependency         |
  | version | The version to compare the real one to |
  | mod     | The modifier of the dependency         |
  |         | ('==', '>=', '<=', '<', or '>')        |
  |---------+----------------------------------------|

PERLISH METHODS

There are also more ways to get attributes. attribs is useful if you want to get all attributes at once in a hash, or many attributes at once into a list or variables.

attribs

  Usage   : my %attribs = $pkg->attribs();
            my ($name, $desc) = $pkg->attribs('name', 'desc');
  Params  : If you specify attribute names, their values are returned as
            a list.  Otherwise, returns a hash of all attributes.
  Returns : Either a hash or a list.

attribs_ref

  This is the same as attribs, but it returns a hashref or
  arrayref instead.

SEE ALSO

Top

ALPM, ALPM::DB

AUTHOR

Top

Justin Davis, <juster at cpan dot org>

COPYRIGHT AND LICENSE

Top


ALPM documentation Contained in the ALPM distribution.

package ALPM::Package;

use warnings;
use strict;

use English qw(-no_match_vars);
use base qw(Exporter);
use Carp qw(croak);

my %_PKG_ATTRIBS = map { /^has_(.*)$/ ? ( $1 => $_ ) : ( $_ => $_ ) }
    qw { filename name version desc url
         builddate installdate packager md5sum
         arch size isize reason licenses requiredby
         groups depends optdepends conflicts
         provides deltas replaces files backup
         has_scriptlet download_size };


#---HELPER METHOD---
#  Usage   : my $name = $pkg->attr('name');
#  Purpose : This is used by attribs().
#  Params  : The name of the attribute.
#  Returns : The attribute value.
#-------------------
sub _attr
{
    croak "Invalid arguments to attrib method" if (@_ != 2);
    my ($self, $attrib_name) = @_;

    croak qq{Unknown package attribute "$attrib_name"}
        unless ( exists $_PKG_ATTRIBS{$attrib_name} );

    my $method_name = $_PKG_ATTRIBS{$attrib_name};

    my $method_ref = $ALPM::Package::{$method_name};
    my $result = eval { $method_ref->($self) };
    if ($EVAL_ERROR) {
        # For ALPM errors, show the line number of the calling script...
        croak $1 if ( $EVAL_ERROR =~ /^(ALPM .*) at .*? line \d+[.]$/ );
        croak $EVAL_ERROR;
    }

    return $result;
}

sub attribs
{
    my $self = shift;

    return map { $self->_attr($_) } @_ if ( @_ > 0 );

    return map { ( $_ => $self->_attr($_) ) } keys %_PKG_ATTRIBS;
}

sub attribs_ref
{
    my $self = shift;

    return ( @_ == 0 ? { $self->attribs(@_) } : [ $self->attribs(@_) ] );
}

1;