=head1 NAME

ALPM::DB - Class to represent a libalpm database

=head1 SYNOPSIS

  ... load ALPM with options first ...

  my $localdb = ALPM->localdb;
  my $name    = $localdb->name;
  my $perl    = $localdb->find('perl');

  my $url       = 'ftp://ftp.archlinux.org/community/os/i686';
  my $syncdb    = ALPM->register_db( 'community' => $url );

  for my $pkg ( $syncdb->search( 'perl' ) ) {
      printf "%s %s\n", $pkg->name, $pkg->version;
  }

  for my $pkg ( $syncdb->find_group('xfce4')->packages ) {
      print join( q{ }, $pkg->attribs('name', 'version') ), "\n";
  }

  my @cache = $syncdb->pkgs;

=head1 METHODS

=head2 name

  Usage   : my $name = $db->name;
  Returns : The name of the repository database.
            Ex: core, extra, community, etc...

=head2 url

  Usage   : my $url = $db->url;
  Returns : The url of the repository, the same one the DB
            was initialized with or the empty string if this
            is a 'local' database.

=head2 find

  Usage   : my $package = $db->find( $package_name )
  Params  : $package_name - Exact name of the package to retrieve.
  Returns : An ALPM::Package object if the package is found.
            undef if the package with that name is not found.

=head2 find_group

  Usage   : my $group = $db->find_group( $group_name );
  Returns : An ALPM::Group object if it is found or undef.
            ALPM::Group objects have two accessors:
            $group->name - the name of the group
            $group->pkgs - A list of package objects in the group

=head2 search

  Usage   : my @results = $db->search( 'foo', 'bar', 'baz' );
  Params  : A list of strings to search for.
  Returns : An array of package objects whose name matched the search.

=head2 packages

  Usage   : my @pkgs = $db->packages;
  Params  : None
  Returns : An array of all packages in the DB.
  Notes   : This is a wrapper for the C<get_pkg_cache> method.
            It is easier if you want a list.

=head2 groups

  Usage   : my @groups = $db->groups;
  Returns : An array of all groups in the DB.

=head2 pkgs

This is an alias for the C<packages> method.

  Usage   : my @pkgs = $db->pkgs;

=head2 get_pkg_cache

  Usage    : my $cache_ref = $db->get_pkg_cache;
  Comments : Resembles the alpm_db_get_pkgcache function.
  Returns  : An arrayref of package objects in the DB cache.

=head2 pkgs_ref

This is an alias for the C<get_pkg_cache> method.

  Usage   : my $pkgs_ref = $db->pkgs_ref;

=head2 update

  Usage   : $db->update;
  Purpose : Updates the local copy of the database's package list.
  Comment : This needs to create a transaction to work, so make sure
            you don't have any active transactions.

            Things may work incorrectly if the database is not updated.
            If there is no local db copy, the package cache will be empty.
  Returns : 1
  TODO    : Provide different return values like alpm does.

=head1 SEE ALSO

L<ALPM>, L<ALPM::Package>, L<ALPM::Transaction>

=head1 AUTHOR

Justin Davis, C<< <jrcd83 at gmail> >>

=head1 COPYRIGHT AND LICENSE

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.