| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | 1 | ▶ | croak "To coerce field ".$self->name.", either 'coerce' must be a coderef or 'type' must have a ->coerce method" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
ref $self->coerce eq "CODE" or defined $self->type and ref($self->type)->can("coerce")
defined $self->type and ref($self->type)->can("coerce")
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")
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | 90 | ▶ | my $pattern= join "[\\W_]*", map { $_ eq "\n"? '\n' : "\Q$_\E" } grep { defined && length } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $_ && length $_
MC/DC50%1/2
defined $_ && length $_
defined $_
length $_
Truth table66%2/3
A && B
A= defined $_B= length $_
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | 71 | ▶ | return \&_default_trim_coderef if !ref $t; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | 4 | ▶ | return $t if ref $t eq 'CODE'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | 2 | ▶ | return sub { s/$t//g; } if ref $t eq 'Regexp'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.2
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | croak("Can't convert ".ref($t)." to a coderef"); | |||||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | 9 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | __END__ | ||||||||||||||||||||||||||||||||||||||||||