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;