r27488 - in /trunk/libxml-rss-perl: Changes MANIFEST META.yml TODO debian/changelog examples/2.0/ lib/XML/RSS.pm lib/XML/RSS/Private/Output/Base.pm t/2.0-parse-2.t t/test-generated-items.t

gregoa at users.alioth.debian.org gregoa at users.alioth.debian.org
Sun Nov 30 15:51:10 UTC 2008


Author: gregoa
Date: Sun Nov 30 15:51:07 2008
New Revision: 27488

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

Added:
    trunk/libxml-rss-perl/examples/2.0/
      - copied from r27487, branches/upstream/libxml-rss-perl/current/examples/2.0/
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/2.0-parse-2.t
    trunk/libxml-rss-perl/t/test-generated-items.t

Modified: trunk/libxml-rss-perl/Changes
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libxml-rss-perl/Changes?rev=27488&op=diff
==============================================================================
--- trunk/libxml-rss-perl/Changes (original)
+++ trunk/libxml-rss-perl/Changes Sun Nov 30 15:51:07 2008
@@ -1,4 +1,14 @@
 Revision history for Perl module XML::RSS
+    
+1.38 - November 27, 2008
+    - Added support for duplicate items of RSS modules.
+        - http://rt.cpan.org/Public/Bug/Display.html?id=4495
+    - Added support for multiple Dublin Core elements. One can point
+    the field to an array and it will create multiple elements:
+        - http://rt.cpan.org/Public/Bug/Display.html?id=6000
+    - Now parsing several <skipDays>/<day>s and <skipHours>/<hour>s into
+    an array reference instead of concatenating them together.
+        - http://rt.cpan.org/Public/Bug/Display.html?id=40978
 
 1.37 - November 18, 2008
     - Extracted the common parts of parse() and parsefile() into one

Modified: trunk/libxml-rss-perl/MANIFEST
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libxml-rss-perl/MANIFEST?rev=27488&op=diff
==============================================================================
--- trunk/libxml-rss-perl/MANIFEST (original)
+++ trunk/libxml-rss-perl/MANIFEST Sun Nov 30 15:51:07 2008
@@ -15,6 +15,7 @@
 examples/1.0/rss1.0.rdf
 examples/1.0/slash.rdf
 examples/1.0/update_rss_1.0.pl
+examples/2.0/rss-2.0-sample-from-rssboard-multiple-skip-days-and-hours.xml
 examples/convert.pl
 examples/create_rss_multiple.pl
 examples/README
@@ -72,7 +73,7 @@
 t/pod-coverage.t
 t/pod.t
 t/rss2-gt-encoding.t
+t/test-generated-items.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=27488&op=diff
==============================================================================
--- trunk/libxml-rss-perl/META.yml (original)
+++ trunk/libxml-rss-perl/META.yml Sun Nov 30 15:51:07 2008
@@ -1,6 +1,6 @@
 ---
 name: XML-RSS
-version: 1.37
+version: 1.38
 author:
   - 'Original code: Jonathan Eisenzopf <eisen at pobox.com>'
   - |-
@@ -24,7 +24,7 @@
 provides:
   XML::RSS:
     file: lib/XML/RSS.pm
-    version: 1.37
+    version: 1.38
   XML::RSS::Private::Output::Base:
     file: lib/XML/RSS/Private/Output/Base.pm
   XML::RSS::Private::Output::Roles::ImageDims:

Modified: trunk/libxml-rss-perl/TODO
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libxml-rss-perl/TODO?rev=27488&op=diff
==============================================================================
--- trunk/libxml-rss-perl/TODO (original)
+++ trunk/libxml-rss-perl/TODO Sun Nov 30 15:51:07 2008
@@ -1,10 +1,17 @@
 
 http://rt.cpan.org/Public/Dist/Display.html?Name=XML-RSS
 
+- Add a way (and an option) to parse module items with duplicate keys into
+an array reference.
+
+- Add a way (and an option) to parse multiple dc:items into an array reference:
+    - http://rt.cpan.org/Public/Bug/Display.html?id=6000
+
+- Convert an array of skipDays/day's or skipHours/hour's to multiple tags,
+when converting to text.
+    - http://rt.cpan.org/Public/Bug/Display.html?id=40978 
+
 --- 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=27488&op=diff
