View on
Fotango Ltd > Froody-42.034 > Froody::Response::PerlDS



Annotate this POD


New  1
Open  0
View/Report Bugs
Source   Latest Release: Froody-42.041_2


Froody::Response::PerlDS - create a response from a Perl data structure


  my $rsp = Froody::Response::PerlDS->new();
    name => "bob",
    attributes => { foo => "bar" },
    value => "harry",
  print $rsp->render();
  # prints out
  <?xml version="1.0" encoding="utf-8" ?>
  <rsp stat="ok">
    <bob foo="bar">harry</bob>


DEPRECATED!!!! Please use Froody::Response::Terse

This is a simple type of response that allows you to quickly create responses from Perl data structures.

For example:

    name => "bob",
    attributes => { foo => "bar" },
    value => "harry",

will result in the XML:

  <?xml version="1.0" encoding="utf-8" ?>
  <rsp stat="ok">
    <bob foo="bar">harry</bob>


    name => "bob",
    attributes => { foo => "bar" },
    children => [
        name => "dave",
        attributes => { fuzz => "ball" },
        value => "ninepence",

will result in the XML

  <?xml version="1.0" encoding="utf-8" ?>
  <rsp stat="ok">
    <bob foo="bar">
      <dave fuzz="ball">ninepence</dave>

Adding content implicitly sets the status to 'ok', unless it is already set, because this is probably what you mean, and therefore you don't have to think about it.


In addition to the attributes inherited from Froody::Response, this class has the following get/set methods:


The status of the response, should be 'ok' or 'fail' only.


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 = { name => "fred", attr => { fred => "wilma" } };
  $data->{attr}{fred} = "barney";

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)

  # in the future, fred is buddies with george
  $response_buddies->content->{attr}{fred} = "george";

the name of the root node. If unset, this will default to 'rsp'. See default_root_name.

Methods ^


Creates a new, empty message object. Inherited from Froody::Base.


Finds the correct node in the Froody::Response structure given an xpath (like) path.


Returns the default name of the root node. Is "rsp" for this class - you can override this by subclassing, or by setting the 'root_name' property on an instance.


Internal method, designed for subclassing. Does the actual rendering.

Converting other Responses to Froody::Response::PerlDS objects

Once you've loaded this class you can automatically convert other Froody::Response class instances to Froody::Response::PerlDS objects with the as_perlds method.

  use Froody::Response::String;
  use Froody::Response::PerlDS;
  my $perlds = Froody::Response::String
      ->set_string('<rsp stat="ok"><foo>bar</foo></rsp>');

  print ref($perlds);  # prints "Froody::Response::PerlDS"


Attribute names are not encoded (so people using non ASCII attribute names do so at their own risk.) This doesn't work for me, and the whole attributes vanish unexpectedly. This is either a XML::LibXML bug or a perl bug, but I can't produce a small enough test case to make it work. Patches welcome.

Please report any bugs you find via the CPAN RT system.


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

syntax highlighting: