Mark Slee | 738ad31 | 2007-05-16 02:40:12 +0000 | [diff] [blame] | 1 | #!/usr/bin/perl |
| 2 | |
| 3 | use strict; |
| 4 | use warnings; |
| 5 | |
| 6 | use lib '../../lib/perl/lib'; |
| 7 | use lib '../gen-perl'; |
| 8 | |
| 9 | use Thrift; |
| 10 | use Thrift::BinaryProtocol; |
| 11 | use Thrift::Socket; |
| 12 | use Thrift::BufferedTransport; |
| 13 | |
| 14 | use SharedService; |
Mark Slee | 738ad31 | 2007-05-16 02:40:12 +0000 | [diff] [blame] | 15 | use Calculator; |
Mark Slee | 27ed6ec | 2007-08-16 01:26:31 +0000 | [diff] [blame^] | 16 | use shared::Types; |
| 17 | use tutorial::Types; |
Mark Slee | 738ad31 | 2007-05-16 02:40:12 +0000 | [diff] [blame] | 18 | |
| 19 | use Data::Dumper; |
| 20 | |
| 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); |
| 25 | |
| 26 | |
| 27 | eval{ |
| 28 | $transport->open(); |
| 29 | |
| 30 | $client->ping(); |
| 31 | print "ping()\n"; |
| 32 | |
| 33 | |
| 34 | my $sum = $client->add(1000000,1); |
| 35 | print "1+1=$sum\n"; |
| 36 | |
| 37 | my $work = new Work(); |
| 38 | |
| 39 | $work->{op} = Operation::DIVIDE; |
| 40 | $work->{num1} = 1; |
| 41 | $work->{num2} = 0; |
| 42 | |
| 43 | eval { |
| 44 | $client->calculate(1, $work); |
| 45 | print "Whoa! We can divide by zero?\n"; |
| 46 | }; if($@) { |
| 47 | warn "InvalidOperation: ".Dumper($@); |
| 48 | } |
| 49 | |
| 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"; |
| 55 | |
| 56 | my $log = $client->getStruct(1); |
| 57 | print "Log: $log->{value}\n"; |
| 58 | |
| 59 | $transport->close(); |
| 60 | |
| 61 | }; if($@){ |
| 62 | warn(Dumper($@)); |
| 63 | } |