==============================================================================
--- trunk/libxml-rss-perl/debian/changelog (original)
+++ trunk/libxml-rss-perl/debian/changelog Sun Nov 30 15:51:07 2008
@@ -1,3 +1,9 @@
+libxml-rss-perl (1.38-1) UNRELEASED; urgency=low
+
+  * New upstream release.
+
+ -- gregor herrmann <gregoa at debian.org>  Sun, 30 Nov 2008 16:50:04 +0100
+
 libxml-rss-perl (1.37-1) unstable; urgency=low
 
   * debian/control: Changed: Switched Vcs-Browser field to ViewSVN

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=27488&op=diff
==============================================================================
--- trunk/libxml-rss-perl/lib/XML/RSS.pm (original)
+++ trunk/libxml-rss-perl/lib/XML/RSS.pm Sun Nov 30 15:51:07 2008
@@ -17,7 +17,7 @@
 
 use vars qw($VERSION $AUTOLOAD @ISA $AUTO_ADD);
 
-$VERSION = '1.37';
+$VERSION = '1.38';
 
 $AUTO_ADD = 0;
 
@@ -685,11 +685,32 @@
     }
 
     $self->_append_text_to_elem_struct(
-        $self->{'items'}->[$self->{num_items} - 1],
+        $self->_last_item,
         $cdata,
         \&_return_item_elem,
     );
 }
+
+sub _append_to_array_elem {
+    my ($self, $category, $cdata) = @_;
+
+    if (! $self->_my_in_element($category))
+    {
+        return;
+    }
+
+    my $el = $self->_current_element;
+
+    if (ref($self->{$category}->{$el}) eq "ARRAY") {
+        $self->{$category}->{$el}->[-1] .= $cdata;
+    }
+    else {
+        $self->{$category}->{$el} .= $cdata;
+    }
+
+    return 1;
+}
+
 sub _handle_char {
     my ($self, $cdata) = (@_);
 
@@ -711,14 +732,11 @@
         $self->_append_text_to_elem("textinput", $cdata);
     }
     # skipHours element
-    elsif ($self->_my_in_element("skipHours")) {
-        $self->{'skipHours'}->{$self->_current_element} .= $cdata;
-
-    }
-    # skipDays element
-    elsif ($self->_my_in_element("skipDays")) {
-        $self->{'skipDays'}->{$self->_current_element} .= $cdata;
-
+    elsif ($self->_append_to_array_elem("skipHours", $cdata)) {
+        # Do nothing - already done in the predicate.
+    }
+    elsif ($self->_append_to_array_elem("skipDays", $cdata)) {
+        # Do nothing - already done in the predicate.
     }
     # channel element
     elsif ($self->_my_in_element("channel")) {
@@ -745,6 +763,34 @@
             && $hashref_ok_elements{$el}
         )
     );
+}
+
+sub _start_array_element {
+    my ($self, $cat, $el) = @_;
+
+    if (!$self->_my_in_element($cat)) {
+        return;
+    }
+
+    # If it's an array - append a new empty element because a new one
+    # was started.
+    if (ref($self->{$cat}->{$el}) eq "ARRAY") {
+        push @{$self->{$cat}->{$el}}, "";
+    }
+    # If it's not an array but still full (i.e: it's only the second
+    # element), then turn it into an array
+    elsif (defined($self->{$cat}->{$el}) && length($self->{$cat}->{$el})) {
+        $self->{$cat}->{$el} = [$self->{$cat}->{$el}, ""];
+    }
+    # Else - do nothing and let the function append to the new array.
+    
+    return 1;
+}
+
+sub _last_item {
+    my $self = shift;
+
+    return ($self->{'items'}->[$self->{num_items} - 1] ||= {});
 }
 
 sub _handle_start {
@@ -810,6 +856,13 @@
 
     # beginning of item element
     }
+    # TODO : Merge skipHours and skipDays
+    elsif ($self->_start_array_element("skipHours", $el)) {
+        # Do nothing - already done in the predicate.
+    }
+    elsif ($self->_start_array_element("skipDays", $el)) {
+        # Do nothing - already done in the predicate.
+    }
     elsif ($el eq 'item') {
 
         # deal with trouble makers who use mod_content :)
@@ -828,13 +881,13 @@
             }
         }
         # handle xml:base
