From e78e225b5046009326fe96ebdc533ba6ff85da38 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Fri, 3 Jul 2015 14:46:27 +0200 Subject: [PATCH] ParseFilter: re-factoring des Anwendens von Filtern und Methoden --- SL/Controller/Helper/ParseFilter.pm | 36 ++++++++++++++--------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/SL/Controller/Helper/ParseFilter.pm b/SL/Controller/Helper/ParseFilter.pm index cdd3eb7a7..243b0b63f 100644 --- a/SL/Controller/Helper/ParseFilter.pm +++ b/SL/Controller/Helper/ParseFilter.pm @@ -104,26 +104,26 @@ sub _parse_filter { my ($key, $value) = ($flattened->[$i], $flattened->[$i+1]); my ($type, $op) = $key =~ m{:(.+)::(.+)}; - if ($key =~ s/:multi//) { - my @multi; - my $orig_key = $key; - for my $value (parse_line('\s+', 0, $value)) { - ($key, $value) = _apply_all($key, $value, qr/\b:(\w+)/, { %filters, %{ $params{filters} || {} } }); - ($key, $value) = _apply_all($key, $value, qr/\b::(\w+)/, { %methods, %{ $params{methods} || {} } }); - ($key, $value) = _dispatch_custom_filters($params{class}, $with_objects, $key, $value) if $params{class}; - ($key, $value) = _apply_value_filters($key, $value, $type, $op); - push @multi, $key, $value; - $key = $orig_key; - } - ($key, $value) = (and => \@multi); - } else { - ($key, $value) = _apply_all($key, $value, qr/\b:(\w+)/, { %filters, %{ $params{filters} || {} } }); - ($key, $value) = _apply_all($key, $value, qr/\b::(\w+)/, { %methods, %{ $params{methods} || {} } }); - ($key, $value) = _dispatch_custom_filters($params{class}, $with_objects, $key, $value) if $params{class}; - ($key, $value) = _apply_value_filters($key, $value, $type, $op); + my $is_multi = $key =~ s/:multi//; + my $orig_key = $key; + my @value_tokens = $is_multi ? parse_line('\s+', 0, $value) : ($value); + + my @args; + + for my $value_token (@value_tokens) { + $key = $orig_key; + + ($key, $value_token) = _apply_all($key, $value_token, qr/\b:(\w+)/, { %filters, %{ $params{filters} || {} } }); + ($key, $value_token) = _apply_all($key, $value_token, qr/\b::(\w+)/, { %methods, %{ $params{methods} || {} } }); + ($key, $value_token) = _dispatch_custom_filters($params{class}, $with_objects, $key, $value_token) if $params{class}; + ($key, $value_token) = _apply_value_filters($key, $value_token, $type, $op); + + push @args, $key, $value_token; } - push @result, $key, $value if defined $key; + next unless defined $key; + + push @result, $is_multi ? (and => [ @args ]) : @args; } return \@result; } -- 2.20.1