X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FXML%2FFeed%2FFormat%2FAtom.pm;h=b0a85549161cb497b8d0e1f9418f9f37fd84d16e;hb=89495df995ce2f594394238fa924ad985c59b935;hp=4e2d8592e88062d7009522e6fa83f149c6776757;hpb=12a4079ff02b376f0e9ff793137e9e35d8ea7645;p=catagits%2FXML-Feed.git diff --git a/lib/XML/Feed/Format/Atom.pm b/lib/XML/Feed/Format/Atom.pm index 4e2d859..b0a8554 100644 --- a/lib/XML/Feed/Format/Atom.pm +++ b/lib/XML/Feed/Format/Atom.pm @@ -1,4 +1,4 @@ -# $Id: Atom.pm 1958 2006-08-14 05:31:27Z btrott $ +# $Id$ package XML::Feed::Format::Atom; use strict; @@ -8,6 +8,7 @@ use XML::Atom::Feed; 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#']); @@ -196,15 +197,25 @@ sub content { 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; @@ -228,10 +239,16 @@ sub category { 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]; } } @@ -293,15 +310,16 @@ sub enclosure { 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]; } }