]> git.proxmox.com Git - ceph.git/blame - ceph/src/jaegertracing/thrift/tutorial/perl/PerlClient.pl
buildsys: switch source download to quincy
[ceph.git] / ceph / src / jaegertracing / thrift / tutorial / perl / PerlClient.pl
CommitLineData
f67539c2
TL
1#!/usr/bin/env perl
2
3#
4# Licensed to the Apache Software Foundation (ASF) under one
5# or more contributor license agreements. See the NOTICE file
6# distributed with this work for additional information
7# regarding copyright ownership. The ASF licenses this file
8# to you under the Apache License, Version 2.0 (the
9# "License"); you may not use this file except in compliance
10# with the License. You may obtain a copy of the License at
11#
12# http://www.apache.org/licenses/LICENSE-2.0
13#
14# Unless required by applicable law or agreed to in writing,
15# software distributed under the License is distributed on an
16# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17# KIND, either express or implied. See the License for the
18# specific language governing permissions and limitations
19# under the License.
20#
21
22use strict;
23use warnings;
24
25use lib '../../lib/perl/lib';
26use lib '../gen-perl';
27
28use Thrift;
29use Thrift::BinaryProtocol;
30use Thrift::Socket;
31use Thrift::BufferedTransport;
32
33use shared::SharedService;
34use tutorial::Calculator;
35use shared::Types;
36use tutorial::Types;
37
38use Data::Dumper;
39
40my $socket = Thrift::Socket->new('localhost',9090);
41my $transport = Thrift::BufferedTransport->new($socket,1024,1024);
42my $protocol = Thrift::BinaryProtocol->new($transport);
43my $client = tutorial::CalculatorClient->new($protocol);
44
45
46eval{
47 $transport->open();
48
49 $client->ping();
50 print "ping()\n";
51
52
53 my $sum = $client->add(1,1);
54 print "1+1=$sum\n";
55
56 my $work = tutorial::Work->new();
57
58 $work->op(tutorial::Operation::DIVIDE);
59 $work->num1(1);
60 $work->num2(0);
61
62 eval {
63 $client->calculate(1, $work);
64 print "Whoa! We can divide by zero?\n";
65 }; if($@) {
66 warn 'InvalidOperation: '.Dumper($@);
67 }
68
69 $work->op(tutorial::Operation::SUBTRACT);
70 $work->num1(15);
71 $work->num2(10);
72 my $diff = $client->calculate(1, $work);
73 print "15-10=$diff\n";
74
75 my $log = $client->getStruct(1);
76 print "Log: $log->{value}\n";
77
78 $transport->close();
79
80}; if($@){
81 warn(Dumper($@));
82}