LP#1631522: include example of ->dispatch in example app
authorGalen Charlton <gmc@esilibrary.com>
Tue, 1 Nov 2016 21:03:03 +0000 (17:03 -0400)
committerGalen Charlton <gmc@esilibrary.com>
Tue, 1 Nov 2016 21:15:39 +0000 (17:15 -0400)
This patch also makes the Perl opensrf.math demo app work
correctly, as it hadn't been constructing opensrf.dbmath
method names correctly.

Signed-off-by: Galen Charlton <gmc@esilibrary.com>

src/perl/lib/OpenSRF/Application/Demo/Math.pm

index 7f41456..9e53dcb 100644 (file)
@@ -20,7 +20,7 @@ sub send_request {
        my @params = @_;
 
        my $session = OpenSRF::AppSession->create( "opensrf.dbmath" );
-       my $request = $session->request( "dbmath.$method_name", @params );
+       my $request = $session->request( "$method_name", @params );
        my $response = $request->recv();
        if(!$response) { return undef; }
        if($response->isa("Error")) {throw $response ($response->stringify);}
@@ -37,10 +37,9 @@ sub add_1 {
        my $client = shift;
        my @args = @_;
 
-       my $meth = $self->method_lookup('_send_request');
-       my ($result) = $meth->run('add',@args);
-
-       return $result;
+       # use ->dispatch rather than run; results of the delegated
+       # method will be directly passed to the caller
+       return $self->method_lookup('_send_request')->dispatch('add', @args);
 }
 
 __PACKAGE__->register_method( method => 'sub_1', api_name => 'sub' );