blib/lib/KinoSearch1/Index/CompoundFileReader.pm

filter: Statementstmt 100% 42 / 42 Branchbran 66.6% 4 / 6 Conditioncond 66.6% 2 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 10 / 10 Podpod 25.0% 1 / 4 totaltotal 88.0% 59 / 67 CC 5 SCAR 6.3
CC
5
Cov
94%
open_instream
3.1
init_instance
3.0
BEGIN
1.0
CRAP 1.9
« blib/lib/KinoSearch1/Store/InvIndex.pm ↑ Summary blib/lib/KinoSearch1/Search/TermQuery.pm »
1 package KinoSearch1::Index::CompoundFileReader;
2 34 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 34 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 34 ▶use KinoSearch1::Util::ToolSet;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 34 ▶use base qw( KinoSearch1::Store::InvIndex ); # !!
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 34 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
8 34 __PACKAGE__->init_instance_vars(
9 # members / constructor params
10 invindex => undef,
11 seg_name => undef,
12 # members
13 instream => undef,
14 entries => undef,
15 );
16 }
17  
18 34 ▶use KinoSearch1::Store::InStream;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 99 ▶sub init_instance {
Subroutine init_instance: called CC=3 SCAR=11.0
Pod documented
21 99 my $self = shift;
22 99 my ( $seg_name, $invindex ) = @{$self}{ 'seg_name', 'invindex' };
23  
24 # read in names and lengths for all the "files" within the compound file
25 my $instream = $self->{instream}
26 99 = $invindex->open_instream("$seg_name.cfs");
27 99 my $num_entries = $instream->lu_read('V');
28 99 my @offsets_and_names = $instream->lu_read( 'QT' x $num_entries );
29 99 my $offset = shift @offsets_and_names;
30 99 my %entries;
31 99 ▶ while (@offsets_and_names) {
Branch: 1 branch
BranchTrueFalseTotal
if (@offsets_and_names) 893 99 992
32 893 my $filename = shift @offsets_and_names;
33 893 ▶ my $next_offset = shift @offsets_and_names || $instream->length;
Condition66%2/3
shift @offsets_and_names || $instream->length
l!l&&r!l&&!r
794990
MC/DC0%0/2
shift @offsets_and_names || $instream->length
shift @offsets_and_names $instream->length
Truth table66%2/3
A || B
A= shift @offsets_and_namesB= $instream->length
ABresult
1X1
011
000
34 893 $entries{$filename} = {
35 offset => $offset,
36 len => $next_offset - $offset,
37 };
38 893 $offset = $next_offset;
39 }
40 99 $self->{entries} = \%entries;
41 }
42  
43 861 ▶sub open_instream {
Subroutine open_instream: called CC=3 SCAR=11.3
Pod undocumented
44 861 my ( $self, $filename ) = @_;
45 861 my $entry = $self->{entries}{$filename};
46 861 ▶ croak("filename '$filename' is not accessible") unless defined $entry;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $entry 0 861 861
47 open( my $duped_fh, '<&=', $self->{instream}->get_fh )
48 861 ▶ or confess("Couldn't dupe filehandle: $!");
Branch: 1 branch
BranchTrueFalseTotal
open my $duped_fh, "<&=", $self->{"instream"}->get_fh or confess("Couldn't dupe filehandle: $!") 861 0 861
49 return KinoSearch1::Store::InStream->new( $duped_fh, $entry->{offset},
50 861 $entry->{len} );
51 }
52  
53 1 ▶sub slurp_file {
Subroutine slurp_file: called CC=1 SCAR=0.0
Pod undocumented
54 1 my ( $self, $filename ) = @_;
55 1 my $instream = $self->open_instream($filename);
56 my $contents
57 1 = $instream->lu_read( 'a' . $self->{entries}{$filename}{len} );
58 1 $instream->close;
59 1 return $contents;
60 }
61  
62 39 ▶sub close { shift->{instream}->close }
Subroutine close: called CC=1 SCAR=0.0
Pod undocumented
63  
64 34 1;
65  
66 __END__
« blib/lib/KinoSearch1/Store/InvIndex.pm ↑ Summary blib/lib/KinoSearch1/Search/TermQuery.pm »