Catmandu/Importer/Text.pm

filter: Statementstmt 100% 21 / 21 Branchbran 100% 4 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod 0.0% 0 / 1 totaltotal 96.9% 32 / 33 CC 3 SCAR 3.7
CC
3
Cov
100%
__ANON__
2.0
__ANON__
2.0
BEGIN
1.0
CRAP 1.4
« Catmandu/Fix/Condition/Builder/Simple.pm ↑ Summary Catmandu/Fix/Condition/Builder.pm »
1 package Catmandu::Importer::Text;
2  
3 3 ▶use Catmandu::Sane;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 3 our $VERSION = '1.2025';
6  
7 3 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 3 with 'Catmandu::Importer';
11  
12 has pattern => (
13 is => 'ro',
14 5 ▶ coerce => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
15 5 ▶ $_[0] =~ /\n/m ? qr{$_[0]}x : qr{$_[0]};
Branch: 1 branch
BranchTrueFalseTotal
$_[0] =~ /\n/m ? : 1 4 5
16 },
17 3 );
18  
19 has split => (
20 is => 'ro',
21 4 ▶ coerce => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
22 4 ▶ length $_[0] == 1 ? quotemeta($_[0]) : qr{$_[0]};
Branch: 1 branch
BranchTrueFalseTotal
length $_[0] == 1 ? : 2 2 4
23 }
24 3 );
25  
26 11 ▶sub generator {
Subroutine generator: called CC=1 SCAR=0.0
Pod undocumented
27 11 my ($self) = @_;
28 sub {
29 state $pattern = $self->pattern;
30 state $split = $self->split;
31 state $count = 0;
32 state $line;
33  
34 while (defined($line = $self->fh->getline)) {
35 chomp $line;
36 next if $pattern and $line !~ $pattern;
37  
38 my $data = {_id => ++$count};
39  
40 if (@+ < 2) { # no capturing groups
41 $data->{text} = $line;
42 }
43 elsif (%+) { # named capturing groups
44 $data->{match} = {%+};
45 }
46 else { # numbered capturing groups
47 3 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
48 $data->{match} = [map {$$_} 1 .. @+ - 1];
49 }
50  
51 if ($split) {
52 $data->{text} = [split $split, $line];
53 }
54  
55 return $data;
56 }
57  
58 return;
59 11 };
60 }
61  
62 3 1;
63  
64 __END__
« Catmandu/Fix/Condition/Builder/Simple.pm ↑ Summary Catmandu/Fix/Condition/Builder.pm »