}
-sub add_enclosure {
- my($entry, $enclosure) = @_;
- my $link = XML::Atom::Link->new;
- $link->rel('enclosure');
- $link->type($enclosure->type);
- $link->href($enclosure->url);
- $link->length($enclosure->length);
- $entry->{entry}->add_link($link);
-};
+sub enclosure {
+ my $entry = shift;
+
+ if (@_) {
+ my $enclosure = shift;
+ # TODO Atom can have multiple enclosures
+ $entry->{entry}->link({ 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 });
+ }
+}
1;