Plucene/Store/OutputStream.pm

filter: Statementstmt 82.8% 53 / 64 Branchbran 66.6% 4 / 6 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 72.7% 16 / 22 Podpod 100% 15 / 15 totaltotal 79.4% 89 / 112 CC 5 SCAR 5.0
CC
5
Cov
79%
new
3.2
write_string
2.0
clone
2.0
CRAP 1.6
« Plucene/Index/Reader.pm ↑ Summary Plucene/Search/Query.pm »
1 package Plucene::Store::OutputStream;
2  
3 =head1 NAME
4  
5 Plucene::Store::OutputStream - a random-access output stream
6  
7 =head1 SYNOPSIS
8  
9 # isa Plucene::Store::InputStream
10  
11 =head1 DESCRIPTION
12  
13 This is an abstract class for output to a file in a Directory.
14 A random-access output stream.
15 Used for all Plucene index output operations.
16  
17 =head1 METHODS
18  
19 =cut
20  
21 20 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 20 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 20 ▶no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 20 ▶use Encode qw(encode);
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 =head2 new
28  
29 Create a new Plucene::Store::OutputStream
30  
31 =cut
32  
33 2750 ▶sub new {
Subroutine new: called CC=3 SCAR=11.8
Pod documented
34 2750 my ($self, $filename) = @_;
35 2750 ▶ $self = ref $self || $self;
Condition33%1/3
ref $self || $self
l!l&&r!l&&!r
027500
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table33%1/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
36 2750 ▶ open my $fh, '>', $filename
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">", $filename or die "$self cannot open $filename for writing: $!" 2750 0 2750
37 or die "$self cannot open $filename for writing: $!";
38 2750 binmode $fh;
39 2750 bless [ $fh, $filename ], $self;
40 }
41  
42 2750 ▶sub DESTROY { CORE::close $_[0]->[0] }
Subroutine DESTROY: called CC=1 SCAR=0.0
43  
44 =head2 clone
45  
46 Clone this
47  
48 =cut
49  
50 0 ▶sub clone {
Subroutine clone: not called CC=1 SCAR=6.9
Pod documented
51 0 my $orig = shift;
52 0 my $clone = $orig->new($orig->[1]);
53 0 CORE::seek($clone->[0], CORE::tell($orig->[0]), 0);
54 0 return $clone;
55 }
56  
57 =head2 fh / read / seek / tell / getc / print / eof / close
58  
59 File operations
60  
61 =cut
62  
63 20 ▶use Carp 'croak';
Subroutine BEGIN: called CC=1 SCAR=0.0
64 0 ▶sub fh { croak "OutputStream fh called" }
Subroutine fh: not called CC=1 SCAR=6.9
Pod documented
65 0 ▶sub read { croak "OutputStream read called" }
Subroutine read: not called CC=1 SCAR=6.9
Pod documented
66 594 ▶sub seek { CORE::seek $_[0]->[0], $_[1], $_[2] }
Subroutine seek: called CC=1 SCAR=0.0
Pod documented
67 1916 ▶sub tell { CORE::tell $_[0]->[0] }
Subroutine tell: called CC=1 SCAR=0.0
Pod documented
68 0 ▶sub getc { croak "OutputStream getc called" }
Subroutine getc: not called CC=1 SCAR=6.9
Pod documented
69 2868 ▶sub print { local $\; my $fh = shift->[0]; CORE::print $fh @_ }
Subroutine print: called CC=1 SCAR=0.0
Pod documented
70 0 ▶sub eof { CORE::eof $_[0]->[0] }
Subroutine eof: not called CC=1 SCAR=6.9
Pod documented
71 2 ▶sub close { CORE::close $_[0]->[0] }
Subroutine close: called CC=1 SCAR=0.0
Pod documented
72  
73 =head2 write_byte
74  
75 This will write a single byte.
76  
77 =cut
78  
79 0 ▶sub write_byte {
Subroutine write_byte: not called CC=1 SCAR=6.9
Pod documented
80 0 local $\;
81 0 CORE::print { $_[0]->[0] } $_[1];
82 }
83  
84 =head2 write_int
85  
86 This will write an int as four bytes.
87  
88 =cut
89  
90 3448 ▶sub write_int {
Subroutine write_int: called CC=1 SCAR=0.0
Pod documented
91 3448 local $\;
92 3448 CORE::print { $_[0]->[0] } pack("N", $_[1]);
93 }
94  
95 =head2 write_vint
96  
97 This will write an int in a variable length format.
98  
99 =cut
100  
101 283155 ▶sub write_vint {
Subroutine write_vint: called CC=2 SCAR=6.9
Pod documented
102 283155 local $\;
103 20 ▶ use bytes;
Subroutine BEGIN: called CC=1 SCAR=0.0
104 283155 my $i = $_[1];
105 283155 my $txt;
106 283155 ▶ while ($i & ~0x7f) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i & '18446744073709551488') 1365 283155 284520
107 1365 $txt .= chr($i | 0x80);
108 1365 $i >>= 7;
109 }
110 283155 $txt .= chr($i);
111 283155 CORE::print { $_[0]->[0] } $txt;
112 }
113  
114 =head2 write_long
115  
116 This will write a long as eight bytes.
117  
118 =cut
119  
120 646 ▶sub write_long {
Subroutine write_long: called CC=1 SCAR=0.0
Pod documented
121 646 local $\;
122 646 CORE::print { $_[0]->[0] }
123 pack("NN", 0xffffffff & ($_[1] >> 32), 0xffffffff & $_[1]);
124 }
125  
126 =head2 write_vlong
127  
128 This will write a long in variable length format.
129  
130 =cut
131  
132 20 *write_vlong = *write_vint;
133  
134 =head2 write_string
135  
136 This will write a string.
137  
138 =cut
139  
140 47523 ▶sub write_string {
Subroutine write_string: called CC=2 SCAR=7.0
Pod documented
141 47523 local $\;
142 47523 my $s = $_[1];
143 47523 ▶ $s = encode("utf8", $s) if $s =~ /[^\x00-\x7f]/;
Branch: 1 branch
BranchTrueFalseTotal
if $s =~ /[^\x00-\x7f]/ 0 47523 47523
144 47523 $_[0]->write_vint(length $s);
145 47523 CORE::print { $_[0]->[0] } $s;
146 }
147  
148 20 1;
« Plucene/Index/Reader.pm ↑ Summary Plucene/Search/Query.pm »