line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catmandu::Fix::substring; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
105298
|
use Catmandu::Sane; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
6
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '1.2020'; |
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
8
|
use Catmandu::Util qw(as_utf8); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
56
|
|
8
|
1
|
|
|
1
|
|
463
|
use Catmandu::Util::Path qw(as_path); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
52
|
|
9
|
1
|
|
|
1
|
|
7
|
use Moo; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
8
|
|
10
|
1
|
|
|
1
|
|
372
|
use namespace::clean; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
4
|
|
11
|
1
|
|
|
1
|
|
741
|
use Catmandu::Fix::Has; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
6
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
has path => (fix_arg => 1); |
14
|
|
|
|
|
|
|
has args => (fix_arg => 'collect'); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
with 'Catmandu::Fix::Builder'; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub _build_fixer { |
19
|
5
|
|
|
5
|
|
49
|
my ($self) = @_; |
20
|
5
|
|
|
|
|
14
|
my $args = $self->args; |
21
|
5
|
|
|
|
|
8
|
my $cb; |
22
|
|
|
|
|
|
|
|
23
|
5
|
100
|
|
|
|
20
|
if (@$args == 1) { |
|
|
100
|
|
|
|
|
|
24
|
|
|
|
|
|
|
$cb = sub { |
25
|
2
|
|
|
2
|
|
7
|
my $val = $_[0]; |
26
|
2
|
|
|
|
|
5
|
my $new_val; |
27
|
2
|
|
|
|
|
3
|
eval { |
28
|
1
|
|
|
1
|
|
457
|
no warnings 'substr'; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
152
|
|
29
|
2
|
|
|
|
|
6
|
$new_val = substr(as_utf8($val), $args->[0]); |
30
|
|
|
|
|
|
|
}; |
31
|
2
|
50
|
|
|
|
44
|
return $new_val if defined $new_val; |
32
|
0
|
|
|
|
|
0
|
return undef, 1, 0; |
33
|
1
|
|
|
|
|
15
|
}; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
elsif (@$args == 2) { |
36
|
|
|
|
|
|
|
$cb = sub { |
37
|
3
|
|
|
3
|
|
7
|
my $val = $_[0]; |
38
|
3
|
|
|
|
|
6
|
my $new_val; |
39
|
3
|
|
|
|
|
4
|
eval { |
40
|
1
|
|
|
1
|
|
7
|
no warnings 'substr'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
137
|
|
41
|
3
|
|
|
|
|
14
|
$new_val = substr(as_utf8($val), $args->[0], $args->[1]); |
42
|
|
|
|
|
|
|
}; |
43
|
3
|
100
|
|
|
|
29
|
return $new_val if defined $new_val; |
44
|
2
|
|
|
|
|
40
|
return undef, 1, 0; |
45
|
3
|
|
|
|
|
14
|
}; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
else { |
48
|
|
|
|
|
|
|
$cb = sub { |
49
|
1
|
|
|
1
|
|
3
|
my $val = $_[0]; |
50
|
1
|
|
|
|
|
9
|
my $new_val = as_utf8($val); |
51
|
1
|
|
50
|
|
|
4
|
eval { |
52
|
1
|
|
|
1
|
|
7
|
no warnings 'substr'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
172
|
|
53
|
1
|
|
|
|
|
162
|
substr($new_val, $args->[0], $args->[1]) = $args->[2]; |
54
|
|
|
|
|
|
|
} // return undef, 1, 0; |
55
|
1
|
|
|
|
|
29
|
$new_val; |
56
|
1
|
|
|
|
|
5
|
}; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
5
|
|
|
|
|
23
|
as_path($self->path)->updater(if_value => $cb); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
1; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
__END__ |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=pod |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=head1 NAME |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
Catmandu::Fix::substring - extract a substring out of the value of a field |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head1 SYNOPSIS |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
# Extract a substring out of the value of a field |
75
|
|
|
|
|
|
|
# - Extact from 'initials' the characters at offset 0 (first character) with a length 3 |
76
|
|
|
|
|
|
|
substring(initials, 0, 3) |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head1 SEE ALSO |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
L<Catmandu::Fix>, substr |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=cut |