line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catmandu::Fix::parse_text; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
106512
|
use Catmandu::Sane; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
6
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '1.2020'; |
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
7
|
use Moo; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
8
|
1
|
|
|
1
|
|
867
|
use Catmandu::Util::Path qw(as_path); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
54
|
|
9
|
1
|
|
|
1
|
|
416
|
use Catmandu::Util::Regex qw(as_regex); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
57
|
|
10
|
1
|
|
|
1
|
|
7
|
use namespace::clean; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
5
|
|
11
|
1
|
|
|
1
|
|
793
|
use Catmandu::Fix::Has; |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
7
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
has path => (fix_arg => 1); |
14
|
|
|
|
|
|
|
has pattern => (fix_arg => 1); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
with 'Catmandu::Fix::Builder'; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub _build_fixer { |
19
|
3
|
|
|
3
|
|
31
|
my ($self) = @_; |
20
|
3
|
|
|
|
|
17
|
my $regex = as_regex($self->pattern); |
21
|
|
|
|
|
|
|
as_path($self->path)->updater( |
22
|
|
|
|
|
|
|
if_string => sub { |
23
|
3
|
|
|
3
|
|
7
|
my $val = $_[0]; |
24
|
3
|
50
|
|
|
|
25
|
if ($val =~ m/$regex/) { |
25
|
3
|
100
|
|
|
|
31
|
if (@+ < 2) { # no capturing groups |
|
|
100
|
|
|
|
|
|
26
|
1
|
|
|
|
|
21
|
return undef, 1, 0; |
27
|
|
|
|
|
|
|
} |
28
|
1
|
|
|
1
|
|
1005
|
elsif (%+) { # named capturing groups |
|
1
|
|
|
|
|
471
|
|
|
1
|
|
|
|
|
52
|
|
29
|
1
|
|
|
|
|
37
|
return +{%+}; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
else { # numbered capturing groups |
32
|
1
|
|
|
1
|
|
7
|
no strict 'refs'; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
131
|
|
33
|
1
|
|
|
|
|
3
|
return [map {${$_}} 1 .. (@+ - 1)]; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
36
|
|
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
} |
36
|
0
|
|
|
|
|
|
return undef, 1, 0; |
37
|
|
|
|
|
|
|
} |
38
|
3
|
|
|
|
|
27
|
); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
1; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
__END__ |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=pod |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=head1 NAME |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
Catmandu::Fix::parse_text - parses a text into an array or hash of values |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head1 SYNOPSIS |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
# date: "2015-03-07" |
54
|
|
|
|
|
|
|
parse_text(date, '(\d\d\d\d)-(\d\d)-(\d\d)') |
55
|
|
|
|
|
|
|
# date: |
56
|
|
|
|
|
|
|
# - 2015 |
57
|
|
|
|
|
|
|
# - 03 |
58
|
|
|
|
|
|
|
# - 07 |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
# date: "2015-03-07" |
61
|
|
|
|
|
|
|
parse_text(date, '(?<year>\d\d\d\d)-(?<month>\d\d)-(?<day>\d\d)') |
62
|
|
|
|
|
|
|
# date: |
63
|
|
|
|
|
|
|
# year: "2015" |
64
|
|
|
|
|
|
|
# month: "03" |
65
|
|
|
|
|
|
|
# day: "07" |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
# date: "abcd" |
68
|
|
|
|
|
|
|
parse_text(date, '(\d\d\d\d)-(\d\d)-(\d\d)') |
69
|
|
|
|
|
|
|
# date: "abcd" |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head1 SEE ALSO |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
L<Catmandu::Fix> |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
L<Catmandu::Importer::Text> |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=cut |