line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catmandu::Fix::Bind::importer; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
6157
|
use Catmandu::Sane; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '1.2020'; |
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
7
|
use Moo; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
5
|
|
8
|
1
|
|
|
1
|
|
393
|
use Catmandu::Util qw(:is); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
306
|
|
9
|
1
|
|
|
1
|
|
8
|
use namespace::clean; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
5
|
|
10
|
1
|
|
|
1
|
|
1093
|
use Catmandu::Fix::Has; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
with 'Catmandu::Fix::Bind', 'Catmandu::Fix::Bind::Group'; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
has importer_name => (fix_arg => 1); |
15
|
|
|
|
|
|
|
has step => (fix_opt => 1); |
16
|
|
|
|
|
|
|
has importer_args => (fix_opt => 'collect'); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
has importer => (is => 'lazy'); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub _build_importer { |
21
|
3
|
|
|
3
|
|
46
|
my ($self) = @_; |
22
|
3
|
|
|
|
|
12
|
Catmandu->importer($self->importer_name, %{$self->importer_args}); |
|
3
|
|
|
|
|
30
|
|
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub unit { |
26
|
3
|
|
|
3
|
0
|
16
|
my ($self, $data) = @_; |
27
|
3
|
|
|
|
|
60
|
$data; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub bind { |
31
|
|
|
|
|
|
|
my ($self, $mvar, $code) = @_; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
if ($self->step) { |
34
|
|
|
|
|
|
|
my $next = $self->importer->next; |
35
|
|
|
|
|
|
|
$code->($next) if $next; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
else { |
38
|
|
|
|
|
|
|
$self->importer->each( |
39
|
|
|
|
|
|
|
sub { |
40
|
|
|
|
|
|
|
$code->($_[0]); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
$mvar; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
1; |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
__END__ |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=pod |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=head1 NAME |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
Catmandu::Fix::Bind::importer - a binder runs fixes on records from an importer |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head1 SYNOPSIS |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
# |
61
|
|
|
|
|
|
|
catmandu run myfix.fix |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
# with myfix.fix |
64
|
|
|
|
|
|
|
do importer(OAI,url: "http://lib.ugent.be/oai") |
65
|
|
|
|
|
|
|
retain(_id) |
66
|
|
|
|
|
|
|
add_to_exporter(.,YAML) |
67
|
|
|
|
|
|
|
end |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
# Or in an runnable Fix script: |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
#!/usr/bin/env catmandu run |
72
|
|
|
|
|
|
|
add_field(hello,world) |
73
|
|
|
|
|
|
|
add_to_exporter(.,YAML) |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
# Or: |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
#!/usr/bin/env catmandu run |
79
|
|
|
|
|
|
|
do importer(OAI,url: "http://lib.ugent.be/oai") |
80
|
|
|
|
|
|
|
retain(_id) |
81
|
|
|
|
|
|
|
add_to_exporter(.,YAML) |
82
|
|
|
|
|
|
|
end |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head1 DESCRIPTION |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
The import binder computes all the Fix function on records read from the given importer. |
88
|
|
|
|
|
|
|
This importer doesn't change the current importer to the given one! Use the 'catmandu run' |
89
|
|
|
|
|
|
|
command line command to control importers solely by the Fix script. |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head1 CONFIGURATION |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head2 importer(IMPORTER_NAME, step: true|false, IMPORTER_ARGS...) |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
Load the import IMPORTER_NAME in the current context. When step is 'true' then for |
96
|
|
|
|
|
|
|
every execution of do importer() only one item will be read from the importer. This |
97
|
|
|
|
|
|
|
latter option can become handy in nested iterators: |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
# This will produce: |
100
|
|
|
|
|
|
|
# {"n":0} |
101
|
|
|
|
|
|
|
# {"m":0} |
102
|
|
|
|
|
|
|
# {"n":1} |
103
|
|
|
|
|
|
|
# {"m":1} |
104
|
|
|
|
|
|
|
# {"n":2} |
105
|
|
|
|
|
|
|
# {"m":2} |
106
|
|
|
|
|
|
|
# ... |
107
|
|
|
|
|
|
|
do importer(Mock,size:20) |
108
|
|
|
|
|
|
|
move_field(n,brol) |
109
|
|
|
|
|
|
|
add_to_exporter(.,JSON) |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
do importer(Mock,size:20,step:true) |
112
|
|
|
|
|
|
|
move_field(n,m) |
113
|
|
|
|
|
|
|
add_to_exporter(.,JSON) |
114
|
|
|
|
|
|
|
end |
115
|
|
|
|
|
|
|
end |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=head1 SEE ALSO |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
L<Catmandu::Fix::Bind>, |
120
|
|
|
|
|
|
|
L<Catmandu::Cmd::run> |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=cut |