Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision abc7a54c

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

  • ID abc7a54cc16668a7803b574c44bddac9ec2abaa3
  • Vorgänger 98c23539
  • Nachfolger 88dea78e

ParseFilter: neuer Filter "trim"

Ausserdem autotrim bei substr, head und tail Filtern

Unterschiede anzeigen:

SL/Controller/Helper/ParseFilter.pm
8 8
use DateTime;
9 9
use SL::Helper::DateTime;
10 10
use List::MoreUtils qw(uniq);
11
use SL::Util qw(trim);
11 12
use SL::MoreCommon qw(listify);
12 13
use Data::Dumper;
13 14
use Text::ParseWords;
......
24 25
  date    => sub { DateTime->from_lxoffice($_[0]) },
25 26
  number  => sub { $::form->parse_amount(\%::myconfig, $_[0]) },
26 27
  percent => sub { $::form->parse_amount(\%::myconfig, $_[0]) / 100 },
27
  head    => sub { $_[0] . '%' },
28
  tail    => sub { '%' . $_[0] },
29
  substr  => sub { '%' . $_[0] . '%' },
28
  head    => sub { trim($_[0]) . '%' },
29
  tail    => sub { '%' . trim($_[0]) },
30
  substr  => sub { '%' . trim($_[0]) . '%' },
31
  trim    => sub { trim($_[0]) },
30 32
);
31 33

  
32 34
my %methods = (
......
432 434

  
433 435
Parses the input string with C<< Form->parse_amount / 100 >>
434 436

  
437
=item trim
438

  
439
Removes whitespace characters (to be precice, characters with the \p{WSpace}
440
property from beginning and end of the value.
441

  
435 442
=item head
436 443

  
437
Adds "%" at the end of the string.
444
Adds "%" at the end of the string and applies C<trim>.
438 445

  
439 446
=item tail
440 447

  
441
Adds "%" at the end of the string.
448
Adds "%" at the end of the string and applies C<trim>.
442 449

  
443 450
=item substr
444 451

  
445
Adds "% .. %" around the search string.
446

  
447
=item eq_ignore_empty
448

  
449
Ignores this item if it's empty. Otherwise compares it with the
450
standard SQL C<=> operator.
452
Adds "% .. %" around the search string and applies C<trim>.
451 453

  
452 454
=back
453 455

  
......
472 474
will match for C<NULL> and C<FALSE>; trueish values will only match
473 475
C<TRUE>.
474 476

  
477
=item eq_ignore_empty
478

  
479
Ignores this item if it's empty. Otherwise compares it with the
480
standard SQL C<=> operator.
481

  
475 482
=back
476 483

  
477 484
=head1 BUGS AND CAVEATS
t/controllers/helpers/parse_filter.t
1 1
use lib 't';
2 2

  
3
use Test::More tests => 38;
3
use Test::More tests => 41;
4 4
use Test::Deep;
5 5
use Data::Dumper;
6 6

  
......
420 420
  with_objects => [ 'part' ],
421 421
}, 'complex methods modifying the key';
422 422

  
423

  
424
test {
425
  'customer:substr::ilike' => ' Meyer'
426
}, {
427
  query => [ customer => { ilike => '%Meyer%' } ]
428
}, 'auto trim 1';
429

  
430
test {
431
  'customer:head::ilike' => ' Meyer '
432
}, {
433
  query => [ customer => { ilike => 'Meyer%' } ]
434
}, 'auto trim 2';
435

  
436
test {
437
  'customer:tail::ilike' => "\nMeyer\x{a0}"
438
}, {
439
  query => [ customer => { ilike => '%Meyer' } ]
440
}, 'auto trim 2';

Auch abrufbar als: Unified diff