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   12 use 5.10.0;
  1         3  
21 1     1   7 use strict;
  1         2  
  1         29  
22 1     1   7 use warnings;
  1         2  
  1         23  
23              
24 1     1   5 use Thrift;
  1         2  
  1         26  
25 1     1   7 use Thrift::MessageType;
  1         2  
  1         18  
26 1     1   4 use Thrift::Protocol;
  1         2  
  1         28  
27 1     1   409 use Thrift::ProtocolDecorator;
  1         3  
  1         44  
28              
29             package Thrift::MultiplexedProtocol;
30 1     1   7 use base qw(Thrift::ProtocolDecorator);
  1         2  
  1         110  
31 1     1   88 use version 0.77; our $VERSION = version->declare("$Thrift::VERSION");
  1         20  
  1         6  
32              
33 1     1   99 use constant SEPARATOR => ':';
  1         2  
  1         246  
34              
35             sub new {
36 2     2 0 3 my $classname = shift;
37 2         5 my $protocol = shift;
38 2         3 my $serviceName = shift;
39 2         11 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 18 my $self = shift;
57 11         21 my ($name, $type, $seqid) = @_;
58              
59 11 50 33     31 if ($type == Thrift::TMessageType::CALL || $type == Thrift::TMessageType::ONEWAY) {
60 11         26 my $nameWithService = $self->{serviceName}.SEPARATOR.$name;
61 11         30 $self->SUPER::writeMessageBegin($nameWithService, $type, $seqid);
62             }
63             else {
64 0           $self->SUPER::writeMessageBegin($name, $type, $seqid);
65             }
66             }
67              
68             1;