Browse Source

Dpkg::Control::Info: Allow not loading the file in the constuctor

Accept an %opts argument for the constructor, and accept either passing
a filename option as undef, or a scalar undef.

Closes: #782019
Guillem Jover 11 years ago
parent
commit
7e85106707
2 changed files with 25 additions and 8 deletions
  1. 3 0
      debian/changelog
  2. 22 8
      scripts/Dpkg/Control/Info.pm

+ 3 - 0
debian/changelog

@@ -85,6 +85,9 @@ dpkg (1.18.0) UNRELEASED; urgency=low
     - Pass PATCH_GET environment varialbe instead of -g0 to the patch command
       in Dpkg::Source::Patch. This allows using non-GNU patch programs, like
       FreeBSD's patch.
+    - Accept an %opts argument for the Dpkg::Control::Info constructor, and
+      accept either passing a filename option as undef, or a scalar undef.
+      Closes: #782019
   * Test suite:
     - Check perl code compilation, warnings and strictness.
     - Fix dpkg-divert unit test to work on BSD «rm -rf» that cannot traverse

+ 22 - 8
scripts/Dpkg/Control/Info.pm

@@ -19,7 +19,7 @@ package Dpkg::Control::Info;
 use strict;
 use warnings;
 
-our $VERSION = '1.00';
+our $VERSION = '1.01';
 
 use Dpkg::Control;
 use Dpkg::ErrorHandling;
@@ -45,26 +45,36 @@ syntax as F<debian/control>.
 
 =over 4
 
-=item $c = Dpkg::Control::Info->new($file)
+=item $c = Dpkg::Control::Info->new(%opts)
 
-Create a new Dpkg::Control::Info object for $file. If $file is omitted, it
-loads F<debian/control>. If file is "-", it parses the standard input.
+Create a new Dpkg::Control::Info object. Loads the file from the filename
+option, if no option is specified filename defaults to F<debian/control>.
+If a scalar is passed instead, it will be used as the filename. If filename
+is "-", it parses the standard input. If filename is undef no loading will
+be performed.
 
 =cut
 
 sub new {
-    my ($this, $arg) = @_;
+    my ($this, @args) = @_;
     my $class = ref($this) || $this;
     my $self = {
 	source => undef,
 	packages => [],
     };
     bless $self, $class;
-    if ($arg) {
-	$self->load($arg);
+
+    my %opts;
+    if (scalar @args == 0) {
+        $opts{filename} = 'debian/control';
+    } elsif (scalar @args == 1) {
+        $opts{filename} = $args[0];
     } else {
-	$self->load('debian/control');
+        %opts = @args;
     }
+
+    $self->load($opts{filename}) if $opts{filename};
+
     return $self;
 }
 
@@ -203,6 +213,10 @@ information.
 
 =head1 CHANGES
 
+=head2 Version 1.01
+
+New argument: The $c->new() constructor accepts an %opts argument.
+
 =head2 Version 1.00
 
 Mark the module as public.