File Coverage

blib/lib/RPC/Lite.pm
Criterion Covered Total %
statement 7 9 77.7
branch n/a
condition n/a
subroutine 3 3 100.0
pod n/a
total 10 12 83.3


line stmt bran cond sub pod time code
1             package RPC::Lite;
2              
3 3     3   75965 use strict;
  3         9  
  3         233  
4              
5             # documentation/placeholder package
6              
7             our $VERSION = '0.20';
8             our $HANDSHAKEFORMATSTRING = 'RPC-Lite %s / %s %s';
9              
10 3     3   1814 use RPC::Lite::Client;
  3         10  
  3         238  
11 3     3   1980 use RPC::Lite::Server;
  0            
  0            
12              
13             use RPC::Lite::Request;
14             use RPC::Lite::Response;
15             use RPC::Lite::Error;
16             use RPC::Lite::Notification;
17             use RPC::Lite::Signature;
18              
19             use RPC::Lite::Transport::TCP;
20              
21             sub VersionSupported
22             {
23             my $version = shift;
24            
25             # FIXME check if we support the protocol version
26             return 1;
27             }
28              
29             =pod
30              
31             =head1 NAME
32              
33             RPC::Lite - A lightweight yet flexible framework for remote process communication.
34              
35             =head1 DESCRIPTION
36              
37             RPC::Lite is intended to be a lightweight, easy-to-use yet flexible
38             and powerful RPC implementation. It was inspired by the headaches
39             of working with other, heavier RPC APIs.
40              
41             RPC::Lite does not require versioning or signatures but provides
42             facilities to enable them. RPC::Lite is developed under the
43             assumption that for most RPC tasks, the programmer is intimately
44             familiar with both the client and server side of the application
45             and that it is unlikely that clients and servers will have APIs
46             change underneath them without the programmer being aware.
47              
48             With the above assumptions, it becomes easier to develop simple
49             (or even not-so-simple) RPC services and clients without jumping
50             through the many hoops other RPC implementation require for even
51             the most trivial implementations.
52              
53             RPC::Lite also supports threading if the Thread::Pool module is
54             available. See RPC::Lite::Threading for more information.
55              
56             =head1 EXAMPLES
57              
58             ##############################################
59             # Client
60              
61             use strict;
62              
63             use RPC::Lite::Client;
64              
65             # this will create a client object that will try to connect to
66             # 192.168.0.3:10000 via TCP and use the JSON serializer.
67             my $client = RPC::Lite::Client->new(
68             {
69             Transport => 'TCP:Host=192.168.0.3,Port=10000',
70             Serializer => 'JSON',
71             }
72             );
73              
74             # print out the results of a call to the system.GetSignatures method
75             print "GetSingatures: ";
76             print Dumper( $client->Request('system.GetSignatures') );
77             print "\n";
78              
79             # print out the results of calling system.GetSignature( 'add' )
80             print "GetSignature(add): ";
81             print $client->Request('system.GetSignature', 'add');
82             print "\n";
83              
84             # ask the server to add two values together and
85             # return the result, $result = 3
86             my $val1 = 1;
87             my $val2 = 2;
88             my $result = $client->Request( 'add', $val1, $val2 );
89             # $result == 3
90              
91             ###############################################
92             # Server
93              
94             use strict;
95              
96             use RPC::Lite::Server;
97              
98             my $threaded = $ARGV[0] eq '-t' ? 1 : 0;
99              
100             my $server = TestServer->new(
101             {
102             Transports => [ 'TCP:ListenPort=10000,LocalAddr=localhost' ],
103             Threaded => $threaded,
104             }
105             );
106              
107             $server->Loop;
108              
109             ###########################
110              
111             package TestServer;
112              
113             use base qw(RPC::Lite::Server);
114              
115             # Initialize is called by the base RPC::Lite::Server class
116             # You should put any initialization you want your server
117             # implementation to do in this function. This function is
118             # not necessary, it's only called if you've implemented it.
119             # As an example, we add a signature for the 'add' method: it
120             # returns an int, and takes two ints as arguments.
121             sub Initialize
122             {
123             my $self = shift;
124              
125             $self->AddSignature('add=int:int,int'); # signatures are optional
126             }
127              
128             # do the addition and return the result
129             sub add
130             {
131             my ( $server, $value1, $value2 ) = @_;
132              
133             return $value1 + $value2;
134             }
135              
136             =head1 SUPPORT
137              
138             Please visit the project homepage at:
139              
140             http://www.rpc-lite.org/
141              
142             If you are interested in discussing RPC::Lite, please consider joining
143             the email list:
144              
145             https://www.fdntech.com/secure/mailman/listinfo/rpc-lite
146              
147             If you would like to join the development email list, please visit:
148              
149             https://www.fdntech.com/secure/mailman/listinfo/rpc-lite-dev
150              
151             =head1 AUTHORS
152              
153             Andrew Burke (aburke@bitflood.org)
154             Jeremy Muhlich (jmuhlich@bitflood.org)
155              
156             =head1 SEE ALSO
157              
158             RPC::Lite::Client, RPC::Lite::Server
159            
160             =cut
161              
162             1;