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