| 1 | package Catmandu::Exporter::Count; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | ▶ | use Catmandu::Sane; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use Catmandu::Util qw(is_hash_ref is_array_ref is_able); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 1 | our $VERSION = '1.2025'; | |||||||||
| 7 | |||||||||||
| 8 | 1 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 1 | ▶ | use namespace::clean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | 1 | with 'Catmandu::Exporter'; | |||||||||
| 12 | |||||||||||
| 13 | # add is a noop since an Exporter is already a Counter | ||||||||||
| 14 | 3 | ▶ | sub add { } | ||||||||
|
Subroutine
add: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 15 | |||||||||||
| 16 | 2 | ▶ | sub commit { | ||||||||
|
Subroutine
commit: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 17 | 2 | my $self = $_[0]; | |||||||||
| 18 | 2 | $self->fh->print($self->count . "\n"); | |||||||||
| 19 | } | ||||||||||
| 20 | |||||||||||
| 21 | # optimize counting | ||||||||||
| 22 | 1 | ▶ | around add_many => sub { | ||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=17.4
| |||||||||||
| 23 | 1 | my ($orig, $self, $many) = @_; | |||||||||
| 24 | |||||||||||
| 25 | 1 | ▶ | if (is_hash_ref($many)) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 26 | 0 | $self->inc_count; | |||||||||
| 27 | 0 | return 1; | |||||||||
| 28 | } | ||||||||||
| 29 | |||||||||||
| 30 | 1 | ▶ | if (is_array_ref($many)) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 31 | 0 | my $n = scalar @$many; | |||||||||
| 32 | 0 | $self->inc_count($n); | |||||||||
| 33 | 0 | return $n; | |||||||||
| 34 | } | ||||||||||
| 35 | |||||||||||
| 36 | 1 | ▶ | if (is_able($many, 'count')) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 37 | 1 | my $n = $many->count; | |||||||||
| 38 | 1 | $self->inc_count($n); | |||||||||
| 39 | 1 | return $n; | |||||||||
| 40 | } | ||||||||||
| 41 | |||||||||||
| 42 | 0 | $orig->($self, $many); | |||||||||
| 43 | 1 | }; | |||||||||
| 44 | |||||||||||
| 45 | 1 | 1; | |||||||||
| 46 | |||||||||||
| 47 | __END__ | ||||||||||