The following commit has been merged in the master branch:
commit 513baa2c1e20036528fd8fb986ef407d4aa8d415
Author: Raphaël Hertzog <[email protected]>
Date: Sat Feb 20 23:39:15 2010 +0100
Dpkg::Control::Info: provide an array representation of the object
Add non-regression test for this interface.
diff --git a/scripts/Dpkg/Control/Info.pm b/scripts/Dpkg/Control/Info.pm
index 14bdad1..3f3ef26 100644
--- a/scripts/Dpkg/Control/Info.pm
+++ b/scripts/Dpkg/Control/Info.pm
@@ -1,4 +1,4 @@
-# Copyright © 2007 Raphaël Hertzog <[email protected]>
+# Copyright © 2007-2010 Raphaël Hertzog <[email protected]>
#
# 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
diff --git a/scripts/t/700_Dpkg_Control.t b/scripts/t/700_Dpkg_Control.t
index 269de5d..03e903c 100644
--- a/scripts/t/700_Dpkg_Control.t
+++ b/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");
--
dpkg's main repository
--
To UNSUBSCRIBE, email to [email protected]
with a subject of "unsubscribe". Trouble? Contact [email protected]