Lines Matching +full:self +full:- +full:working

2 # Copyright 2018-2023 The OpenSSL Project Authors. All Rights Reserved.
25 OpenSSL::Ordinals - a private module to read and walk through ordinals
31 my $ordinals = OpenSSL::Ordinals->new(from => "foo.num");
33 my $ordinals = OpenSSL::Ordinals->new();
34 $ordinals->load("foo.num");
36 foreach ($ordinals->items(comparator => by_name()) {
37 print $_->name(), "\n";
99 $instance->set_version($opts{version});
100 $instance->load($opts{from}) if defined($opts{from});
105 =item B<< $ordinals->load FILENAME >>
111 contents and is treated as read-only. The other database is an exact copy of
118 my $self = shift;
133 my $item = OpenSSL::Ordinals::Item->new(source => $filename, from => $_);
135 my $num = $item->number();
148 $item->intnum($num);
150 $tmp_name2num{$item->name()} = $num;
154 $self->{contents} = [ @tmp_contents ];
155 $self->{name2num} = { %tmp_name2num };
156 $self->{maxassigned} = $max_assigned;
157 $self->{maxnum} = $max_num;
158 $self->{filename} = $filename;
163 $self->{loaded_contents}->[$i] =
164 [ map { OpenSSL::Ordinals::Item->new($_) }
168 $self->{loaded_maxnum} = $max_num;
172 =item B<< $ordinals->renumber >>
179 my $self = shift;
182 foreach ($self->items(sort => by_number())) {
183 $_->number($_->intnum()) if $_->number() =~ m|^\?|;
184 if ($max_assigned < $_->number()) {
185 $max_assigned = $_->number();
188 $self->{maxassigned} = $max_assigned;
191 =item B<< $ordinals->rewrite >>
193 =item B<< $ordinals->rewrite >>, I<%options>
199 same semantics as for B<< $ordinals->items >> described below, apart
205 my $self = shift;
208 $self->write($self->{filename}, %opts);
211 =item B<< $ordinals->write FILENAME >>
213 =item B<< $ordinals->write FILENAME >>, I<%options>
216 This also validates the data, see B<< $ordinals->validate >> below.
219 same semantics as for B<< $ordinals->items >> described next, apart
225 my $self = shift;
232 $self->validate();
235 foreach ($self->items(%opts, sort => by_number())) {
236 print F $_->to_string(),"\n";
239 $self->{filename} = $filename;
240 $self->{loaded_maxnum} = $self->{maxnum};
244 =item B<< $ordinals->items >> I<%options>
268 my $self = shift;
277 if ($filter->[0] == F_NUMBER) {
278 my $index = $filter->[1];
279 @l = $index ? @{$self->{contents}->[$index] // []} : ();
280 } elsif ($filter->[0] == F_NAME) {
281 my $index = $self->{name2num}->{$filter->[1]};
282 @l = $index ? @{$self->{contents}->[$index] // []} : ();
284 croak __PACKAGE__."->items called with invalid filter";
287 @l = grep { $filter->($_) }
289 @{$self->{contents}};
291 croak __PACKAGE__."->items called with invalid filter";
294 return sort { $comparator->($a, $b); } @l
301 # - They MUST have the same number
302 # - They MUST have the same version
303 # - For platforms, both MUST hold the same ones, but with opposite values
304 # - For features, both MUST hold the same ones.
305 # - They MUST NOT have identical name, type, numeral, version, platforms, and features
309 my $self = shift;
314 join("\n ", map { $_->{source}.": ".$_->name() } @items), "\n";
322 $numbers{$_->intnum()} = 1;
323 $versions{$_->version()} = 1;
324 foreach ($_->features()) {
331 join(", ", map { $_->name()." => ".$_->intnum() } @items), "\n"
334 join(", ", map { $_->name()." => ".$_->version() } @items), "\n"
344 $items[0]->name(), " and ", $items[1]->name(), ":",
349 croak "Duplicate entries for ".$items[0]->name()." from ".
350 $items[0]->source()." and ".$items[1]->source()."\n"
351 if $items[0]->name() eq $items[1]->name()
352 && $items[0]->type() eq $items[1]->type()
353 && $items[0]->platforms() eq $items[1]->platforms();
356 my @platforms = ( { $items[0]->platforms() },
357 { $items[1]->platforms() } );
359 if (exists $platforms[1]->{$platform}) {
360 if ($platforms[0]->{$platform} != !$platforms[1]->{$platform}) {
363 map { my %tmp_h = $_->platforms();
364 $_->name().":".$platform
371 delete $platforms[0]->{$platform};
372 delete $platforms[1]->{$platform};
378 $items[0]->name(), " and ", $items[1]->name(), "\n";
381 $self->{contents}->[$items[0]->intnum()] = [ @items ];
385 my $self = shift;
407 my $self = shift;
425 my $self = shift;
427 my $baseversion = $self->{baseversion};
436 =item B<< $ordinals->add SOURCE, NAME, TYPE, LIST >>
450 my $self = shift;
460 croak __PACKAGE__."->add got a bad type '$type'"
466 my @items = $self->items(filter => f_name($name));
467 my $version = @items ? $items[0]->version() : $self->{currversion};
468 my $intnum = @items ? $items[0]->intnum() : ++$self->{maxnum};
469 my $number = @items ? $items[0]->number() : '?';
471 @items ? map { "\t".$_->to_string()."\n" } @items : "No previous items\n",
472 if $self->{debug};
473 @items = grep { $_->exists() } @items;
476 OpenSSL::Ordinals::Item->new( source => $source,
482 $self->_adjust_version($version),
490 print STDERR "DEBUG[",__PACKAGE__,"::add] $verbsig\n", map { "\t".$_->to_string()."\n" } @items
491 if $self->{debug};
492 $self->_putback(@items);
495 my $alias = $self->{aliases}->{$name};
496 delete $self->{aliases}->{$name};
500 push @returns, $self->add_alias($source, $alias->{name}, $name, @{$alias->{defs}})
505 =item B<< $ordinals->add_alias SOURCE, ALIAS, NAME, LIST >>
518 my $self = shift;
538 my @items = $self->items(filter => $f_byalias);
539 foreach my $item ($self->items(filter => $f_byname)) {
542 @items = grep { $_->exists() } @items;
549 $self->{aliases}->{$name} = { source => $source,
554 if $self->{debug};
560 my %alias_platforms = $items[0]->platforms();
565 $items[0]->{platforms} = { %alias_platforms };
568 $items[0]->number() =~ m|^\?| ? '?+' : $items[0]->number();
569 my $alias_item = OpenSSL::Ordinals::Item->new(
572 type => $items[0]->type(),
574 intnum => $items[0]->intnum(),
575 version => $self->_adjust_version($items[0]->version()),
576 exists => $items[0]->exists(),
578 features => [ $items[0]->features() ]
583 map { "\t".$_->to_string()."\n" } @items
584 if $self->{debug};
585 $self->_putback(@items);
588 return ( $alias_item->to_string() );
591 "\t", join(", ", map { $_->name() } @items), "\n";
594 =item B<< $ordinals->set_version VERSION >>
596 =item B<< $ordinals->set_version VERSION BASEVERSION >>
621 my $self = shift;
647 $self->{currversion} = $version;
648 $self->{baseversion} = $baseversion;
649 foreach ($self->items(filter => sub { $_[0] eq '*' })) {
650 $_->{version} = $self->{currversion};
655 =item B<< $ordinals->invalidate >>
657 Invalidates the whole working database. The practical effect is that all
664 my $self = shift;
666 foreach (@{$self->{contents}}) {
668 $_->{exists} = 0;
671 $self->{stats} = {};
674 =item B<< $ordinals->validate >>
676 Validates the current working database by collection statistics on how many
678 with B<< $ordinals->stats >>.
683 my $self = shift;
685 $self->{stats} = {};
686 for my $i (1..$self->{maxnum}) {
687 if ($i > $self->{loaded_maxnum}
688 || (!@{$self->{loaded_contents}->[$i] // []}
689 && @{$self->{contents}->[$i] // []})) {
690 $self->{stats}->{new}++;
692 if ($i <= $self->{maxassigned}) {
693 $self->{stats}->{assigned}++;
695 $self->{stats}->{unassigned}++;
697 next if ($i > $self->{loaded_maxnum});
700 map { $_->to_string() } @{$self->{loaded_contents}->[$i] // []};
702 map { $_->to_string() } @{$self->{contents}->[$i] // []};
708 $self->{stats}->{modified}++;
713 =item B<< $ordinals->stats >>
720 my $self = shift;
722 return %{$self->{stats}};
771 (C<letter> and C<digit> are assumed self evident)
787 return $class->new( map { $_ => $_[0]->{$_} } keys %{$_[0]} );
800 && $a[0] =~ /^[A-Za-z_][A-Za-z_0-9]*$/
802 && $a[2] =~ /^(?:\*|\d+_\d+_\d+[a-z]{0,2})$/
839 croak __PACKAGE__."->new() called with bad arguments\n".
849 =item B<< $item->name >>
853 =item B<< $item->number >> (read-write)
861 =item B<< $item->version >> (read-only)
866 =item B<< $item->exists >> (read-only)
870 =item B<< $item->platforms >> (read-only)
877 =item B<< $item->type >> (read-only)
882 =item B<< $item->features >> (read-only)
895 my $self = shift;
900 croak "$funcname invalid" unless exists $self->{$item};
901 return $self->{$item} if ref($self->{$item}) eq '';
902 return @{$self->{$item}} if ref($self->{$item}) eq 'ARRAY';
903 return %{$self->{$item}} if ref($self->{$item}) eq 'HASH';
906 =item B<< $item->intnum >> (read-write)
908 Internal positional number. If I<< $item->number >> is '?' or '?+', the
910 If I<< $item->number >> is a number, I<< $item->intnum >> should be the
917 my $self = shift;
922 $self->{$item} = "$value" if defined $value;
923 return $self->{$item};
927 my $self = shift;
932 $self->{$item} = "$value" if defined $value;
933 return $self->{$item};
936 =item B<< $item->to_string >>
943 my $self = shift;
946 my %platforms = $self->platforms();
947 my @features = $self->features();
948 my $version = $self->version();
950 return sprintf "%-39s %s\t%s\t%s:%s:%s:%s",
951 $self->name(),
952 $self->number(),
954 $self->exists() ? 'EXIST' : 'NOEXIST',
957 $self->type(),
965 For the B<< $ordinals->items >> method, there are a few functions to create
985 return sub { $_[0]->name() cmp $_[1]->name() };
996 return sub { $_[0]->intnum() <=> $_[1]->intnum() };
1009 return cmp_versions($_[0]->version(), $_[1]->version());
1035 unless $version && $version =~ /^\d+\.\d+\.\d+[a-z]{0,2}$/;
1037 return sub { $_[0]->version() eq $version };