[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[SCM] Debian package checker branch, master, updated. 2.5.10-62-g6181042



The following commit has been merged in the master branch:
commit 61810422456fd10238b428f02ef4258bdcb784ca
Author: Niels Thykier <niels@thykier.net>
Date:   Thu Jul 19 14:47:04 2012 +0200

    L::P::Package: Determine guess type if not given in new
    
    Let the constructor of Lintian::Processable::Package guess the type of
    the processable if it is not explicitly given.  At the same time,
    re-order the arguments so the type argument can be omitted.
    
    Remove the constructor and _init in L::Processable; they are no longer
    used.
    
    Signed-off-by: Niels Thykier <niels@thykier.net>

diff --git a/collection/index b/collection/index
index 348f3db..0abe2ae 100755
--- a/collection/index
+++ b/collection/index
@@ -64,7 +64,7 @@ sub gather_tarballs {
     fail "Cannot resolve \"dsc\" link for $pkg or it does not point to a file." unless $file and -e $file;
     # Use Lintian::Processable::Package to determine source and version as handles missing fields
     # for us to some extend.
-    $proc = Lintian::Processable::Package->new ('source', $file);
+    $proc = Lintian::Processable::Package->new ($file, 'source');
     $data = get_dsc_info($file) or fail "Could not parse dsc file for $pkg.\n";
     #  Version handling is based on Dpkg::Version::parseversion.
     $version = $proc->pkg_src_version;
diff --git a/lib/Lintian/Processable.pm b/lib/Lintian/Processable.pm
index e63c768..f2ec90d 100644
--- a/lib/Lintian/Processable.pm
+++ b/lib/Lintian/Processable.pm
@@ -35,7 +35,7 @@ Lintian::Processable -- An (abstract) object that Lintian can process
  use Lintian::Processable::Package;
  
  # Instantiate via Lintian::Processable::Package
- my $proc = Lintian::Processable::Package->new ('binary', 'lintian_2.5.0_all.deb');
+ my $proc = Lintian::Processable::Package->new ('lintian_2.5.0_all.deb');
  my $pkg_name = $proc->pkg_name;
  my $pkg_version = $proc->pkg_version;
  # etc.
@@ -47,35 +47,12 @@ deb files).  Multiple objects can then be combined into
 L<groups|Lintain::ProcessableGroup>, which Lintian will process
 together.
 
-=head1 METHODS
+=head1 INSTANCE METHODS
 
 =over 4
 
-=item Lintian::Processable->new ($pkg_type[, ...])
-
-Creates a new processable of type $pkg_type, which must be one of:
- 'binary', 'udeb', 'source' or 'changes'
-
-This rest of the arguments (if any) will be passed to $self->_init,
-which sub-classes must override.
-
-Note: This method should not be called directly via
-Lintian::Processable.  Please refer to a sub-class like
-L<Lintian::Processable::Package>.
-
 =cut
 
-sub new {
-    my ($class, $pkg_type, @args) = @_;
-    my $self = {};
-    bless $self, $class;
-    $self->{pkg_type} = $pkg_type;
-    $self->{tainted} = 0;
-    $self->_init ($pkg_type, @args);
-    $self->_make_identifier unless exists $self->{identifier};
-    return $self;
-}
-
 sub _make_identifier {
     my ($self) = @_;
     my $pkg_type = $self->pkg_type;
@@ -177,17 +154,6 @@ sub clear_cache {
     my ($self) = @_;
 }
 
-sub _init {
-    my ($self, $pkg_type, @args) = @_;
-    my $type = ref $self;
-    if ($type && $type eq 'Lintian::Processable') {
-        croak 'Cannot create Lintian::Processable directly';
-    } elsif ($type) {
-        croak "$type has not overridden " . ${type} . '::_init';
-    }
-    croak 'Lintian::Processable::_init should not be called directly';
-}
-
 
 =back
 
diff --git a/lib/Lintian/Processable/Package.pm b/lib/Lintian/Processable/Package.pm
index 661cc51..55c3998 100644
--- a/lib/Lintian/Processable/Package.pm
+++ b/lib/Lintian/Processable/Package.pm
@@ -24,6 +24,7 @@ use base qw(Lintian::Processable Class::Accessor);
 use strict;
 use warnings;
 
+use Cwd qw(realpath);
 use Carp qw(croak);
 
 use Lintian::Util qw(get_deb_info get_dsc_info);
@@ -39,7 +40,7 @@ Lintian::Processable::Package -- An object that Lintian can process
 
  use Lintian::Processable::Package;
  
- my $proc = Lintian::Processable::Package->new ('binary', 'lintian_2.5.0_all.deb');
+ my $proc = Lintian::Processable::Package->new ('lintian_2.5.0_all.deb');
  my $pkg_name = $proc->pkg_name;
  my $pkg_version = $proc->pkg_version;
  # etc.
@@ -51,32 +52,54 @@ deb files).  Multiple objects can then be combined into
 L<groups|Lintian::ProcessableGroup>, which Lintian will process
 together.
 
-=head1 METHODS
+=head1 CLASS METHODS
 
 =over 4
 
-=item Lintian::Processable::Package->new($pkg_type, $pkg_path)
+=item new (FILE[, TYPE])
 
-Creates a new processable of type $pkg_type, which must be one of:
- 'binary', 'udeb', 'source' or 'changes'
+Creates a processable from FILE.  If TYPE is given, the FILE is
+assumed to be that TYPE otherwise the type is determined by the file
+extension.
 
-$pkg_path should be the absolute path to the package file that
-defines this type of processable (e.g. the changes file).
-
-=item $proc->lab_pkg([$lpkg])
-
-Returns or sets the L<$lpkg|Lintian::Lab::Entry> element for this processable.
+TYPE is one of "binary" (.deb), "udeb" (.udeb), "source" (.dsc) or
+"changes" (.changes).
 
 =cut
 
-Lintian::Processable::Package->mk_accessors (qw(group lab_pkg));
-
 # internal initialization method.
 #  reads values from fields etc.
-sub _init {
-    my ($self, $pkg_type, $pkg_path) = @_;
+sub new {
+    my ($class, $file, $pkg_type) = @_;
+    my $pkg_path;
+    my $self;
+
+    if (not defined $pkg_type) {
+        if ($file =~ m/\.dsc$/o) {
+            $pkg_type = 'source';
+        } elsif ($file =~ m/\.deb$/o) {
+            $pkg_type = 'binary';
+        } elsif ($file =~ m/\.udeb$/o) {
+            $pkg_type = 'udeb';
+        } elsif ($file =~ m/\.changes$/o) {
+            $pkg_type = 'changes';
+        } else {
+            croak "$file is not a known type of package";
+        }
+    }
+
+    croak "$file does not exists"
+        unless -f $file;
 
-    $self->{pkg_path} = $pkg_path;
+    $pkg_path = realpath ($file);
+    croak "Cannot resolve $file: $!"
+        unless $pkg_path;
+
+    $self = {
+        pkg_type => $pkg_type,
+        pkg_path => $pkg_path,
+        tainted => 0,
+    };
 
     if ($pkg_type eq 'binary' or $pkg_type eq 'udeb'){
         my $dinfo = get_deb_info ($pkg_path) or
@@ -149,9 +172,26 @@ sub _init {
             $self->{$field} =~ s,${\EVIL_CHARACTERS},_,go;
         }
     }
-    return 1;
+    bless $self, $class;
+    $self->_make_identifier;
+    return $self;
 }
 
+
+=back
+
+=head1 INSTANCE METHODS
+
+=over 4
+
+=item $proc->lab_pkg([$lpkg])
+
+Returns or sets the L<$lpkg|Lintian::Lab::Entry> element for this processable.
+
+=cut
+
+Lintian::Processable::Package->mk_accessors (qw(group lab_pkg));
+
 # _derive_name ($file, $ext)
 #
 # Derive the name from the file name
diff --git a/lib/Lintian/ProcessableGroup.pm b/lib/Lintian/ProcessableGroup.pm
index d127f5f..5fc1f0c 100644
--- a/lib/Lintian/ProcessableGroup.pm
+++ b/lib/Lintian/ProcessableGroup.pm
@@ -75,7 +75,7 @@ sub _init_group_from_changes {
     fail "$changes does not exist" unless -e $changes;
     $cinfo = get_dsc_info ($changes) or
         fail "$changes is not a valid changes file";
-    $self->add_new_processable('changes', $changes);
+    $self->add_new_processable ($changes, 'changes');
     $cdir = $changes;
     if ( $changes =~ m,^/+[^/]++$,o){
         # it is "/files.changes?"
@@ -87,7 +87,7 @@ sub _init_group_from_changes {
         $cdir =~ s,(.+)/[^/]+$,$1,;
     }
     foreach my $line (split (/\n/o, $cinfo->{'files'}//'')) {
-        my ($file, $pkg_type);
+        my ($file);
         next unless defined $line;
         chomp($line);
         $line =~ s/^\s++//o;
@@ -108,38 +108,33 @@ sub _init_group_from_changes {
             exit 2;
         }
 
-        if ($file =~ /\.deb$/o) {
-            $pkg_type = 'binary';
-        } elsif ($file =~ /\.udeb$/o){
-            $pkg_type = 'udeb';
-        } elsif ($file =~ /\.dsc$/o){
-            $pkg_type = 'source';
-        } else {
+        if ($file !~ /\.u?deb$/o and $file !~ m/\.dsc$/o) {
             # Some file we do not care about (at least not here).
             next;
         }
 
-        $self->add_new_processable($pkg_type, "$cdir/$file");
+        $self->add_new_processable ("$cdir/$file");
 
     }
     return 1;
 }
 
-=item $group->add_new_processable($pkg_type, $pkg_path)
+=item $group->add_new_processable ($pkg_path[, $pkg_type])
 
-Adds a new processable of type $pkg_type from $pkg_path.
+Adds a new processable of type $pkg_type from $pkg_path.  If $pkg_type
+is not given, it will be determined by the file extension.
 
 This is short hand for:
 
  $group->add_processable(
-    Lintian::Processable->new($pkg_type, $pkg_path));
+    Lintian::Processable->new ($pkg_path, $pkg_type));
 
 =cut
 
 sub add_new_processable {
-    my ($self, $pkg_type, $pkg_path) = @_;
+    my ($self, $pkg_path, $pkg_type) = @_;
     return $self->add_processable(
-        Lintian::Processable::Package->new($pkg_type, $pkg_path));
+        Lintian::Processable::Package->new ($pkg_path, $pkg_type));
 }
 
 =item $group->add_processable($proc)
diff --git a/lib/Lintian/ProcessablePool.pm b/lib/Lintian/ProcessablePool.pm
index f25f683..b38abc6 100644
--- a/lib/Lintian/ProcessablePool.pm
+++ b/lib/Lintian/ProcessablePool.pm
@@ -75,23 +75,14 @@ processables from the same source package (if any).
 
 sub add_file {
     my ($self, $file) = @_;
-    my ($pkg_path, $pkg_type, $proc, $procid);
-    croak "$file does not exist" unless -e $file;
-    $pkg_path = Cwd::abs_path ($file);
-    if ($pkg_path =~ m/\.changes$/o){
+    if ($file =~ m/\.changes$/o){
+        croak "$file does not exist" unless -f $file;
+        my $pkg_path = Cwd::abs_path ($file);
+        croak "Cannot resolve $file: $!" unless $pkg_path;
         return $self->_add_changes_file ($pkg_path);
     }
-    if ($pkg_path =~ m/\.dsc$/o) {
-        $pkg_type = 'source';
-    } elsif ($pkg_path =~ m/\.deb$/o) {
-        $pkg_type = 'binary';
-    } elsif ($pkg_path =~ m/\.udeb$/o) {
-        $pkg_type = 'udeb';
-    } else {
-        croak "$pkg_path is not a known type of package.";
-    }
 
-    $proc = Lintian::Processable::Package->new ($pkg_type, $pkg_path);
+    my $proc = Lintian::Processable::Package->new ($file);
     return $self->add_proc ($proc);
 }
 
diff --git a/reporting/harness b/reporting/harness
index 089b95c..10bd29c 100755
--- a/reporting/harness
+++ b/reporting/harness
@@ -221,7 +221,7 @@ unless ($opt{'reports-only'}) {
             my $entry;
             unless ($opt{'dry-run'}) {
                 eval {
-                    $proc = Lintian::Processable::Package->new ($type, $file);
+                    $proc = Lintian::Processable::Package->new ($file, $type);
                 };
                 unless ($proc) {
                     my $name = "$type:$pkg_name/$pkg_version";

-- 
Debian package checker


Reply to: