blib/lib/Catmandu/Fix/parse_text.pm

filter: Statementstmt 100% 20 / 20 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod 0.0% 0 / 1 totaltotal 96.1% 25 / 26 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« blib/lib/Catmandu/Fix/format.pm ↑ Summary blib/lib/Catmandu/Fix/prepend.pm »
1 package Catmandu::Fix::parse_text;
2  
3 1 ▶use Catmandu::Sane;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 our $VERSION = '1.0201_02';
6  
7 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Catmandu::Fix::Has;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 has path => (fix_arg => 1);
12 1 has pattern => (fix_arg => 1);
13  
14 1 with 'Catmandu::Fix::SimpleGetValue';
15  
16 sub emit_value {
17 3 ▶ my ($self, $var, $fixer) = @_;
Subroutine emit_value: called CC=1 SCAR=0.0
Pod undocumented
18 3 my $pattern = $fixer->emit_match($self->pattern);
19  
20 3 "if (is_string(${var}) && ${var} =~ ${pattern}) {" . "if (\@+ < 2) { " .
21  
22 # # no capturing groups
23 "}" . "elsif (\%+) { " .
24  
25 # named capturing groups
26 "${var} = { \%+ }; " . "} else {" .
27  
28 # numbered capturing groups
29 "no strict 'refs';"
30 . "${var} = [ map { \${\$_} } 1..(\@{+} - 1) ];" . "}" . "}";
31 }
32  
33 1 1;
34  
35 __END__
36  
37 =pod
38  
39 =head1 NAME
40  
41 Catmandu::Fix::parse_text - parses a text into an array or hash of values
42  
43 =head1 SYNOPSIS
44  
45 # date: "2015-03-07"
46 parse_text(date, '(\d\d\d\d)-(\d\d)-(\d\d)')
47 # date:
48 # - 2015
49 # - 03
50 # - 07
51  
52 # date: "2015-03-07"
53 parse_text(date, '(?<year>\d\d\d\d)-(?<month>\d\d)-(?<day>\d\d)')
54 # date:
55 # year: "2015"
56 # month: "03"
57 # day: "07"
58  
59 # date: "abcd"
60 parse_text(date, '(\d\d\d\d)-(\d\d)-(\d\d)')
61 # date: "abcd"
62  
63 =head1 SEE ALSO
64  
65 L<Catmandu::Fix>
66  
67 L<Catmandu::Importer::Text>
68  
69 =cut
« blib/lib/Catmandu/Fix/format.pm ↑ Summary blib/lib/Catmandu/Fix/prepend.pm »