File Coverage

blib/lib/Thrift/MultiplexedProtocol.pm
Criterion Covered Total %
statement 40 41 97.5
branch 1 2 50.0
condition 1 3 33.3
subroutine 12 12 100.0
pod 0 2 0.0
total 54 60 90.0


line stmt bran cond sub pod time code
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     1   11 use 5.10.0;
  1         3  
21 1     1   5 use strict;
  1         2  
  1         30  
22 1     1   6 use warnings;
  1         1  
  1         24  
23              
24 1     1   4 use Thrift;
  1         2  
  1         31  
25 1     1   6 use Thrift::MessageType;
  1         1  
  1         17  
26 1     1   16 use Thrift::Protocol;
  1         3  
  1         19  
27 1     1   406 use Thrift::ProtocolDecorator;
  1         2  
  1         37  
28              
29             package Thrift::MultiplexedProtocol;
30 1     1   7 use base qw(Thrift::ProtocolDecorator);
  1         12  
  1         90  
31 1     1   57 use version 0.77; our $VERSION = version->declare("$Thrift::VERSION");
  1         18  
  1         6  
32              
33 1     1   93 use constant SEPARATOR => ':';
  1         2  
  1         211  
34              
35             sub new {
36 2     2 0 4 my $classname = shift;
37 2         2 my $protocol = shift;
38 2         5 my $serviceName = shift;
39 2         7 my $self = $classname->SUPER::new($protocol);
40              
41 2         4 $self->{serviceName} = $serviceName;
42              
43 2         5 return bless($self,$classname);
44             }
45              
46             #
47             # Writes the message header.
48             # Prepends the service name to the function name, separated by MultiplexedProtocol::SEPARATOR.
49             #
50             # @param string $name Function name.
51             # @param int $type Message type.
52             # @param int $seqid The sequence id of this message.
53             #
54             sub writeMessageBegin
55             {
56 11     11 0 16 my $self = shift;
57 11         20 my ($name, $type, $seqid) = @_;
58              
59 11 50 33     33 if ($type == Thrift::TMessageType::CALL || $type == Thrift::TMessageType::ONEWAY) {
60 11         24 my $nameWithService = $self->{serviceName}.SEPARATOR.$name;
61 11         28 $self->SUPER::writeMessageBegin($nameWithService, $type, $seqid);
62             }
63             else {
64 0           $self->SUPER::writeMessageBegin($name, $type, $seqid);
65             }
66             }
67              
68             1;