buildlib/Lucy/Build/Binding/Store.pm

filter: Statementstmt 100% 69 / 69 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 12 / 12 Podpod 0.0% 0 / 10 totaltotal 89.0% 81 / 91 CC 2 SCAR 1.4
CC
2
Cov
100%
bind_instream
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.2
« buildlib/Lucy/Build/Binding/Index.pm ↑ Summary buildlib/Lucy/Build/Binding/Analysis.pm »
1 # Licensed to the Apache Software Foundation (ASF) under one or more
2 # contributor license agreements. See the NOTICE file distributed with
3 # this work for additional information regarding copyright ownership.
4 # The ASF licenses this file to You under the Apache License, Version 2.0
5 # (the "License"); you may not use this file except in compliance with
6 # the License. You may obtain a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 package Lucy::Build::Binding::Store;
16 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 1 our $VERSION = '0.008000';
20 1 $VERSION = eval $VERSION;
21  
22 1 ▶sub bind_all {
Subroutine bind_all: called CC=1 SCAR=0.0
Pod undocumented
23 1 my $class = shift;
24 1 $class->bind_fsfilehandle;
25 1 $class->bind_fsfolder;
26 1 $class->bind_filehandle;
27 1 $class->bind_folder;
28 1 $class->bind_instream;
29 1 $class->bind_lockerr;
30 1 $class->bind_outstream;
31 1 $class->bind_ramfilehandle;
32 1 $class->bind_ramfolder;
33 }
34  
35 1 ▶sub bind_fsfilehandle {
Subroutine bind_fsfilehandle: called CC=1 SCAR=0.0
Pod undocumented
36 1 my $binding = Clownfish::CFC::Binding::Perl::Class->new(
37 parcel => "Lucy",
38 class_name => "Lucy::Store::FSFileHandle",
39 );
40 1 $binding->bind_constructor( alias => '_open', initializer => 'do_open' );
41 1 Clownfish::CFC::Binding::Perl::Class->register($binding);
42 }
43  
44 1 ▶sub bind_fsfolder {
Subroutine bind_fsfolder: called CC=1 SCAR=0.0
Pod undocumented
45 1 my $pod_spec = Clownfish::CFC::Binding::Perl::Pod->new;
46 1 my $synopsis = <<'END_SYNOPSIS';
47 my $folder = Lucy::Store::FSFolder->new(
48 path => '/path/to/folder',
49 );
50 END_SYNOPSIS
51 1 my $constructor = $synopsis;
52 1 $pod_spec->set_synopsis($synopsis);
53 1 $pod_spec->add_constructor( alias => 'new', sample => $constructor, );
54  
55 1 my $binding = Clownfish::CFC::Binding::Perl::Class->new(
56 parcel => "Lucy",
57 class_name => "Lucy::Store::FSFolder",
58 );
59 1 $binding->set_pod_spec($pod_spec);
60  
61 1 Clownfish::CFC::Binding::Perl::Class->register($binding);
62 }
63  
64 1 ▶sub bind_filehandle {
Subroutine bind_filehandle: called CC=1 SCAR=0.0
Pod undocumented
65 1 my $xs_code = <<'END_XS_CODE';
66 MODULE = Lucy PACKAGE = Lucy::Store::FileHandle
67  
68 =for comment
69  
70 For testing purposes only. Track number of FileHandle objects in existence.
71  
72 =cut
73  
74 uint32_t
75 FH_READ_ONLY()
76 CODE:
77 RETVAL = LUCY_FH_READ_ONLY;
78 OUTPUT: RETVAL
79  
80 uint32_t
81 FH_WRITE_ONLY()
82 CODE:
83 RETVAL = LUCY_FH_WRITE_ONLY;
84 OUTPUT: RETVAL
85  
86 uint32_t
87 FH_CREATE()
88 CODE:
89 RETVAL = LUCY_FH_CREATE;
90 OUTPUT: RETVAL
91  
92 uint32_t
93 FH_EXCLUSIVE()
94 CODE:
95 RETVAL = LUCY_FH_EXCLUSIVE;
96 OUTPUT: RETVAL
97  
98  
99 int32_t
100 object_count()
101 CODE:
102 RETVAL = lucy_FH_object_count;
103 OUTPUT: RETVAL
104  
105 =for comment
106  
107 For testing purposes only. Used to help produce buffer alignment tests.
108  
109 =cut
110  
111 IV
112 _BUF_SIZE()
113 CODE:
114 RETVAL = LUCY_IO_STREAM_BUF_SIZE;
115 OUTPUT: RETVAL
116 END_XS_CODE
117  
118 1 my $binding = Clownfish::CFC::Binding::Perl::Class->new(
119 parcel => "Lucy",
120 class_name => "Lucy::Store::FileHandle",
121 );
122 1 $binding->bind_constructor( alias => '_open', initializer => 'do_open' );
123 1 $binding->append_xs($xs_code);
124  
125 1 Clownfish::CFC::Binding::Perl::Class->register($binding);
126 }
127  
128 1 ▶sub bind_folder {
Subroutine bind_folder: called CC=1 SCAR=0.0
Pod undocumented
129 1 my $pod_spec = Clownfish::CFC::Binding::Perl::Pod->new;
130 1 $pod_spec->set_synopsis(" # Abstract base class.\n");
131  
132 1 my $binding = Clownfish::CFC::Binding::Perl::Class->new(
133 parcel => "Lucy",
134 class_name => "Lucy::Store::Folder",
135 );
136 1 $binding->set_pod_spec($pod_spec);
137  
138 1 Clownfish::CFC::Binding::Perl::Class->register($binding);
139 }
140  
141 1 ▶sub bind_instream {
Subroutine bind_instream: called CC=2 SCAR=6.9
Pod undocumented
142 1 my @hand_rolled = qw(
143 Read_Raw_C64
144 );
145  
146 1 my $xs_code = <<'END_XS_CODE';
147 MODULE = Lucy PACKAGE = Lucy::Store::InStream
148  
149 void
150 read(self, buffer_sv, len, ...)
151 lucy_InStream *self;
152 SV *buffer_sv;
153 size_t len;
154 PPCODE:
155 {
156 UV offset = items == 4 ? SvUV(ST(3)) : 0;
157 char *ptr;
158 size_t total_len = offset + len;
159 (void)SvUPGRADE(buffer_sv, SVt_PV);
160 if (!SvPOK(buffer_sv)) { SvCUR_set(buffer_sv, 0); }
161 ptr = SvGROW(buffer_sv, total_len + 1);
162 LUCY_InStream_Read_Bytes(self, ptr + offset, len);
163 SvPOK_on(buffer_sv);
164 if (SvCUR(buffer_sv) < total_len) {
165 SvCUR_set(buffer_sv, total_len);
166 *(SvEND(buffer_sv)) = '\0';
167 }
168 }
169  
170 SV*
171 read_string(self)
172 lucy_InStream *self;
173 CODE:
174 {
175 char *ptr;
176 size_t len = LUCY_InStream_Read_CU32(self);
177 RETVAL = newSV(len + 1);
178 SvCUR_set(RETVAL, len);
179 SvPOK_on(RETVAL);
180 SvUTF8_on(RETVAL); // Trust source. Reconsider if API goes public.
181 *SvEND(RETVAL) = '\0';
182 ptr = SvPVX(RETVAL);
183 LUCY_InStream_Read_Bytes(self, ptr, len);
184 }
185 OUTPUT: RETVAL
186  
187 int
188 read_raw_c64(self, buffer_sv)
189 lucy_InStream *self;
190 SV *buffer_sv;
191 CODE:
192 {
193 char *ptr;
194 (void)SvUPGRADE(buffer_sv, SVt_PV);
195 ptr = SvGROW(buffer_sv, 10 + 1);
196 RETVAL = LUCY_InStream_Read_Raw_C64(self, ptr);
197 SvPOK_on(buffer_sv);
198 SvCUR_set(buffer_sv, RETVAL);
199 }
200 OUTPUT: RETVAL
201 END_XS_CODE
202  
203 1 my $binding = Clownfish::CFC::Binding::Perl::Class->new(
204 parcel => "Lucy",
205 class_name => "Lucy::Store::InStream",
206 );
207 1 $binding->bind_constructor( alias => 'open', initializer => 'do_open' );
208 1 $binding->exclude_method($_) for @hand_rolled;
209 1 $binding->append_xs($xs_code);
210  
211 1 Clownfish::CFC::Binding::Perl::Class->register($binding);
212 }
213  
214 1 ▶sub bind_lockerr {
Subroutine bind_lockerr: called CC=1 SCAR=0.0
Pod undocumented
215 1 my $pod_spec = Clownfish::CFC::Binding::Perl::Pod->new;
216 1 my $synopsis = <<'END_SYNOPSIS';
217 while (1) {
218 my $bg_merger = eval {
219 Lucy::Index::BackgroundMerger->new( index => $index );
220 };
221 if ( blessed($@) and $@->isa("Lucy::Store::LockErr") ) {
222 warn "Retrying...\n";
223 }
224 elsif (!$bg_merger) {
225 # Re-throw.
226 die "Failed to open BackgroundMerger: $@";
227 }
228 ...
229 }
230 END_SYNOPSIS
231 1 $pod_spec->set_synopsis($synopsis);
232  
233 1 my $binding = Clownfish::CFC::Binding::Perl::Class->new(
234 parcel => "Lucy",
235 class_name => "Lucy::Store::LockErr",
236 );
237 1 $binding->set_pod_spec($pod_spec);
238  
239 1 Clownfish::CFC::Binding::Perl::Class->register($binding);
240 }
241  
242 1 ▶sub bind_outstream {
Subroutine bind_outstream: called CC=1 SCAR=0.0
Pod undocumented
243 1 my $xs_code = <<'END_XS_CODE';
244 MODULE = Lucy PACKAGE = Lucy::Store::OutStream
245  
246 void
247 print(self, ...)
248 lucy_OutStream *self;
249 PPCODE:
250 {
251 int i;
252 for (i = 1; i < items; i++) {
253 STRLEN len;
254 char *ptr = SvPV(ST(i), len);
255 LUCY_OutStream_Write_Bytes(self, ptr, len);
256 }
257 }
258  
259 void
260 write_string(self, aSV)
261 lucy_OutStream *self;
262 SV *aSV;
263 PPCODE:
264 {
265 STRLEN len = 0;
266 char *ptr = SvPVutf8(aSV, len);
267 if (len > INT32_MAX) {
268 CFISH_THROW(CFISH_ERR, "String too long: %u64", (uint64_t)len);
269 }
270 LUCY_OutStream_Write_CU32(self, len);
271 LUCY_OutStream_Write_Bytes(self, ptr, len);
272 }
273 END_XS_CODE
274  
275 1 my $binding = Clownfish::CFC::Binding::Perl::Class->new(
276 parcel => "Lucy",
277 class_name => "Lucy::Store::OutStream",
278 );
279 1 $binding->bind_constructor( alias => 'open', initializer => 'do_open' );
280 1 $binding->append_xs($xs_code);
281  
282 1 Clownfish::CFC::Binding::Perl::Class->register($binding);
283 }
284  
285 1 ▶sub bind_ramfilehandle {
Subroutine bind_ramfilehandle: called CC=1 SCAR=0.0
Pod undocumented
286 1 my $binding = Clownfish::CFC::Binding::Perl::Class->new(
287 parcel => "Lucy",
288 class_name => "Lucy::Store::RAMFileHandle",
289 );
290 1 $binding->bind_constructor( alias => '_open', initializer => 'do_open' );
291  
292 1 Clownfish::CFC::Binding::Perl::Class->register($binding);
293 }
294  
295 1 ▶sub bind_ramfolder {
Subroutine bind_ramfolder: called CC=1 SCAR=0.0
Pod undocumented
296 1 my $pod_spec = Clownfish::CFC::Binding::Perl::Pod->new;
297 1 my $synopsis = <<'END_SYNOPSIS';
298 my $folder = Lucy::Store::RAMFolder->new;
299
300 # or sometimes...
301 my $folder = Lucy::Store::RAMFolder->new(
302 path => $relative_path,
303 );
304 END_SYNOPSIS
305 1 my $constructor = <<'END_CONSTRUCTOR';
306 my $folder = Lucy::Store::RAMFolder->new(
307 path => $relative_path, # default: empty string
308 );
309 END_CONSTRUCTOR
310 1 $pod_spec->set_synopsis($synopsis);
311 1 $pod_spec->add_constructor( alias => 'new', sample => $constructor, );
312  
313 1 my $binding = Clownfish::CFC::Binding::Perl::Class->new(
314 parcel => "Lucy",
315 class_name => "Lucy::Store::RAMFolder",
316 );
317 1 $binding->set_pod_spec($pod_spec);
318  
319 1 Clownfish::CFC::Binding::Perl::Class->register($binding);
320 }
321  
322 1 1;
« buildlib/Lucy/Build/Binding/Index.pm ↑ Summary buildlib/Lucy/Build/Binding/Analysis.pm »