Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Frontier::Client and <struct>

by DreamT (Pilgrim)
on Mar 22, 2011 at 13:11 UTC ( [id://894790]=perlquestion: print w/replies, xml ) Need Help??

DreamT has asked for the wisdom of the Perl Monks concerning the following question:

I'm using Frontier::Client with success, sending arguments as an array:
$Result = $server->call('myCall', @arguments);

, which generates
<?xml version="1.0" encoding="ISO-8859-1"?> <methodCall> <methodName>myCall</methodName> <params> <param><value><string>myString</string></value> </param> <param><value><int>123</int></value> </param> </methodCall>
How can I do this?:
<param><value><struct> <member> <name>lowerBound</name> <value><i4>18</i4></value> </member> <member> <name>upperBound</name> <value><i4>139</i4></value> </member> </struct> </param>

I.e., how can I create a nested parameter like that?

Replies are listed 'Best First'.
Re: Frontier::Client and <struct>
by CountZero (Bishop) on Mar 23, 2011 at 09:17 UTC
    A hash (or rather a reference to a hash) generates a "struct":
    use Modern::Perl; use Frontier::Client; my $server = Frontier::Client->new( 'url' => 'http://my.server.com/RPC +2', debug => 1 ); my $result = $server->call('MyCall', {test1 => "one", test2 => 'two'}) +;
    Output:
    ---- request ---- <?xml version="1.0"?> <methodCall> <methodName>MyCall</methodName> <params> <param><value><struct> <member> <name>test1</name> <value><string>one</string></value> </member> <member> <name>test2</name> <value><string>two</string></value> </member> </struct></value></param> </params> </methodCall>

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

      Thank you, worked great:)

      Any idea how to get the fields (hash) ordered? Looking in the source, I can't see how it can be possible :-/
        Try
        use Tie::IxHash; tie(%myhash, 'Tie::IxHash', test1 => "one", test2 => 'two' ); my $result = $server->call('MyCall', \%myhash );
        Mmm, interesting.

        And why would you need the fields to be ordered?

        CountZero

        A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

Re: Frontier::Client and <struct>
by dHarry (Abbot) on Mar 23, 2011 at 09:49 UTC

    I think you get what you ask for:) XMLRPC supports arbitrary nested data structures. I have no experience with Frontier::Client, I assume you can format request and response by using the XMLRPC types array and struct. I think you can try something like:

    my $result = $server->call('MyCall', {lowerBound => "one", upperBound +=> 'two'});

    Cheers

    Harry

    UPDATE

    Please ignore post, CountZero did not only beat me by at least half an hour, he also provided a working solution!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://894790]
Approved by Corion
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2024-03-19 08:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found