-        $self->{'items'}->[$self->{num_items} - 1]->{'xml:base'} = $attribs{'base'} if exists $attribs{'base'};
+        $self->_last_item->{'xml:base'} = $attribs{'base'} if exists $attribs{'base'};
 
 
         # guid element is a permanent link unless isPermaLink attribute is set to false
     }
     elsif ($el eq 'guid') {
-        $self->{'items'}->[$self->{num_items} - 1]->{'isPermaLink'} =
+        $self->_last_item->{'isPermaLink'} =
           (exists($attribs{'isPermaLink'}) && 
               (lc($attribs{'isPermaLink'}) eq 'true')
           );
@@ -853,7 +906,7 @@
     {
 
         #print "taxo: ", $attribs{'resource'},"\n";
-        push(@{$self->{'items'}->[$self->{num_items} - 1]->{'taxo'}}, $attribs{'resource'});
+        push(@{$self->_last_item->{'taxo'}}, $attribs{'resource'});
         $self->{'modules'}->{'http://purl.org/rss/1.0/modules/taxonomy/'} = 'taxo';
 
         # beginning of taxo li in channel element
@@ -909,23 +962,23 @@
         # in the 'rdf_resource_fields' so this condition always evaluates
         # to false.
         # if ( $ns eq $self->{rss_namespace} ) {
-        #   $self->{'items'}->[$self->{num_items}-1]->{ $el } = $attribs{resource};
+        #   $self->_last_item->{ $el } = $attribs{resource};
         # }
         # else
         {
-            $self->{'items'}->[$self->{num_items} - 1]->{$ns}->{$el} = $attribs{resource};
+            $self->_last_item->{$ns}->{$el} = $attribs{resource};
 
             # add short cut
             #
             if (exists($self->{modules}->{$ns})) {
                 $ns = $self->{modules}->{$ns};
-                $self->{'items'}->[$self->{num_items} - 1]->{$ns}->{$el} = $attribs{resource};
+                $self->_last_item->{$ns}->{$el} = $attribs{resource};
             }
         }
     }
     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;
+        $self->_last_item->{$el} = \%attribs if keys %attribs;
     }
 }
 
@@ -1579,6 +1632,20 @@
   dc:   http://purl.org/dc/elements/1.1/
   taxo: http://purl.org/rss/1.0/modules/taxonomy/
 
+The Dublin Core ('dc') hash keys may be point to an array
+reference, which in turn will specify multiple such keys, and render them
+one after the other. For example:
+
+    $rss->add_item (
+        title => $title,
+        link => $link,
+        dc => { 
+            subject=> ["Jungle", "Desert", "Swamp"],
+            creator=>$creator,
+            date=>$date
+        },
+    );
+
 Dublin Core elements may occur in channel, image, item(s), and textinput
 -- albeit uncomming to find them under image and textinput.  Syndication
 elements are limited to the channel element. Taxonomy elements can occur
@@ -1607,6 +1674,15 @@
 Then proceed as usual:
 
   $rss->add_item (title=>$title, link=>$link, my=>{ rating=>$rating });
+
+You can also set the value of the module's prefix to an array reference 
+of C<<< { el => , val => } >>> hash-references, in which case duplicate 
+elements are possible:
+
+  $rss->add_item(title=>$title, link=>$link, my=> [
+    {el => "rating", value => $rating1, }
+    {el => "rating", value => $rating2, },
+  ]
 
 Non-standard namespaces are not, however, currently accessible via a simple
 prefix; access them via their namespace URL like so:

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=27488&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 Sun Nov 30 15:51:07 2008
@@ -169,6 +169,22 @@
     return;
 }
 
