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