Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Mojolicious::Plugin::JsonToXml – JSON to XML Mojolicious Plugin

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib
Octocat-spinner-32 t
Octocat-spinner-32 Build.PL
Octocat-spinner-32 Changes
Octocat-spinner-32 README.pod
README.pod

NAME

Mojolicious::Plugin::JsonToXml - JSON to XML Mojolicious Plugin

SYNOPSIS

        # Mojolicious
        $self->plugin('json_to_xml');
        
        # Mojolicious::Lite
        plugin 'json_to_xml';
        
        # or
        plugin 'json_to_xml', { status => 200 }; # JSON to XML only 200 status code
        
        # or
        plugin 'json_to_xml', {
                exclude => [ qr{/no\.xml}, '/no2.xml' ] # Exclude urls
        };

Simple:

        get '/test.json' => sub { shift->render_json({ response => 'ok' }) };
        
        # /test.json : {"response": "ok"}
        # /test.xml  :
        <?xml version="1.0" encoding="UTF-8"?>
        <response>ok</response>

List:

        get '/list.json' => sub { shift->render_json([1, 2, 3]) };
        
        # /list.json : [1,2,3]
        # /list.xml  :
        <?xml version="1.0" encoding="UTF-8"?>
        <list><item>1</item><item>2</item><item>3</item></list>

Tags:

        get '/tags.json' => sub { shift->render_json({
                tests => [
                        { id => 1, title => 'JSON & XML', __node => 'test' },
                        { id => 2, title => 'JSON > XML', },
                ]
        }) };
        
        # /tags.json : {"tests":[{"id":1},{"id":2}]}
        # /tags.xml  :
        <?xml version="1.0" encoding="UTF-8"?>
        <tests>
                <test><id>1</id><title>JSON &amp; XML</title></test>
                <test><id>2</id><title>JSON &gt; XML</title></test>
        </tests>

DESCRIPTION

Mojolicous::Plugin::JsonToXml is a plugin to easily use XML format if exists JSON format. Automatiс render JSON to XML data

METHODS

Mojolicious::Plugin::JsonToXml inherits all methods from Mojolicious::Plugin and implements the following new ones.

register

        $plugin->register;

Register plugin hooks in Mojolicious application.

json2xml

        my $xml = $plugin->json2xml( $json );

Simple render json to xml.

If $json is missing or empty, xml contains root tag <empty />.

Each element of array is <item> ... </item>.

SEE ALSO

Mojolicious, Mojolicious::Guides, http://mojolicious.org.

AUTHOR

Anatoly Sharifulin <sharifulin@gmail.com>

BUGS

Please report any bugs or feature requests to bug-mojolicious-plugin-jsontoxml at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.htMail?Queue=Mojolicious-Plugin-JsonToXml. We will be notified, and then you'll automatically be notified of progress on your bug as we make changes.

COPYRIGHT & LICENSE

Copyright (C) 2010 by Anatoly Sharifulin.

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

Something went wrong with that request. Please try again.