blob: 9451a948a082be81a3ce5b93058ce29319384ca8 [file] [log] [blame]
T Jake Luciani41687fc2008-12-23 03:45:43 +00001#!/usr/bin/env perl
Mark Slee738ad312007-05-16 02:40:12 +00002
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
T Jake Luciani41687fc2008-12-23 03:45:43 +000014use shared::SharedService;
15use tutorial::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);
T Jake Luciani41687fc2008-12-23 03:45:43 +000024my $client = new tutorial::CalculatorClient($protocol);
Mark Slee738ad312007-05-16 02:40:12 +000025
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
T Jake Luciani41687fc2008-12-23 03:45:43 +000039 $work->op(tutorial::Operation::DIVIDE);
Mark Slee82664432007-09-19 06:49:30 +000040 $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
T Jake Luciani41687fc2008-12-23 03:45:43 +000050 $work->op(tutorial::Operation::SUBTRACT);
Mark Slee82664432007-09-19 06:49:30 +000051 $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}