use DateTime;
use SL::Helper::DateTime;
use List::MoreUtils qw(uniq);
+use SL::Util qw(trim);
use SL::MoreCommon qw(listify);
use Data::Dumper;
use Text::ParseWords;
date => sub { DateTime->from_lxoffice($_[0]) },
number => sub { $::form->parse_amount(\%::myconfig, $_[0]) },
percent => sub { $::form->parse_amount(\%::myconfig, $_[0]) / 100 },
- head => sub { $_[0] . '%' },
- tail => sub { '%' . $_[0] },
- substr => sub { '%' . $_[0] . '%' },
+ head => sub { trim($_[0]) . '%' },
+ tail => sub { '%' . trim($_[0]) },
+ substr => sub { '%' . trim($_[0]) . '%' },
+ trim => sub { trim($_[0]) },
);
my %methods = (
Parses the input string with C<< Form->parse_amount / 100 >>
+=item trim
+
+Removes whitespace characters (to be precice, characters with the \p{WSpace}
+property from beginning and end of the value.
+
=item head
-Adds "%" at the end of the string.
+Adds "%" at the end of the string and applies C<trim>.
=item tail
-Adds "%" at the end of the string.
+Adds "%" at the end of the string and applies C<trim>.
=item substr
-Adds "% .. %" around the search string.
-
-=item eq_ignore_empty
-
-Ignores this item if it's empty. Otherwise compares it with the
-standard SQL C<=> operator.
+Adds "% .. %" around the search string and applies C<trim>.
=back
will match for C<NULL> and C<FALSE>; trueish values will only match
C<TRUE>.
+=item eq_ignore_empty
+
+Ignores this item if it's empty. Otherwise compares it with the
+standard SQL C<=> operator.
+
=back
=head1 BUGS AND CAVEATS
use lib 't';
-use Test::More tests => 38;
+use Test::More tests => 41;
use Test::Deep;
use Data::Dumper;
with_objects => [ 'part' ],
}, 'complex methods modifying the key';
+
+test {
+ 'customer:substr::ilike' => ' Meyer'
+}, {
+ query => [ customer => { ilike => '%Meyer%' } ]
+}, 'auto trim 1';
+
+test {
+ 'customer:head::ilike' => ' Meyer '
+}, {
+ query => [ customer => { ilike => 'Meyer%' } ]
+}, 'auto trim 2';
+
+test {
+ 'customer:tail::ilike' => "\nMeyer\x{a0}"
+}, {
+ query => [ customer => { ilike => '%Meyer' } ]
+}, 'auto trim 2';