r27115 - in /trunk/libxml-rss-perl: Changes MANIFEST META.yml TODO debian/changelog lib/XML/RSS.pm lib/XML/RSS/Private/Output/Base.pm t/1.0-generate.t t/2.0-generate.t t/items-are-0.t t/test-generated-items.t t/test_manifest

gregoa at users.alioth.debian.org gregoa at users.alioth.debian.org
Sat Nov 22 15:43:32 UTC 2008


Author: gregoa
Date: Sat Nov 22 15:43:29 2008
New Revision: 27115

URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=27115
Log:
New upstream release.

Added:
    trunk/libxml-rss-perl/t/test-generated-items.t
      - copied unchanged from r27114, branches/upstream/libxml-rss-perl/current/t/test-generated-items.t
Removed:
    trunk/libxml-rss-perl/t/items-are-0.t
Modified:
    trunk/libxml-rss-perl/Changes
    trunk/libxml-rss-perl/MANIFEST
    trunk/libxml-rss-perl/META.yml
    trunk/libxml-rss-perl/TODO
    trunk/libxml-rss-perl/debian/changelog
    trunk/libxml-rss-perl/lib/XML/RSS.pm
    trunk/libxml-rss-perl/lib/XML/RSS/Private/Output/Base.pm
    trunk/libxml-rss-perl/t/1.0-generate.t
    trunk/libxml-rss-perl/t/2.0-generate.t
    trunk/libxml-rss-perl/t/test_manifest

Modified: trunk/libxml-rss-perl/Changes
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libxml-rss-perl/Changes?rev=27115&op=diff
==============================================================================
--- trunk/libxml-rss-perl/Changes (original)
+++ trunk/libxml-rss-perl/Changes Sat Nov 22 15:43:29 2008
@@ -1,4 +1,15 @@
 Revision history for Perl module XML::RSS
+
+1.37 - November 18, 2008
+    - Extracted the common parts of parse() and parsefile() into one
+    method (Refactoring - Shlomi Fish)
+    - Incorporated a modified version of a patch from Simon Wistow to
+    add support for the "xml:base" attribute.
+    - Renamed t/items-are-0.t into the more descriptive 
+    t/test-generated-items.t , to highlight its significance and make
+    it easier to notice.
+    - Enabled backwards-compatibility mode for the "description" item
+    to not become a hash-ref by default if xml:base is specified.
 
 1.36 - October 7, 2008
     - ->parse() now explicitly returns $self.

Modified: trunk/libxml-rss-perl/MANIFEST
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libxml-rss-perl/MANIFEST?rev=27115&op=diff
==============================================================================
--- trunk/libxml-rss-perl/MANIFEST (original)
+++ trunk/libxml-rss-perl/MANIFEST Sat Nov 22 15:43:29 2008
@@ -67,12 +67,12 @@
 testlib/Test/Run/CmdLine/WithTestManifest.pm
 t/generated/placeholder.txt
 t/guid.t
-t/items-are-0.t
 t/load.t
 TODO
 t/pod-coverage.t
 t/pod.t
 t/rss2-gt-encoding.t
 t/test_manifest
+t/test-generated-items.t
 t/version.t
 t/xml-header.t

Modified: trunk/libxml-rss-perl/META.yml
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libxml-rss-perl/META.yml?rev=27115&op=diff
==============================================================================
--- trunk/libxml-rss-perl/META.yml (original)
+++ trunk/libxml-rss-perl/META.yml Sat Nov 22 15:43:29 2008
@@ -1,6 +1,6 @@
 ---
 name: XML-RSS
-version: 1.36
+version: 1.37
 author:
   - 'Original code: Jonathan Eisenzopf <eisen at pobox.com>'
   - |-
@@ -24,7 +24,7 @@
 provides:
   XML::RSS:
     file: lib/XML/RSS.pm
-    version: 1.36
+    version: 1.37
   XML::RSS::Private::Output::Base:
     file: lib/XML/RSS/Private/Output/Base.pm
   XML::RSS::Private::Output::Roles::ImageDims:
