Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 585dc465

Von Moritz Bunkus vor mehr als 9 Jahren hinzugefügt

  • ID 585dc465bc6db6c1525563e64dbeb84da61b6fdf
  • Vorgänger e78e225b
  • Nachfolger 3e988f3d

ParseFilter: re-factor das Parsen von Filter- und Methodennamen

Unterschiede anzeigen:

SL/Controller/Helper/ParseFilter.pm
99 99

  
100 100
  $flattened = _collapse_indirect_filters($flattened);
101 101

  
102
  my $all_filters = { %filters, %{ $params{filters} || {} } };
103
  my $all_methods = { %methods, %{ $params{methods} || {} } };
104

  
102 105
  my @result;
103 106
  for (my $i = 0; $i < scalar @$flattened; $i += 2) {
107
    my (@args, @filters, @methods);
108

  
104 109
    my ($key, $value) = ($flattened->[$i], $flattened->[$i+1]);
105 110
    my ($type, $op)   = $key =~ m{:(.+)::(.+)};
106 111

  
107 112
    my $is_multi      = $key =~ s/:multi//;
108
    my $orig_key      = $key;
109 113
    my @value_tokens  = $is_multi ? parse_line('\s+', 0, $value) : ($value);
110 114

  
111
    my @args;
115
    ($key, @methods)  = split m{::}, $key;
116
    ($key, @filters)  = split m{:},  $key;
117

  
118
    my $orig_key      = $key;
112 119

  
113 120
    for my $value_token (@value_tokens) {
114 121
      $key                 = $orig_key;
115 122

  
116
      ($key, $value_token) = _apply_all($key, $value_token, qr/\b:(\w+)/,  { %filters, %{ $params{filters} || {} } });
117
      ($key, $value_token) = _apply_all($key, $value_token, qr/\b::(\w+)/, { %methods, %{ $params{methods} || {} } });
123
      $value_token         = _apply($value_token, $_, $all_filters) for @filters;
124
      $value_token         = _apply($value_token, $_, $all_methods) for @methods;
118 125
      ($key, $value_token) = _dispatch_custom_filters($params{class}, $with_objects, $key, $value_token) if $params{class};
119 126
      ($key, $value_token) = _apply_value_filters($key, $value_token, $type, $op);
120 127

  
......
239 246
  return $filters->{$name}->($value);
240 247
}
241 248

  
242
sub _apply_all {
243
  my ($key, $value, $re, $subs) = @_;
244

  
245
  while ($key =~ s/$re//) {
246
    $value = _apply($value, $1, $subs);
247
  }
248

  
249
  return $key, $value;
250
}
251

  
252 249
1;
253 250

  
254 251
__END__

Auch abrufbar als: Unified diff