blib/lib/KinoSearch1/Store/RAMInvIndex.pm

filter: Statementstmt 100% 68 / 68 Branchbran 57.1% 8 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 95.2% 20 / 21 Podpod 10.0% 1 / 10 totaltotal 85.8% 97 / 113 CC 9 SCAR 4.9
CC
9
Cov
93%
open_instream
3.1
rename_file
2.0
delete_file
2.0
CRAP 1.6
« blib/lib/KinoSearch1/Index/TermEnum.pm ↑ Summary blib/lib/KinoSearch1/Analysis/PolyAnalyzer.pm »
1 package KinoSearch1::Store::RAMInvIndex;
2 38 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 38 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 38 ▶use KinoSearch1::Util::ToolSet;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 38 ▶use base qw( KinoSearch1::Store::InvIndex );
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 38 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
8 38 __PACKAGE__->init_instance_vars(
9 # members
10 ramfiles => undef,
11 );
12 }
13  
14 38 ▶use Digest::MD5 qw( md5_hex );
Subroutine BEGIN: called CC=1 SCAR=0.0
15 38 ▶use KinoSearch1::Store::FSInvIndex;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 38 ▶use KinoSearch1::Store::InStream;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 38 ▶use KinoSearch1::Store::OutStream;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 38 ▶use KinoSearch1::Store::RAMLock;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 48 ▶sub init_instance {
Subroutine init_instance: called CC=2 SCAR=6.9
Pod documented
21 48 my $self = shift;
22 48 $self->{ramfiles} = {};
23  
24 # read in an FSInvIndex if specified
25 48 ▶ $self->_read_invindex if defined $self->{path};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"path"} 1 47 48
26 }
27  
28 1 ▶sub _read_invindex {
Subroutine _read_invindex: called CC=2 SCAR=6.9
29 1 my $self = shift;
30  
31 # open an FSInvIndex for reading
32 my $source_invindex
33 1 = KinoSearch1::Store::FSInvIndex->new( path => $self->{path}, );
34  
35 # copy every file in the FSInvIndex into RAM.
36 1 for my $filename ( $source_invindex->list ) {
37 1 my $source_stream = $source_invindex->open_instream($filename);
38 1 my $outstream = $self->open_outstream($filename);
39 1 $outstream->absorb($source_stream);
40 1 $source_stream->close;
41 1 $outstream->close;
42 }
43  
44 1 $source_invindex->close;
45 }
46  
47 839 ▶sub open_outstream {
Subroutine open_outstream: called CC=2 SCAR=7.0
Pod undocumented
48 839 my ( $self, $filename ) = @_;
49  
50 # use perl scalars as virtual files;
51 839 my $data = '';
52 839 $self->{ramfiles}{$filename} = \$data;
53 839 ▶ open( my $fh, '>:scalar', \$data ) or die $!;
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">:scalar", \$data or die $! 839 0 839
54 839 binmode($fh);
55 839 return KinoSearch1::Store::OutStream->new($fh);
56 }
57  
58 619 ▶sub open_instream {
Subroutine open_instream: called CC=3 SCAR=11.3
Pod undocumented
59 619 my ( $self, $filename, $offset, $len ) = @_;
60 confess("File '$filename' not loaded into RAM")
61 619 ▶ unless exists $self->{ramfiles}{$filename};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"ramfiles"}{$filename} 0 619 619
62 619 ▶ open( my $fh, '<:scalar', $self->{ramfiles}{$filename} ) or die $!;
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<:scalar", $self->{"ramfiles"}{$filename} or die $! 619 0 619
63 619 binmode($fh);
64 619 return KinoSearch1::Store::InStream->new( $$fh, $offset, $len );
65 }
66  
67 1 ▶sub list {
Subroutine list: called CC=1 SCAR=0.0
Pod undocumented
68 1 keys %{ $_[0]->{ramfiles} };
69 }
70  
71 1206 ▶sub file_exists {
Subroutine file_exists: called CC=1 SCAR=0.0
Pod undocumented
72 1206 my ( $self, $filename ) = @_;
73 1206 return ( exists $self->{ramfiles}{$filename} );
74 }
75  
76 135 ▶sub rename_file {
Subroutine rename_file: called CC=2 SCAR=7.1
Pod undocumented
77 135 my ( $self, $from, $to ) = @_;
78 confess("File '$from' not currently in RAM")
79 135 ▶ unless exists $self->{ramfiles}{$from};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"ramfiles"}{$from} 0 135 135
80 135 $self->{ramfiles}{$to} = delete $self->{ramfiles}{$from};
81 }
82  
83 672 ▶sub delete_file {
Subroutine delete_file: called CC=2 SCAR=7.1
Pod undocumented
84 672 my ( $self, $filename ) = @_;
85 672 my $file = delete $self->{ramfiles}{$filename};
86 672 ▶ confess("File '$filename' not currently in RAM")
Branch: 1 branch
BranchTrueFalseTotal
unless $file 0 672 672
87 unless $file;
88 }
89  
90 11 ▶sub slurp_file {
Subroutine slurp_file: called CC=2 SCAR=7.0
Pod undocumented
91 11 my ( $self, $filename ) = @_;
92 11 my $virtual_file_ref = $self->{ramfiles}{$filename};
93 11 ▶ confess("File '$filename' not currently in RAM")
Branch: 1 branch
BranchTrueFalseTotal
unless defined $virtual_file_ref 0 11 11
94 unless defined $virtual_file_ref;
95  
96 # return a copy of the virtual file's content
97 11 return $$virtual_file_ref;
98 }
99  
100 190 ▶sub make_lock {
Subroutine make_lock: called CC=1 SCAR=0.0
Pod undocumented
101 190 my $self = shift;
102 190 return KinoSearch1::Store::RAMLock->new( @_, invindex => $self );
103 }
104 0 ▶sub close { }
Subroutine close: not called CC=1 SCAR=0.0
Pod undocumented
105  
106 38 1;
107  
108 __END__
« blib/lib/KinoSearch1/Index/TermEnum.pm ↑ Summary blib/lib/KinoSearch1/Analysis/PolyAnalyzer.pm »