@@ -39,7 +39,7 @@
     file: lib/XML/RSS/Private/Output/V1_0.pm
   XML::RSS::Private::Output::V2_0:
     file: lib/XML/RSS/Private/Output/V2_0.pm
-generated_by: Module::Build version 0.2808
+generated_by: Module::Build version 0.3
 meta-spec:
   url: http://module-build.sourceforge.net/META-spec-v1.2.html
   version: 1.2

Modified: trunk/libxml-rss-perl/TODO
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libxml-rss-perl/TODO?rev=27115&op=diff
==============================================================================
--- trunk/libxml-rss-perl/TODO (original)
+++ trunk/libxml-rss-perl/TODO Sat Nov 22 15:43:29 2008
@@ -2,6 +2,9 @@
 http://rt.cpan.org/Public/Dist/Display.html?Name=XML-RSS
 
 --- before the next release-ish
+
+- Make sure the xml:base parsing into-hash-refs with an "xml:base" key
+is triggered only with a special option to parse.
 
 - wrong handling enclosure subelement of item
   http://rt.cpan.org/Ticket/Display.html?id=21740

Modified: trunk/libxml-rss-perl/debian/changelog
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libxml-rss-perl/debian/changelog?rev=27115&op=diff
==============================================================================
--- trunk/libxml-rss-perl/debian/changelog (original)
+++ trunk/libxml-rss-perl/debian/changelog Sat Nov 22 15:43:29 2008
@@ -1,7 +1,8 @@
-libxml-rss-perl (1.36-2) UNRELEASED; urgency=low
+libxml-rss-perl (1.37-1) UNRELEASED; urgency=low
 
   * debian/control: Changed: Switched Vcs-Browser field to ViewSVN
     (source stanza).
+  * New upstream release.
 
  -- gregor herrmann <gregoa at debian.org>  Sun, 16 Nov 2008 20:49:27 +0100
 

Modified: trunk/libxml-rss-perl/lib/XML/RSS.pm
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libxml-rss-perl/lib/XML/RSS.pm?rev=27115&op=diff
==============================================================================
--- trunk/libxml-rss-perl/lib/XML/RSS.pm (original)
+++ trunk/libxml-rss-perl/lib/XML/RSS.pm Sat Nov 22 15:43:29 2008
@@ -17,7 +17,7 @@
 
 use vars qw($VERSION $AUTOLOAD @ISA $AUTO_ADD);
 
-$VERSION = '1.36';
+$VERSION = '1.37';
 
 $AUTO_ADD = 0;
 
@@ -250,7 +250,8 @@
     };
 }
 
-my %empty_ok_elements = (enclosure => 1,);
+my %empty_ok_elements = (enclosure => 1);
+my %hashref_ok_elements = (description => 1);
 
 sub _get_default_modules {
     return {
@@ -309,6 +310,7 @@
         {key => "output",        default => "",},
         {key => "encoding",      default => "UTF-8",},
         {key => "encode_cb",     default => undef(),},
+        {key => "xml:base",      default => undef(),},
     ];
 }
 
@@ -351,7 +353,6 @@
     # namespaces
     $self->{namespaces}    = {};
     $self->{rss_namespace} = '';
-
     foreach my $k (@{$self->_get_init_default_key_assignments()})
     {
         my $key = $k->{key};
@@ -615,7 +616,7 @@
 
     # If it's in the default namespace
     if ($verdict) {
-        $struct->{$mapping_sub->($struct, $elem)} .= $cdata;
+        $self->_append_struct($struct, $mapping_sub->($struct, $elem), $cdata);
     }
     else {
         # If it's in another namespace
@@ -628,6 +629,15 @@
     }
 
     return;
+}
+
+sub _append_struct {
+    my ($self, $struct, $key, $cdata) = @_;
+    if (defined $struct->{$key} && ref($struct->{$key}) eq 'HASH') {
+        $struct->{$key}->{content} .= $cdata;
+    } else {
+        $struct->{$key} .= $cdata;
+    }
 }
 
 sub _return_elem {
@@ -725,7 +735,17 @@
     #print "ENCODING: $encoding\n";
 }
 
