Fotango Ltd > Froody-42.041_2 > Froody::Response::PerlDS

Download:
Froody-42.041_2.tar.gz

Dependencies

Annotate this POD

CPAN RT

Open  0
View/Report Bugs
Source  

NAME ^

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

SYNOPSIS ^

  my $rsp = Froody::Response::PerlDS->new();
  $rsp->structure($froody_method);
  $rsp->content({
    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>
  </rsp>

DESCRIPTION ^

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:

  $response->content({
    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>
  </rsp>

and

  $response->content({
    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>
    </bob>
  </rsp>

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.

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

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

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

Methods ^

new()

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

find_by_path($xpath)

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

default_root_name

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.

raw_render

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
      ->new()
      ->structure($froody_method)
      ->set_string('<rsp stat="ok"><foo>bar</foo></rsp>');
      ->as_perlds;

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

BUGS ^

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. 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.

SEE ALSO ^

Froody, Froody::Response

syntax highlighting: