blib/lib/Catmandu/Fix/Bind/importer.pm

filter: Statementstmt 95.0% 38 / 40 Branchbran 33.3% 2 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 10 / 10 Podpod 0.0% 0 / 3 totaltotal 84.7% 50 / 59 CC 4 SCAR 8.4
CC
4
Cov
87%
bind
5.3
BEGIN
1.0
BEGIN
1.0
CRAP 2.3
« blib/lib/Catmandu/Store/Multi.pm ↑ Summary blib/lib/Catmandu/Fix/trim.pm »
1 package Catmandu::Fix::Bind::importer;
2  
3 1 ▶use Catmandu::Sane;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 our $VERSION = '1.0201_02';
6  
7 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Catmandu::Util qw(:is);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Catmandu::Fix::Has;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 with 'Catmandu::Fix::Bind';
13  
14 1 has importer_name => (fix_arg => 1);
15 1 has step => (fix_opt => 1);
16 1 has importer_args => (fix_opt => 'collect');
17  
18 1 has importer => (is => 'lazy');
19 3 ▶has flag => (is => 'rw', default => sub {0});
Subroutine __ANON__: called CC=1 SCAR=0.0
20  
21 sub _build_importer {
22 3 ▶ my ($self) = @_;
Subroutine _build_importer: called CC=1 SCAR=0.0
23 3 Catmandu->importer($self->importer_name, %{$self->importer_args});
24 }
25  
26 sub unit {
27 3 ▶ my ($self, $data) = @_;
Subroutine unit: called CC=1 SCAR=0.0
Pod undocumented
28 3 $data;
29 }
30  
31 sub bind {
32 3 ▶ my ($self, $mvar, $func, $name, $fixer) = @_;
Subroutine bind: called CC=4 SCAR=16.6
Pod undocumented
33  
34 3 ▶ return if $self->flag;
Branch: 1 branch
BranchTrueFalseTotal
if $self->flag 0 3 3
35  
36 3 ▶ if ($self->step) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->step) { } 0 3 3
37 0 my $next = $self->importer->next;
38 0 ▶ $fixer->fix($next) if $next;
Branch: 1 branch
BranchTrueFalseTotal
if $next 0 0 0
39 }
40 else {
41 $self->importer->each(
42 sub {
43 $fixer->fix($_[0]);
44 }
45 3 );
46 }
47  
48 3 $self->flag(1);
49  
50 3 $mvar;
51 }
52  
53 sub result {
54 3 ▶ my ($self, $mvar) = @_;
Subroutine result: called CC=1 SCAR=0.0
Pod undocumented
55  
56 3 $self->flag(0);
57  
58 3 $mvar;
59 }
60  
61 1 1;
62  
63 __END__
64  
65 =pod
66  
67 =head1 NAME
68  
69 Catmandu::Fix::Bind::importer - a binder runs fixes on records from an importer
70  
71 =head1 SYNOPSIS
72  
73 #
74 catmandu run myfix.fix
75  
76 # with myfix.fix
77 do importer(OAI,url: "http://lib.ugent.be/oai")
78 retain(_id)
79 add_to_exporter(.,YAML)
80 end
81  
82 # Or in an runnable Fix script:
83  
84 #!/usr/bin/env catmandu run
85 add_field(hello,world)
86 add_to_exporter(.,YAML)
87  
88  
89 # Or:
90  
91 #!/usr/bin/env catmandu run
92 do importer(OAI,url: "http://lib.ugent.be/oai")
93 retain(_id)
94 add_to_exporter(.,YAML)
95 end
96  
97  
98 =head1 DESCRIPTION
99  
100 The import binder computes all the Fix function on records read from the given importer.
101 This importer doesn't change the current importer to the given one! Use the 'catmandu run'
102 command line command to control importers solely by the Fix script.
103  
104 =head1 CONFIGURATION
105  
106 =head2 importer(IMPORTER_NAME, step: true|false, IMPORTER_ARGS...)
107  
108 Load the import IMPORTER_NAME in the current context. When step is 'true' then for
109 every execution of do importer() only one item will be read from the importer. This
110 latter option can become handy in nested iterators:
111  
112 # This will produce:
113 # {"n":0}
114 # {"m":0}
115 # {"n":1}
116 # {"m":1}
117 # {"n":2}
118 # {"m":2}
119 # ...
120 do importer(Mock,size:20)
121 move_field(n,brol)
122 add_to_exporter(.,JSON)
123  
124 do importer(Mock,size:20,step:true)
125 move_field(n,m)
126 add_to_exporter(.,JSON)
127 end
128 end
129  
130 =head1 SEE ALSO
131  
132 L<Catmandu::Fix::Bind>,
133 L<Catmandu::Cmd::run>
134  
135 =cut
« blib/lib/Catmandu/Store/Multi.pm ↑ Summary blib/lib/Catmandu/Fix/trim.pm »