From: Richard Levitte Date: Thu, 8 Oct 2020 04:27:51 +0000 (+0200) Subject: OpenSSL::Ordinals: Add options for the writing functions X-Git-Tag: openssl-3.0.0-alpha7~41 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=0c12ca7294ac887d3d07a3294d1ee7c35a2be7e4;p=thirdparty%2Fopenssl.git OpenSSL::Ordinals: Add options for the writing functions OpenSSL::Ordinals::rewrite() and OpenSSL::Ordinals::write() now take options, that are simply passed to OpenSSL::Ordinals::items(). The 'sort' option is forbidden, though, since write() already uses it, but that means it's possible to filter the output. Reviewed-by: Paul Dale (Merged from https://github.com/openssl/openssl/pull/13092) --- diff --git a/util/perl/OpenSSL/Ordinals.pm b/util/perl/OpenSSL/Ordinals.pm index 0b1db48dd30..7008ebf5368 100644 --- a/util/perl/OpenSSL/Ordinals.pm +++ b/util/perl/OpenSSL/Ordinals.pm @@ -179,7 +179,7 @@ sub renumber { my $self = shift; my $max_assigned = 0; - foreach ($self->items(by => by_number())) { + foreach ($self->items(sort => by_number())) { $_->number($_->intnum()) if $_->number() =~ m|^\?|; if ($max_assigned < $_->number()) { $max_assigned = $_->number(); @@ -190,34 +190,49 @@ sub renumber { =item B<< $ordinals->rewrite >> +=item B<< $ordinals->rewrite >>, I<%options> + If an ordinals file has been loaded, it gets rewritten with the data from the current work database. +If there are more arguments, they are used as I<%options> with the +same semantics as for B<< $ordinals->items >> described below, apart +from B, which is forbidden here. + =cut sub rewrite { my $self = shift; + my %opts = @_; - $self->write($self->{filename}); + $self->write($self->{filename}, %opts); } =item B<< $ordinals->write FILENAME >> +=item B<< $ordinals->write FILENAME >>, I<%options> + Writes the current work database data to the ordinals file FILENAME. This also validates the data, see B<< $ordinals->validate >> below. +If there are more arguments, they are used as I<%options> with the +same semantics as for B<< $ordinals->items >> described next, apart +from B, which is forbidden here. + =cut sub write { my $self = shift; my $filename = shift; + my %opts = @_; croak "Undefined filename" unless defined($filename); + croak "The 'sort' option is not allowed" if $opts{sort}; $self->validate(); open F, '>', $filename or croak "Unable to open $filename"; - foreach ($self->items(by => by_number())) { + foreach ($self->items(%opts, sort => by_number())) { print F $_->to_string(),"\n"; } close F;