XML::RAI::Item - An interface to the item elements of a RSS feed.


XML-RAI documentation Contained in the XML-RAI distribution.

Index


Code Index:


XML-RAI documentation Contained in the XML-RAI distribution.

# Copyright (c) 2004-2009 Timothy Appnel
# http://appnel.com/
# This code is released under the Artistic License.
#
# XML::RAI::Item - an interface to the item elements in a RSS feed.
#

package XML::RAI::Item;

use strict;
use XML::RAI::Object;

use vars qw(@ISA $XMap);
@ISA = qw( XML::RAI::Object );

$XMap = {
    'format' => ['dc:format'],

#'link'=>['link','@rdf:about','guid[@isPermaLink="true"]'], # use special handler.
    abstract       => ['dcterms:abstract', 'description', 'dc:description'],
    content_strict => ['xhtml:body',       'xhtml:div',   'content:encoded'],
    content        => [
        'xhtml:body',      'xhtml:div',
        'content:encoded', 'description',
        'dc:description',  'rss091:description'
    ],
    contentstrict => ['xhtml:body', 'xhtml:div', 'content:encoded']
    ,    # deprecated
    contributor    => ['dc:contributor'],
    coverage       => ['dc:coverage'],
    created_strict => ['dcterms:created'],
    created => ['dcterms:created', 'dc:date', 'pubDate', 'rss091:pubDate'],
    creator     => ['dc:creator',  'author'],
    description => ['description', 'dc:description', 'dcterms:abstract'],
    identifier =>
      ['dc:identifier/@rdf:resource', 'dc:identifier', 'guid', 'link'],
    issued_strict => ['dcterms:issued'],
    issued   => ['dcterms:issued', 'dc:date', 'pubDate', 'rss091:pubDate'],
    language => [
        '@xml:lang',         'dc:language',
        '/@xml:lang',        '/channel/dc:language',
        '/channel/language', '/channel/rss091:language'
    ],
    modified_strict => ['dcterms:modified'],
    modified => ['dcterms:modified', 'dc:date', 'pubDate', 'rss091:pubDate'],
    ping      => ['trackback:ping/@rdf:resource',  'trackback:ping'],
    pinged    => ['trackback:about/@rdf:resource', 'trackback:about'],
    publisher => [
        'dc:publisher',            '/channel/dc:publisher',
        '/channel/managingEditor', '/channel/rss091:managingEditor'
    ],
    relation => ['dc:relation/@rdf:resource', 'dc:relation'],
    rights   => [
        'dc:rights',                        '/channel/copyright',
        '/channel/creativeCommons:license', '/channel/rss091:copyright'
    ],
    source  => ['dc:source',  'source/@url', 'source'],
    subject => ['dc:subject', 'category'],
    title   => ['title',      'dc:title'],
    type    => ['dc:type'],
    valid => ['dcterms:valid', 'expirationDate']
};

# Class::XPath is missing some functionality we need here so we
# help it along.
sub link {
    my $this = shift;
    my @nodes;

    # awkward use, but achieves the effect we need.
    if    (@nodes = $this->src->query('link'))       { }
    elsif (@nodes = $this->src->query('@rdf:about')) { }
    elsif (
        @nodes = grep {
            !$_->attributes
              || (!$_->attributes->{isPermaLink}
                || $_->attributes->{isPermaLink} eq 'true')
        } $this->src->query('guid')
      )
    {
    }
    elsif (
        @nodes = grep {
            $_->attributes->{type} =~ m!^(text/html|application/xhtml+xml)$!
        } $this->src->query('l:link[@rel="permalink"]')
      )
    {
    }
    elsif (@nodes = $this->src->query('comment')) {
    }
    my @n = map { ref($_) ? $_->text_content : $_ } @nodes;
    wantarray ? @n : $n[0];
}

1;

__END__