]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
OpenSSL::Ordinals: Add options for the writing functions
authorRichard Levitte <levitte@openssl.org>
Thu, 8 Oct 2020 04:27:51 +0000 (06:27 +0200)
committerRichard Levitte <levitte@openssl.org>
Fri, 9 Oct 2020 08:19:47 +0000 (10:19 +0200)
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 <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/13092)

util/perl/OpenSSL/Ordinals.pm

index 0b1db48dd30af262520e86bd2f7a1dba8b7500b4..7008ebf5368f02221ef0586cadfb8f5ae4633d19 100644 (file)
@@ -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<sort>, 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<sort>, 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;