-
+sub _should_be_hashref {
+    my ($self, $el) = @_;
+
+    return
+    (
+        $empty_ok_elements{$el}
+        || ($self->_parse_options()->{'hashrefs_instead_of_strings'}
+            && $hashref_ok_elements{$el}
+        )
+    );
+}
 
 sub _handle_start {
     my $self    = shift;
@@ -733,7 +753,7 @@
     my %attribs = @_;
 
     my $parser = $self->_parser;
-
+    
     # beginning of RSS 0.91
     if ($el eq 'rss') {
         if (exists($attribs{version})) {
@@ -743,7 +763,10 @@
             croak "Malformed RSS: invalid version\n";
         }
 
-        # beginning of RSS 1.0 or RSS 0.9
+        # handle xml:base
+        $self->{'xml:base'} = $attribs{'base'} if exists $attribs{'base'};
+
+    # beginning of RSS 1.0 or RSS 0.9
     }
     elsif ($el eq 'RDF') {
         my @prefixes = $parser->new_ns_prefixes;
@@ -782,7 +805,10 @@
         #    croak "Malformed RSS: invalid version\n";
         #}
 
-        # beginning of item element
+        # handle xml:base
+        $self->{'xml:base'} = $attribs{'base'} if exists $attribs{'base'};
+
+    # beginning of item element
     }
     elsif ($el eq 'item') {
 
@@ -801,6 +827,9 @@
                 $self->{_inside_item_elem} = $parser->depth();
             }
         }
+        # handle xml:base
+        $self->{'items'}->[$self->{num_items} - 1]->{'xml:base'} = $attribs{'base'} if exists $attribs{'base'};
+
 
         # guid element is a permanent link unless isPermaLink attribute is set to false
     }
@@ -894,8 +923,9 @@
             }
         }
     }
-    elsif ($empty_ok_elements{$el} and $self->_current_element eq 'item') {
-        $self->{items}->[$self->{num_items} - 1]->{$el} = \%attribs;
+    elsif ($self->_should_be_hashref($el) and $self->_current_element eq 'item') {
+        $attribs{'xml:base'} = delete $attribs{base} if defined $attribs{base};
+        $self->{items}->[$self->{num_items} - 1]->{$el} = \%attribs if keys %attribs;
     }
 }
 
@@ -974,12 +1004,25 @@
     );    
 }
 
-
-sub parse {
-    my $self = shift;
-    my $text_to_parse = shift;
+sub _parse_options {
+    my $self = shift;
+
+    if (@_) {
+        $self->{_parse_options} = shift;
+    }
+
+    return $self->{_parse_options};
+}
+
+sub _generic_parse {
+    my $self = shift;
+    my $method = shift;
+    my $arg = shift;
+    my $options = shift;
 
     $self->_reset;
+
+    $self->_parse_options($options || {});
 
     # Workaround to make sure that if we were defined with version => "2.0"
     # then we can still parse 1.0 and 0.9.x feeds correctly.
@@ -987,7 +1030,7 @@
         $self->{modules} = +{%{$self->_get_default_modules()}, %{$self->{modules}}};
     }
 
-    $self->_get_parser()->parse($text_to_parse);
+    $self->_get_parser()->$method($arg);
 
     $self->_auto_add_modules if $AUTO_ADD;
     $self->{version} = $self->{_internal}->{version};
@@ -995,23 +1038,20 @@
     return $self;
 }
 
