| XML-Feed-Format-hAtom documentation | Contained in the XML-Feed-Format-hAtom distribution. |
XML::Feed::Format::hAtom - plugin to provide transparent parsing and generation support for hAtom to XML::Feed
use XML::Feed;
my $feed = XML::Feed->parse(URI->new('http://example.com/hatom.html'))
or die XML::Feed->errstr;
print $feed->title, "\n";
for my $entry ($feed->entries) {
}
XML::Feed is a syndication feed parser for both RSS and Atom feeds. It also implements feed auto-discovery for finding feeds, given a URI.
XML::Feed::Format::hAtom adds transparent support for the hAtom microformat.
http://microformats.org/wiki/hatom
See XML::Feed and XML::Feed::Entry - hAtom support is transparent.
Whether or not this in hAtom feed.
Initialise a new Feed from a string.
Alias for parse.
Returns the id of the feed.
Returns the format of the feed (hAtom).
The title of the feed/channel.
The url base of the feed/channel.
The permalink of the feed/channel.
The description or tagline of the feed/channel.
Alias for $feed->tagline.
The language of the feed.
The copyright notice of the feed.
A DateTime object representing the last-modified date of the feed.
If present, $modified should be a DateTime object.
Alias for modified.
The generator of the feed.
The category for this feed.
The Atom Self-link of the feed:
http://validator.w3.org/feed/docs/warning/MissingAtomSelfLink.html
A string.
The longitude and latitude of the entry if available.
A list of the entries/items in the feed. Returns an array containing XML::Feed::Entry objects.
A synonym for $feed-entries>.
Adds an entry to the feed. $entry should be an XML::Feed::Entry object in the correct format for the feed.
Returns an HTML representation of the feed, in the format determined by the current format of the $feed object.
XML::Feed::Format::hAtom is free software; you may redistribute it and/or modify it under the same terms as Perl itself.
Written by Simon Wistow <swistow@sixapart.com>
Except where otherwise noted, XML::Feed::Format::hAtom is Copyright 2008 Six Apart, cpan@sixapart.com. All rights reserved.
The latest version of XML::Feed::Format::hAtom can be found at
http://code.sixapart.com/svn/XML-Feed-Format-hAtom/trunk/
| XML-Feed-Format-hAtom documentation | Contained in the XML-Feed-Format-hAtom distribution. |
package XML::Feed::Format::hAtom; use strict; use base qw( XML::Feed ); use Data::Microformat::hFeed; use Data::Microformat::hCard; use Data::Microformat::geo; our $VERSION = "0.5"; sub identify { my $class = shift; my $xml = shift; my $tag = $class->_get_first_tag($xml); return ($tag eq 'html'); } sub init_empty { my ($feed, %args) = @_; $feed->{hatom} = Data::Microformat::hFeed->new(%args); $feed; } sub init_string { my $feed = shift; my ($str) = @_; if ($str) { eval { $feed->{hatom} = Data::Microformat::hFeed->parse($str) }; return $feed->error($@) if $@; } $feed; } sub format { 'hAtom' } sub tagline { shift->{hatom}->tagline(@_) } sub description { shift->{hatom}->tagline(@_) } sub title { shift->{hatom}->title(@_) } sub link { shift->{hatom}->link(@_) } sub self_link { shift->{hatom}->link(@_) } sub generator { shift->{hatom}->generator(@_) } sub id { shift->{hatom}->id(@_) } sub updated { shift->{hatom}->modified(@_) } sub modified { shift->{hatom}->modified(@_) } sub copyright { my $feed = shift; if (@_ && defined $_[0]) { $feed->{hatom}->copyright({ text => $_[0] }); } else { $feed->{hatom}->copyright ? $feed->{hatom}->copyright->{text} : undef; } } sub lat { shift->_do_geo('longitude', @_) } sub long { shift->_do_geo('longitude', @_) } sub _do_geo { my $thing = shift; my $what = shift; my $geo = $thing->geo; if (@_ && defined $_[0]) { $geo = Data::Microformat::geo->new unless defined $geo; $geo->$what($_[0]); $thing->geo($geo); } elsif (defined $geo) { return $geo->$what; } else { return undef; } } sub category { shift->{hatom}->categories(@_) } sub language { shift->{hatom}->language(@_) } # TODO # add_link sub author { my $feed = shift; if (@_ && defined $_[0]) { my $person = Data::Microformat::hCard->new; $person->fn($_[0]); $feed->{hatom}->author($person); } else { $feed->{hatom}->author ? $feed->{hatom}->author->fn : undef; } } sub entries { my @entries; for my $entry ($_[0]->{hatom}->entries) { push @entries, XML::Feed::Entry::Format::hAtom->wrap($entry); } @entries; } sub add_entry { my $feed = shift; my $entry = shift || return; $entry = $feed->_convert_entry($entry); $feed->{hatom}->entries($entry->{entry}); } sub as_xml { shift->{hatom}->to_html } package XML::Feed::Entry::Format::hAtom; use strict; use base qw( XML::Feed::Entry ); use XML::Feed::Content; use Data::Microformat::hFeed::hEntry; use Data::Microformat::geo; use HTML::Entities; sub init_empty { my $entry = shift; $entry->{entry} = Data::Microformat::hFeed::hEntry->new; $entry; } sub title { shift->{entry}->title(@_) } sub source { shift->{entry}->source(@_) } sub updated { shift->{entry}->updated(@_) } sub base { shift->{entry}->base(@_) } sub link { shift->{entry}->link(@_) } sub id { shift->{entry}->id(@_) } sub issued { shift->{entry}->issued(@_) } sub modified { shift->{entry}->modified(@_) } sub lat { shift->_do_geo('longitude', @_) } sub long { shift->_do_geo('longitude', @_) } sub _do_geo { my $thing = shift; my $what = shift; my $geo = $thing->{entry}->geo; if (@_ && defined $_[0]) { $geo = Data::Microformat::geo->new unless defined $geo; $geo->$what($_[0]); $thing->geo($geo); } elsif (defined $geo) { return $geo->$what; } else { return undef; } } sub summary { shift->_do_text('summary', @_) } sub content { shift->_do_text('content', @_) } sub _do_text { my $entry = shift; my $field = shift; if (@_ && defined $_[0]) { if (ref($_[0]) eq 'XML::Feed::Content') { my $content = (defined $_[0]->type && $_[0]->type eq 'text/plain') ? encode_entities($_[0]->body) : $_[0]->body; $entry->{entry}->$field($content); } else { $entry->{entry}->$field($_[0]); } } else { return XML::Feed::Content->new({ type => 'text/html', body => $entry->{entry}->$field }); } } sub category { shift->{entry}->tags(@_) } sub author { my $entry = shift; if (@_ && $_[0]) { my $person = Data::Microformat::hCard->new; $person->fn($_[0]); $entry->{entry}->author($person); } else { $entry->{entry}->author ? $entry->{entry}->author->fn : undef; } } sub as_xml { shift->{entry}->to_html } 1; __END__