| 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
| |||||||||||||||||||||||||||||
| 13 | 18 | ▶ | if (ref $fields eq 'HASH') {return [sort keys %$fields]} | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
Condition66%2/3
$self->collect_fields and not $self->fields
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
| |||||||||||||||||||||||||||||
| 39 | 2 | my $coll; | |||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 2 | ▶ | if (is_array_ref($many)) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
MC/DC100%1/1
$keys->{$key} ||= 1
$keys->{$key}
Truth table100%2/2
A
A= $keys->{$key}
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||