XML::OPDS - OPDS (Open Publication Distribution System) feed creation
Version 0.06
This module facilitates the creation of OPDS feeds.
The specifications can be found at http://opds-spec.org/ while the validator is at http://opds-validator.appspot.com/.
The idea is that it should be enough to pass the navigation links and the title entries with some data, and have the feed back.
The OPDS feeds are basically Atom feeds, hence this module uses XML::Atom under the hood.
Some features are not supported yet, but patches are welcome. Also keep in mind that the applications which are supposed to talk to your server have a level of support which varies from decent to "keep crashing".
This is still very much a work in progress, but it's already generating valid and usable catalogs.
use XML::OPDS; my $feed = XML::OPDS->new(prefix => 'http://amusewiki.org'); # add two links, self and start are mandatory. $feed->add_to_navigations( rel => 'self', title => 'Root', href => '/', ); $feed->add_to_navigations( rel => 'start', title => 'Root', href => '/', ); # add a navigation for the title list, marking as leaf, where the # download links can be retrieved. $feed->add_to_navigations( title => 'Titles', description => 'texts sorted by title', href => '/titles', acquisition => 1, ); # and render print $feed->render; # you can reuse the object for leaf feeds (i.e. the acquistion # feeds), pushing another self navigation, which will replace the # previous one. $feed->add_to_navigations( rel => 'self', title => 'Titles', description => 'texts sorted by title', href => '/titles', ); # or, implicitely setting the self rel and cleaning the navigation # stash, keeping the meta $feed->add_to_navigations_new_level( title => 'Titles', acquisition => 1, href => '/titles', ); $feed->add_to_acquisitions( href => '/my/title', title => 'My title', files => [ '/my/title.epub' ], ); # and here we have an acquisition feed, because of the presence of # the acquisition. print $feed->render;
Even if the module wants characters as input (decoded strings, not bytes), the output XML is an UTF-8 encoded string.
Arrayref of XML::OPDS::Navigation objects. An object with a rel self (the feed itself) and one with the rel start (the root feed) are mandatory. If not present, the module will crash while rendering the feed.
self
start
Arrayref of XML::OPDS::Acquisition objects. If one or more objects are present, the feed will become an acquistion feed.
The producer of the feed. Defaults to this class name and version.
The uri of the author. Defaults to http://amusewiki.org (which is the home of this class).
Default to the empty string. On instances of this class, by itself has no effect. However, when calling add_to_acquisitions and add_to_navigations, it will be passed to the constructors of those objects.
add_to_acquisitions
add_to_navigations
This is usually the hostname of the OPDS server. So you need just to pass, e.g. 'http://amusewiki.org' and have all the links prefixed by that (no slash mangling or adding is performed). If you are going to pass the full urls, leave it at the default.
Default to current timestamp. When calling create_navigation or create_acquistion, use this timestamp as default.
create_navigation
create_acquistion
The feed logo. If prefix is set, prepend it.
The feed icon. If prefix is set, prepend it.
Return the generated xml.
Return the XML::Atom::Feed object.
Create a XML::OPDS::Navigation object inheriting the prefix.
Create a XML::OPDS::Acquisition object inheriting the prefix.
Call create_navigation and add it to the navigations stack.
navigations
Like add_to_navigations, but it's meant to be used for rel:self elements.
rel:self
The rel:self attribute is injected in the arguments which are passed to create_navigation.
If a navigation with the attribute rel set to self was already present in the stack, the new one will become the new self, while the old one will become an up rel.
rel
up
Also, this will remove any existing navigation with the rel attribute set to subsection, given that you are creating a new level.
subsection
This is designed to play well with chained actions (so you can reuse the object, stack selfs, and the result will be correct).
Call create_acquisition and add it to the acquisition stack.
create_acquisition
acquisition
Return a list of XML::OPDS::Navigation objects excluding unique relationships like self, start, up, previous, next, first, last.
previous
next
first
last
Return an hashref, where the keys are the rel attributes of the navigation objects. The value is an object if the navigation is meant to be unique, or an arrayref of objects if not so.
Return true if there are acquisition objects stacked.
The following attributes can be set if you are building an Atom response for OpenSearch. See XML::OPDS::OpenSearch::Query for a concrete example.
A Data::Page object with the specification of the pages.
A string with the query for which you are serving the results.
Additional Query elements, should be an arrayref of XML::OPDS::OpenSearch::Query objects.
Marco Pessotto, <melmothx at gmail.com>
<melmothx at gmail.com>
Please report any bugs or feature requests to bug-xml-opds at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=XML-OPDS. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
bug-xml-opds at rt.cpan.org
You can find documentation for this module with the perldoc command.
perldoc XML::OPDS
You can also look for information at:
RT: CPAN's request tracker (report bugs here)
http://rt.cpan.org/NoAuth/Bugs.html?Dist=XML-OPDS
MetaCPAN
http://metacpan.org/pod/XML::OPDS
Copyright 2016 Marco Pessotto.
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.
To install XML::OPDS, copy and paste the appropriate command in to your terminal.
cpanm
cpanm XML::OPDS
CPAN shell
perl -MCPAN -e shell install XML::OPDS
For more information on module installation, please visit the detailed CPAN module installation guide.