Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 9fac28d8

Von Sven Schöling vor mehr als 11 Jahren hinzugefügt

  • ID 9fac28d83f55524f85cfa32cab463e0b8c063d92
  • Vorgänger 1b960273
  • Nachfolger 1264cff6

ParseFilter: _collapse_indirect_filters ausgelagert und algorithmus auf array umgeschrieben

Unterschiede anzeigen:

SL/Controller/Helper/ParseFilter.pm
90 90

  
91 91
  return () unless 'ARRAY' eq ref $flattened;
92 92

  
93
  my %sorted = ( @$flattened );
93
  $flattened = _collapse_indirect_filters($flattened);
94

  
95
  my @result;
96
  for (my $i = 0; $i < scalar @$flattened; $i += 2) {
97
    my ($key, $value) = ($flattened->[$i], $flattened->[$i+1]);
98
    ($key, $value) = _apply_all($key, $value, qr/\b:(\w+)/,  { %filters, %{ $params{filters} || {} } });
99
    ($key, $value) = _apply_all($key, $value, qr/\b::(\w+)/, { %methods, %{ $params{methods} || {} } });
100
    push @result, $key, $value;
101
  }
102
  return \@result;
103
}
104

  
105
sub _collapse_indirect_filters {
106
  my ($flattened) = @_;
107

  
108
  die 'flattened filter array length is uneven, should be possible to use as hash' if @$flattened % 2;
109

  
110
  my (%keys_to_delete, %keys_to_move, @collapsed);
111

  
112
  # search keys matching /::$/;
113
  for (my $i = 0; $i < scalar @$flattened; $i += 2) {
114
    my ($key, $value) = ($flattened->[$i], $flattened->[$i+1]);
94 115

  
95
  my @keys = sort { length($b) <=> length($a) } keys %sorted;
96
  for my $key (@keys) {
97 116
    next unless $key =~ /^(.*\b)::$/;
98
    $sorted{$1 . '::' . delete $sorted{$key} } = delete $sorted{$1} if $sorted{$1} && $sorted{$key};
117

  
118
    $keys_to_delete{$key}++;
119
    $keys_to_move{$1} = $1 . '::' . $value;
99 120
  }
100 121

  
101
  my %result;
102
  while (my ($key, $value) = each %sorted) {
103
    ($key, $value) = _apply_all($key, $value, qr/\b:(\w+)/,  { %filters, %{ $params{filters} || {} } });
104
    ($key, $value) = _apply_all($key, $value, qr/\b::(\w+)/, { %methods, %{ $params{methods} || {} } });
105
    $result{$key} = $value;
122
  for (my $i = 0; $i < scalar @$flattened; $i += 2) {
123
    my ($key, $value) = ($flattened->[$i], $flattened->[$i+1]);
124

  
125
    if ($keys_to_move{$key}) {
126
      push @collapsed, $keys_to_move{$key}, $value;
127
      next;
128
    }
129
    if (!$keys_to_delete{$key}) {
130
      push @collapsed, $key, $value;
131
    }
106 132
  }
107
  return [ %result ];
133

  
134
  return \@collapsed;
108 135
}
109 136

  
110 137
sub _prefix {

Auch abrufbar als: Unified diff