+2008-01-13 Raphael Hertzog <hertzog@debian.org>
+
+ * scripts/Dpkg/Fields.pm: Drop public function
+ set_fields_importance() in favor of a method on
+ Dpkg::Fields::Object. Integrate public function
+ sort_field_by_importance() in the output() method where it was
+ used.
+ * scripts/Dpkg/Changelog.pm, scripts/dpkg-genchanges.pl,
+ scripts/dpkg-gencontrol.pl, scripts/dpkg-source.pl: Updated to use
+ the set_field_importance() method instead of the removed function.
+ * scripts/Dpkg/Control.pm: Update pod documentation to refer to
+ Dpkg::Fields::Object instead of the invalid Dpkg::Cdata::Object.
+
2008-01-13 Frank Lichtenheld <djpig@debian.org>
* scripts/Dpkg/Fields.pm (dump): Allow to omit the
use Dpkg::Gettext;
use Dpkg::ErrorHandling qw(warning report syserr subprocerr);
use Dpkg::Cdata;
-use Dpkg::Fields qw(set_field_importance);
+use Dpkg::Fields;
use base qw(Exporter);
Urgency_comment Urgency_lc);
tie %CHANGELOG_FIELDS, 'Dpkg::Fields::Object';
%CHANGELOG_FIELDS = map { $_ => 1 } @CHANGELOG_FIELDS;
- set_field_importance(@CHANGELOG_FIELDS);
@URGENCIES = qw(low medium high critical emergency);
my $i = 1;
%URGENCIES = map { $_ => $i++ } @URGENCIES;
=head3 parse_changelog($file, $format, $since)
Calls "dpkg-parsechangelog -l$file -F$format -v$since" and returns a
-Dpkg::Cdata::Object with the values output by the program.
+Dpkg::Fields::Object with the values output by the program.
=cut
sub parse_changelog {
my ($classname) = @_;
tie my %entry, 'Dpkg::Fields::Object';
+ tied(%entry)->set_field_importance(@CHANGELOG_FIELDS);
my $entry = \%entry;
bless $entry, $classname;
}
=item $c->get_source()
Returns a reference to a hash containing the fields concerning the
-source package. The hash is tied to Dpkg::Cdata::Object.
+source package. The hash is tied to Dpkg::Fields::Object.
=cut
sub get_source {
Returns a reference to a hash containing the fields concerning the binary
package numbered $idx (starting at 1). The hash is tied to
-Dpkg::Cdata::Object.
+Dpkg::Fields::Object.
=cut
sub get_pkg_by_idx {
=item $c->get_pkg_by_name($name)
Returns a reference to a hash containing the fields concerning the binary
-package named $name. The hash is tied to Dpkg::Cdata::Object.
+package named $name. The hash is tied to Dpkg::Fields::Object.
=cut
sub get_pkg_by_name {
use Dpkg::Deps qw(@src_dep_fields @pkg_dep_fields);
our @ISA = qw(Exporter);
-our @EXPORT_OK = qw(capit set_field_importance sort_field_by_importance
- %control_src_fields %control_pkg_fields $control_src_field_regex
- $control_pkg_field_regex);
+our @EXPORT_OK = qw(capit %control_src_fields %control_pkg_fields
+ $control_src_field_regex $control_pkg_field_regex);
our %EXPORT_TAGS = ('list' => [qw(%control_src_fields %control_pkg_fields
$control_src_field_regex $control_pkg_field_regex)]);
return join '-', @pieces;
}
-my %fieldimps;
-
-sub set_field_importance(@)
-{
- my @fields = @_;
- my $i = 1;
-
- grep($fieldimps{$_} = $i++, @fields);
-}
-
-sub sort_field_by_importance($$)
-{
- my ($a, $b) = @_;
-
- if (defined $fieldimps{$a} && defined $fieldimps{$b}) {
- $fieldimps{$a} <=> $fieldimps{$b};
- } elsif (defined($fieldimps{$a})) {
- -1;
- } elsif (defined($fieldimps{$b})) {
- 1;
- } else {
- $a cmp $b;
- }
-}
-
package Dpkg::Fields::Object;
=head1 OTHER OBJECTS
Dpkg::Fields::capit). It also stores the order in which fields have been
added in order to be able to dump them in the same order.
-You can also dump the content of the hash with tied(%hash)->dump($fh).
-
=cut
use Tie::Hash;
our @ISA = qw(Tie::ExtraHash Tie::Hash);
use Dpkg::ErrorHandling qw(internerr syserr);
# Import capit
-Dpkg::Fields->import('capit', 'sort_field_by_importance');
+Dpkg::Fields->import('capit');
# $self->[0] is the real hash
# $self->[1] is an array containing the ordered list of keys
+# $self->[2] is an hash describing the relative importance of each field
+# (used to sort the output).
=head2 Dpkg::Fields::Object->new()
sub TIEHASH {
my $class = shift;
- return bless [{}, []], $class;
+ return bless [{}, [], {}], $class;
}
sub FETCH {
return undef;
}
+=head2 my $str = tied(%hash)->dump()
+=head2 tied(%hash)->dump($fh)
+
+Dump the raw content of the hash either as a string or to a filehandle.
+
+=cut
sub dump {
my ($self, $fh) = @_;
my $str = "";
return $str;
}
+=head2 tied(%hash)->set_field_importance(@fields)
+
+Define the order in which fields will be displayed in the output() method.
+
+=cut
+sub set_field_importance {
+ my ($self, @fields) = @_;
+ my $i = 1;
+
+ $self->[2] = {};
+ $self->[2]{$_} = $i++ foreach (@fields);
+}
+
+=head2 tied(%hash)->output($fh, $substvars)
+
+If $fh is defined, print the fields on the $fh filehandle after
+substitution of variables defined in the Dpkg::Substvars object.
+
+Also returns the string of what would printed on the filehandle.
+
+=cut
sub output {
my ($self, $fh, $substvars) = @_;
my $str = "";
+ my $imp = $self->[2]; # Hash of relative importance
# Add substvars to refer to other fields
if (defined($substvars)) {
}
}
- for my $f (sort sort_field_by_importance keys %{$self->[0]}) {
+ my @keys = sort {
+ if (defined $imp->{$a} && defined $imp->{$b}) {
+ $imp->{$a} <=> $imp->{$b};
+ } elsif (defined($imp->{$a})) {
+ -1;
+ } elsif (defined($imp->{$b})) {
+ 1;
+ } else {
+ $a cmp $b;
+ }
+ } keys %{$self->[0]};
+
+ foreach my $f (@keys) {
my $v = $self->[0]->{$f};
if (defined($substvars)) {
$v = $substvars->substvars($v);
use Dpkg::ErrorHandling qw(warning error failure unknown internerr syserr
subprocerr usageerr);
use Dpkg::Arch qw(get_host_arch debarch_eq debarch_is);
-use Dpkg::Fields qw(:list capit set_field_importance sort_field_by_importance);
+use Dpkg::Fields qw(:list capit);
use Dpkg::Compression;
use Dpkg::Control;
use Dpkg::Cdata;
delete $fields->{$f};
}
-set_field_importance(@changes_fields);
$substvars->parse($varlistfile) if -e $varlistfile;
+tied(%{$fields})->set_field_importance(@changes_fields);
tied(%{$fields})->output(\*STDOUT, $substvars);
subprocerr usageerr);
use Dpkg::Arch qw(get_host_arch debarch_eq debarch_is);
use Dpkg::Deps qw(@pkg_dep_fields %dep_field_type);
-use Dpkg::Fields qw(:list capit set_field_importance);
+use Dpkg::Fields qw(:list capit);
use Dpkg::Control;
use Dpkg::Substvars;
use Dpkg::Vars;
binmode(STDOUT);
}
-set_field_importance(@control_fields);
+tied(%{$fields})->set_field_importance(@control_fields);
tied(%{$fields})->output(\*STDOUT, $substvars);
if (!$stdout) {
$warnable_error $quiet_warnings);
use Dpkg::Arch qw(debarch_eq);
use Dpkg::Deps qw(@src_dep_fields %dep_field_type);
-use Dpkg::Fields qw(:list capit set_field_importance);
+use Dpkg::Fields qw(:list capit);
use Dpkg::Compression;
use Dpkg::Cdata;
use Dpkg::Control;
open(STDOUT, "> $basenamerev.dsc") ||
syserr(_g("create %s"), "$basenamerev.dsc");
- set_field_importance(@dsc_fields);
$substvars->parse($varlistfile) if -e $varlistfile;
+ tied(%{$fields})->set_field_importance(@dsc_fields);
tied(%{$fields})->output(\*STDOUT, $substvars);
if ($ur) {