blib/lib/LucyX/Index/ByteBufDocReader.pm

filter: Statementstmt 96.5% 56 / 58 Branchbran 50.0% 7 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 10 / 10 Podpod 50.0% 2 / 4 totaltotal 87.2% 75 / 86 CC 8 SCAR 13.8
CC
8
Cov
88%
new
7.9
read_record
2.0
BEGIN
1.0
CRAP 4.0
« buildlib/Lucy/Test/TestUtils.pm ↑ Summary blib/lib/LucyX/Index/ZlibDocReader.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  
16 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 package LucyX::Index::ByteBufDocReader;
20 2 ▶use base qw( Lucy::Index::DocReader );
Subroutine BEGIN: called CC=1 SCAR=0.0
21 2 ▶use Lucy::Document::HitDoc;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 2 our $VERSION = '0.008000';
23 2 $VERSION = eval $VERSION;
24 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 # Inside-out member vars.
27 2 our %width;
28 2 our %field;
29 2 our %instream;
30  
31 6 ▶sub new {
Subroutine new: called CC=7 SCAR=20.7
Pod documented
32 6 my ( $either, %args ) = @_;
33 6 my $width = delete $args{width};
34 6 my $field = delete $args{field};
35 6 my $self = $either->SUPER::new(%args);
36 6 ▶ confess("Missing required param 'width'") unless defined $width;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $width 0 6 6
37 6 ▶ confess("Missing required param 'field'") unless $field;
Branch: 1 branch
BranchTrueFalseTotal
unless $field 0 6 6
38 0 ▶ if ( $width < 1 ) { confess("'width' must be at least 1") }
Branch: 1 branch
BranchTrueFalseTotal
if ($width < 1) 0 6 6
39 6 $width{$$self} = $width;
40 6 $field{$$self} = $field;
41  
42 6 my $segment = $self->get_segment;
43 6 my $metadata = $self->get_segment->fetch_metadata("bytebufdocs");
44 6 ▶ if ($metadata) {
Branch: 1 branch
BranchTrueFalseTotal
if ($metadata) 6 0 6
45 6 ▶ if ( $metadata->{format} != 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($metadata->{"format"} != 1) 0 6 6
46 0 confess("Unrecognized format: '$metadata->{format}'");
47 }
48 6 my $filename = $segment->get_name . "/bytebufdocs.dat";
49 6 ▶ $instream{$$self} = $self->get_folder->open_in($filename)
Branch: 1 branch
BranchTrueFalseTotal
$LucyX::Index::ByteBufDocReader::instream{$$self} = $self->get_folder->open_in($filename) or "Clownfish"->confess->error 6 0 6
50 or confess Clownfish->error;
51 }
52  
53 6 return $self;
54 }
55  
56 3 ▶sub fetch_doc {
Subroutine fetch_doc: called CC=1 SCAR=0.0
Pod documented
57 3 my ( $self, $doc_id ) = @_;
58 3 my $field = $field{$$self};
59 3 my %fields = ( $field => '' );
60 3 $self->read_record( $doc_id, \$fields{$field} );
61 3 return Lucy::Document::HitDoc->new(
62 doc_id => $doc_id,
63 fields => \%fields,
64 );
65 }
66  
67 24 ▶sub read_record {
Subroutine read_record: called CC=2 SCAR=7.0
Pod undocumented
68 24 my ( $self, $doc_id, $buf ) = @_;
69 24 my $instream = $instream{$$self};
70 24 ▶ if ($instream) {
Branch: 1 branch
BranchTrueFalseTotal
if ($instream) 24 0 24
71 24 my $width = $width{$$self};
72 24 $instream->seek( $width * $doc_id );
73 24 $instream->read( $$buf, $width );
74 }
75 }
76  
77 6 ▶sub close {
Subroutine close: called CC=1 SCAR=0.0
Pod undocumented
78 6 my $self = shift;
79 6 delete $width{$$self};
80 6 delete $instream{$$self};
81 }
82  
83 6 ▶sub DESTROY {
Subroutine DESTROY: called CC=1 SCAR=0.0
84 6 my $self = shift;
85 6 delete $width{$$self};
86 6 delete $field{$$self};
87 6 delete $instream{$$self};
88 6 $self->SUPER::DESTROY;
89 }
90  
91 2 1;
92  
93 __END__
« buildlib/Lucy/Test/TestUtils.pm ↑ Summary blib/lib/LucyX/Index/ZlibDocReader.pm »