NAME
Froody::Response::Terse - create a response from a Terse data structure
SYNOPSIS
my $rsp = Froody::Response::Terse->new();
$rsp->structure($froody_method);
$rsp->content({
group => "imperialframeworks"
person => [
{ nick => "Trelane", number => "243", name => "Mark Fowler" }
{ nick => "jerakeen", number => "235", name => "Tom Insam" }
],
-text => "Some of Frameworks went to Imperial Collage"
}
print $rsp->render();
# prints out (more or less)
<?xml version="1.0" encoding="utf-8" ?>
<people group="imperialframeworks">
<person nick="Trelane" number="234"><name>Mark Fowler</name></person>
<person nick="jerakeen" number="235"><name>Tom Insam</name></person>
Some of Frameworks went to Imperial Collage
</people>
DESCRIPTION
The Terse response class allows you to construct Responses from a very small data structure that is the most logical form for the data to take. It is able to convert the data to XML by virtue of the specification stored in the Froody::Method alone.
The data structure is exactly the same that's returned from a method implementation that's defined in a Froody::Implementation subclass (If you don't know what that is, I'd go read that module's documentation now if I were you.)
Methods
- create_envelope( XML::Document, XML::Node (content) )
-
You're given one last shot to change the overall format of the response.
The default behavior injects an <rsp stat='status'> wrapper around the
content
node.
Attributes
In addition to the attributes inherited from Froody::Response, this class has the following get/set methods:
- status
-
The status of the response, should be 'ok' or 'fail' only.
- content
-
The contents of the data structure. Setting this accessor causes a deep clone of the data structure to happen, meaning that you can add similar content to multiple Response objects by setting on one object, altering, then setting another object.
my $data = { keywords => [qw( fotango office daytime )] }; $picture_of_office->content($data); push @{ $data->{keywords} } = "Trelane"; $picture_of_me_in_office->content($data);
Note however, this is not true for the returned value from content. Altering that data structure really does alter the data in the response (this is considered a feature)
# add my name as a keyword as well push @{ $picture_of_me_in_office->content->{keywords} }, "Mark";
Converting other Responses to Froody::Response::Terse objects
Once you've loaded this class you can automatically convert other Froody::Response class instances to Froody::Response::Terse objects with the as_terse
method.
use Froody::Response::Terse;
my $terse = Froody::Response::XML
->new()
->structure($froody_method)
->content({ name => "foo", text => "bar" })
->as_terse;
print ref($terse); # prints "Froody::Response::Terse"
BUGS
None known.
Please report any bugs you find via the CPAN RT system. http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Froody
AUTHOR
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.