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


  # Mojolicious
    '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');

    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

  # 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

  # Render document with the correct mime-type

  # Content-Type: application/xrd+xml
  # <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
  # <XRD xmlns=""
  #      xmlns:hm=""
  #      xmlns:xsi="">
  #   <hm:Host></hm:Host>
  # </XRD>


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


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


  # 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).



  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.


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

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


Mojolicious, XML::Loy.



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.