| 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::ByteBufDocWriter; | ||||||||||||||||||||||||||||
| 20 | 2 | ▶ | use base qw( Lucy::Index::DataWriter ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | 2 | our $VERSION = '0.008000'; | |||||||||||||||||||||||||||
| 22 | 2 | $VERSION = eval $VERSION; | |||||||||||||||||||||||||||
| 23 | 2 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 24 | 2 | ▶ | use Scalar::Util qw( blessed ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 25 | 2 | ▶ | use bytes; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 26 | 2 | ▶ | no bytes; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | # Inside-out member vars. | ||||||||||||||||||||||||||||
| 29 | 2 | our %field; | |||||||||||||||||||||||||||
| 30 | 2 | our %width; | |||||||||||||||||||||||||||
| 31 | 2 | our %outstream; | |||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 4 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=4 SCAR=14.4
Pod
documented
| |||||||||||||||||||||||||||||
| 34 | 4 | my ( $either, %args ) = @_; | |||||||||||||||||||||||||||
| 35 | 4 | my $width = delete $args{width}; | |||||||||||||||||||||||||||
| 36 | 4 | my $field = delete $args{field}; | |||||||||||||||||||||||||||
| 37 | 4 | my $self = $either->SUPER::new(%args); | |||||||||||||||||||||||||||
| 38 | 4 | ▶ | confess("Missing required param 'width'") unless defined $width; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 39 | 4 | ▶ | confess("Missing required param 'field'") unless defined $field; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 40 | 0 | ▶ | if ( $width < 1 ) { confess("'width' must be at least 1") } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 41 | 4 | $field{$$self} = $field; | |||||||||||||||||||||||||||
| 42 | 4 | $width{$$self} = $width; | |||||||||||||||||||||||||||
| 43 | 4 | return $self; | |||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 4 | ▶ | sub _lazy_init { | ||||||||||||||||||||||||||
|
Subroutine
_lazy_init: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||
| 47 | 4 | my $self = shift; | |||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | # Get outstream. Skip past non-doc #0. | ||||||||||||||||||||||||||||
| 50 | 4 | my $folder = $self->get_folder; | |||||||||||||||||||||||||||
| 51 | 4 | my $filename = $self->get_segment->get_name . "/bytebufdocs.dat"; | |||||||||||||||||||||||||||
| 52 | 4 | ▶ | my $outstream = $outstream{$$self} = $folder->open_out($filename) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | or confess Clownfish->error; | ||||||||||||||||||||||||||||
| 54 | 4 | my $nulls = "\0" x $width{$$self}; | |||||||||||||||||||||||||||
| 55 | 4 | $outstream->print($nulls); | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 4 | return $outstream; | |||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 13 | ▶ | sub add_inverted_doc { | ||||||||||||||||||||||||||
|
Subroutine
add_inverted_doc: called CC=3 SCAR=11.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 61 | 13 | my ( $self, %args ) = @_; | |||||||||||||||||||||||||||
| 62 | 13 | ▶ | my $outstream = $outstream{$$self} || _lazy_init($self); | ||||||||||||||||||||||||||
|
Condition66%2/3
$LucyX::Index::ByteBufDocWriter::outstream{$$self} || _lazy_init($self)
MC/DC0%0/2
$LucyX::Index::ByteBufDocWriter::outstream{$$self} || _lazy_init($self)
$LucyX::Index::ByteBufDocWriter::outstream{$$self}
_lazy_init($self)
Truth table66%2/3
A || B
A= $LucyX::Index::ByteBufDocWriter::outstream{$$self}B= _lazy_init($self)
| |||||||||||||||||||||||||||||
| 63 | 13 | my $fields = $args{inverter}->get_doc->get_fields; | |||||||||||||||||||||||||||
| 64 | 13 | my $width = $width{$$self}; | |||||||||||||||||||||||||||
| 65 | 13 | my $field = $field{$$self}; | |||||||||||||||||||||||||||
| 66 | 13 | ▶ | if ( bytes::length( $fields->{$field} ) != $width ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 67 | 0 | confess("Width of '$fields->{$field}' not $width"); | |||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | 13 | $outstream->print( $fields->{$field} ); | |||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 3 | ▶ | sub add_segment { | ||||||||||||||||||||||||||
|
Subroutine
add_segment: called CC=7 SCAR=19.9
Pod
documented
| |||||||||||||||||||||||||||||
| 73 | 3 | my ( $self, %args ) = @_; | |||||||||||||||||||||||||||
| 74 | 3 | my $seg_reader = $args{reader}; | |||||||||||||||||||||||||||
| 75 | 3 | my $doc_map = $args{doc_map}; | |||||||||||||||||||||||||||
| 76 | 3 | my $doc_max = $seg_reader->doc_max; | |||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | # Bail if the supplied segment is empty. */ | ||||||||||||||||||||||||||||
| 79 | 3 | ▶ | return unless $doc_max; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 3 | ▶ | my $outstream = $outstream{$$self} || _lazy_init($self); | ||||||||||||||||||||||||||
|
Condition66%2/3
$LucyX::Index::ByteBufDocWriter::outstream{$$self} || _lazy_init($self)
MC/DC0%0/2
$LucyX::Index::ByteBufDocWriter::outstream{$$self} || _lazy_init($self)
$LucyX::Index::ByteBufDocWriter::outstream{$$self}
_lazy_init($self)
Truth table66%2/3
A || B
A= $LucyX::Index::ByteBufDocWriter::outstream{$$self}B= _lazy_init($self)
| |||||||||||||||||||||||||||||
| 82 | 3 | my $doc_reader = $seg_reader->obtain("Lucy::Index::DocReader"); | |||||||||||||||||||||||||||
| 83 | 3 | ▶ | confess("Not a ByteBufDocReader") | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
builtin::blessed($doc_reader) and $doc_reader->isa("LucyX::Index::ByteBufDocReader")
MC/DC0%0/2
builtin::blessed($doc_reader) and $doc_reader->isa("LucyX::Index::ByteBufDocReader")
builtin::blessed($doc_reader)
$doc_reader->isa("LucyX::Index::ByteBufDocReader")
Truth table33%1/3
A and B
A= builtin::blessed($doc_reader)B= $doc_reader->isa("LucyX::Index::ByteBufDocReader")
| |||||||||||||||||||||||||||||
| 84 | unless ( blessed($doc_reader) | ||||||||||||||||||||||||||||
| 85 | and $doc_reader->isa("LucyX::Index::ByteBufDocReader") ); | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 3 | ▶ | for ( my $i = 1; $i <= $doc_max; $i++ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 88 | 24 | ▶ | next unless $doc_map->get($i); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 89 | 21 | my $buf; | |||||||||||||||||||||||||||
| 90 | 21 | $doc_reader->read_record( $i, \$buf ); | |||||||||||||||||||||||||||
| 91 | 21 | $outstream->print($buf); | |||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 4 | ▶ | sub finish { | ||||||||||||||||||||||||||
|
Subroutine
finish: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||
| 96 | 4 | my $self = shift; | |||||||||||||||||||||||||||
| 97 | 4 | my $outstream = $outstream{$$self}; | |||||||||||||||||||||||||||
| 98 | 4 | ▶ | if ($outstream) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 99 | 4 | $outstream->close; | |||||||||||||||||||||||||||
| 100 | 4 | my $segment = $self->get_segment; | |||||||||||||||||||||||||||
| 101 | 4 | $segment->store_metadata( | |||||||||||||||||||||||||||
| 102 | key => 'bytebufdocs', | ||||||||||||||||||||||||||||
| 103 | metadata => $self->metadata | ||||||||||||||||||||||||||||
| 104 | ); | ||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 4 | ▶ | sub format {1} | ||||||||||||||||||||||||||
|
Subroutine
format: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | 4 | ▶ | sub DESTROY { | ||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 111 | 4 | my $self = shift; | |||||||||||||||||||||||||||
| 112 | 4 | delete $field{$$self}; | |||||||||||||||||||||||||||
| 113 | 4 | delete $width{$$self}; | |||||||||||||||||||||||||||
| 114 | 4 | delete $outstream{$$self}; | |||||||||||||||||||||||||||
| 115 | 4 | $self->SUPER::DESTROY; | |||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | 2 | 1; | |||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | __END__ | ||||||||||||||||||||||||||||