.\" Automatically generated by Pod::Man 2.28 (Pod::Simple 3.28) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is turned on, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{ . if \nF \{ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "JSON::RPC::Legacy::Server 3pm" .TH JSON::RPC::Legacy::Server 3pm "2014-10-13" "perl v5.20.1" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" JSON::RPC::Server \- Perl implementation of JSON\-RPC sever .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 2 \& # CGI version \& use JSON::RPC::Legacy::Server::CGI; \& \& my $server = JSON::RPC::Legacy::Server::CGI\->new; \& \& $server\->dispatch_to(\*(AqMyApp\*(Aq)\->handle(); \& \& \& \& # Apache version \& # In apache conf \& \& PerlRequire /your/path/start.pl \& PerlModule MyApp \& \& \& SetHandler perl\-script \& PerlResponseHandler JSON::RPC::Legacy::Server::Apache \& PerlSetVar dispatch "MyApp" \& PerlSetVar return_die_message 0 \& \& \& \& \& # Daemon version \& use JSON::RPC::Legacy::Server::Daemon; \& \& JSON::RPC::Legacy::Server::Daemon\->new(LocalPort => 8080); \& \->dispatch({\*(Aq/jsonrpc/API\*(Aq => \*(AqMyApp\*(Aq}) \& \->handle(); \& \& \& \& # FastCGI version \& use JSON::RPC::Legacy::Server::FastCGI; \& \& my $server = JSON::RPC::Legacy::Server::FastCGI\->new; \& \& $server\->dispatch_to(\*(AqMyApp\*(Aq)\->handle(); .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" Gets a client request. .PP Parses its \s-1JSON\s0 data. .PP Passes the server object and the object decoded from the \s-1JSON\s0 data to your procedure (method). .PP Takes your returned value (scalar or arrayref or hashref). .PP Sends a response. .PP Well, you write your procedure code only. .SH "METHODS" .IX Header "METHODS" .IP "new" 4 .IX Item "new" Creates new JSON::RPC::Legacy::Server object. .IP "dispatch($package)" 4 .IX Item "dispatch($package)" .PD 0 .ie n .IP "dispatch([$package1, $package1, ...])" 4 .el .IP "dispatch([$package1, \f(CW$package1\fR, ...])" 4 .IX Item "dispatch([$package1, $package1, ...])" .ie n .IP "dispatch({$path => $package, ...})" 4 .el .IP "dispatch({$path => \f(CW$package\fR, ...})" 4 .IX Item "dispatch({$path => $package, ...})" .PD Sets your procedure module using package name list or arrayref or hashref. Hashref version is used for path_info access. .IP "dispatch_to" 4 .IX Item "dispatch_to" An alias to \f(CW\*(C`dispatch\*(C'\fR. .IP "handle" 4 .IX Item "handle" Runs server object and returns a response. .IP "raise_error(%hash)" 4 .IX Item "raise_error(%hash)" .Vb 4 \& return $server\->raise_error( \& code => 501, \& message => "This is error in my procedure." \& ); .Ve .Sp Sets an error. An error code number in your procedure is an integer between 501 and 899. .IP "json" 4 .IX Item "json" Setter/Getter to json encoder/decoder object. The default value is \s-1JSON\s0 object in the below way: .Sp .Vb 1 \& JSON\->new\->utf8 .Ve .Sp In your procedure, changes its behaviour. .Sp .Vb 1 \& $server\->json\->utf8(0); .Ve .Sp The \s-1JSON\s0 coder creating method is \f(CW\*(C`create_json_coder\*(C'\fR. .IP "version" 4 .IX Item "version" Setter/Getter to JSON-RPC protocol version used by a client. If version is 1.1, returns 1.1. Otherwise returns 0. .IP "charset" 4 .IX Item "charset" Setter/Getter to charset. Default is '\s-1UTF\-8\s0'. .IP "content_type" 4 .IX Item "content_type" Setter/Getter to content type. Default is 'application/json'. .IP "return_die_message" 4 .IX Item "return_die_message" When your program dies in your procedure, sends a return object with error message 'Procedure error' by default. .Sp If this option is set, uses \f(CW\*(C`die\*(C'\fR message. .Sp .Vb 5 \& sub your_procedure { \& my ($s) = @_; \& $s\->return_die_message(1); \& die "This is test."; \& } .Ve .IP "retrieve_json_from_post" 4 .IX Item "retrieve_json_from_post" It is used by JSON::RPC::Legacy::Server subclass. .IP "retrieve_json_from_get" 4 .IX Item "retrieve_json_from_get" In the protocol v1.1, '\s-1GET\s0' request method is also allowable. .Sp It is used by JSON::RPC::Legacy::Server subclass. .IP "response" 4 .IX Item "response" It is used by JSON::RPC::Legacy::Server subclass. .IP "request" 4 .IX Item "request" Returns HTTP::Request object. .IP "path_info" 4 .IX Item "path_info" Returns \s-1PATH_INFO.\s0 .IP "max_length" 4 .IX Item "max_length" Returns max content-length to your application. .IP "translate_error_message" 4 .IX Item "translate_error_message" Implemented in your subclass. Three arguments (server object, error code and error message) are passed. It must return a message. .Sp .Vb 4 \& sub translate_error_message { \& my ($s, $code, $message) = @_; \& return $translation_jp_message{$code}; \& } .Ve .IP "create_json_coder" 4 .IX Item "create_json_coder" (Class method) Returns a \s-1JSON\s0 de/encoder in \f(CW\*(C`new\*(C'\fR. You can override it to use your favorite \s-1JSON\s0 de/encode. .SH "RESERVED PROCEDURE" .IX Header "RESERVED PROCEDURE" When a client call a procedure (method) name 'system.foobar', JSON::RPC::Legacy::Server look up MyApp::system::foobar. .PP .PP .PP There is JSON::RPC::Legacy::Server::system::describe for default response of 'system.describe'. .SH "SEE ALSO" .IX Header "SEE ALSO" \&\s-1JSON\s0 .PP .PP .SH "AUTHOR" .IX Header "AUTHOR" Makamaka Hannyaharamitu, .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" Copyright 2007\-2008 by Makamaka Hannyaharamitu .PP This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.