-# $Id: Atom.pm 1958 2006-08-14 05:31:27Z btrott $
+# $Id$
package XML::Feed::Format::Atom;
use strict;
use XML::Atom::Util qw( iso2dt );
use List::Util qw( first );
use DateTime::Format::W3CDTF;
+use HTML::Entities;
use XML::Atom::Entry;
XML::Atom::Entry->mk_elem_accessors(qw( lat long ), ['http://www.w3.org/2003/01/geo/wgs84_pos#']);
if (@_) {
my %param;
my $base;
+ my $orig_body;
if (ref($_[0]) eq 'XML::Feed::Content') {
- if (defined $_[0]->type && defined $types{$_[0]->type}) {
- %param = (Body => $_[0]->body, Type => $types{$_[0]->type});
- } else {
- %param = (Body => $_[0]->body);
- }
+ $orig_body = $_[0]->body;
+ if (defined $_[0]->type && defined $types{$_[0]->type}) {
+ %param = (Body => $orig_body, Type => $types{$_[0]->type});
+
+ if ($param{Type} eq 'html') {
+ $param{Body} = HTML::Entities::encode_entities($param{Body});
+ }
+ } else {
+ # %param = (Body => $_[0]->body);
+ }
$base = $_[0]->base if defined $_[0]->base;
} else {
- %param = (Body => $_[0]);
+ $orig_body = $_[0];
+ # %param = (Body => $_[0]);
+ }
+ if (!exists $param{Body}) {
+ $param{Body} = $orig_body;
}
$entry->{entry}->content(XML::Atom::Content->new(%param, Version => 1.0));
$entry->{entry}->content->base($base) if defined $base;
my $entry = shift;
my $ns = XML::Atom::Namespace->new(dc => 'http://purl.org/dc/elements/1.1/');
if (@_) {
- $entry->{entry}->add_category({ term => $_[0] });
+ $entry->{entry}->add_category({ term => $_ }) for @_;
+ return 1
} else {
- my $category = $entry->{entry}->category;
- my @return = $category ? ($category->label || $category->term) : $entry->{entry}->getlist($ns, 'subject');
+
+
+ my @category = ($entry->{entry}->can('categories')) ? $entry->{entry}->categories : $entry->{entry}->category;
+ my @return = @category
+ ? (map { $_->label || $_->term } @category)
+ : $entry->{entry}->getlist($ns, 'subject');
+
return wantarray? @return : $return[0];
}
}
if (@_) {
my $enclosure = shift;
- # TODO Atom can have multiple enclosures
- $entry->{entry}->link({ rel => 'enclosure', href => $enclosure->{url},
+ my $method = ($XML::Feed::MULTIPLE_ENCLOSURES)? 'add_link' : 'link';
+ $entry->{entry}->$method({ rel => 'enclosure', href => $enclosure->{url},
length => $enclosure->{length},
type => $enclosure->{type} });
return 1;
} else {
- my $l = first { defined $_->rel && $_->rel eq 'enclosure' } $entry->{entry}->link;
- return undef unless $l;
- return XML::Feed::Enclosure->new({ url => $l->href, length => $l->length, type => $l->type });
+ my @links = grep { defined $_->rel && $_->rel eq 'enclosure' } $entry->{entry}->link;
+ return undef unless @links;
+ my @encs = map { XML::Feed::Enclosure->new({ url => $_->href, length => $_->length, type => $_->type }) } @links ;
+ return ($XML::Feed::MULTIPLE_ENCLOSURES)? @encs : $encs[-1];
}
}