| 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
| |||||||||||||||||||||||||||||
| 21 | 457 | ▶ | $data = $self->_fixer->fix($data) if $self->_fixer; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 22 | 457 | ▶ | $orig->($self, $data) if defined $data; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 37 | 1 | $self->add($many); | |||||||||||||||||||||||||||
| 38 | 1 | return 1; | |||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 43 | ▶ | if (is_array_ref($many)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 42 | 20 | $self->add($_) for @$many; | |||||||||||||||||||||||||||
| 43 | 20 | return scalar @$many; | |||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 23 | ▶ | if (is_invocant($many)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
Condition66%2/3
$self->autocommit and not $self->_commit
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
| |||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 41 | 1; | |||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | __END__ | ||||||||||||||||||||||||||||