blob: 44a5a5213684aea417756a2ac6b2fbbc368fad73 [file] [log] [blame]
Mark Slee738ad312007-05-16 02:40:12 +00001#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6use lib '../../lib/perl/lib';
7use lib '../gen-perl';
8
9use Thrift;
10use Thrift::BinaryProtocol;
11use Thrift::Socket;
12use Thrift::BufferedTransport;
13
14use SharedService;
Mark Slee738ad312007-05-16 02:40:12 +000015use Calculator;
Mark Slee27ed6ec2007-08-16 01:26:31 +000016use shared::Types;
17use tutorial::Types;
Mark Slee738ad312007-05-16 02:40:12 +000018
19use Data::Dumper;
20
21my $socket = new Thrift::Socket('localhost',9090);
22my $transport = new Thrift::BufferedTransport($socket,1024,1024);
23my $protocol = new Thrift::BinaryProtocol($transport);
24my $client = new CalculatorClient($protocol);
25
26
27eval{
28 $transport->open();
29
30 $client->ping();
31 print "ping()\n";
32
33
Mark Slee82664432007-09-19 06:49:30 +000034 my $sum = $client->add(1,1);
Mark Slee738ad312007-05-16 02:40:12 +000035 print "1+1=$sum\n";
36
Mark Slee82664432007-09-19 06:49:30 +000037 my $work = new tutorial::Work();
Mark Slee738ad312007-05-16 02:40:12 +000038
Mark Slee82664432007-09-19 06:49:30 +000039 $work->op(Operation::DIVIDE);
40 $work->num1(1);
41 $work->num2(0);
Mark Slee738ad312007-05-16 02:40:12 +000042
43 eval {
44 $client->calculate(1, $work);
45 print "Whoa! We can divide by zero?\n";
46 }; if($@) {
47 warn "InvalidOperation: ".Dumper($@);
48 }
49
Mark Slee82664432007-09-19 06:49:30 +000050 $work->op(Operation::SUBTRACT);
51 $work->num1(15);
52 $work->num2(10);
Mark Slee738ad312007-05-16 02:40:12 +000053 my $diff = $client->calculate(1, $work);
54 print "15-10=$diff\n";
55
56 my $log = $client->getStruct(1);
57 print "Log: $log->{value}\n";
58
59 $transport->close();
60
61}; if($@){
62 warn(Dumper($@));
63}