Read and write extensible XML with Mojolicious
Perl
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib/Mojolicious/Plugin/XML
t
.gitignore
Changes
LICENSE
MANIFEST
Makefile.PL
Readme.pod

Readme.pod

NAME

Mojolicious::Plugin::XML::Loy - XML Generation with Mojolicious

SYNOPSIS

# Mojolicious
$mojo->plugin(
  'XML::Loy' => {
    new_activity => [-Atom, -ActivityStreams],
    new_hostmeta => [-XRD, -HostMeta],
    new_myXML    => [-Loy, -Atom, -Atom::Threading]
  });

# In controllers use the generic new_xml helper
my $xml = $c->new_xml('entry');

# Create a new XML::Loy document
my $xml = $app->new_xml('html');

$xml->add('header')->add(
  title => 'XML-Loy example' => 'My Title!'
);

for ($xml->add('body' => { style => 'color: red' })) {
  $_->add(p => 'First paragraph');
  $_->add(p => { -type => 'raw' } => 'Second')
    ->add(b => 'paragraph');
};

# Render document with the correct mime-type
$c->reply->xml($xml);

# Content-Type: application/xml
# <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
# <html>
#   <header>
#
#     <!-- My Title! -->
#     <title>XML-Loy example</title>
#   </header>
#   <body style="color: red">
#     <p>First paragraph</p>
#     <p>Second<b>paragraph</b></p>
#   </body>
# </html>

# Use newly created helper
my $xrd = $c->new_hostmeta;

# Create a document based on the defined xml profile
$xrd->host('sojolicio.us');

# Render document with the correct mime-type
$c->reply->xml($xrd);

# Content-Type: application/xrd+xml
# <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
# <XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0"
#      xmlns:hm="http://host-meta.net/xrd/1.0"
#      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
#   <hm:Host>sojolicio.us</hm:Host>
# </XRD>

DESCRIPTION

Mojolicious::Plugin::XML::Loy is a plugin to support XML document generation based on XML::Loy.

METHODS

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

register

# Mojolicious
$mojo->plugin(XML::Loy => {
  max_size     => 2048,
  new_activity => [-Atom, -ActivityStreams]
});

# Mojolicious::Lite
plugin XML::Loy => {
  new_activity => [-Atom, -ActivityStreams]
};

# In your config file
{
  XML::Loy => {
    new_activity => [-Atom, -ActivityStreams]
  }
};

Called when registering the plugin. Accepts new xml profiles, defined by the name of the associated generation helper and an array reference defining the profile. The first element in the array is the base class, followed by all extensions. To create a helper extending the base class, use -Loy as the first element.

$mojo->plugin('XML::Loy' => {
  new_myXML => [-Loy, 'MyXML::Loy::Extension']
});

In addition to that, the max_size in bytes of xml documents to be parsed can be defined (defaults to 1024 * 1024).

All parameters can be set either as part of the configuration file with the key XML-Loy or on registration (that can be overwritten by configuration).

HELPERS

new_xml

my $xml = $c->new_xml('entry');
print $xml->to_pretty_xml;

Creates a new generic XML::Loy document. All helpers created on registration accept the parameters as defined in the constructors of the XML::Loy base classes.

reply->xml

$c->reply->xml($xml);
$c->reply->xml($xml, status => 404);

Renders documents based on XML::Loy using the defined mime-type of the base class.

DEPENDENCIES

Mojolicious, XML::Loy.

AVAILABILITY

https://github.com/Akron/Mojolicious-Plugin-XML-Loy

COPYRIGHT AND LICENSE

Copyright (C) 2011-2016, Nils Diewald.

This program is free software, you can redistribute it and/or modify it under the terms of the Artistic License version 2.0.