File: rpc-client.pl

package info (click to toggle)
libfrontier-rpc-perl 0.07b4-2
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 152 kB
  • ctags: 73
  • sloc: perl: 785; sh: 82; xml: 49; makefile: 41
file content (82 lines) | stat: -rw-r--r-- 2,231 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#
# Copyright (C) 1998 Ken MacLeod
# See the file COPYING for distribution terms.
#
# $Id: rpc-client.pl,v 1.3 1999/09/02 20:16:49 kmacleod Exp $
#

=head1 NAME

rpc-client -- example XML RPC client

=head1 SYNOPSIS

 rpc-client [--debug] [--encoding ENCODING] [--proxy PROXY] \
     URL METHOD ["ARGLIST"]

=head1 DESCRIPTION

`C<rpc-client>' exercises an XML RPC server.  I<URL> is the URL of the
RPC server to contact, including a path if necessary, like `C</RPC2>'.
I<METHOD> is the procedure to call on the remote server.

`C<"I<ARGLIST>">' is the argument list to be sent to the remote server.
I<ARGLIST> may include Perl array and hash constructors and should
always be quoted.

The result returned from the XML RPC server is displayed using Perl's
`dumpvar.pl' utility, showing the internal structure of the objects
returned from the server.

The `C<--debug>' option will cause the client to print the XML request
sent to and XML response received from the server.

The `C<--encoding>' option will supply an alternate encoding for the
XML request.  The default is none, which uses XML 1.0's default of
UTF-8.

The `C<--proxy>' option is a URL of an HTTP proxy to pass the request
through.

=head1 EXAMPLES

 rpc-client http://betty.userland.com/RPC2 examples.getStateName "41"

 rpc-client http://betty.userland.com/RPC2 \
   examples.getStateList "[12, 28, 33, 39, 46]"

 rpc-client http://betty.userland.com/RPC2 \
   examples.getStateStruct "{state1 => 18, state2 => 27, state3 => 48}"

=cut

use Frontier::Client;
use Getopt::Long;

my $debug = 0;
my $encoding = undef;
my $proxy = undef;

GetOptions( 'debug' => \$debug,
            'encoding=s' => \$encoding,
            'proxy=s' => \$proxy );

die "usage: rpc-client URL METHOD [\"ARGLIST\"]\n"
    if ($#ARGV != 1 && $#ARGV != 2);

my $url = shift @ARGV;
my $method = shift @ARGV;
my $arglist = shift @ARGV;

$server = Frontier::Client->new( 'url' => $url,
                                 'debug' => $debug,
                                 'encoding' => $encoding,
                                 'proxy' => $proxy );

my @arglist;
eval "\@arglist = ($arglist)";

$result = $server->call ($method, @arglist);

require 'dumpvar.pl';
dumpvar ('main', 'result');