1package JSON::RPC::Legacy;
2
3use strict;
4
51;
6__END__
7
8=pod
9
10=head1 NAME
11
12JSON::RPC - Perl implementation of JSON-RPC 1.1 protocol
13
14=head1 DESCRIPTION
15
16 JSON-RPC is a stateless and light-weight remote procedure call (RPC)
17 protocol for inter-networking applications over HTTP. It uses JSON
18 as the data format for of all facets of a remote procedure call,
19 including all application data carried in parameters.
20
21quoted from L<http://json-rpc.org/wd/JSON-RPC-1-1-WD-20060807.html>.
22
23
24This module was in JSON package on CPAN before.
25Now its interfaces was completely changed.
26
27The old modules - L<JSONRPC::Transport::HTTP> and L<Apache::JSONRPC> are deprecated.
28Please try to use JSON::RPC::Server and JSON::RPC::Client which support both JSON-RPC
29protocol version 1.1 and 1.0.
30
31
32=head1 EXAMPLES
33
34CGI version.
35
36 #--------------------------
37 # In your application class
38 package MyApp;
39
40 use base qw(JSON::RPC::Procedure); # Perl 5.6 or more than
41
42 sub echo : Public {    # new version style. called by clients
43     # first argument is JSON::RPC::Server object.
44     return $_[1];
45 }
46
47
48 sub sum : Public(a:num, b:num) { # sets value into object member a, b.
49     my ($s, $obj) = @_;
50     # return a scalar value or a hashref or an arryaref.
51     return $obj->{a} + $obj->{b};
52 }
53
54
55 sub a_private_method : Private {
56     # ... can't be called by client
57 }
58
59
60 sub sum_old_style {  # old version style. taken as Public
61     my ($s, @arg) = @_;
62    return $arg[0] + $arg[1];
63 }
64
65
66 #--------------------------
67 # In your triger script.
68 use JSON::RPC::Server::CGI;
69 use MyApp;
70
71 # simple
72  JSON::RPC::Server::CGI->dispatch('MyApp')->handle();
73
74 # or
75 JSON::RPC::Server::CGI->dispatch([qw/MyApp FooBar/])->handle();
76
77 # or INFO_PATH version
78 JSON::RPC::Server::CGI->dispatch({'/Test' => 'MyApp'})->handle();
79
80 #--------------------------
81 # Client
82 use JSON::RPC::Client;
83
84 my $client = new JSON::RPC::Client;
85
86 my $uri = 'http://www.example.com/jsonrpc/Test';
87 my $obj = {
88    method  => 'sum', # or 'MyApp.sum'
89    params  => [10, 20],
90 };
91
92 my $res = $client->call( $uri, $obj )
93
94 if($res){
95    if ($res->is_error) {
96        print "Error : ", $res->error_message;
97    }
98    else {
99        print $res->result;
100    }
101 }
102 else {
103    print $client->status_line;
104 }
105
106 # or
107
108 $client->prepare($uri, ['sum', 'echo']);
109 print $client->sum(10, 23);
110
111
112See to L<JSON::RPC::Server::CGI>, L<JSON::RPC::Server::Daemon>, L<JSON::RPC::Server::Apache>
113L<JSON::RPC::Client> and L<JSON::RPC::Procedure>.
114
115
116=head1 ABOUT NEW VERSION
117
118=over
119
120=item supports JSON-RPC protocol v1.1
121
122
123=back
124
125=head1 TODO
126
127=over
128
129=item Document
130
131=item Examples
132
133=item More Tests
134
135
136=back
137
138
139=head1 AUTHOR
140
141Makamaka Hannyaharamitu, E<lt>makamaka[at]cpan.orgE<gt>
142
143
144=head1 COPYRIGHT AND LICENSE
145
146Copyright 2007-2008 by Makamaka Hannyaharamitu
147
148This library is free software; you can redistribute it and/or modify
149it under the same terms as Perl itself.
150
151=cut
152
153
154