1#!/bin/env perl
2#!d:\perl\bin\perl.exe
3
4# -- XMLRPC::Lite -- soaplite.com -- Copyright (C) 2001 Paul Kulchenko --
5
6use strict;
7use XMLRPC::Lite;
8use Data::Dumper; $Data::Dumper::Terse = 1; $Data::Dumper::Indent = 1;
9
10@ARGV or die "Usage: $0 endpoint [commands...]\n";
11my $proxy = shift;
12my %can;
13my $xmlrpc = XMLRPC::Lite->proxy($proxy)->on_fault(sub{});
14print STDERR "Usage: method[(parameters)]\n> ";
15while (defined($_ = shift || <>)) {
16  next unless /\w/;
17  my($method, $parameters) = /^\s*([.\w]+)(.*)/;
18  $can{$method} = $xmlrpc->can($method) unless exists $can{$method};
19  my $res = $method =~ /\./ ? eval "\$xmlrpc->call(\$method, $parameters)" : eval "\$xmlrpc->$_";
20  $@                               ? print(STDERR join "\n", "--- SYNTAX ERROR ---", $@, '') :
21  $can{$method} && !UNIVERSAL::isa($res => 'XMLRPC::SOM')
22                                   ? print(STDERR join "\n", "--- METHOD RESULT ---", $res || '', '') :
23  defined($res) && $res->fault     ? print(STDERR join "\n", "--- XMLRPC FAULT ---", @{$res->fault}{'faultCode', 'faultString'}, '') :
24  !$xmlrpc->transport->is_success  ? print(STDERR join "\n", "--- TRANSPORT ERROR ---", $xmlrpc->transport->status, '') :
25                                     print(STDERR join "\n", "--- XMLRPC RESULT ---", Dumper($res->paramsall), '')
26} continue {
27  print STDERR "\n> ";
28}
29
30__END__
31
32=head1 NAME
33
34XMLRPCsh.pl - Interactive shell for XMLRPC calls
35
36=head1 SYNOPSIS
37
38  perl XMLRPCsh.pl http://betty.userland.com/RPC2
39  > examples.getStateName(2)
40  > examples.getStateNames(1,2,3,7)
41  > examples.getStateList([1,9])
42  > examples.getStateStruct({a=>1, b=>24})
43  > Ctrl-D (Ctrl-Z on Windows)
44
45or
46
47  # all parameters after uri will be executed as methods
48  perl XMLRPCsh.pl http://betty.userland.com/RPC2 examples.getStateName(2)
49  > Ctrl-D (Ctrl-Z on Windows)
50
51=head1 DESCRIPTION
52
53XMLRPCsh.pl is a shell for making XMLRPC calls. It takes one parameter,
54endpoint (actually it will tell you about it if you try to run it).
55Additional commands can follow.
56
57After that you'll be able to run any methods of XMLRPC::Lite, like autotype,
58readable, etc. You can run it the same way as you do it in
59your Perl script. You'll see output from method, result of XMLRPC call,
60detailed info on XMLRPC faulure or transport error.
61
62For full list of available methods see documentation for XMLRPC::Lite.
63
64Along with methods of XMLRPC::Lite you'll be able (and that's much more
65interesting) run any XMLRPC methods you know about on remote server and
66see processed results. You can even switch on debugging (with call
67something like: C<on_debug(sub{print@_})>) and see XMLRPC code with
68headers sent and recieved.
69
70=head1 COPYRIGHT
71
72Copyright (C) 2000 Paul Kulchenko. All rights reserved.
73
74=head1 AUTHOR
75
76Paul Kulchenko (paulclinger@yahoo.com)
77
78=cut
79