+sub _out_array_tag {
+    my ($self, $tag, $inner) = @_;
+
+    if (ref($inner) eq "ARRAY") {
+        foreach my $elem (@$inner)
+        {
+            $self->_out_defined_tag($tag, $elem);
+        }
+    }
+    else {
+        $self->_out_defined_tag($tag, $inner);
+    }
+
+    return;
+}
+
 sub _out_inner_tag {
     my ($self, $params, $tag) = @_;
 
@@ -608,10 +624,95 @@
     foreach my $dc (@{$self->_get_dc_ok_fields()}) {
         next if $skip_hash->{$dc};
 
-        $self->_out_defined_tag("dc:$dc", $elem->{dc}->{$dc});
-    }
-
-    return;
+        $self->_out_array_tag("dc:$dc", $elem->{dc}->{$dc});
+    }
+
+    return;
+}
+
+sub _out_module_prefix_elements_hash
+{
+    my ($self, $args) = @_;
+
+    my $prefix = $args->{prefix};
+    my $data = $args->{data};
+    my $url = $args->{url};
+    
+    while (my ($el, $value) = each(%$data)) {
+        $self->_out_module_prefix_pair(
+            {
+                %$args,
+                el => $el,
+                val => $value,
+            }
+        );
+    }
+
+    return;
+}
+
+sub _out_module_prefix_pair
+{
+    my ($self, $args) = @_;
+
+    my $prefix = $args->{prefix};
+    my $url = $args->{url};
+    
+    my $el = $args->{el};
+    my $value = $args->{val};
+
+    if ($self->_main->_is_rdf_resource($el,$url)) {
+        $self->_out(
+            qq{<${prefix}:${el} rdf:resource="} . $self->_encode($value) . qq{" />\n});
+    }
+    else {
+        $self->_out_ns_tag($prefix, $el, $value);
+    }
+
+    return;
+}
+
+sub _out_module_prefix_elements_array
+{
+    my ($self, $args) = @_;
+
+    my $prefix = $args->{prefix};
+    my $data = $args->{data};
+    my $url = $args->{url};
+
+    foreach my $element (@$data)
+    {
+        $self->_out_module_prefix_pair(
+            {
+                %$args,
+                el => $element->{'el'},
+                val => $element->{'val'},
+            }
+        )
+    }
+
+    return;
+}
+
+sub _out_module_prefix_elements
+{
+    my ($self, $args) = @_;
+
+    my $data = $args->{'data'};
+
+    if (! $data) {
+        # Do nothing - empty data
+        return;
+    }
+    elsif (ref($data) eq "HASH") {
+        return $self->_out_module_prefix_elements_hash($args);
+    }
+    elsif (ref($data) eq "ARRAY") {
+        return $self->_out_module_prefix_elements_array($args);
+    }
+    else {
+        die "Don't know how to handle module data of type " . ref($data) . "!";
+    }
 }
 
 # Output the Ad-hoc modules
@@ -621,16 +722,15 @@
     # Ad-hoc modules
     while (my ($url, $prefix) = each %{$self->_modules}) {
         next if $prefix =~ /^(dc|syn|taxo)$/;
-        while (my ($el, $value) = each %{$super_elem->{$prefix} || {}}) {
-            if ($self->_main->_is_rdf_resource($el,$url))
+        
+        $self->_out_module_prefix_elements(
             {
-                $self->_out(
-                    qq{<${prefix}:${el} rdf:resource="} . $self->_encode($value) . qq{" />\n});
+                prefix => $prefix,
+                url => $url,
+                data => $super_elem->{$prefix},
             }
-            else {
-                $self->_out_ns_tag($prefix, $el, $value);
-            }
-        }
+        );
+
     }
 
     return;

Modified: trunk/libxml-rss-perl/t/2.0-parse-2.t
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libxml-rss-perl/t/2.0-parse-2.t?rev=27488&op=diff
==============================================================================
--- trunk/libxml-rss-perl/t/2.0-parse-2.t (original)
+++ trunk/libxml-rss-perl/t/2.0-parse-2.t Sun Nov 30 15:51:07 2008
@@ -3,13 +3,15 @@
 use strict;
 use warnings;
 
-use Test::More tests => 2;
+use Test::More tests => 4;
 
 use XML::RSS;
+use File::Spec;
 
