Git Product home page Git Product logo

mojo-xmlrpc's Introduction

NAME

Mojo::XMLRPC - An XMLRPC message parser/encoder using the Mojo stack

SYNOPSIS

use Mojo::UserAgent;
use Mojo::XMLRPC qw[to_xmlrpc from_xmlrpc];

my $ua = Mojo::UserAgent->new;
my $url = ...;
my $tx = $ua->post($url, encode_xmlrpc(call => 'mymethod', 'myarg'));
my $res = decode_xmlrpc($tx->res->body)

DESCRIPTION

Mojo::XMLRPC is a pure-perl XML-RPC message parser and encoder. It uses tools from the Mojo toolkit to do all of the work.

This does not mean that it must only be used in conjunction with a Mojolicious app, far from it. Feel free to use it in any circumstance that needs XML-RPC messages.

MAPPING

The mapping between Perl types and XMLRPC types is not perfectly one-to-one, especially given Perl's scalar types. The following is a description of the procedure used to encode and decode XMLRPC message from/to Perl.

Perl to XMLRPC

If the item is a blessed reference:

  • If the item/object implements a TO_XMLRPC method, it is called and the result is encoded.

  • If the item is a JSON::PP::Boolean, as the Mojo::JSON booleans are, it is encoded as a boolean.

  • If the item is a Mojo::Date then it is encoded as a dateTime.iso8601.

  • If the item is a Mojo::XMLRPC::Base64 then it is encode as a base64. This wrapper class is used to distinguish a string from a base64 and aid in encoding/decoding.

  • If the item/object implements a TO_JSON method, it is called and the result is encoded.

  • If none of the above cases are true, the item is stringified and encoded as a string.

If the item is an unblessed reference:

  • An array reference is encoded as an array.

  • A hash reference is encoded as a struct.

  • A scalar reference is encoded as a boolean depending on the truthiness of the referenced value. This is the standard shortcut seen in JSON modules allowing \1 for true and \0 for false.

If the item is a non-reference scalar:

  • If the item is undefined it is encoded as <nil/>.

  • If the item has NOK (it has been used as a floating point number) it is encoded as double.

  • If the item has IOK (it has been used as an integer (and not a float)) it is encoded as an int.

  • All other values are encoded as string.

XMLRPC to Perl

Most values decode back into Perl in a manner that would survive a round trip. The exceptions are blessed objects that implement TO_XMLRPC or TO_JSON or are stringified. The shortcuts for booleans will round-trip to being Mojo::JSON booleans objects.

Values encoded as integers will not be truncated via int however no attempt is made to upgrade them to IOK or NOK. Values encoded as floating point double will be forcably upgraded to NOK (by dividing by 1.0). This is so that an integer value encoded as a floating point will round trip, the reverse case isn't as useful and thus isn't handled.

FUNCTIONS

decode_xmlrpc

Like "from_xmlrpc" but first decodes from UTF-8 encoded bytes.

encode_xmlrpc

Like "to_xmlrpc" but encodes the result to UTF-8 encoded bytes.

from_xmlrpc

Takes a character string, interprets it, and returns a Mojo::XMLRPC::Message containing the result. If the input is UTF-8 encoded bytes, you can use "decode_xmlrpc" instead.

to_xmlrpc

Generates an XMLRPC message from data passed to the function. The input may be a Mojo::XMLRPC::Message or it could be of the following form.

  • A message type, one of call, response, fault.

  • If the message type is call, then the method name.

  • If the message is not a fault, then all remaining arguments are parameters. If the message is a fault, then the fault code followed by the fault string, all remaining arguments are ignored.

The return value is a character string. To generate UTF-8 encoded bytes, you can use "encode_xmlrpc" instead.

THANKS

This module was inspired by XMLRPC::Fast written by Sébastien Aperghis-Tramoni.

Mojo::XMLRPC was a port of that module initially to use the Mojo::DOM module rather than XML::Parser. By the time port to the Mojo stack was complete, the module was entirely rewritten. That said, the algorithm still owes a debt of gratitude to that one.

SOURCE REPOSITORY

http://github.com/jberger/Mojo-XMLRPC

AUTHOR

Joel Berger, <[email protected]>

CONTRIBUTORS

Andreas Vögele (voegelas)

rai-gaurav

COPYRIGHT AND LICENSE

Copyright (C) 2017 by "AUTHOR" and "CONTRIBUTORS" This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

mojo-xmlrpc's People

Contributors

jberger avatar rai-gaurav avatar voegelas avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

rai-gaurav

mojo-xmlrpc's Issues

Support for large ints using i8 tag

While working through one of the request, I got an exception 'unknown tag: i8 at C:/berrybrew/5.30.1_64/perl/site/lib/Mojo/XMLRPC.pm line 199'.

Looking through code I found 'i8' is not supported.

elsif ($tag eq 'int' || $tag eq 'i4') {
    return $elem->text + 0;
 
  }

So, just wanted to know is there any plan for supporting i8 also?

Document auxiliary classes

The initial release was motivated by need at $work. The documentation of auxiliary classes was not completed in time. This issue is to track the back-fill of these documents.

Parsing issue

Getting error when parsing valid xml string:

my $xmltest = '<?xml version="1.0" encoding="UTF-8"?><methodResponse><params><param><value><array><data><value><struct><member><name>Contact.OwnerID</name><value><i4>6</i4></value></member><member><name>Contact.LastName</name><value>Wheat</value></member><member><name>DateCreated</name><value><dateTime.iso8601>20160303T11:58:50</dateTime.iso8601></value></member><member><name>Contact.FirstName</name><value>Kiel</value></member><member><name>ContactId</name><value><i4>3510</i4></value></member><member><name>ContactGroup</name><value>DNA Mentoring - Active</value></member><member><name>Contact.Email</name><value>[email protected]</value></member></struct></value><value><struct><member><name>Contact.OwnerID</name><value><i4>6</i4></value></member><member><name>Contact.LastName</name><value>Westbom</value></member><member><name>DateCreated</name><value><dateTime.iso8601>20160303T11:00:26</dateTime.iso8601></value></member><member><name>Contact.FirstName</name><value>Daniel</value></member><member><name>ContactId</name><value><i4>8194</i4></value></member><member><name>ContactGroup</name><value>DNA Mentoring - Active</value></member><member><name>Contact.Email</name><value>[email protected]</value></member></struct></value></data></array></value></param></params></methodResponse>';

No issue with XML::Parser

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.