Froody::Response::XML - create a response from a XML::LibXML document
my $response = Froody::Response::XML->new() ->structure($froody_method) ->xml($xml_doc); print $response->render;
This is a concrete implementation of Froody::Response. It takes its input from an XML::LibXML::Document.
use XML::LibXML; my $xml_doc = XML::LibXML::Document->new( "1.0", "utf-8" ); # create the rsp my $rsp = $xml_doc->createElement("rsp"); $rsp->setAttribute("stat", "ok"); $xml_doc->setDocumentElement($rsp); # add the child node foo my $foo = $xml_doc->createElement("foo"); $foo->appendText("bar"); # note, must pass bytes in the above encoding $rsp->appendChild($foo); my $rsp = Froody::Response::XML->new() ->structure($froody_method) ->xml($xml_doc);
You can get and set the current XML document by usinc xml. We only hold a reference to the data so you can modify the XML after you've assigned it to the response and it'll still effect that response. This means the above could be re-ordered as:
xml
use XML::LibXML; my $xml_doc = XML::LibXML::Document->new( "1.0", "utf-8" ); my $rsp = Froody::Response::XML->new() ->structure($froody_method) ->xml($xml_doc); # create the rsp my $rsp = $xml_doc->createElement("rsp"); $rsp->setAttribute("stat", "ok"); $xml_doc->setDocumentElement($rsp); # add the child node foo my $foo = $xml_doc->createElement("foo"); $foo->appendText("bar"); # note, must pass bytes in the above encoding $rsp->appendChild($foo);
And it'll work just as fine. This does however mean you should be careful about re-using XML::LibXML objects between responses.
Once you've loaded this class you can automatically convert other Froody::Response class instances to Froody::Response::XML objects with the as_xml method.
as_xml
use Froody::Response::String; use Froody::Response::XML; my $string = Froody::Response::String ->new() ->structure($froody_method) ->set_bytes($bytes); ->as_xml; print ref($string); # prints "Froody::Response::XML"
None known.
Please report any bugs you find via the CPAN RT system. http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Froody
Copyright Fotango 2005. All rights reserved.
Please see the main Froody documentation for details of who has worked on this project.
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Froody, Froody::Response
To install Froody, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Froody
CPAN shell
perl -MCPAN -e shell install Froody
For more information on module installation, please visit the detailed CPAN module installation guide.