Catmandu/Addable.pm

filter: Statementstmt 100% 49 / 49 Branchbran 87.5% 14 / 16 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 11 / 11 Podpod 50.0% 1 / 2 totaltotal 93.9% 78 / 83 CC 11 SCAR 12.0
CC
11
Cov
96%
add_many
6.0
__ANON__
4.1
DESTROY
3.0
CRAP 3.3
« Catmandu/Importer/DKVP.pm ↑ Summary Catmandu/Fix/rename.pm »
1 package Catmandu::Addable;
2  
3 41 ▶use Catmandu::Sane;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 41 our $VERSION = '1.2025';
6  
7 41 ▶use Catmandu::Util qw(:is :check);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 41 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 41 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 41 with 'Catmandu::Fixable';
12  
13 41 requires 'add';
14  
15 130 ▶has autocommit => (is => 'ro', default => sub {0});
Subroutine __ANON__: called CC=1 SCAR=0.0
16 133 ▶has _commit => (is => 'rw', default => sub {0});
Subroutine __ANON__: called CC=1 SCAR=0.0
17  
18 458 ▶around add => sub {
Subroutine __ANON__: called CC=4 SCAR=14.1
19 458 my ($orig, $self, $data) = @_;
20 458 ▶ return unless defined $data;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $data 1 457 458
21 457 ▶ $data = $self->_fixer->fix($data) if $self->_fixer;
Branch: 1 branch
BranchTrueFalseTotal
if $self->_fixer 0 457 457
22 457 ▶ $orig->($self, $data) if defined $data;
Branch: 1 branch
BranchTrueFalseTotal
if defined $data 457 0 457
23 457 $data;
24 41 };
25  
26 68 ▶around commit => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
27 68 my ($orig, $self) = @_;
28 68 my (@res) = $orig->($self);
29 68 $self->_commit(1);
30 68 @res;
31 41 };
32  
33 44 ▶sub add_many {
Subroutine add_many: called CC=6 SCAR=17.9
Pod undocumented
34 44 my ($self, $many) = @_;
35  
36 44 ▶ if (is_hash_ref($many)) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_hash_ref($many)) 1 43 44
37 1 $self->add($many);
38 1 return 1;
39 }
40  
41 43 ▶ if (is_array_ref($many)) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_array_ref($many)) 20 23 43
42 20 $self->add($_) for @$many;
43 20 return scalar @$many;
44 }
45  
46 23 ▶ if (is_invocant($many)) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_invocant($many)) 22 1 23
47 22 $many = check_able($many, 'generator')->generator;
48 }
49  
50 22 check_code_ref($many);
51  
52 22 my $data;
53 22 my $n = 0;
54 22 ▶ while (defined($data = $many->())) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($data = &$many())) 272 20 292
55 272 $self->add($data);
56 272 $n++;
57 }
58 20 $n;
59 }
60  
61 20 ▶sub commit { }
Subroutine commit: called CC=1 SCAR=0.0
Pod documented
62  
63 90 ▶sub DESTROY {
Subroutine DESTROY: called CC=3 SCAR=11.1
64 90 my ($self) = shift;
65 90 ▶ $self->commit if $self->autocommit && !$self->_commit;
Branch: 1 branch
BranchTrueFalseTotal
if $self->autocommit and not $self->_commit 3 87 90
Condition66%2/3
$self->autocommit and not $self->_commit
!ll&&!rl&&r
8703
MC/DC50%1/2
$self->autocommit and not $self->_commit
$self->autocommit not $self->_commit
Truth table66%2/3
A and not(B)
A= $self->autocommitB= not $self->_commit
ABresult
0X0
100
111
66 }
67  
68 41 1;
69  
70 __END__
« Catmandu/Importer/DKVP.pm ↑ Summary Catmandu/Fix/rename.pm »