line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
use Catmandu::Sane; |
3
|
1
|
|
|
1
|
|
88107
|
use Catmandu::Util qw(is_hash_ref is_array_ref is_able); |
|
1
|
|
|
|
|
12
|
|
|
1
|
|
|
|
|
6
|
|
4
|
1
|
|
|
1
|
|
6
|
|
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
61
|
|
5
|
|
|
|
|
|
|
our $VERSION = '1.2018'; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use Moo; |
8
|
1
|
|
|
1
|
|
6
|
use namespace::clean; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
4
|
|
9
|
1
|
|
|
1
|
|
293
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
3
|
|
10
|
|
|
|
|
|
|
with 'Catmandu::Exporter'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
# add is a noop since an Exporter is already a Counter |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
my $self = $_[0]; |
15
|
|
|
|
|
|
|
$self->fh->print($self->count . "\n"); |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# optimize counting |
19
|
|
|
|
|
|
|
around add_many => sub { |
20
|
|
|
|
|
|
|
my ($orig, $self, $many) = @_; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
if (is_hash_ref($many)) { |
23
|
|
|
|
|
|
|
$self->inc_count; |
24
|
|
|
|
|
|
|
return 1; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
if (is_array_ref($many)) { |
28
|
|
|
|
|
|
|
my $n = scalar @$many; |
29
|
|
|
|
|
|
|
$self->inc_count($n); |
30
|
|
|
|
|
|
|
return $n; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
if (is_able($many, 'count')) { |
34
|
|
|
|
|
|
|
my $n = $many->count; |
35
|
|
|
|
|
|
|
$self->inc_count($n); |
36
|
|
|
|
|
|
|
return $n; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
$orig->($self, $many); |
40
|
|
|
|
|
|
|
}; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
1; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=pod |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=head1 NAME |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
Catmandu::Exporter::Count - a exporter that counts things |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head1 SYNOPSIS |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
# From the commandline |
54
|
|
|
|
|
|
|
$ catmandu convert JSON to Count < /tmp/data.json |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head1 DESCRIPTION |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
This exporter exports nothing and just counts the number of items found |
60
|
|
|
|
|
|
|
in the input data. |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head1 SEE ALSO |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
L<Catmandu::Cmd::count> |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
L<Catmandu::Exporter::Null> |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=cut |