r1497@opsdev009 (orig r78879): mcslee | 2008-01-21 20:04:30 -0800
[amiethrift.git] / tutorial / perl / PerlClient.pl
blob44a5a5213684aea417756a2ac6b2fbbc368fad73
1 #!/usr/bin/perl
3 use strict;
4 use warnings;
6 use lib '../../lib/perl/lib';
7 use lib '../gen-perl';
9 use Thrift;
10 use Thrift::BinaryProtocol;
11 use Thrift::Socket;
12 use Thrift::BufferedTransport;
14 use SharedService;
15 use Calculator;
16 use shared::Types;
17 use tutorial::Types;
19 use Data::Dumper;
21 my $socket = new Thrift::Socket('localhost',9090);
22 my $transport = new Thrift::BufferedTransport($socket,1024,1024);
23 my $protocol = new Thrift::BinaryProtocol($transport);
24 my $client = new CalculatorClient($protocol);
27 eval{
28 $transport->open();
30 $client->ping();
31 print "ping()\n";
34 my $sum = $client->add(1,1);
35 print "1+1=$sum\n";
37 my $work = new tutorial::Work();
39 $work->op(Operation::DIVIDE);
40 $work->num1(1);
41 $work->num2(0);
43 eval {
44 $client->calculate(1, $work);
45 print "Whoa! We can divide by zero?\n";
46 }; if($@) {
47 warn "InvalidOperation: ".Dumper($@);
50 $work->op(Operation::SUBTRACT);
51 $work->num1(15);
52 $work->num2(10);
53 my $diff = $client->calculate(1, $work);
54 print "15-10=$diff\n";
56 my $log = $client->getStruct(1);
57 print "Log: $log->{value}\n";
59 $transport->close();
61 }; if($@){
62 warn(Dumper($@));