{
    "content": [
        {
            "type": "text",
            "text": "# RPC::XML (perldoc)\n\n## NAME\n\nRPC::XML - A set of classes for core data, message and XML handling\n\n## SYNOPSIS\n\nuse RPC::XML;\n$req = RPC::XML::request->new('fetchprimefactors',\nRPC::XML::int->new(985120528));\n...\n$resp = RPC::XML::ParserFactory->new()->parse(STREAM);\nif (ref($resp))\n{\nreturn $resp->value->value;\n}\nelse\n{\ndie $resp;\n}\n\n## DESCRIPTION\n\nThe RPC::XML package is an implementation of the XML-RPC standard. The package as a whole\nprovides classes for data, for clients, for servers and for parsers (based on the XML::Parser\nand XML::LibXML packages from CPAN).\n\n## Sections\n\n- **NAME**\n- **SYNOPSIS**\n- **DESCRIPTION**\n- **SUBROUTINES/METHODS** (2 subsections)\n- **CLASSES** (5 subsections)\n- **DATES AND TIMES**\n- **DIAGNOSTICS**\n- **GLOBAL VARIABLES**\n- **CAVEATS**\n- **BUGS**\n- **SUPPORT**\n- **LICENSE AND COPYRIGHT**\n- **CREDITS**\n- **SEE ALSO**\n- **AUTHOR**\n\nUse structuredContent.sections for detailed options, examples, and full documentation.\n"
        }
    ],
    "structuredContent": {
        "command": "RPC::XML",
        "section": "",
        "mode": "perldoc",
        "summary": "RPC::XML - A set of classes for core data, message and XML handling",
        "synopsis": "use RPC::XML;\n$req = RPC::XML::request->new('fetchprimefactors',\nRPC::XML::int->new(985120528));\n...\n$resp = RPC::XML::ParserFactory->new()->parse(STREAM);\nif (ref($resp))\n{\nreturn $resp->value->value;\n}\nelse\n{\ndie $resp;\n}",
        "tldr_summary": null,
        "tldr_examples": [],
        "tldr_source": null,
        "flags": [],
        "examples": [],
        "see_also": [],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 15,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 12,
                "subsections": []
            },
            {
                "name": "SUBROUTINES/METHODS",
                "lines": 3,
                "subsections": [
                    {
                        "name": "time2iso8601",
                        "lines": 7
                    },
                    {
                        "name": "smart_encode",
                        "lines": 32
                    }
                ]
            },
            {
                "name": "CLASSES",
                "lines": 3,
                "subsections": [
                    {
                        "name": "Data Classes",
                        "lines": 7
                    },
                    {
                        "name": "new",
                        "lines": 9
                    },
                    {
                        "name": "serialize",
                        "lines": 129
                    },
                    {
                        "name": "Message Classes",
                        "lines": 12
                    },
                    {
                        "name": "serialize",
                        "lines": 35
                    }
                ]
            },
            {
                "name": "DATES AND TIMES",
                "lines": 30,
                "subsections": []
            },
            {
                "name": "DIAGNOSTICS",
                "lines": 3,
                "subsections": []
            },
            {
                "name": "GLOBAL VARIABLES",
                "lines": 21,
                "subsections": []
            },
            {
                "name": "CAVEATS",
                "lines": 4,
                "subsections": []
            },
            {
                "name": "BUGS",
                "lines": 4,
                "subsections": []
            },
            {
                "name": "SUPPORT",
                "lines": 24,
                "subsections": []
            },
            {
                "name": "LICENSE AND COPYRIGHT",
                "lines": 6,
                "subsections": []
            },
            {
                "name": "CREDITS",
                "lines": 3,
                "subsections": []
            },
            {
                "name": "SEE ALSO",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "AUTHOR",
                "lines": 2,
                "subsections": []
            }
        ],
        "sections": {
            "NAME": {
                "content": "RPC::XML - A set of classes for core data, message and XML handling\n",
                "subsections": []
            },
            "SYNOPSIS": {
                "content": "use RPC::XML;\n\n$req = RPC::XML::request->new('fetchprimefactors',\nRPC::XML::int->new(985120528));\n...\n$resp = RPC::XML::ParserFactory->new()->parse(STREAM);\nif (ref($resp))\n{\nreturn $resp->value->value;\n}\nelse\n{\ndie $resp;\n}\n",
                "subsections": []
            },
            "DESCRIPTION": {
                "content": "The RPC::XML package is an implementation of the XML-RPC standard. The package as a whole\nprovides classes for data, for clients, for servers and for parsers (based on the XML::Parser\nand XML::LibXML packages from CPAN).\n\nThis module provides a set of classes for creating values to pass to the constructors for\nrequests and responses. These are lightweight objects, most of which are implemented as blessed\nscalar references so as to associate specific type information with the value. Classes are also\nprovided for requests, responses and faults (errors).\n\nThis module does not actually provide any transport implementation or server basis. For these,\nsee RPC::XML::Client and RPC::XML::Server, respectively.\n",
                "subsections": []
            },
            "SUBROUTINES/METHODS": {
                "content": "At present, two subroutines are available for import. They must be explicitly imported as part\nof the \"use\" statement, or with a direct call to \"import\":\n",
                "subsections": [
                    {
                        "name": "time2iso8601",
                        "content": "Convert the integer time value in $time (which defaults to calling the built-in \"time\" if\nnot present) to a (pseudo) ISO 8601 string in the UTC time zone. This is a convenience\nfunction for occassions when the return value needs to be of the dateTime.iso8601 type, but\nthe value on hand is the return from the \"time\" built-in. Note that the format of this\nstring is not strictly compliant with ISO 8601 due to the way the dateTime.iso8601 data-type\nwas defined in the specification. See \"DATES AND TIMES\", below.\n"
                    },
                    {
                        "name": "smart_encode",
                        "content": "Converts the passed-in arguments to datatype objects. Any that are already encoded as such\nare passed through unchanged. The routine is called recursively on hash and array\nreferences. Note that this routine can only deduce a certain degree of detail about the\nvalues passed. Boolean values will be wrongly encoded as integers. Pretty much anything not\nspecifically recognizable will get encoded as a string object. Thus, for types such as\n\"fault\", the ISO time value, base-64 data, etc., the program must still explicitly encode\nit. However, this routine will hopefully simplify things a little bit for a majority of the\nusage cases.\n\nIf an argument is a blessed reference (an object), smartencode will generally treat it as a\nnon-blessed reference of the underlying type. That is, objects based on hash references will\nbe encoded as if they are unblessed hash references (becoming RPC::XML::struct objects),\nobjects based on array references are encoded as array references (RPC::XML::array), etc.\nOnly hash references, array references and scalar references are treated in this fashion;\nany other blessed references cannot be down-graded and will cause an exception to be thrown.\n\nThe exception to this are objects of the DateTime class: this package does not utilize\nDateTime directly, but if you pass in a reference to an existing object of that class, it is\nproperly converted to an object of the RPC::XML::datetimeiso8601 class.\n\nIn addition to these, the following \"helper\" functions are also available. They may be imported\nexplicitly, or all may be imported via the tag \":types\":\n\nRPCBOOLEAN RPCINT RPCI4 RPCI8 RPCDOUBLE\nRPCDATETIMEISO8601 RPCBASE64 RPCSTRING RPCNIL\n\nEach creates a data object of the appropriate type from a single value (or, in the case of\nRPCNIL, from no value). They are merely short- hand for calling the constructors of the data\nclasses directly.\n\nAll of the above (helpers and the first two functions) may be imported via the tag \":all\".\n"
                    }
                ]
            },
            "CLASSES": {
                "content": "The classes provided by this module are broken into two groups: *data* classes and *message*\nclasses.\n",
                "subsections": [
                    {
                        "name": "Data Classes",
                        "content": "The following data classes are provided by this library. Each of these provide at least the set\nof methods below. Note that these classes are designed to create throw-away objects. There is\ncurrently no mechanism for changing the value stored within one of these object after the\nconstructor returns. It is assumed that a new object would be created, instead.\n\nThe common methods to all data classes are:\n"
                    },
                    {
                        "name": "new",
                        "content": "Constructor. The value passed in is the value to be encapsulated in the new object.\n\nvalue\nReturns the value kept in the object. Processes recursively for \"array\" and \"struct\"\nobjects.\n\nasstring\nReturns the value as a XML-RPC fragment, with the proper tags, etc.\n"
                    },
                    {
                        "name": "serialize",
                        "content": "Send the stringified rendition of the data to the given file handle. This allows messages\nwith arbitrarily-large base-64 data within them to be sent without having to hold the entire\nmessage within process memory.\n\nlength\nReturns the length, in bytes, of the object when serialized into XML. This is used by the\nclient and server classes to calculate message length.\n\ntype\nReturns the type of data being stored in an object. The type matches the XML-RPC\nspecification, so the normalized form \"datetimeiso8601\" comes back as \"dateTime.iso8601\".\n\nisfault\nAll types except the fault class return false for this. This is to allow consistent testing\nof return values for fault status, without checking for a hash reference with specific keys\ndefined.\n\nThe classes themselves are:\n\nRPC::XML::int\nCreates an integer value. Constructor expects the integer value as an argument.\n\nRPC::XML::i4\nThis is like the \"int\" class. Note that services written in strictly-typed languages such as\nC, C++ or Java may consider the \"i4\" and \"int\" types as distinct and different.\n\nRPC::XML::i8\nThis represents an 8-byte integer, and is not officially supported by the XML-RPC\nspecification. This has been added to accommodate services already in use that have chosen\nto add this extension.\n\nRPC::XML::double\nCreates a floating-point value.\n\nRPC::XML::string\nCreates an arbitrary string. No special encoding is done to the string (aside from XML\ndocument encoding, covered later) with the exception of the \"<\", \">\" and \"&\" characters,\nwhich are XML-escaped during object creation, and then reverted when the \"value\" method is\ncalled.\n\nRPC::XML::boolean\nCreates a boolean value. The value returned will always be either of 1 or 0, for true or\nfalse, respectively. When calling the constructor, the program may specify any of: 0, \"no\",\n\"false\", 1, \"yes\", \"true\".\n\nRPC::XML::datetimeiso8601\nCreates an instance of the XML-RPC \"dateTime.iso8601\" type. The specification for ISO 8601\nmay be found elsewhere. No processing is done to the data. Note that the XML-RPC\nspecification actually got the format of an ISO 8601 date slightly wrong. Because this is\nwhat is in the published spec, this package produces dates that match the XML-RPC spec, not\nthe the ISO 8601 spec. However, it will *read* date-strings in proper ISO 8601 format. See\n\"DATES AND TIMES\", below.\n\nRPC::XML::nil\nCreates a \"nil\" value. The value returned will always be undef. No value should be passed\nwhen calling the constructor.\n\nNote that nil is an extension to XML-RPC, which is not supported by all implementations.\n$RPC::XML::ALLOWNIL must be set to a non-false value before objects of this type can be\nconstructed. See \"GLOBAL VARIABLES\". However, even if $RPC::XML::ALLOWNIL is set to a false\nvalue, the parsers will recognize the \"<nil />\" tag and construct an object.\n\nIn practice, this type is only useful to denote the equivalent of a \"void\" return value from\na function. The type itself is not interchangeable with any of the other data-types.\n\nRPC::XML::base64\nCreates an object that encapsulates a chunk of data that will be treated as base-64 for\ntransport purposes. The value may be passed in as either a string or as a scalar reference.\nAdditionally, a second (optional) parameter may be passed, that if true identifies the data\nas already base-64 encoded. If so, the data is decoded before storage. The \"value\" method\nreturns decoded data, and the \"asstring\" method encodes it before stringification.\n\nAlternately, the constructor may be given an open filehandle argument instead of direct\ndata. When this is the case, the data is never read into memory in its entirety, unless the\n\"value\" or \"asstring\" methods are called. This allows the manipulation of arbitrarily-large\nBase-64-encoded data chunks. In these cases, the flag (optional second argument) is still\nrelevant, but the data is not pre-decoded if it currently exists in an encoded form. It is\nonly decoded as needed. Note that the filehandle passed must be open for reading, at least.\nIt will not be written to, but it will be read from. The position within the file will be\npreserved between operations.\n\nBecause of this, this class supports a special method called \"tofile\", that takes one\nargument. The argument may be either an open, writable filehandle or a string. If it is a\nstring, \"tofile\" will attempt to open it as a file and write the *decoded* data to it. If\nthe argument is a an open filehandle, the data will be written to it without any pre- or\npost-adjustment of the handle position (nor will it be closed upon completion). This differs\nfrom the \"serialize\" method in that it always writes the decoded data (where the other\nalways writes encoded data), and in that the XML opening and closing tags are not written.\nThe return value of \"tofile\" is the size of the data written in bytes.\n\nRPC::XML::array\nCreates an array object. The constructor takes zero or more data-type instances as\narguments, which are inserted into the array in the order specified. \"value\" returns an\narray reference of native Perl types. If a non-null value is passed as an argument to\n\"value()\", then the array reference will contain datatype objects (a shallow rather than\ndeep copy).\n\nRPC::XML::struct\nCreates a struct object, the analogy of a hash table in Perl. The keys are ordinary strings,\nand the values must all be data-type objects. The \"value\" method returns a hash table\nreference, with native Perl types in the values. Key order is not preserved. Key strings are\nnow encoded for special XML characters, so the use of such (\"<\", \">\", etc.) should be\ntransparent to the user. If a non-null value is passed as an argument to \"value()\", then the\nhash reference will contain the datatype objects rather than native Perl data (a shallow vs.\ndeep copy, as with the array type above).\n\nWhen creating RPC::XML::struct objects, there are two ways to pass the content in for the\nnew object: Either an existing hash reference may be passed, or a series of key/value pairs\nmay be passed. If a reference is passed, the existing data is copied (the reference is not\nre-blessed), with the values encoded into new objects as needed.\n\nRPC::XML::fault\nA fault object is a special case of the struct object that checks to ensure that there are\ntwo keys, \"faultCode\" and \"faultString\".\n\nAs a matter of convenience, since the contents of a RPC::XML::fault structure are\nspecifically defined, the constructor may be called with exactly two arguments, the first of\nwhich will be taken as the code, and the second as the string. They will be converted to\nRPC::XML types automatically and stored by the pre-defined key names.\n\nAlso as a matter of convenience, the fault class provides the following accessor methods for\ndirectly retrieving the integer code and error string from a fault object:\n\ncode\nstring\n\nBoth names should be self-explanatory. The values returned are Perl values, not RPC::XML\nclass instances.\n"
                    },
                    {
                        "name": "Message Classes",
                        "content": "The message classes are used both for constructing messages for outgoing communication as well\nas representing the parsed contents of a received message. Both implement the following methods:\n\nnew This is the constructor method for the two message classes. The response class may have only\na single value (as a response is currently limited to a single return value), and requests\nmay have as many arguments as appropriate. In both cases, the arguments are passed to the\nexported \"smartencode\" routine described earlier.\n\nasstring\nReturns the message object expressed as an XML document. The document will be lacking in\nlinebreaks and indention, as it is not targeted for human reading.\n"
                    },
                    {
                        "name": "serialize",
                        "content": "Serialize the message to the given file-handle. This avoids creating the entire XML message\nwithin memory, which may be relevant if there is especially-large Base-64 data within the\nmessage.\n\nlength\nReturns the total size of the message in bytes, used by the client and server classes to set\nthe Content-Length header.\n\nThe two message-object classes are:\n\nRPC::XML::request\nThis creates a request object. A request object expects the first argument to be the name of\nthe remote routine being called, and all remaining arguments are the arguments to that\nroutine. Request objects have the following methods (besides \"new\" and \"asstring\"):\n\nname\nThe name of the remote routine that the request will call.\n\nargs\nReturns a list reference with the arguments that will be passed. No arguments will\nresult in a reference to an empty list.\n\nRPC::XML::response\nThe response object is much like the request object in most ways. It may take only one\nargument, as that is all the specification allows for in a response. Responses have the\nfollowing methods (in addition to \"new\" and \"asstring\"):\n\nvalue\nThe value the response is returning. It will be a RPC::XML data-type.\n\nisfault\nA boolean test whether or not the response is signalling a fault. This is the same as\ntaking the \"value\" method return value and testing it, but is provided for clarity and\nsimplicity.\n"
                    }
                ]
            },
            "DATES AND TIMES": {
                "content": "The XML-RPC specification refers to the date/time values as ISO 8601, but unfortunately got the\nsyntax slightly wrong in the examples. However, since this is the published specification it is\nnecessary to produce time-stamps that conform to this format. The specification implies that the\nonly format for date/time values is:\n\nYYYYMMDDThh:mm:ss\n\n(Here, the \"T\" is literal, the rest represent elements of the date and time.) However, the ISO\n8601 specification does not allow this particular format, and in generally is *considerably*\nmore flexible than this. Yet there are implementations of the XML-RPC standard in other\nlanguages that rely on a strict interpretation of this format.\n\nTo accommodate this, the RPC::XML package only produces dateTime.iso8601 values in the format\ngiven in the spec, with the possible addition of timezone information if the string used to\ncreate a RPC::XML::datetimeiso8601 instance included a timezone offset. The string passed in to\nthe constructor for that class must match:\n\n\\d\\d\\d\\d-?\\d\\d-?\\d\\dT?\\d\\d:\\d\\d:\\d\\d([.,]\\d+)?(Z|[-+]\\d\\d:\\d\\d)?\n\nThis pattern is also used by smartencode to distinguish a date/time string from a regular\nstring. Note that the \"T\" is optional here, as it is in the ISO 8601 spec. The timezone is\noptional, and if it is not given then UTC is assumed. The XML-RPC specification says not to\nassume anything about the timezone in the absence of one, but the format of ISO 8601 declares\nthat that absence of an explicit timezone dictates UTC.\n\nIf you have DateTime::Format::ISO8601 installed, then RPC::XML::datetimeiso8601 will fall back\non it to try and parse any input strings that do not match the above pattern. If the string\ncannot be parsed by the DateTime::Format::ISO8601 module, then the constructor returns undef and\n$RPC::XML::ERROR is set.\n",
                "subsections": []
            },
            "DIAGNOSTICS": {
                "content": "All constructors (in all data classes) return \"undef\" upon failure, with the error message\navailable in the package-global variable $RPC::XML::ERROR.\n",
                "subsections": []
            },
            "GLOBAL VARIABLES": {
                "content": "The following global variables may be changed to control certain behavior of the library. All\nvariables listed below may be imported into the application namespace when you \"use\" RPC::XML:\n\n$ENCODING\nThis variable controls the character-set encoding reported in outgoing XML messages. It\ndefaults to \"us-ascii\", but may be set to any value recognized by XML parsers.\n\n$FORCESTRINGENCODING\nBy default, \"smartencode\" uses heuristics to determine what encoding is required for a data\ntype. For example, 123 would be encoded as \"int\", where 3.14 would be encoded as \"double\".\nIn some situations it may be handy to turn off all these heuristics, and force encoding of\n\"string\" on all data types encountered during encoding. Setting this flag to \"true\" will do\njust that.\n\nDefaults to \"false\".\n\n$ALLOWNIL\nBy default, the XML-RPC \"nil\" extension is not supported. Set this to a non-false value to\nallow use of nil values. Data objects that are \"nil\" are represented as undef by Perl. See\n\"The nil Datatype\".\n",
                "subsections": []
            },
            "CAVEATS": {
                "content": "This began as a reference implementation in which clarity of process and readability of the code\ntook precedence over general efficiency. It is now being maintained as production code, but may\nstill have parts that could be written more efficiently.\n",
                "subsections": []
            },
            "BUGS": {
                "content": "Please report any bugs or feature requests to \"bug-rpc-xml at rt.cpan.org\", or through the web\ninterface at <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=RPC-XML>. I will be notified, and\nthen you'll automatically be notified of progress on your bug as I make changes.\n",
                "subsections": []
            },
            "SUPPORT": {
                "content": "*   RT: CPAN's request tracker\n\n<http://rt.cpan.org/NoAuth/Bugs.html?Dist=RPC-XML>\n\n*   AnnoCPAN: Annotated CPAN documentation\n\n<http://annocpan.org/dist/RPC-XML>\n\n*   CPAN Ratings\n\n<http://cpanratings.perl.org/d/RPC-XML>\n\n*   Search CPAN\n\n<http://search.cpan.org/dist/RPC-XML>\n\n*   MetaCPAN\n\n<https://metacpan.org/release/RPC-XML>\n\n*   Source code on GitHub\n\n<http://github.com/rjray/rpc-xml>\n",
                "subsections": []
            },
            "LICENSE AND COPYRIGHT": {
                "content": "This file and the code within are copyright (c) 2011 by Randy J. Ray.\n\nCopying and distribution are permitted under the terms of the Artistic License 2.0\n(<http://www.opensource.org/licenses/artistic-license-2.0.php>) or the GNU LGPL 2.1\n(<http://www.opensource.org/licenses/lgpl-2.1.php>).\n",
                "subsections": []
            },
            "CREDITS": {
                "content": "The XML-RPC standard is Copyright (c) 1998-2001, UserLand Software, Inc. See\n<http://www.xmlrpc.com> for more information about the XML-RPC specification.\n",
                "subsections": []
            },
            "SEE ALSO": {
                "content": "RPC::XML::Client, RPC::XML::Server\n",
                "subsections": []
            },
            "AUTHOR": {
                "content": "Randy J. Ray <rjray@blackperl.com>\n",
                "subsections": []
            }
        }
    }
}