File Coverage

blib/lib/CGI/JSONRPC/Obj.pm
Criterion Covered Total %
statement 5 14 35.7
branch 0 2 0.0
condition 0 3 0.0
subroutine 2 5 40.0
pod 3 4 75.0
total 10 28 35.7


line stmt bran cond sub pod time code
1             package CGI::JSONRPC::Obj;
2 1     1   867 use strict;
  1         1  
  1         163  
3              
4             1;
5              
6             sub jsonrpc_new {
7 2     2 1 3 my($class, $id, $dispatcher) = @_;
8 2         13 return bless { id => $id, dispatcher => $dispatcher }, $class;
9             }
10              
11             sub jsonrpc_js_name {
12 0     0 1   my $class = shift;
13 0 0         $class = ref($class) if ref($class);
14 0           $class =~ s/::/\./g;
15 0           return $class;
16             }
17              
18             sub js_class {
19 0     0 0   my $self = shift;
20 0   0       my $name = shift || $self->jsonrpc_js_name();
21 0           return '';
22             }
23              
24             sub jsonrpc_javascript {
25 0     0 1   my $self = shift;
26 0           return $self->js_class
27             }
28              
29              
30              
31             =pod
32              
33             =head1 NAME
34              
35             CGI::JSONRPC::Obj - Base class for easy handler creation
36              
37             =head1 SYNOPSIS
38              
39             package MyHandler;
40             use CGI::JSONRPC::Obj;
41              
42             sub jsonrpc_javascript {
43             my $js;
44             # construct javascript object
45             return
46             }
47            
48             sub do_something {
49             # handler that jsonrpc will call...
50             }
51            
52              
53             =head1 DESCRIPTION
54              
55             CGI::JSONRPC::Obj is a base class you can use to ease the creation
56             of object handlers. Although it's fairly trivial to roll your own
57             we recommend that all handlers use this class for forward compatablity
58             reasons.
59              
60             This object can all be viewed as documenting and defining the behaviour
61             required of all objects served via CGI::JSONRPC.
62              
63             =head1 INTERACTION WITH DISPATCHER
64              
65             When a CGI::JSONRPC call is dispatched the following happens:
66              
67             =over
68              
69             =item dispatcher creates object
70              
71             The dispatcher calls the I method for you object passing
72             the id value recieved from javascript.
73              
74             =item dispatcher calls method
75              
76             The dispatcher will then call your method passing in the arguments recieved
77             in the call.
78              
79             =item GET request
80              
81             The dispatcher will return the output of the json_javascript method.
82              
83             =back
84              
85              
86             =head1 METHODS
87              
88             =over
89              
90             =item jsonrpc_new($id)
91              
92             Constructs the jsonrpc_object and inititializes it from the passed id
93             if appropriate. By default there is no serialization of objects so it
94             is the sole responsibility of all base classes to implement it.
95             (see L for an example)
96              
97             =item jsonrpc_javascript
98              
99             Should return the javascript that is the javascript expression of this
100             object. By default this returns the empty string.
101              
102             =item jsonrpc_js_name
103              
104             Convenience method that returns a javascript safe expression of this
105             objects class. Never called by the dispatcher but can be used to
106             generate the name to be passed in the I argument in subsequent
107             L calls.
108              
109             =back
110              
111             =head1 AUTHOR
112              
113             Tyler "Crackerjack" MacDonald and
114             David Labatte .
115              
116             A lot of the JavaScript code was borrowed from Ingy döt Net's
117             L package.
118              
119             =head1 LICENSE
120              
121             Copyright 2006 Tyler "Crackerjack" MacDonald
122              
123             This is free software; You may distribute it under the same terms as perl
124             itself.
125              
126             =head1 SEE ALSO
127              
128             The "examples" directory (examples/httpd.conf and examples/hello.html),
129             L, L.
130              
131             =cut
132