| 1 | # | ||||||||||||
| 2 | # Licensed to the Apache Software Foundation (ASF) under one | ||||||||||||
| 3 | # or more contributor license agreements. See the NOTICE file | ||||||||||||
| 4 | # distributed with this work for additional information | ||||||||||||
| 5 | # regarding copyright ownership. The ASF licenses this file | ||||||||||||
| 6 | # to you under the Apache License, Version 2.0 (the | ||||||||||||
| 7 | # "License"); you may not use this file except in compliance | ||||||||||||
| 8 | # with the License. You may obtain a copy of the License at | ||||||||||||
| 9 | # | ||||||||||||
| 10 | # http://www.apache.org/licenses/LICENSE-2.0 | ||||||||||||
| 11 | # | ||||||||||||
| 12 | # Unless required by applicable law or agreed to in writing, | ||||||||||||
| 13 | # software distributed under the License is distributed on an | ||||||||||||
| 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||||||||||||
| 15 | # KIND, either express or implied. See the License for the | ||||||||||||
| 16 | # specific language governing permissions and limitations | ||||||||||||
| 17 | # under the License. | ||||||||||||
| 18 | # | ||||||||||||
| 19 | |||||||||||||
| 20 | 3 | ▶ | use 5.10.0; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 21 | 3 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 22 | 3 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 23 | |||||||||||||
| 24 | 3 | ▶ | use Thrift; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 25 | 3 | ▶ | use Thrift::Transport; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 26 | |||||||||||||
| 27 | package Thrift::MemoryBuffer; | ||||||||||||
| 28 | 3 | ▶ | use base('Thrift::Transport'); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 29 | 3 | ▶ | use version 0.77; our $VERSION = version->declare("$Thrift::VERSION"); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 30 | |||||||||||||
| 31 | sub new | ||||||||||||
| 32 | 7 | ▶ | { | ||||||||||
|
Subroutine
new: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 33 | 7 | my $classname = shift; | |||||||||||
| 34 | |||||||||||||
| 35 | 7 | ▶ | my $bufferSize= shift || 1024; | ||||||||||
|
Condition100%2/2
shift() || 1024
MC/DC100%1/1
shift() || 1024
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||
| 36 | |||||||||||||
| 37 | 7 | my $self = { | |||||||||||
| 38 | buffer => '', | ||||||||||||
| 39 | bufferSize => $bufferSize, | ||||||||||||
| 40 | wPos => 0, | ||||||||||||
| 41 | rPos => 0, | ||||||||||||
| 42 | }; | ||||||||||||
| 43 | |||||||||||||
| 44 | 7 | return bless($self,$classname); | |||||||||||
| 45 | } | ||||||||||||
| 46 | |||||||||||||
| 47 | sub isOpen | ||||||||||||
| 48 | 0 | ▶ | { | ||||||||||
|
Subroutine
isOpen: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 49 | 0 | return 1; | |||||||||||
| 50 | } | ||||||||||||
| 51 | |||||||||||||
| 52 | sub open | ||||||||||||
| 53 | 2 | ▶ | { | ||||||||||
|
Subroutine
open: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 54 | |||||||||||||
| 55 | } | ||||||||||||
| 56 | |||||||||||||
| 57 | sub close | ||||||||||||
| 58 | 0 | ▶ | { | ||||||||||
|
Subroutine
close: not called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 59 | |||||||||||||
| 60 | } | ||||||||||||
| 61 | |||||||||||||
| 62 | sub peek | ||||||||||||
| 63 | 0 | ▶ | { | ||||||||||
|
Subroutine
peek: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 64 | 0 | my $self = shift; | |||||||||||
| 65 | 0 | return($self->{rPos} < $self->{wPos}); | |||||||||||
| 66 | } | ||||||||||||
| 67 | |||||||||||||
| 68 | |||||||||||||
| 69 | sub getBuffer | ||||||||||||
| 70 | 4 | ▶ | { | ||||||||||
|
Subroutine
getBuffer: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 71 | 4 | my $self = shift; | |||||||||||
| 72 | 4 | return $self->{buffer}; | |||||||||||
| 73 | } | ||||||||||||
| 74 | |||||||||||||
| 75 | sub resetBuffer | ||||||||||||
| 76 | 2 | ▶ | { | ||||||||||
|
Subroutine
resetBuffer: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||
| 77 | 2 | my $self = shift; | |||||||||||
| 78 | |||||||||||||
| 79 | 2 | ▶ | my $new_buffer = shift || ''; | ||||||||||
|
Condition50%1/2
shift() || ''
MC/DC0%0/1
shift() || ''
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||
| 80 | |||||||||||||
| 81 | 2 | $self->{buffer} = $new_buffer; | |||||||||||
| 82 | 2 | $self->{bufferSize} = length($new_buffer); | |||||||||||
| 83 | 2 | $self->{wPos} = length($new_buffer); | |||||||||||
| 84 | 2 | $self->{rPos} = 0; | |||||||||||
| 85 | } | ||||||||||||
| 86 | |||||||||||||
| 87 | sub available | ||||||||||||
| 88 | 0 | ▶ | { | ||||||||||
|
Subroutine
available: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 89 | 0 | my $self = shift; | |||||||||||
| 90 | 0 | return ($self->{wPos} - $self->{rPos}); | |||||||||||
| 91 | } | ||||||||||||
| 92 | |||||||||||||
| 93 | sub read | ||||||||||||
| 94 | 222 | ▶ | { | ||||||||||
|
Subroutine
read: called CC=3 SCAR=11.1
Pod
undocumented
| |||||||||||||
| 95 | 222 | my $self = shift; | |||||||||||
| 96 | 222 | my $len = shift; | |||||||||||
| 97 | 222 | my $ret; | |||||||||||
| 98 | |||||||||||||
| 99 | 222 | my $avail = ($self->{wPos} - $self->{rPos}); | |||||||||||
| 100 | 222 | ▶ | return '' if $avail == 0; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 101 | |||||||||||||
| 102 | #how much to give | ||||||||||||
| 103 | 222 | my $give = $len; | |||||||||||
| 104 | 222 | ▶ | $give = $avail if $avail < $len; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 105 | |||||||||||||
| 106 | 222 | $ret = substr($self->{buffer},$self->{rPos},$give); | |||||||||||
| 107 | |||||||||||||
| 108 | 222 | $self->{rPos} += $give; | |||||||||||
| 109 | |||||||||||||
| 110 | 222 | return $ret; | |||||||||||
| 111 | } | ||||||||||||
| 112 | |||||||||||||
| 113 | sub readAll | ||||||||||||
| 114 | 223 | ▶ | { | ||||||||||
|
Subroutine
readAll: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||
| 115 | 223 | my $self = shift; | |||||||||||
| 116 | 223 | my $len = shift; | |||||||||||
| 117 | |||||||||||||
| 118 | 223 | my $avail = ($self->{wPos} - $self->{rPos}); | |||||||||||
| 119 | 223 | ▶ | if ($avail < $len) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 120 | 1 | die Thrift::TTransportException->new("Attempt to readAll($len) found only $avail available", | |||||||||||
| 121 | Thrift::TTransportException::END_OF_FILE); | ||||||||||||
| 122 | } | ||||||||||||
| 123 | |||||||||||||
| 124 | 222 | my $data = ''; | |||||||||||
| 125 | 222 | my $got = 0; | |||||||||||
| 126 | |||||||||||||
| 127 | 222 | ▶ | while (($got = length($data)) < $len) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 128 | 222 | $data .= $self->read($len - $got); | |||||||||||
| 129 | } | ||||||||||||
| 130 | |||||||||||||
| 131 | 222 | return $data; | |||||||||||
| 132 | } | ||||||||||||
| 133 | |||||||||||||
| 134 | sub write | ||||||||||||
| 135 | 226 | ▶ | { | ||||||||||
|
Subroutine
write: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 136 | 226 | my $self = shift; | |||||||||||
| 137 | 226 | my $buf = shift; | |||||||||||
| 138 | |||||||||||||
| 139 | 226 | $self->{buffer} .= $buf; | |||||||||||
| 140 | 226 | $self->{wPos} += length($buf); | |||||||||||
| 141 | } | ||||||||||||
| 142 | |||||||||||||
| 143 | sub flush | ||||||||||||
| 144 | 26 | ▶ | { | ||||||||||
|
Subroutine
flush: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 145 | |||||||||||||
| 146 | } | ||||||||||||
| 147 | |||||||||||||
| 148 | 3 | 1; | |||||||||||