line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
use Catmandu::Sane; |
3
|
41
|
|
|
41
|
|
117172
|
|
|
41
|
|
|
|
|
89
|
|
|
41
|
|
|
|
|
223
|
|
4
|
|
|
|
|
|
|
our $VERSION = '1.2018'; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
use Catmandu::Util qw(:is :check); |
7
|
41
|
|
|
41
|
|
263
|
use Moo::Role; |
|
41
|
|
|
|
|
82
|
|
|
41
|
|
|
|
|
15410
|
|
8
|
41
|
|
|
41
|
|
288
|
use namespace::clean; |
|
41
|
|
|
|
|
81
|
|
|
41
|
|
|
|
|
254
|
|
9
|
41
|
|
|
41
|
|
19294
|
|
|
41
|
|
|
|
|
82
|
|
|
41
|
|
|
|
|
335
|
|
10
|
|
|
|
|
|
|
with 'Catmandu::Fixable'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
requires 'add'; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
has autocommit => (is => 'ro', default => sub {0}); |
15
|
|
|
|
|
|
|
has _commit => (is => 'rw', default => sub {0}); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
around add => sub { |
18
|
|
|
|
|
|
|
my ($orig, $self, $data) = @_; |
19
|
|
|
|
|
|
|
return unless defined $data; |
20
|
|
|
|
|
|
|
$data = $self->_fixer->fix($data) if $self->_fixer; |
21
|
|
|
|
|
|
|
$orig->($self, $data) if defined $data; |
22
|
|
|
|
|
|
|
$data; |
23
|
|
|
|
|
|
|
}; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
around commit => sub { |
26
|
|
|
|
|
|
|
my ($orig, $self) = @_; |
27
|
|
|
|
|
|
|
my (@res) = $orig->($self); |
28
|
|
|
|
|
|
|
$self->_commit(1); |
29
|
|
|
|
|
|
|
@res; |
30
|
|
|
|
|
|
|
}; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
my ($self, $many) = @_; |
33
|
|
|
|
|
|
|
|
34
|
43
|
|
|
43
|
0
|
2059
|
if (is_hash_ref($many)) { |
35
|
|
|
|
|
|
|
$self->add($many); |
36
|
43
|
100
|
|
|
|
234
|
return 1; |
37
|
1
|
|
|
|
|
21
|
} |
38
|
1
|
|
|
|
|
3
|
|
39
|
|
|
|
|
|
|
if (is_array_ref($many)) { |
40
|
|
|
|
|
|
|
$self->add($_) for @$many; |
41
|
42
|
100
|
|
|
|
177
|
return scalar @$many; |
42
|
20
|
|
|
|
|
428
|
} |
43
|
20
|
|
|
|
|
102
|
|
44
|
|
|
|
|
|
|
if (is_invocant($many)) { |
45
|
|
|
|
|
|
|
$many = check_able($many, 'generator')->generator; |
46
|
22
|
100
|
|
|
|
83
|
} |
47
|
21
|
|
|
|
|
136
|
|
48
|
|
|
|
|
|
|
check_code_ref($many); |
49
|
|
|
|
|
|
|
|
50
|
21
|
|
|
|
|
96
|
my $data; |
51
|
|
|
|
|
|
|
my $n = 0; |
52
|
21
|
|
|
|
|
4937
|
while (defined($data = $many->())) { |
53
|
21
|
|
|
|
|
47
|
$self->add($data); |
54
|
21
|
|
|
|
|
70
|
$n++; |
55
|
270
|
|
|
|
|
9869
|
} |
56
|
270
|
|
|
|
|
1424
|
$n; |
57
|
|
|
|
|
|
|
} |
58
|
19
|
|
|
|
|
310
|
|
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
my ($self) = shift; |
61
|
|
|
|
20
|
1
|
|
$self->commit if $self->autocommit && !$self->_commit; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
89
|
|
|
89
|
|
24217
|
1; |
65
|
89
|
100
|
66
|
|
|
2790
|
|
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=pod |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head1 NAME |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
Catmandu::Addable - Base class for all Catmandu modules need to implement add |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head1 SYNOPSIS |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
package My::Adder; |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
use Moo; |
78
|
|
|
|
|
|
|
use Data::Dumper; |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
with 'Catmandu::Addable'; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub add { |
83
|
|
|
|
|
|
|
my ($self,$object) = @_; |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
print "So you want to add:\n"; |
86
|
|
|
|
|
|
|
print Dumper($object); |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
1; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub commit { |
92
|
|
|
|
|
|
|
my $self = shift; |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
print "And now you are done?\n"; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
package main; |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
my $adder = My::Adder->new(fix => ['upcase(foo)']); |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
# prints foo => BAR |
102
|
|
|
|
|
|
|
$adder->add({ foo => 'bar' }); |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
# prints: |
105
|
|
|
|
|
|
|
# foo => BAR |
106
|
|
|
|
|
|
|
# foo => BAR |
107
|
|
|
|
|
|
|
$adder->add_many([ { foo => 'bar' } , { foo => 'bar' }]); |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
# prints a commit statement |
110
|
|
|
|
|
|
|
$adder->commit; |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head1 OPTIONS |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=over |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=item autocommit |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
Autocommit when the exporter gets out of scope. Default 0. |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=back |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head1 METHODS |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head2 add($hash) |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
Receives a Perl hash and should return true or false. |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=head2 commit |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
This method is usually called at the end of many add or add_many operations. |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head1 INHERIT |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
If you provide an 'add' method, then automatically your package gets a add_many |
135
|
|
|
|
|
|
|
method, plus a fix attribute which transforms all Perl hashes provided to the |
136
|
|
|
|
|
|
|
add method. |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=head1 SEE ALSO |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
L<Catmandu::Fixable>, L<Catmandu::Exporter> , L<Catmandu::Store> |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=cut |