Revision 05047096
Von Sven Schöling vor mehr als 10 Jahren hinzugefügt
SL/Controller/Helper/ParseFilter.pm | ||
---|---|---|
10 | 10 |
use List::MoreUtils qw(uniq); |
11 | 11 |
use SL::MoreCommon qw(listify); |
12 | 12 |
use Data::Dumper; |
13 |
use Text::ParseWords; |
|
13 | 14 |
|
14 | 15 |
my %filters = ( |
15 | 16 |
date => sub { DateTime->from_lxoffice($_[0]) }, |
... | ... | |
106 | 107 |
if ($key =~ s/:multi//) { |
107 | 108 |
my @multi; |
108 | 109 |
my $orig_key = $key; |
109 |
for my $value (split / /, $value) {
|
|
110 |
for my $value (parse_line('\s+', 0, $value)) {
|
|
110 | 111 |
($key, $value) = _apply_all($key, $value, qr/\b:(\w+)/, { %filters, %{ $params{filters} || {} } }); |
111 | 112 |
($key, $value) = _apply_all($key, $value, qr/\b::(\w+)/, { %methods, %{ $params{methods} || {} } }); |
112 | 113 |
($key, $value) = _dispatch_custom_filters($params{class}, $with_objects, $key, $value) if $params{class}; |
t/controllers/helpers/parse_filter.t | ||
---|---|---|
1 | 1 |
use lib 't'; |
2 | 2 |
|
3 |
use Test::More tests => 30;
|
|
3 |
use Test::More tests => 31;
|
|
4 | 4 |
use Test::Deep; |
5 | 5 |
use Data::Dumper; |
6 | 6 |
|
... | ... | |
322 | 322 |
] |
323 | 323 |
], |
324 | 324 |
}, 'complex :multi with custom dispatch and prefix', class => 'SL::DB::Manager::OrderItem'; |
325 |
|
|
326 |
test { |
|
327 |
'description:substr:multi::ilike' => q|term1 "term2 and half" 'term3 and stuff'|, |
|
328 |
}, { |
|
329 |
query => [ |
|
330 |
and => [ |
|
331 |
description => { ilike => '%term1%' }, |
|
332 |
description => { ilike => '%term2 and half%' }, |
|
333 |
description => { ilike => '%term3 and stuff%' }, |
|
334 |
] |
|
335 |
] |
|
336 |
}, ':multi with complex tokenizing'; |
Auch abrufbar als: Unified diff
ParseFilter: splitting von :multi über Text::ParseWords