+sub parse {
+    my $self = shift;
+    my $text_to_parse = shift;
+    my $options = shift;
+
+    return $self->_generic_parse("parse", $text_to_parse, $options);
+}
+
 sub parsefile {
     my $self = shift;
-
-    $self->_reset;
-
-    # Workaround to make sure that if we were defined with version => "2.0"
-    # then we can still parse 1.0 and 0.9.x feeds correctly.
-    if ($self->{version} eq "2.0") {
-        $self->{modules} = +{%{$self->_get_default_modules()}, %{$self->{modules}}};
-    }
-
-    $self->_get_parser()->parsefile(shift);
-
-    $self->_auto_add_modules if $AUTO_ADD;
-    $self->{version} = $self->{_internal}->{version};
-
-    return $self;
+    my $file_to_parse = shift;
+    my $options = shift;
+
+    return $self->_generic_parse("parsefile", $file_to_parse, $options);
 }
 
 # Check if Perl supports the :encoding layer in File I/O.
@@ -1365,7 +1405,7 @@
 =over 4
 
 =item new XML::RSS (version=>$version, encoding=>$encoding,
-output=>$output, stylesheet=>$stylesheet_url)
+output=>$output, stylesheet=>$stylesheet_url, 'xml:base'=>$base)
 
 Constructor for XML::RSS. It returns a reference to an XML::RSS object.
 You may also pass the RSS version and the XML encoding to use. The default
@@ -1387,6 +1427,10 @@
 the text to encode. If not set, then the module will encode using its
 custom encoding routine.
 
+xml:base will set an C<xml:base> property as per
+
+    http://www.w3.org/TR/xmlbase/
+
 Note that in order to encode properly, you need to handle "CDATA" sections
 properly. Look at L<XML::RSS::Private::Output::Base>'s C<_default_encode()>
 method for how to do it properly.
@@ -1431,7 +1475,7 @@
 The method for retrieving the values for the image is the same as it
 is for B<channel()>.
 
-=item parse ($string)
+=item parse ($string, \%options)
 
 Parses an RDF Site Summary which is passed into B<parse()> as the first 
 parameter. Returns the instance of the object so one can say 
@@ -1440,7 +1484,22 @@
 See the add_module() method for instructions on automatically adding
 modules as a string is parsed.
 
