[SCM] Debian package checker branch, master, updated. 2.5.10-159-g7b8db3d
The following commit has been merged in the master branch:
commit 2a438e7c0e131ea984df645a48caec6c5f63c2e7
Author: Niels Thykier <niels@thykier.net>
Date: Fri Sep 21 12:33:50 2012 +0200
L::Proccessable: Add get_field to access extra fields
Signed-off-by: Niels Thykier <niels@thykier.net>
diff --git a/lib/Lintian/Processable.pm b/lib/Lintian/Processable.pm
index 7bb5625..ee2f0cf 100644
--- a/lib/Lintian/Processable.pm
+++ b/lib/Lintian/Processable.pm
@@ -73,6 +73,9 @@ from the required fields according to the Policy Manual.
my %KEEP = map { $_ => 1 } qw(
pkg_name pkg_version pkg_src pkg_src_version pkg_type pkg_path pkg_arch
);
+my %KEEP_EXTRA = map { $_ => 1} qw(
+ section binary uploaders maintainer area
+);
sub new_from_metadata {
my ($clazz, $pkg_type, $paragraph, $basepath) = @_;
@@ -140,8 +143,13 @@ sub new_from_metadata {
}
# Prune the field list...
foreach my $k (keys %$self) {
- delete $self->{$k} unless exists $KEEP{$k};
+ my $val;
+ $val = delete $self->{$k} unless exists $KEEP{$k};
+ if (defined $val && exists $KEEP_EXTRA{$k}) {
+ $self->{'extra-fields'}->{$k} = $val;
+ }
}
+ $self->_make_identifier;
return $self;
}
@@ -259,6 +267,32 @@ sub clear_cache {
}
+=item $proc->get_field ($field[, $def])
+
+Optional method to access a field in the underlying data set.
+
+Returns $def if the field is not present or the implementation does
+not have (or want to expose) it. This method is I<not> guaranteed to
+return the same value as "$proc->info->field ($field, $def)".
+
+If C<$def> is omitted is defaults to C<undef>.
+
+Default implementation accesses them via the hashref stored in
+"extra-fields" if present. If the field is present, but not defined
+$def is returned instead.
+
+NB: This is mostly an optimization used by L<Lintian::Lab> to avoid
+(re-)reading the underlying package data.
+
+=cut
+
+sub get_field {
+ my ($self, $field, $def) = @_;
+ return $def unless exists $self->{'extra-fields'} and
+ exists $self->{'extra-fields'}->{$field};
+ return $self->{'extra-fields'}->{$field}//$def;
+}
+
=back
=head1 AUTHOR
diff --git a/lib/Lintian/Processable/Package.pm b/lib/Lintian/Processable/Package.pm
index 55c3998..1ac0101 100644
--- a/lib/Lintian/Processable/Package.pm
+++ b/lib/Lintian/Processable/Package.pm
@@ -129,6 +129,7 @@ sub new {
$self->{pkg_arch} = $dinfo->{architecture};
$self->{pkg_src} = $pkg_src;
$self->{pkg_src_version} = $pkg_src_version;
+ $self->{'extra-fields'} = $dinfo;
} elsif ($pkg_type eq 'source'){
my $dinfo = get_dsc_info ($pkg_path) or croak "$pkg_path is not valid dsc file";
my $pkg_name = $dinfo->{source};
@@ -142,6 +143,7 @@ sub new {
$self->{pkg_arch} = 'source';
$self->{pkg_src} = $pkg_name; # it is own source pkg
$self->{pkg_src_version} = $pkg_version;
+ $self->{'extra-fields'} = $dinfo;
} elsif ($pkg_type eq 'changes'){
my $cinfo = get_dsc_info ($pkg_path) or croak "$pkg_path is not a valid changes file";
my $pkg_version = $cinfo->{version};
@@ -155,6 +157,7 @@ sub new {
$self->{pkg_src} = $pkg_name;
$self->{pkg_src_version} = $pkg_version;
$self->{pkg_arch} = $cinfo->{architecture};
+ $self->{'extra-fields'} = $cinfo;
} else {
croak "Unknown package type $pkg_type";
}
--
Debian package checker
Reply to: