User Tools

Site Tools


osrf-devel:example-server

User Comments

Example Application

Perl module and package implementing a math server.

  package MyMathServer;
  use OpenSRF::Application;
  use base 'OpenSRF::Application';
 
  sub do_math {
     my $self = shift;    # instance of MyMathServer
 
     my $client = shift;  # instance of OpenSRF::AppRequest connected
                          # to the client
 
     my $left_side = shift;
     my $op = shift;
     my $right_side = shift;
 
     return eval "$left_side $op $right_side";
  }
 
  __PACKAGE__->register_method(
     api_name => 'useless.do_math',
     argc => 3,
     method => 'do_math'
  );
 
  1;

Another Perl module and package implementing a square-root server on top of the previous math server.

  package MySquareRootServer;
  use OpenSRF::Application;
  use base 'OpenSRF::Application';
 
  sub sqrt_math {
     my $self = shift;    # instance of MySquareRootServer
 
     my $client = shift;  # instance of OpenSRF::AppRequest connected
                          # to the client
 
     my $math_method = $self->method_lookup('useless.do_math');
     my ($result) = $math_method->run( @_ );
 
     return sqrt( $result );
  }
 
  __PACKAGE__->register_method(
     api_name => 'simple.sqrt',
     argc => 3,
     method => 'sqrt_math'
  );
 
  1;
osrf-devel/example-server.txt · Last modified: 2022/02/10 13:34 by 127.0.0.1

Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International
CC Attribution-Share Alike 4.0 International Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki

© 2008-2022 GPLS and others. Evergreen is open source software, freely licensed under GNU GPLv2 or later.
The Evergreen Project is a U.S. 501(c)3 non-profit organization.