Thread

Posted on Mon Feb 26 14:02:42 2007 by jtalbot
Does this do enclosures?
Does this module recognize enclosures? In the module instructions there's no such mention, so if there is could you please add it in the pod, and if not could you please add the functionality? Thx
Direct Responses: 6860 | Write a response
Posted on Sat Jan 12 16:56:01 2008 by martinw in response to 4428
Re: Does this do enclosures?
Hi jtalbot, at this time (version: 0.12) the XML::Feed module does not support enclosures out of the box. While I need this feature too, I've extendes the module. Patch to XML-Feed-0.12:
diff -u -r XML-Feed-0.12/lib/XML/Feed/Entry.pm XML-Feed-0.12.1/lib/XML/Feed/Entry.pm --- XML-Feed-0.12/lib/XML/Feed/Entry.pm 2005-08-12 06:28:43.000000000 +0200 +++ XML-Feed-0.12.1/lib/XML/Feed/Entry.pm 2008-01-12 15:17:22.000000000 +0100 @@ -32,7 +32,7 @@ my $entry = shift; my($format) = @_; my $new = __PACKAGE__->new($format); - for my $field (qw( title link content summary category author id issued modified )) { + for my $field (qw( title link content summary category author id issued modified enclosure)) { my $val = $entry->$field(); next unless defined $val; $new->$field($val); diff -u -r XML-Feed-0.12/lib/XML/Feed/RSS.pm XML-Feed-0.12.1/lib/XML/Feed/RSS.pm --- XML-Feed-0.12/lib/XML/Feed/RSS.pm 2006-04-22 07:13:55.000000000 +0200 +++ XML-Feed-0.12.1/lib/XML/Feed/RSS.pm 2008-01-12 16:18:16.000000000 +0100 @@ -138,6 +138,13 @@ } } +sub enclosure +{ + my $entry = shift; + @_ ? $entry->{entry}{enclosure} = $_[0] : $entry->{entry}{enclosure}; + bless $entry->{entry}{enclosure}, 'XML::Feed::Entry::RSS::Enclosure'; +} + sub summary { my $item = shift->{entry}; if (@_) { @@ -242,4 +249,10 @@ } } +package XML::Feed::Entry::RSS::Enclosure; + +sub length { shift->{length}; } +sub url { shift->{url}; } +sub type { shift->{type}; } + 1; diff -u -r XML-Feed-0.12/lib/XML/Feed.pm XML-Feed-0.12.1/lib/XML/Feed.pm --- XML-Feed-0.12/lib/XML/Feed.pm 2006-08-14 07:31:28.000000000 +0200 +++ XML-Feed-0.12.1/lib/XML/Feed.pm 2008-01-12 16:18:55.000000000 +0100 @@ -97,7 +97,7 @@ my $feed = shift; my($format) = @_; my $new = __PACKAGE__->new($format); - for my $field (qw( title link description language author copyright modified generator )) { + for my $field (qw( title link description language author copyright modified generator)) { my $val = $feed->$field(); next unless defined $val; $new->$field($val);
Write a response