GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages


Manual Reference Pages  -  DANCER::SERIALIZER::MUTABLE (3)

.ds Aq ’

NAME

Dancer::Serializer::Mutable - Serialize and deserialize content using the appropriate HTTP header

CONTENTS

VERSION

version 1.3138

SYNOPSIS



    # in config.yml
    serializer: Mutable

    # in the app
    put /something => sub {
        # deserialized from request
        my $name = param( name );
       
        ...

        # will be serialized to the most
        # fitting format
        return { message => "user $name added" };
    };



DESCRIPTION

This serializer will try find the best (de)serializer for a given request. For this, it will pick the first content type found from the following list and use its related serializer.
o The <B>content_typeB> from the request headers
o the <B>content_typeB> parameter from the URL
o the <B>acceptB> from the request headers
o The default is <B>application/jsonB>
The content-type/serializer mapping that Dancer::Serializer::Mutable uses is



    serializer               | content types
    ----------------------------------------------------------
    Dancer::Serializer::YAML | text/x-yaml, text/html
    Dancer::Serializer::XML  | text/xml
    Dancer::Serializer::JSON | text/x-json, application/json



EXPORTABLE FUNCTIONS

template_or_serialize( CW$template, CW$data, CW$options )

For instances where you want to render a template for normal browser requests, and return serialized content for AJAX calls.

If the requested content-type is text/html, template_or_serialize returns the rendered template, else it returns $data unmodified (which will then be serialized as usual).

template_or_serialize is not exported by default.



    use Dancer::Serializer::Mutable qw/ template_or_serialize /;

    get /greetings => sub {
        ...;

        return template_or_serialize greetings => {
            title => $title,
            name  => $name,
        };
    };



    INTERNAL METHODS

The following methods are used internally by Dancer and are not made accessible via the DSL.

    serialize

Serialize a data structure. The format it is serialized to is determined automatically as described above. It can be one of YAML, XML, JSON, defaulting to JSON if there’s no clear preference from the request.

    deserialize

Deserialize the provided serialized data to a data structure. The type of serialization format depends on the request’s content-type. For now, it can be one of YAML, XML, JSON.

    content_type

Returns the content-type that was used during the last serialize / deserialize call. <B>WARNINGB> : you must call serialize / deserialize before calling content_type. Otherwise the return value will be undef.

AUTHOR

Dancer Core Developers

COPYRIGHT AND LICENSE

This software is copyright (c) 2010 by Alexis Sukrieh.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

Search for    or go to Top of page |  Section 3 |  Main Index


perl v5.20.3 DANCER::SERIALIZER::MUTABLE (3) 2015-06-12

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with manServer 1.07.