line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catmandu::Fix::trim; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
104633
|
use Catmandu::Sane; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
7
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '1.2020'; |
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
8
|
use Moo; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
10
|
|
8
|
1
|
|
|
1
|
|
793
|
use Catmandu::Util::Path qw(as_path); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
54
|
|
9
|
1
|
|
|
1
|
|
7
|
use Catmandu::Util qw(trim); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
40
|
|
10
|
1
|
|
|
1
|
|
630
|
use Unicode::Normalize; |
|
1
|
|
|
|
|
2117
|
|
|
1
|
|
|
|
|
62
|
|
11
|
1
|
|
|
1
|
|
7
|
use namespace::clean; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
6
|
|
12
|
1
|
|
|
1
|
|
778
|
use Catmandu::Fix::Has; |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
16
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
with 'Catmandu::Fix::Builder'; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
has path => (fix_arg => 1); |
17
|
|
|
|
|
|
|
has mode => (fix_arg => 1, default => sub {'whitespace'}); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub _build_fixer { |
20
|
7
|
|
|
7
|
|
63
|
my ($self) = @_; |
21
|
7
|
|
|
|
|
14
|
my $cb; |
22
|
7
|
100
|
|
|
|
37
|
if ($self->mode eq 'whitespace') { |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
23
|
|
|
|
|
|
|
$cb = sub { |
24
|
6
|
|
|
6
|
|
21
|
trim($_[0]); |
25
|
5
|
|
|
|
|
18
|
}; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
elsif ($self->mode eq 'nonword') { |
28
|
|
|
|
|
|
|
$cb = sub { |
29
|
1
|
|
|
1
|
|
4
|
my $val = $_[0]; |
30
|
1
|
|
|
|
|
6
|
$val =~ s/^\W+//; |
31
|
1
|
|
|
|
|
6
|
$val =~ s/\W+$//; |
32
|
1
|
|
|
|
|
20
|
$val; |
33
|
1
|
|
|
|
|
4
|
}; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
elsif ($self->mode eq 'diacritics') { |
36
|
|
|
|
|
|
|
$cb = sub { |
37
|
1
|
|
|
1
|
|
3
|
my $val = $_[0]; |
38
|
1
|
|
|
|
|
12
|
$val = Unicode::Normalize::NFKD($val); |
39
|
1
|
|
|
1
|
|
674
|
$val =~ s/\p{NonspacingMark}//g; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
16
|
|
|
1
|
|
|
|
|
13
|
|
40
|
1
|
|
|
|
|
20
|
$val; |
41
|
1
|
|
|
|
|
6
|
}; |
42
|
|
|
|
|
|
|
} |
43
|
7
|
|
|
|
|
62
|
as_path($self->path)->updater(if_string => $cb); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
1; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
__END__ |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=pod |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=encoding utf-8 |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=head1 NAME |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
Catmandu::Fix::trim - trim leading and ending junk from the value of a field |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head1 SYNOPSIS |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
# the default mode trims whitespace |
61
|
|
|
|
|
|
|
# e.g. foo => ' abc '; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
trim(foo) # foo => 'abc'; |
64
|
|
|
|
|
|
|
trim(foo, whitespace) # foo => 'abc'; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
# trim non-word characters |
67
|
|
|
|
|
|
|
# e.g. foo => ' abc / : .'; |
68
|
|
|
|
|
|
|
trim(foo, nonword) # foo => 'abc'; |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
# trim accents |
71
|
|
|
|
|
|
|
# e.g. foo => 'français' ; |
72
|
|
|
|
|
|
|
trim(foo,diacritics) # foo => 'francais' |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head1 SEE ALSO |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
L<Catmandu::Fix> |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=cut |