=== t/2.0-generate.t
==================================================================
--- t/2.0-generate.t (revision 444)
+++ t/2.0-generate.t (revision 445)
@@ -84,9 +84,6 @@
enclosure => { type=>"application/x-bittorrent", url => '
http://127.0.0.1/torrents/The_Passion_of_Dave_Winer.torrent' },
), "Set one RSS item" );
-my $len = length($rss->as_string());
-ok( $len, "RSS feed has '$len' characters" );
-
ok( $rss->add_module( prefix => RSS_MOD_PREFIX, uri => RSS_MOD_URI ),
"Added module: " . RSS_MOD_PREFIX );
@@ -97,6 +94,9 @@
is( $rss->{modules}->{$uri}, RSS_MOD_PREFIX, "Namespace URI is " . RSS_MOD_URI);
+my $len = length($rss->as_string());
+ok( $len, "RSS feed has '$len' characters" );
+
ok( $rss->save(RSS_SAVEAS), "Wrote to disk: " . RSS_SAVEAS );
my $size = -s (RSS_SAVEAS);
@@ -163,4 +163,4 @@
http://backend.userland.com/rss2
-=cu
\ No newline at end of file
+=cu
=== t/test_manifest
==================================================================
--- t/test_manifest (revision 444)
+++ t/test_manifest (revision 445)
@@ -11,6 +11,7 @@
1.0-parse.t
1.0-parse-exotic.t
2.0-generate.t
+2.0-modules.t
2.0-permalink.t
2.0-parse.t
2.0-wo-title.t
=== t/2.0-modules.t
==================================================================
--- t/2.0-modules.t (revision 444)
+++ t/2.0-modules.t (revision 445)
@@ -0,0 +1,17 @@
+#!/usr/bin/perl -w
+use strict;
+
+use Test::More tests => 1;
+use XML::RSS;
+
+my $rss = XML::RSS->new( version => '2.0' );
+$rss->add_module(
+ prefix => 'content',
+ uri => '
http://purl.org/rss/1.0/modules/content/'
+ );
+$rss->add_item(
+ title => 'title',
+ content => { encoded => 'this is content' },
+ );
+
+like $rss->as_string, qr/this is content/;
=== MANIFEST
==================================================================
--- MANIFEST (revision 444)
+++ MANIFEST (revision 445)
@@ -36,6 +36,7 @@
t/1.0-parse.t
t/1.0-to-2.0.t
t/2.0-generate.t
+t/2.0-modules.t
t/2.0-parse.t
t/2.0-permalink.t
t/2.0-wo-title.t
=== lib/XML/RSS.pm
==================================================================
--- lib/XML/RSS.pm (revision 444)
+++ lib/XML/RSS.pm (revision 445)
@@ -420,6 +420,14 @@
};
}
+sub _get_default_rss_2_0_modules
+{
+ return
+ {
+ '
http://backend.userland.com/blogChannelModule' => 'blogChannel',
+ };
+}
+
sub new {
my $class = shift;
@@ -460,18 +468,23 @@
$self->{namespaces} = {};
$self->{rss_namespace} = '';
+ #get version info
+ (exists($hash{version}))
+ ? ($self->{version} = $hash{version})
+ : ($self->{version} = '1.0');
+
# modules
- $self->{modules} = $self->_get_default_modules();
+ $self->{modules} =
+ (($self->{version} eq "2.0") ?
+ $self->_get_default_rss_2_0_modules() :
+ $self->_get_default_modules()
+ );
# encode output from as_string?
(exists($hash{encode_output}))
? ($self->{encode_output} = $hash{encode_output})
: ($self->{encode_output} = 1);
- #get version info
- (exists($hash{version}))
- ? ($self->{version} = $hash{version})
- : ($self->{version} = '1.0');
# set default output
(exists($hash{output}))
@@ -1274,7 +1287,17 @@
# RSS root element
# $output .= '<rss version="0.91">'."\n\n";
- $output .= '<rss version="2.0" xmlns:blogChannel="
http://backend.userland.com/blogChannelModule">' . "\n\n";
+
+ # RSS namespaces declaration
+ $output .="<rss\n";
+ $output .=' version="2.0"'."\n";
+
+ # print all imported namespaces
+ while (my($k, $v) = each %{$self->{modules}}) {
+ $output.=" xmlns:$v=\"$k\"\n";
+ }
+
+ $output .=">"."\n\n";
###################
# Channel Element #
@@ -1342,8 +1365,23 @@
$output .= '<ttl>'.$self->_encode($self->{channel}->{ttl}).'</ttl>'."\n";
}
+ # Ad-hoc modules
+ while ( my($url, $prefix) = each %{$self->{modules}} ) {
+ next if $prefix =~ /^(dc|syn|taxo)$/;
+ while ( my($el, $value) = each %{$self->{channel}->{$prefix}} ) {
+ if ( exists( $rdf_resource_fields{ $url } ) and
+ exists( $rdf_resource_fields{ $url }{ $el }) )
+ {
+ $output .= "<$prefix:$el rdf:resource=\"" .
+ $self->_encode($value) .
+ "\" />\n";
+ }
+ else {
+ $output .= "<$prefix:$el>". $self->_encode($value) ."</$prefix:$el>\n";
+ }
+ }
+ }
-
$output .= "\n";
#################
@@ -1362,6 +1400,23 @@
[qw(link width height description)]
);
+ # Ad-hoc modules for images
+ while ( my($url, $prefix) = each %{$self->{modules}} ) {
+ next if $prefix =~ /^(dc|syn|taxo)$/;
+ while ( my($el, $value) = each %{$self->{image}->{$prefix}} ) {
+ if ( exists( $rdf_resource_fields{ $url } ) and
+ exists( $rdf_resource_fields{ $url }{ $el }) )
+ {
+ $output .= qq{<$prefix:$el rdf:resource="} .
+ $self->_encode($value) .
+ qq{" />\n};
+ }
+ else {
+ $output .= "<$prefix:$el>". $self->_encode($value) ."</$prefix:$el>\n";
+ }
+ }
+ }
+
# end image element
$output .= '</image>'."\n\n";
}
@@ -1403,6 +1458,23 @@
. ' />' . "\n";
}
+ # Ad-hoc modules
+ while ( my($url, $prefix) = each %{$self->{modules}} ) {
+ next if $prefix =~ /^(dc|syn|taxo)$/;
+ while ( my($el, $value) = each %{$item->{$prefix}} ) {
+ if ( exists( $rdf_resource_fields{ $url } ) and
+ exists( $rdf_resource_fields{ $url }{ $el }) )
+ {
+ $output .= "<$prefix:$el rdf:resource=\"" .
+ $self->_encode($value) .
+ "\" />\n";
+ }
+ else {
+ $output .= "<$prefix:$el>". $self->_encode($value) ."</$prefix:$el>\n";
+ }
+ }
+ }
+
# end image element
$output .= '</item>'."\n\n";
}