-
-
01 Nov 2018 14:46:09 UTC
- Distribution: Mojolicious-Plugin-XML-Loy
- Module version: 0.15
- Source (raw)
- Browse (raw)
- Changes
- How to Contribute
- Repository
- Issues
- Testers (1517 / 0 / 9)
- Kwalitee
Bus factor: 1- 86.15% Coverage
- License: artistic_2
- Perl: v5.10.1
- Activity
24 month- Tools
- Download (9.45KB)
- MetaCPAN Explorer
- Permissions
- Subscribe to distribution
- Permalinks
- This version
- Latest version
- Dependencies
- Mojolicious
- XML::Loy
- and possibly others
- Reverse dependencies
- CPAN Testers List
- Dependency graph
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 to1024 * 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
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.
Module Install Instructions
To install Mojolicious::Plugin::XML::Loy, copy and paste the appropriate command in to your terminal.
cpanm Mojolicious::Plugin::XML::Loy
perl -MCPAN -e shell install Mojolicious::Plugin::XML::Loy
For more information on module installation, please visit the detailed CPAN module installation guide.