Catmandu/TabularExporter.pm

filter: Statementstmt 86.0% 43 / 50 Branchbran 56.2% 9 / 16 Conditioncond 80.0% 4 / 5 MC/DCmcdc 66.6% 2 / 3 Subroutinesub 100% 8 / 8 Podpod n/a totaltotal 80.4% 66 / 82 CC 13 SCAR 23.2
CC
13
Cov
79%
__ANON__
18.6
_coerce_array
3.0
__ANON__
2.0
CRAP 10.2
« Catmandu/Cmd/copy.pm ↑ Summary Catmandu/Fix/vacuum.pm »
1 package Catmandu::TabularExporter;
2  
3 7 ▶use Catmandu::Sane;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 7 our $VERSION = '1.2025';
6  
7 7 ▶use Catmandu::Util qw(:is :check);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 7 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 19 ▶sub _coerce_array {
Subroutine _coerce_array: called CC=3 SCAR=11.0
11 19 my $fields = $_[0];
12 19 ▶ if (ref $fields eq 'ARRAY') {return $fields}
Branch: 1 branch
BranchTrueFalseTotal
if (ref $fields eq "ARRAY") 1 18 19
13 18 ▶ if (ref $fields eq 'HASH') {return [sort keys %$fields]}
Branch: 1 branch
BranchTrueFalseTotal
if (ref $fields eq "HASH") 11 7 18
14 7 [split ',', $fields];
15 }
16  
17 7 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 7 with 'Catmandu::Exporter';
20  
21 7 has fields => (is => 'rwp', coerce => \&_coerce_array,);
22  
23 7 has columns => (is => 'rwp', coerce => \&_coerce_array,);
24  
25 7 has collect_fields => (is => 'ro',);
26  
27 18 ▶has header => (is => 'ro', default => sub {1});
Subroutine __ANON__: called CC=1 SCAR=0.0
28  
29 45 ▶around add => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
30 45 my ($orig, $self, $data) = @_;
31 45 ▶ $self->_set_fields($data) unless $self->fields;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->fields 9 36 45
32 45 $orig->($self, $data);
33 7 };
34  
35 11 ▶around add_many => sub {
Subroutine __ANON__: called CC=10 SCAR=29.2
36 11 my ($orig, $self, $many) = @_;
37  
38 11 ▶ if ($self->collect_fields && !$self->fields) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->collect_fields and not $self->fields) 2 9 11
Condition66%2/3
$self->collect_fields and not $self->fields
!ll&&!rl&&r
902
MC/DC50%1/2
$self->collect_fields and not $self->fields
$self->collect_fields not $self->fields
Truth table66%2/3
A and not(B)
A= $self->collect_fieldsB= not $self->fields
ABresult
0X0
100
111
39 2 my $coll;
40  
41 2 ▶ if (is_array_ref($many)) {
Branch: 2 branches
BranchTrueFalseTotal
if (is_array_ref($many)) { } 2 0 2
elsif (is_hash_ref($many)) { } 0 0 0
42 2 $coll = $many;
43 }
44 elsif (is_hash_ref($many)) {
45 0 $coll = [$many];
46 }
47 else {
48 0 ▶ if (is_invocant($many)) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_invocant($many)) 0 0 0
49 0 $many = check_able($many, 'generator')->generator;
50 }
51 0 check_code_ref($many);
52 0 $coll = [];
53 0 ▶ while (defined(my $data = $many->())) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $data = &$many())) 0 0 0
54 0 push @$coll, $data;
55 }
56 }
57  
58 2 my $keys = {};
59 2 for my $data (@$coll) {
60 6 for my $key (keys %$data) {
61 10 ▶ $keys->{$key} ||= 1;
Condition100%2/2
$keys->{$key} ||= 1
l!l
64
MC/DC100%1/1
$keys->{$key} ||= 1
$keys->{$key}
Truth table100%2/2
A
A= $keys->{$key}
Aresult
11
00
62 }
63 }
64 2 $self->_set_fields($keys);
65  
66 2 $many = $coll;
67 }
68  
69 11 $orig->($self, $many);
70 7 };
71  
72 7 1;
73  
74 __END__
« Catmandu/Cmd/copy.pm ↑ Summary Catmandu/Fix/vacuum.pm »