Parse-Debian-PackageDesc
view release on metacpan or search on metacpan
Changes
lib/Parse/Debian/PackageDesc.pm
Makefile.PL
MANIFEST This list of files
t/01-simple.t
t/02-gpg.t
t/03-versions.t
t/files/ack_1.66-1_i386.changes
t/files/libparse-debian-packagedesc-perl_0.12-1+b3_i386.changes
t/files/libwww-scraper-yahoo360-perl_0.03-0opera1_amd64.changes
t/files/signed-ack_1.66-1_i386.changes
t/gnupg/pubring.gpg
t/gnupg/secring.gpg
t/gnupg/trustdb.gpg
META.yml Module meta-data (added by MakeMaker)
lib/Parse/Debian/PackageDesc.pm view on Meta::CPAN
return map { my @fields = split(/\s+/, $_); $fields[5] }
split(/\n/, $files);
}
sub binary_package_files {
my ($self) = @_;
grep { $_ =~ /\.deb$/ } $self->files;
}
sub execute_gpg_verify {
my ($self) = @_;
my $options = defined $self->{options}->{gpg_homedir} ?
"--homedir '$self->{options}->{gpg_homedir}'" :
"";
my $gpg_cmd_line = "LC_ALL=C gpg $options --verify ".$self->path." 2>&1";
$self->{gpg_verify_output} = `$gpg_cmd_line`;
$self->{gpg_verify_status} = $?;
}
sub gpg_verify_status {
my ($self) = @_;
if (!$self->{gpg_verify_status}) {
$self->execute_gpg_verify;
}
return $self->{gpg_verify_status};
}
sub gpg_verify_output {
my ($self) = @_;
if (!$self->{gpg_verify_output}) {
$self->execute_gpg_verify;
}
return $self->{gpg_verify_output};
}
sub correct_signature {
my ($self) = @_;
return ($self->gpg_verify_status == 0);
}
sub signature_id {
my ($self) = @_;
$self->gpg_verify_output =~ /^gpg: Signature.*ID (\w+)$/m;
return $1;
}
1;
__END__
=head1 NAME
Parse::Debian::PackageDesc - Parses Debian changes and source package files
=head1 SYNOPSIS
use Parse::Debian::PackageDesc;
my $changes = Parse::Debian::PackageDesc->new('/path/foo.changes');
my $source = Parse::Debian::PackageDesc->new('/path/foo.dsc');
my $pkg = Parse::Debian::PackageDesc->new($changes_or_dsc,
gpg_homedir => '/dir/gnupg');
print $pkg->name, "\n";
print $pkg->version, "\n";
print $pkg->debian_revision, "\n";
print $pkg->distribution, "\n";
print join(", ", $pkg->binary_packages), "\n";
print $pkg->changes, "\n";
=head1 DESCRIPTION
C<Parse::Debian::PackageDesc> parses a Debian C<.changes> file (or a C<.dsc>
lib/Parse/Debian/PackageDesc.pm view on Meta::CPAN
=head2 CLASS METHODS
=over 4
=item C<new($path)>
=item C<new($path, %user_opts)>
Creates a new object representing the C<.changes> or C<.dsc> file in C<$path>.
The only valid option for C<%user_opts> is C<gpg_homedir>, which points to the
GNUPG home directory with the appropriate options and keyrings for GPG
signature validation.
=back
=head2 INSTANCE METHODS
=over 4
=item C<path>
lib/Parse/Debian/PackageDesc.pm view on Meta::CPAN
Returns the list of files referenced by the changes/dsc file.
=item C<binary_package_files>
Returns the list of binary package files referenced by the changes/dsc file.
=item C<signature_id>
Returns the key id for the signature of the changes/dsc file, or C<undef> if
there was no signature or there was some error with C<gpg>.
=item C<correct_signature>
Returns whether the the changes/dsc file has a correct signature.
=back
=head1 CONFIGURATION AND ENVIRONMENT
This module requires no configuration file or environment variables. However,
use strict;
use warnings;
use English qw(-no_match_vars);
use Test::More;
BEGIN { use FindBin qw($Bin); use lib $Bin; };
# Check if there's a sane "gpg" available
my $gpg_version_unused = `gpg --version`;
my $ret = $CHILD_ERROR;
if ($ret == -1) {
plan skip_all => "No working 'gpg' installation available";
}
else {
plan tests => 8;
}
use_ok('Parse::Debian::PackageDesc');
my $unsigned_path = 't/files/ack_1.66-1_i386.changes';
my $unsigned = Parse::Debian::PackageDesc->new($unsigned_path,
gpg_homedir => 't/gnupg');
is($unsigned->name, "ack");
is($unsigned->signature_id, undef,
"Unsigned files should get an undefined signature id");
ok(!$unsigned->correct_signature,
"Unsigned files shouldn't get a correct signature");
my $signed_path = 't/files/libwww-scraper-yahoo360-perl_0.03-0opera1_amd64.changes';
my $signed = Parse::Debian::PackageDesc->new($signed_path,
gpg_homedir => 't/gnupg');
is($signed->signature_id, "0CBC2987",
"The signature id should be correctly determined");
ok($signed->correct_signature,
"The signature should be correct");
my $unknown_signed_path = 't/files/signed-ack_1.66-1_i386.changes';
my $unknown_signed = Parse::Debian::PackageDesc->new($unknown_signed_path,
gpg_homedir => 't/gnupg');
is($unknown_signed->signature_id, "8BC4E29A",
"The signature id should be correctly determined even if unknown");
ok(!$unknown_signed->correct_signature,
"An unknown signature should be recognised as such");
__END__
# Local Variables:
# mode: cperl
( run in 1.539 second using v1.01-cache-2.11-cpan-df04353d9ac )