-my $rss = XML::RSS->new();
+{
+    my $rss = XML::RSS->new();
 
-$rss->parse(<<"EOF");
+    $rss->parse(<<"EOF");
 <?xml version="1.0" encoding="UTF-8" ?>
 <?xml-stylesheet href="/rss/news/journalism.xsl" type="text/xsl"?>
 <rss version="2.0">
@@ -40,12 +42,40 @@
 </rss>
 EOF
 
-# TEST
-is ($rss->{textinput}->{link}, "http://www.topix.net/search/", 
-    "Testing for textinput link"
-);
+    # TEST
+    is ($rss->{textinput}->{link}, "http://www.topix.net/search/", 
+        "Testing for textinput link"
+    );
 
-# TEST
-is ($rss->{channel}->{link}, "http://www.topix.net/news/journalism",
-    "Testing for channel link"
-);
+    # TEST
+    is ($rss->{channel}->{link}, "http://www.topix.net/news/journalism",
+        "Testing for channel link"
+    );
+}
+
+{
+    my $rss = XML::RSS->new();
+
+    $rss->parsefile(
+        File::Spec->catfile(
+            File::Spec->curdir(), 
+            "examples",
+            "2.0",
+            "rss-2.0-sample-from-rssboard-multiple-skip-days-and-hours.xml"
+        )
+    );
+
+    # TEST
+    is_deeply(
+        $rss->{'skipHours'}->{'hour'}, 
+        [qw(0 1 2 22 23)],
+        "skipHours/hour is parsed into an array with the individual elements",
+    );
+
+    # TEST
+    is_deeply(
+        $rss->{'skipDays'}->{'day'},
+        [qw(Saturday Sunday)],
+        "skipDays/day is parsed into an array with indiv elements",
+    );
+}

Modified: trunk/libxml-rss-perl/t/test-generated-items.t
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libxml-rss-perl/t/test-generated-items.t?rev=27488&op=diff
==============================================================================
--- trunk/libxml-rss-perl/t/test-generated-items.t (original)
+++ trunk/libxml-rss-perl/t/test-generated-items.t Sun Nov 30 15:51:07 2008
@@ -3,7 +3,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 190;
+use Test::More tests => 192;
 
 use XML::RSS;
 use HTML::Entities qw(encode_entities);
@@ -4088,3 +4088,60 @@
         );
     }
 }
+
+{
+    my $rss = create_rss_1({
+        version => "1.0",
+        image_params => 
+        [
+            eloq =>
+            [
+                { 'el' => 'grow', 'val' => "There" },
+                { 'el' => 'grow', 'val' => "Position", },
+                { 'el' => 'show', 'val' => "and tell", },
+                { 'el' => 'show', 'val' => "must go on", },
+            ],
+        ],
+    });
+
+    $rss->add_module(prefix => "eloq", uri => "http://eloq.tld2/Gorj/");
+    # TEST
+    contains($rss, "<image rdf:about=\"0\">\n" .
+        "<title>freshmeat.net</title>\n" .
+        "<url>0</url>\n" .
+        "<link>http://freshmeat.net/</link>\n" .
+        "<eloq:grow>There</eloq:grow>\n" .
+        "<eloq:grow>Position</eloq:grow>\n" .
+        "<eloq:show>and tell</eloq:show>\n" .
+        "<eloq:show>must go on</eloq:show>\n" .
+        "</image>",
+        'Multiple values for the same key in a module, usign an array ref'
+    );
+}
+
+{
+    my $rss = create_channel_rss({
+        version => "1.0",
+    });
+
+    $rss->add_item(
+        title => "In the Dublin Core Jungle",
+        link => "http://jungle.tld/Enter/",
+        dc => {
+            subject => ['tiger', 'elephant', 'snake',],
+            language => "en-GB",
+        },
+    );
+
+    # TEST
+    contains($rss, "<item rdf:about=\"http://jungle.tld/Enter/\">\n" .
+        "<title>In the Dublin Core Jungle</title>\n" .
+        "<link>http://jungle.tld/Enter/</link>\n" .
+        "<dc:language>en-GB</dc:language>\n" .
+        "<dc:subject>tiger</dc:subject>\n" .
+        "<dc:subject>elephant</dc:subject>\n" .
+        "<dc:subject>snake</dc:subject>\n" .
+        "</item>\n",
+        "1.0 - item/multiple dc:subject's"
+    );
+}




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