NAME

CGI::JSONRPC::Session::Obj - Base class for easy handler creation

SYNOPSIS

  package MyHandler;
  use CGI::JSONRPC::Session::Obj;

  sub jsonrpc_javascript {
    my $js;
     # construct javascript object
    return 
  }
  
  sub do_something {
    $self->{count}++; # count will increment
    my $ac = $self->param('another_count');
    $self->param('another_count',$ac++);
    # handler that jsonrpc will call... 
  }
 

DESCRIPTION

CGI::JSONRPC::Session::Obj is a base class you can use to ease the creation of sessioned object handlers. Although it's fairly trivial to roll your own we recommend that all handlers use this class for forward compatablity reasons.

This object can all be viewed as documenting and defining the behaviour required of all session objects served via CGI::JSONRPC.

INTERACTION WITH DISPATCHER

When a CGI::JSONRPC::Session call is dispatched the following happens:

dispatcher creates object

The dispatcher calls the jsonrcp_new method for you object passing the id value recieved from javascript.

dispatcher calls method

The dispatcher will then call your method passing in the arguments recieved in the call.

GET request

The dispatcher will return the output of the json_javascript method.

METHODS

jsonrpc_new($id,$session)

Constructs the jsonrpc_object and inititializes it from the passed id if appropriate from the passed CGI::Session object. By default all data stored in the object without a leading underscore will be serialized and made available between dispatches.

jsonrpc_javascript

Should return the javascript that is the javascript expression of this object. By default this returns the empty string.

jsonrpc_js_name

Convenience method that returns a javascript safe expression of this objects class. Never called by the dispatcher but can be used to generate the name to be passed in the class argument in subsequent CGI::JSONRPC calls.

_jsonrpc_restore($data)

Will be passed the data that was saved as a result of a previous _jsonrpc_serialize call. Should return the restored object.

_jsonrpc_serialize

Should return a reference to the state that will be needed to restore this object. By default this method removes some internal keys from the self object and returns it.

_jsonrpc_finish

Will be called after the dispatch has completed. Will by default call the _jsonrpc_serialze method, store the result into it's session and flush the it.

session

Convenience wrapper that returns the value of the configured session object

param

Convenience wrapper that passes any arguments to the configured session object.

AUTHOR

Tyler "Crackerjack" MacDonald <japh@crackerjack.net> and David Labatte <buggyd@justanotherperlhacker.com>.

A lot of the JavaScript code was borrowed from Ingy döt Net's Jemplate package.

LICENSE

Copyright 2006 Tyler "Crackerjack" MacDonald <japh@crackerjack.net>

This is free software; You may distribute it under the same terms as perl itself.

SEE ALSO

The "examples" directory (examples/httpd.conf and examples/hello.html), JSON::Syck, http://www.json-rpc.org/.

1 POD Error

The following errors were encountered while parsing the POD:

Around line 193:

Non-ASCII character seen before =encoding in 'döt'. Assuming UTF-8