| 1 | package MyApp::Service::Calculator; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | |||
| 6 | use Beekeeper::Client; | ||
| 7 | use Beekeeper::Config; | ||
| 8 | |||
| 9 | |||
| 10 | sub new { | ||
| 11 | my $class = shift; | ||
| 12 | |||
| 13 | my $self = {}; | ||
| 14 | |||
| 15 | my $config = Beekeeper::Config->read_config_file('client.config.json'); | ||
| 16 | |||
| 17 | # Connect to bus 'frontend', wich will forward requests to 'backend' | ||
| 18 | $self->{client} = Beekeeper::Client->instance( | ||
| 19 | bus_role => "frontend", | ||
| 20 | forward_to => 'backend', | ||
| 21 | %$config, | ||
| 22 | ); | ||
| 23 | |||
| 24 | bless $self, $class; | ||
| 25 | } | ||
| 26 | |||
| 27 | sub client { | ||
| 28 | my $self = shift; | ||
| 29 | |||
| 30 | return $self->{client}; | ||
| 31 | } | ||
| 32 | |||
| 33 | sub eval_expr { | ||
| 34 | my ($self, $str) = @_; | ||
| 35 | |||
| 36 | my $resp = $self->client->call_remote( | ||
| 37 | method => 'myapp.calculator.eval_expr', | ||
| 38 | params => { expr => $str }, | ||
| 39 | ); | ||
| 40 | |||
| 41 | return $resp->result; | ||
| 42 | } | ||
| 43 | |||
| 44 | 1; |