NAME

Dancer::Plugin::FormattedOutput - Provide output in a variety of formats

VERSION

Version 0.01

SYNOPSIS

Similar in functionality to the standard Dancer serialisation routines, this module provides functions for serialising output to a variety of formats. Where it differs from the default Dancer functionality is that it:

Correctly sets the content type
Allows html as a format using templates
Allows per-call configuration of default format
Works with jsonp
use Dancer::Plugin::FormattedOutput;

get '/some/route' => sub {
    my $data = get_data();
    format "template" => $data;
};

get '/some/other/route' => sub {
    my $data = get_data();
    format $data;
};
...

EXPORT

The function "format" is automatically exported.

SUBROUTINES/METHODS

format

This function is exported in the calling namespace, and it manages the formatting of data into the various available formats.

It can be called as:

format($data)

format("template_name" => $data);

format($data, "default_format");

format("template_name", $data, "default_format");

return_json

The formatter for json. It appends the callback if any, and sets the content type to application/json or text/javascript as appropriate

return_xml

The formatter for xml. It sets the content type, and does a basic transformation to xml.

return_yaml

The formatter for yaml. It sets the content type and does a basic transformation to yaml.

return_text

The formatter for text. It sets the content type, and, if the data is a hashref and has a key named "text", returns the value of that key. Otherwise it returns a Data::Dumper version of the data.

AUTHOR

Alex Kalderimis, <alex kalderimis at gmail dot com>

BUGS

Please report any bugs or feature requests to bug-dancer-plugin-formattedoutput at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Dancer-Plugin-FormattedOutput. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

You can find documentation for this module with the perldoc command.

perldoc Dancer::Plugin::FormattedOutput

You can also look for information at:

ACKNOWLEDGEMENTS

LICENSE AND COPYRIGHT

Copyright 2011 Alex Kalderimis.

This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.

See http://dev.perl.org/licenses/ for more information.