-=item parsefile ($file)
+%options is a list of options that specify how parsing is to be done. The
+available options are:
+
+=over 4
+
+=item * hashrefs_instead_of_strings
+
+If true, then some items (so far "C<description>") will become hash-references
+instead of strings (with a B<content> key containing their content , B<if>
+they have XML attributes. Without this key, the attributes will be ignored
+and there will only be a string. Thus, specifying this option may break
+compatibility.
+
+=back
+
+=item parsefile ($file, \%options)
 
 Same as B<parse()> except it parses a file rather than a string.
 

Modified: trunk/libxml-rss-perl/lib/XML/RSS/Private/Output/Base.pm
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libxml-rss-perl/lib/XML/RSS/Private/Output/Base.pm?rev=27115&op=diff
==============================================================================
--- trunk/libxml-rss-perl/lib/XML/RSS/Private/Output/Base.pm (original)
+++ trunk/libxml-rss-perl/lib/XML/RSS/Private/Output/Base.pm Sat Nov 22 15:43:29 2008
@@ -79,6 +79,7 @@
 sub _default_encode {
     my ($self, $text) = @_;
 
+    #return "" unless defined $text;
     if (!defined($text)) {
         confess "\$text is undefined in XML::RSS::_encode(). We don't know how " . "to handle it!";
     }
@@ -107,8 +108,21 @@
 
 sub _out_tag {
     my ($self, $tag, $inner) = @_;
-
-    return $self->_out("<$tag>" . $self->_encode($inner) . "</$tag>\n");
+    my $content = $inner;
+    my $attr    = "";
+    if (ref($inner) eq 'HASH') {
+        my %inner_copy = %$inner;
+        $content = delete $inner_copy{content}; 
+        foreach my $key (keys %inner_copy) {
+            my $value = $inner->{$key};
+            if (defined($value)) {
+                $attr .= " " . $self->_encode($key) . qq{="}
+                    . $self->_encode($value) . '"'
+                    ;
+            }
+        }
+    }
+    return $self->_out("<$tag$attr>" . $self->_encode($content) . "</$tag>\n");
 }
 
 # Remove non-alphanumeric elements and return the modified string.
@@ -214,7 +228,7 @@
     my ($self, $tag, $about_sub) = @_;
     
     my $about = $self->_get_top_elem_about($tag, $about_sub);
-
+    
     return $self->_out("<$tag$about>\n");
 }
 
@@ -373,7 +387,8 @@
 sub _output_xml_declaration {
     my $self = shift;
 
-    $self->_out('<?xml version="1.0" encoding="' . $self->_main->_encoding() . '"?>' . "\n");
+    my $encoding = (defined $self->_main->_encoding())? ' encoding="' . $self->_main->_encoding() . '"' : "";
+    $self->_out('<?xml version="1.0"' . $encoding . '?>' . "\n");
     if (defined(my $stylesheet = $self->_main->_stylesheet)) {
         my $style_url = $self->_encode($stylesheet);
         $self->_out(qq{<?xml-stylesheet type="text/xsl" href="$style_url"?>\n});
@@ -405,7 +420,10 @@
 sub _start_item {
     my ($self, $item) = @_;
 
-    $self->_start_top_elem("item", sub { $self->_get_item_about($item)});
+    my $tag  = "item";
+    my $base = $item->{'xml:base'};
+    $tag .= qq{ xml:base="$base"} if defined $base;
+    $self->_start_top_elem($tag, sub { $self->_get_item_about($item)});
 
     $self->_output_common_item_tags($item);
 
@@ -447,7 +465,6 @@
 
 sub _out_item_desc {
     my ($self, $item) = @_;
-
     return $self->_output_def_item_tag($item, "description");
 }
 
@@ -759,8 +776,9 @@
 sub _get_rdf_decl
 {
     my $self = shift;
-
-    return $self->_get_rdf_decl_open_tag() .
+    my $base = $self->_main()->{'xml:base'};
+    my $base_decl = (defined $base)? qq{ xml:base="$base"\n} : "";
+    return $self->_get_rdf_decl_open_tag() . $base_decl .
         $self->_get_rdf_xmlnses() . ">\n\n";
 }
 

Modified: trunk/libxml-rss-perl/t/1.0-generate.t
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libxml-rss-perl/t/1.0-generate.t?rev=27115&op=diff
==============================================================================
--- trunk/libxml-rss-perl/t/1.0-generate.t (original)
+++ trunk/libxml-rss-perl/t/1.0-generate.t Sat Nov 22 15:43:29 2008
@@ -2,7 +2,7 @@
 use warnings;
 
 use Test::More;
-plan tests => 22;
+plan tests => 24;
 
 # 1-2
 use_ok("XML::RSS");
@@ -29,16 +29,18 @@
 use constant RSS_ITEM_TITLE => "This is an item";
 use constant RSS_ITEM_LINK  => "http://example.com/$short_date";
 use constant RSS_ITEM_DESC  => "Yadda & yadda & yadda";
+use constant RSS_XML_BASE   => "http://example.com/";
 
 # 3
 ok($current_date,"Current date:$current_date");
 
 # 4
-my $rss = XML::RSS->new(version => RSS_VERSION);
+my $rss = XML::RSS->new(version => RSS_VERSION, 'xml:base' => RSS_XML_BASE);
 isa_ok($rss,"XML::RSS");
 
-# 5
+# 5-6
 cmp_ok($rss->{'version'},"eq",RSS_VERSION,"Version is ".RSS_VERSION);
+cmp_ok($rss->{'xml:base'},"eq",RSS_XML_BASE,"Base is ".RSS_XML_BASE);
 
 ok($rss->channel(
 		 'title'          => "Test 1.0 Feed",
@@ -111,34 +113,37 @@
 eval { $rss->parsefile(RSS_SAVEAS)};
 is($@,'',"Parsed ".RSS_SAVEAS);
 
-# 16
+# 17
 cmp_ok($rss->{channel}->{dc}{date},
        "eq",
        $current_date,
        "dc:date:".$current_date);
 
-# 17
+# 18
 cmp_ok(keys(%{$rss->{namespaces}}),
        ">=",
        1,
        "RSS feed has atleast one namespace");
 
-# 18
+# 19
+cmp_ok($rss->{'xml:base'}, "eq", RSS_XML_BASE, "Base is still ".RSS_XML_BASE);
+
+# 20
 cmp_ok(ref($rss->{'items'}),"eq","ARRAY","RSS object has an array of objects");
 
-# 19 
+# 21 
 cmp_ok(scalar(@{$rss->{'items'}}),"==",1,"RSS object has one item");
 
-# 20
+# 22
 cmp_ok($rss->{items}->[0]->{title},"eq",RSS_ITEM_TITLE,RSS_ITEM_TITLE);
 
-# 21
+# 23
 cmp_ok($rss->{items}->[0]->{link},"eq",RSS_ITEM_LINK,RSS_ITEM_LINK);
 
-# 22 
+# 24 
 cmp_ok($rss->{items}->[0]->{description},"eq",RSS_ITEM_DESC,RSS_ITEM_DESC);
 
-# 23
+# 25
 cmp_ok($rss->{items}->[0]->{dc}->{creator},"eq",RSS_CREATOR,RSS_CREATOR);
 
 __END__

Modified: trunk/libxml-rss-perl/t/2.0-generate.t
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libxml-rss-perl/t/2.0-generate.t?rev=27115&op=diff
==============================================================================
--- trunk/libxml-rss-perl/t/2.0-generate.t (original)
+++ trunk/libxml-rss-perl/t/2.0-generate.t Sat Nov 22 15:43:29 2008
@@ -1,7 +1,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 27;
+use Test::More tests => 29;
 
 BEGIN {
   use_ok("XML::RSS");
@@ -30,11 +30,13 @@
 use constant RSS_ITEM_TITLE => "This is an item";
 use constant RSS_ITEM_LINK  => "http://example.com/" . &POSIX::strftime( DATE_TEMPLATE_SHORT, gmtime ); # "$short_date";
 use constant RSS_ITEM_DESC  => "Yadda yadda yadda - R&D;";
+use constant RSS_XML_BASE   => "http://example.com";
 
-my $rss = XML::RSS->new( version => RSS_VERSION );
+my $rss = XML::RSS->new( version => RSS_VERSION, 'xml:base' => RSS_XML_BASE );
 isa_ok( $rss, "XML::RSS" );
 
-is( $rss->{'version'}, RSS_VERSION, 'Version is ' . RSS_VERSION );
+is( $rss->{'version'},  RSS_VERSION,  'Version is ' . RSS_VERSION );
+is( $rss->{'xml:base'}, RSS_XML_BASE, 'Base is ' . RSS_XML_BASE );
 
 # This includes all fields, only title, link, and description 
 # are required.
@@ -120,6 +122,8 @@
 
 is( $rss->{channel}->{category}, 'MyCategory', 'channel->{category}');
 
+is( $rss->{'xml:base'}, RSS_XML_BASE, 'Base has been reparsed');
+
 cmp_ok( keys %{ $rss->{namespaces} }, ">=", 1,
        "RSS feed has at least one namespace");
 

Modified: trunk/libxml-rss-perl/t/test_manifest
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libxml-rss-perl/t/test_manifest?rev=27115&op=diff
==============================================================================
--- trunk/libxml-rss-perl/t/test_manifest (original)
+++ trunk/libxml-rss-perl/t/test_manifest Sat Nov 22 15:43:29 2008
@@ -22,7 +22,7 @@
 enclosures.t
 enclosures2.t
 encode-output.t
-items-are-0.t
+test-generated-items.t
 pod-coverage.t
 rss2-gt-encoding.t
 charset1.t




More information about the Pkg-perl-cvs-commits mailing list