Просмотр исходного кода

Dpkg::Control::Info: provide an array representation of the object

Add non-regression test for this interface.
Raphaël Hertzog лет назад: 16
Родитель
Сommit
513baa2c1e
2 измененных файлов с 18 добавлено и 2 удалено
  1. 15 1
      scripts/Dpkg/Control/Info.pm
  2. 3 1
      scripts/t/700_Dpkg_Control.t

+ 15 - 1
scripts/Dpkg/Control/Info.pm

@@ -1,4 +1,4 @@
-# Copyright © 2007 Raphaël Hertzog <hertzog@debian.org>
+# Copyright © 2007-2010 Raphaël Hertzog <hertzog@debian.org>
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -24,6 +24,9 @@ use Dpkg::Gettext;
 
 use base qw(Dpkg::Interface::Storable);
 
+use overload
+    '@{}' => sub { return [ $_[0]->{source}, @{$_[0]->{packages}} ] };
+
 =head1 NAME
 
 Dpkg::Control::Info - parse files like debian/control
@@ -108,6 +111,7 @@ sub parse {
     }
 }
 
+=item $c->[0]
 =item $c->get_source()
 
 Returns a Dpkg::Control object containing the fields concerning the
@@ -176,6 +180,16 @@ sub output {
     return $str;
 }
 
+=item "$c"
+
+Return a string representation of the content.
+
+=item @{$c}
+
+Return a list of Dpkg::Control objects, the first one is corresponding to
+source information and the following ones are the binary packages
+information.
+
 =back
 
 =head1 AUTHOR

+ 3 - 1
scripts/t/700_Dpkg_Control.t

@@ -13,7 +13,7 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-use Test::More tests => 9;
+use Test::More tests => 11;
 
 use strict;
 use warnings;
@@ -55,6 +55,7 @@ Description: short one
 is($value, $expected, "Dump of $datadir/control-1");
 
 my $src = $c->get_source();
+is($src, $c->[0], "array representation of Dpkg::Control::Info 1/2");
 is($src->{'my-field-one'}, 'myvalue1', "Access field through badly capitalized field name");
 is($src->{'long-field'}, 
 'line1
@@ -66,6 +67,7 @@ line 4', "Get multi-line field");
 is($src->{'Empty-field'}, "", "Get empty field");
 
 my $pkg = $c->get_pkg_by_idx(1);
+is($pkg, $c->[1], "array representation of Dpkg::Control::Info 2/2");
 is($pkg->{package}, 'mypackage1', 'Name of first package');
 
 $pkg = $c->get_pkg_by_name("mypackage3");