1 OpenSRF Application development API
2 -----------------------------------
4 OpenSRF offers a very simple Application development API to users of the
5 framework. All that is required is to create a Perl module that subclasses
6 the OpenSRF::Application package and register it's methods with the
7 Method Dispatcher framework.
9 Each method executes in the OpenSRF::Application namespace as an instance of
10 the custom Application. There are some instance methods on this object which
11 can be used by the method to alter the behavior or response that the method
14 $self->api_name # returns the name of the method as called by the client
16 $self->method # returns the actual perl name of the sub implementing the
19 my $meth = $self->method_lookup( 'api_name' )
20 # constructs a new instance object implementing another
21 # method in the same Application package as a subrequest
23 my ($subresult) = $meth->run( @params )
24 # runs the subrequest method and returns the array of
28 The method is also handed an OpenSRF::AppRequest object that has been
29 constructed for the client request that generated the call to the method.
30 This OpenSRF::AppRequest object is used to communicate back to the client,
31 passing status messages or streaming response packets.
33 All that is required to register an Application with OpenSRF is to place a
34 setting in the configuration file that names the module that implements the
35 new Application, and to add the new Application's symbolic name to the list of
36 servers that should be started by OpenSRF.
41 # Perl module and package implementing an math server.
43 use OpenSRF::Application;
44 use base 'OpenSRF::Application';
47 my $self = shift; # instance of MyMathServer
49 my $client = shift; # instance of OpenSRF::AppRequest connected
52 my $left_side = shift;
54 my $right_side = shift;
56 return eval "$left_side $op $right_side";
59 __PACKAGE__->register_method(
60 api_name => 'useless.do_math',
69 # Another Perl module and package implementing a square-root server on top
70 # of the previous math server
71 package MySquareRootServer;
72 use OpenSRF::Application;
73 use base 'OpenSRF::Application';
77 my $self = shift; # instance of MySquareRootServer
79 my $client = shift; # instance of OpenSRF::AppRequest connected
82 my $math_method = $self->method_lookup('useless.do_math');
83 my ($result) = $math_method->run( @_ );
85 return sqrt( $result );
88 __PACKAGE__->register_method(
89 api_name => 'simple.sqrt',