blib/lib/Thrift/MultiplexedProcessor.pm

filter: Statementstmt 90.0% 72 / 80 Branchbran 37.5% 3 / 8 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 94.1% 16 / 17 Podpod 0.0% 0 / 4 totaltotal 80.7% 92 / 114 CC 6 SCAR 11.9
CC
6
Cov
84%
process
9.2
defaultProcessor
2.0
BEGIN
1.0
CRAP 3.3
« gen-perl/BenchmarkService.pm ↑ Summary blib/lib/Thrift/UnixServerSocket.pm »
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 1 ▶use 5.10.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 1 ▶use Thrift;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 1 ▶use Thrift::MessageType;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 1 ▶use Thrift::MultiplexedProtocol;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 1 ▶use Thrift::Protocol;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 1 ▶use Thrift::ProtocolDecorator;
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 package Thrift::StoredMessageProtocol;
31 1 ▶use base qw(Thrift::ProtocolDecorator);
Subroutine BEGIN: called CC=1 SCAR=0.0
32 1 ▶use version 0.77; our $VERSION = version->declare("$Thrift::VERSION");
Subroutine BEGIN: called CC=1 SCAR=0.0
33  
34 11 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
35 11 my $classname = shift;
36 11 my $protocol = shift;
37 11 my $fname = shift;
38 11 my $mtype = shift;
39 11 my $rseqid = shift;
40 11 my $self = $classname->SUPER::new($protocol);
41  
42 11 $self->{fname} = $fname;
43 11 $self->{mtype} = $mtype;
44 11 $self->{rseqid} = $rseqid;
45  
46 11 return bless($self,$classname);
47 }
48  
49 sub readMessageBegin
50 11 ▶{
Subroutine readMessageBegin: called CC=1 SCAR=0.0
51 11 my $self = shift;
52 11 my $name = shift;
53 11 my $type = shift;
54 11 my $seqid = shift;
55  
56 11 $$name = $self->{fname};
57 11 $$type = $self->{mtype};
58 11 $$seqid = $self->{rseqid};
59 }
60  
61 package Thrift::MultiplexedProcessor;
62 1 ▶use version 0.77; our $VERSION = version->declare("$Thrift::VERSION");
Subroutine BEGIN: called CC=1 SCAR=0.0
63  
64 1 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
65 1 my $classname = shift;
66 1 my $self = {};
67  
68 1 $self->{serviceProcessorMap} = {};
69 1 $self->{defaultProcessor} = undef;
70  
71 1 return bless($self,$classname);
72 }
73  
74 0 ▶sub defaultProcessor {
Subroutine defaultProcessor: not called CC=1 SCAR=6.9
Pod undocumented
75 0 my $self = shift;
76 0 my $processor = shift;
77  
78 0 $self->{defaultProcessor} = $processor;
79 }
80  
81 2 ▶sub registerProcessor {
Subroutine registerProcessor: called CC=1 SCAR=0.0
Pod undocumented
82 2 my $self = shift;
83 2 my $serviceName = shift;
84 2 my $processor = shift;
85  
86 2 $self->{serviceProcessorMap}->{$serviceName} = $processor;
87 }
88  
89 11 ▶sub process {
Subroutine process: called CC=6 SCAR=22.1
Pod undocumented
90 11 my $self = shift;
91 11 my $input = shift;
92 11 my $output = shift;
93  
94 #
95 # Use the actual underlying protocol (e.g. BinaryProtocol) to read the
96 # message header. This pulls the message "off the wire", which we'll
97 # deal with at the end of this method.
98 #
99  
100 11 my ($fname, $mtype, $rseqid);
101 11 $input->readMessageBegin(\$fname, \$mtype, \$rseqid);
102  
103 11 ▶ if ($mtype ne Thrift::TMessageType::CALL && $mtype ne Thrift::TMessageType::ONEWAY) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mtype ne 1 and $mtype ne 4) 0 11 11
Condition33%1/3
$mtype ne 1 and $mtype ne 4
!ll&&!rl&&r
1100
MC/DC0%0/2
$mtype ne 1 and $mtype ne 4
$mtype ne 1 $mtype ne 4
Truth table33%1/3
A and B
A= $mtype ne 1B= $mtype ne 4
ABresult
0X0
100
111
104 0 die Thrift::TException->new('This should not have happened!?');
105 }
106  
107 # Extract the service name and the new Message name.
108 11 ▶ if (index($fname, Thrift::MultiplexedProtocol::SEPARATOR) == -1) {
Branch: 1 branch
BranchTrueFalseTotal
if (index($fname, ":") == -1) 0 11 11
109 0 ▶ if (defined $self->{defaultProcessor}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'defaultProcessor'}) { } 0 0 0
110 return $self->{defaultProcessor}->process(
111 0 Thrift::StoredMessageProtocol->new($input, $fname, $mtype, $rseqid), $output
112 );
113 } else {
114 0 die Thrift::TException->new("Service name not found in message name: {$fname} and no default processor defined. Did you " .
115 'forget to use a MultiplexProtocol in your client?');
116 }
117 }
118  
119 11 (my $serviceName, my $messageName) = split(':', $fname, 2);
120  
121 11 ▶ if (!exists($self->{serviceProcessorMap}->{$serviceName})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"serviceProcessorMap"}{$serviceName}) 0 11 11
122 0 die Thrift::TException->new("Service name not found: {$serviceName}. Did you forget " .
123 'to call registerProcessor()?');
124 }
125  
126 # Dispatch processing to the stored processor
127 11 my $processor = $self->{serviceProcessorMap}->{$serviceName};
128 11 return $processor->process(
129 Thrift::StoredMessageProtocol->new($input, $messageName, $mtype, $rseqid), $output
130 );
131 }
132  
133 1 1;
« gen-perl/BenchmarkService.pm ↑ Summary blib/lib/Thrift/UnixServerSocket.pm »