[Melbourne-pm] catalyst xmlrpc
Scott Penrose
scottp at dd.com.au
Tue Mar 14 16:32:31 PST 2006
Fixing my own code (now that I have my laptop booted again) (don't
ask, hard disk failure !)
On 14/03/2006, at 22:57, Scott Penrose wrote:
> hey guys.
>
> i just wanted to share with you a tiny addition to my addressbook
> code in catalyst that enables xmlrpc calls
>
> 1. add XMLRPC to the pluggins
> 2. add to the controller
>
> sub Xmlrpc : Local
> my (4self, $c) = @_,
> return $c-xmlrpc,
# Make a new local method (eg: /addressbook/xmlrpc) to handle the XML
RPC base
sub xmlrpc : Local {
my ($self, $c) = @_;
return $c->xmlrpc;
}
>
> sub get : Remote
> ... as per suggest
> return @ret,
# Add a new method to return users via XML RPC (ala : Remote)
# TODO - Refactor so that "sub suggest : Local" uses the same code as
"sub get : Remote"
sub get : Remote {
my ($self, $c, $lookup, $val) = @_;
my %ret = ();
my $ab = $c->model('AddressBook')->ab;
foreach my $key ($ab->search($lookup => $val) {
$ret{$ab->entry($key)->{$lookup}}++;
}
return [sort keys %ret];
}
> and that (in rough organiser email) is it...
Now you can test the connection by using XMLRPCsh (a command line
simple shell)
(note XMLRPC.sh comes with SOAP::Lite, not with RPC::XML - although
SOAP::Lite comes with XMLRPC - another implementation)
$ XMLRPCsh.pl http://localhost:3000/addressbook/xmlrpc
Usage: method[(parameters)]
> get('last', 'p')
--- XMLRPC RESULT ---
[
'Penrose',
'Presser'
]
Of course it is just as easy to add REST and SOAP based calls.
Enjoy
Scott
-------------- next part --------------
A non-text attachment was scrubbed...
Name: PGP.sig
Type: application/pgp-signature
Size: 186 bytes
Desc: This is a digitally signed message part
Url : http://mail.pm.org/pipermail/melbourne-pm/attachments/20060315/74ab3398/PGP.bin
More information about the Melbourne-pm
mailing list