use List::Util qw( first );
use DateTime::Format::W3CDTF;
+use XML::Atom::Entry;
+XML::Atom::Entry->mk_elem_accessors(qw( lat long ), ['http://www.w3.org/2003/01/geo/wgs84_pos#']);
+
sub init_empty {
my ($feed, %args) = @_;
$args{'Version'} ||= '1.0';
$l ? $l->href : undef;
}
}
+
+sub self_link {
+ my $feed = shift;
+ if (@_) {
+ my $uri = shift;
+ $feed->{atom}->add_link({type => "application/atom+xml", rel => "self", href => $uri});
+ return $uri;
+ }
+ else
+ {
+ my $l =
+ first
+ { !defined $_->rel || $_->rel eq 'self' }
+ $feed->{atom}->link;
+ ;
+
+ return $l ? $l->href : undef;
+ }
+}
+
sub description { shift->{atom}->tagline(@_) }
sub copyright { shift->{atom}->copyright(@_) }
sub language { shift->{atom}->language(@_) }
}
sub add_entry {
- my $feed = shift;
- my($entry) = @_;
+ my $feed = shift;
+ my $entry = shift || return;
+ $entry = $feed->_convert_entry($entry);
$feed->{atom}->add_entry($entry->unwrap);
}
sub summary {
my $entry = shift;
if (@_) {
- $entry->{entry}->summary(ref($_[0]) eq 'XML::Feed::Content' ?
- $_[0]->body : $_[0]);
+ my %param;
+ if (ref($_[0]) eq 'XML::Feed::Content') {
+ %param = (Body => $_[0]->body);
+ } else {
+ %param = (Body => $_[0]);
+ }
+ $entry->{entry}->summary(XML::Atom::Content->new(%param, Version => 1.0));
} else {
- XML::Feed::Content->wrap({ type => 'html',
- body => $entry->{entry}->summary });
+ my $s = $entry->{entry}->summary;
+ # map Atom types to MIME types
+ my $type = ($s && ref($s) eq 'XML::Feed::Content') ? $s->type : undef;
+ if ($type) {
+ $type = 'text/html' if $type eq 'xhtml' || $type eq 'html';
+ $type = 'text/plain' if $type eq 'text';
+ }
+ my $body = $s;
+ if (defined $s && ref($s) eq 'XML::Feed::Content') {
+ $body = $s->body;
+ }
+ XML::Feed::Content->wrap({ type => $type,
+ body => $body });
}
}
+my %types = (
+ 'text/xhtml' => 'xhtml',
+ 'text/html' => 'html',
+ 'text/plain' => 'text',
+);
+
sub content {
my $entry = shift;
if (@_) {
my %param;
if (ref($_[0]) eq 'XML::Feed::Content') {
- %param = (Body => $_[0]->body, Type => ($_[0]->type eq 'text/html')? 'html' : 'text');
+ if (defined $_[0]->type && defined $types{$_[0]->type}) {
+ %param = (Body => $_[0]->body, Type => $types{$_[0]->type});
+ } else {
+ %param = (Body => $_[0]->body);
+ }
} else {
%param = (Body => $_[0]);
}
}
}
+sub lat {
+ my $entry = shift;
+ if (@_) {
+ $entry->{entry}->lat($_[0]) if $_[0];
+ } else {
+ $entry->{entry}->lat;
+ }
+}
+
+sub long {
+ my $entry = shift;
+ if (@_) {
+ $entry->{entry}->long($_[0]) if $_[0];
+ } else {
+ $entry->{entry}->long;
+ }
+}
+
1;