]> git.evergreen-ils.org Git - Evergreen.git/blob - OpenSRF/src/perlmods/OpenSRF/DomainObject/oilsMethod.pm
Initial revision
[Evergreen.git] / OpenSRF / src / perlmods / OpenSRF / DomainObject / oilsMethod.pm
1 package OpenILS::DomainObject::oilsMethod;
2 use OpenILS::DOM::Element::params;
3 use OpenILS::DOM::Element::param;
4 use JSON;
5 use base 'OpenILS::DomainObject';
6
7 =head1 NAME
8
9 OpenILS::DomainObject::oilsMethod
10
11 =head1 SYNOPSIS
12
13 use OpenILS::DomainObject::oilsMethod;
14
15 my $method = OpenILS::DomainObject::oilsMethod->new( method => 'search' );
16
17 $method->return_type( 'mods' );
18
19 $method->params( 'title:harry potter' );
20
21 $client->send( 'REQUEST', $method );
22
23 =head1 METHODS
24
25 =head2 OpenILS::DomainObject::oilsMethod->method( [$new_method_name] )
26
27 =over 4
28
29 Sets or gets the method name that will be called on the server.  As above,
30 this can be specified as a build attribute as well as added to a prebuilt
31 oilsMethod object.
32
33 =back
34
35 =cut
36
37 sub method {
38         my $self = shift;
39         return $self->_attr_get_set( method => shift );
40 }
41
42 =head2 OpenILS::DomainObject::oilsMethod->return_type( [$new_return_type] )
43
44 =over 4
45
46 Sets or gets the return type for this method call.  This can also be supplied as
47 a build attribute.
48
49 This option does not require that the server return the type you request.  It is
50 used as a suggestion when more than one return type or format is possible.
51
52 =back
53
54 =cut
55
56
57 sub return_type {
58         my $self = shift;
59         return $self->_attr_get_set( return_type => shift );
60 }
61
62 =head2 OpenILS::DomainObject::oilsMethod->params( [@new_params] )
63
64 =over 4
65
66 Sets or gets the parameters for this method call.  Just pass in either text
67 parameters, or DOM nodes of any type.
68
69 =back
70
71 =cut
72
73
74 sub params {
75         my $self = shift;
76         my @args = @_;
77
78         my ($old_params) = $self->getChildrenByTagName('oils:params');
79
80         my $params;
81         if (@args) {
82
83                 $self->removeChild($old_params) if ($old_params);
84
85                 my $params = OpenILS::DOM::Element::params->new;
86                 $self->appendChild($params);
87                 $params->appendTextNode( JSON->perl2JSON( \@args );
88
89                 $old_params = $params unless ($old_params);
90         }
91
92         if ($old_params) {
93                 $params = JSON->JSON2perl( $old_params->textContent );
94                 return @$params;
95         }
96
97         return @args;
98 }
99
100 1;