AxKit-App-TABOO
view release on metacpan or search on metacpan
lib/AxKit/App/TABOO/XSP/Category.pm view on Meta::CPAN
package AxKit::App::TABOO::XSP::Category;
use 5.6.0;
use strict;
use warnings;
use Apache::AxKit::Language::XSP::SimpleTaglib;
use Apache::AxKit::Exception;
use AxKit;
use AxKit::App::TABOO;
use AxKit::App::TABOO::Data::Category;
use AxKit::App::TABOO::Data::Plurals::Categories;
use Session;
use Time::Piece ':override';
use XML::LibXML;
use vars qw/$NS/;
our $VERSION = '0.4';
=head1 NAME
AxKit::App::TABOO::XSP::Category - Category management tag library for TABOO
=head1 SYNOPSIS
Add the category: namespace to your XSP C<E<lt>xsp:pageE<gt>> tag, e.g.:
<xsp:page
language="Perl"
xmlns:xsp="http://apache.org/xsp/core/v1"
xmlns:category="http://www.kjetil.kjernsmo.net/software/TABOO/NS/Category"
>
Add this taglib to AxKit (via httpd.conf or .htaccess):
AxAddXSPTaglib AxKit::App::TABOO::XSP::Category
=head1 DESCRIPTION
This XSP taglib provides two tags to retrieve a structured XML
fragment with all information of a single category or all categories
of a certain type.
L<Apache::AxKit::Language::XSP::SimpleTaglib> has been used to write
this taglib.
=cut
$NS = 'http://www.kjetil.kjernsmo.net/software/TABOO/NS/Category';
sub _sanatize_catname {
my $tmp = lc shift;
$tmp =~ tr/a-z/_/cs;
return $tmp;
}
package AxKit::App::TABOO::XSP::Category::Handlers;
=head1 Tag Reference
=head2 C<E<lt>get-category catname="foo"/E<gt>>
This tag will replace itself with some structured XML containing all
fields of categories of type C<foo>. It relates to the TABOO Data
object L<AxKit::App::TABOO::Data::Category>, and calls on that to do
the hard work.
The root element of the returned object is C<cat:categories> and each
category is wrapped in an element C<cat:category> and contains C<catname>
and C<name>.
=cut
sub get_category : struct attribOrChild(catname) {
return << 'EOC'
my $cat = AxKit::App::TABOO::Data::Category->new();
$cat->load(limit => {catname => $attr_catname});
my $doc = XML::LibXML::Document->new();
my $root = $doc->createElementNS('http://www.kjetil.kjernsmo.net/software/TABOO/NS/Category/Output', 'cat:categories');
$doc->setDocumentElement($root);
$doc = $cat->write_xml($doc, $root);
$doc;
EOC
}
=head2 C<E<lt>get-categories type="foo" onlycontent="true"/E<gt>>
This tag will replace itself with some structured XML containing all
categories of type C<foo>. It relates to the TABOO Data object
L<AxKit::App::TABOO::Data::Plurals::Categories>, and calls on that to
do the hard work. See the documentation of that class to see the
available types. If a boolean C<onlycontent> attribute (or child
element) is set, it will check if there are articles or stories in the
C<categ> category types, and return only those.
The root element of the returned object is C<categories> and each
( run in 1.591 second using v1.01-cache-2.11-cpan-b16cb0d3907 )