TableReader/Field.pm

filter: Statementstmt 98.1% 53 / 54 Branchbran 84.6% 22 / 26 Conditioncond 44.4% 4 / 9 MC/DCmcdc 20.0% 1 / 5 Subroutinesub 100% 13 / 13 Podpod 50.0% 1 / 2 totaltotal 86.2% 94 / 109 CC 17 SCAR 13.0
CC
17
Cov
89%
BUILD
6.4
_build_trim_coderef
5.1
_build_header_regex
5.0
CRAP 3.7
« TableReader/Decoder/Mock.pm ↑ Summary TableReader/Decoder/XLS.pm »
1 package Data::TableReader::Field;
2 9 ▶use Moo 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 9 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 9 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 # ABSTRACT: Field specification for Data::TableReader
7 9 our $VERSION = '0.023'; # VERSION
8  
9  
10 9 has name => ( is => 'ro', required => 1 );
11 9 *addr= \&Scalar::Util::refaddr;
12 9 has header => ( is => 'ro' );
13 93 ▶has required => ( is => 'ro', default => sub { 1 } );
Subroutine __ANON__: called CC=1 SCAR=0.0
14 95 ▶has trim => ( is => 'ro', default => sub { 1 } );
Subroutine __ANON__: called CC=1 SCAR=0.0
15 9 has blank => ( is => 'ro' ); # default is undef
16 9 ▶has type => ( is => 'ro', isa => sub { ref $_[0] eq 'CODE' or $_[0]->can('validate') } );
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq "CODE" or $_[0]->can("validate") 6 3 9
17 1 ▶has coerce => ( is => 'ro', isa => sub { ref $_[0] eq 'CODE' or !ref $_[0] } );
Subroutine __ANON__: called CC=2 SCAR=7.2
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq "CODE" or not ref $_[0] 0 1 1
18 9 has array => ( is => 'ro' );
19 9 has follows => ( is => 'ro' );
20 132 ▶sub follows_list { my $f= shift->follows; ref $f? @$f : defined $f? ( $f ) : () }
Subroutine follows_list: called CC=3 SCAR=11.1
Pod documented
Branch: 2 branches
BranchTrueFalseTotal
ref $f ? : 0 132 132
defined $f ? : 23 109 132
21  
22 105 ▶sub BUILD {
Subroutine BUILD: called CC=5 SCAR=18.6
Pod undocumented
23 105 my $self= shift;
24 105 ▶ if ($self->coerce) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->coerce) 1 104 105
25 1 ▶ croak "To coerce field ".$self->name.", either 'coerce' must be a coderef or 'type' must have a ->coerce method"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self->coerce eq "CODE" or defined $self->type and ref($self->type)->can("coerce") 0 1 1
Condition33%2/6
ref $self->coerce eq "CODE" or defined $self->type and ref($self->type)->can("coerce")
l!l&&r!l&&!r
010
defined $self->type and ref($self->type)->can("coerce")
!ll&&!rl&&r
001
MC/DC0%0/3
ref $self->coerce eq "CODE" or defined $self->type and ref($self->type)->can("coerce")
ref $self->coerce eq "CODE" defined $self->type ref($self->type)->can("coerce")
Truth table25%1/4
A or B and C
A= ref $self->coerce eq "CODE"B= defined $self->typeC= ref($self->type)->can("coerce")
ABCresult
1XX1
0111
00X0
0100
26 unless ref $self->coerce eq 'CODE' or (defined $self->type && ref($self->type)->can('coerce'));
27 }
28 }
29  
30  
31 9 has header_regex => ( is => 'lazy' );
32  
33 94 ▶sub _build_header_regex {
Subroutine _build_header_regex: called CC=5 SCAR=16.1
34 94 my $self= shift;
35 94 my $h= $self->header;
36 94 ▶ unless (defined $h) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $h) 83 11 94
37 83 $h= $self->name;
38 83 $h =~ s/([[:lower:]])([[:upper:]])/$1 $2/g; # split words on camelCase
39 83 $h =~ s/([[:alpha:]])([[:digit:]])/$1 $2/g; # or digit
40 83 $h =~ s/([[:digit:]])([[:alpha:]])/$1 $2/g;
41 83 $h =~ s/_/ /g; # then split on underscore
42 }
43 94 ▶ return $h if ref($h) eq 'Regexp';
Branch: 1 branch
BranchTrueFalseTotal
if ref $h eq "Regexp" 4 90 94
44 90 ▶ my $pattern= join "[\\W_]*", map { $_ eq "\n"? '\n' : "\Q$_\E" } grep { defined && length }
Branch: 1 branch
BranchTrueFalseTotal
$_ eq "\n" ? : 3 104 107
Condition66%2/3
defined $_ && length $_
!ll&&!rl&&r
270107
MC/DC50%1/2
defined $_ && length $_
defined $_ length $_
Truth table66%2/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
45 split /(\n)|\s+|(\W)/, $h; # capture newline or non-word, except for other whitespace
46 90 return qr/^[\W_]*$pattern[\W_]*$/im;
47 }
48  
49 9 has trim_coderef => ( is => 'lazy' );
50  
51 178 ▶sub _default_trim_coderef {
Subroutine _default_trim_coderef: called CC=1 SCAR=0.0
52 178 $_ =~ s/\s+$//;
53 178 $_ =~ s/^\s+//;
54 }
55  
56 72 ▶sub _build_trim_coderef {
Subroutine _build_trim_coderef: called CC=5 SCAR=16.2
57 72 my $t= shift->trim;
58 72 ▶ return undef unless $t;
Branch: 1 branch
BranchTrueFalseTotal
unless $t 1 71 72
59 71 ▶ return \&_default_trim_coderef if !ref $t;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $t 67 4 71
60 4 ▶ return $t if ref $t eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if ref $t eq "CODE" 2 2 4
61 2 ▶ return sub { s/$t//g; } if ref $t eq 'Regexp';
Subroutine __ANON__: called CC=1 SCAR=0.2
Branch: 1 branch
BranchTrueFalseTotal
if ref $t eq "Regexp" 2 0 2
62 0 croak("Can't convert ".ref($t)." to a coderef");
63 }
64  
65 9 1;
66  
67 __END__
« TableReader/Decoder/Mock.pm ↑ Summary TableReader/Decoder/XLS.pm »