r43672 - in /trunk/libxml-libxml-iterator-perl: Changes LICENSE MANIFEST META.yml debian/changelog debian/copyright lib/XML/LibXML/Iterator.pm lib/XML/LibXML/NodeList/Iterator.pm t/01basic.t t/02tree.t t/03list.t
dmn at users.alioth.debian.org
dmn at users.alioth.debian.org
Fri Sep 4 12:02:26 UTC 2009
Author: dmn
Date: Fri Sep 4 12:01:56 2009
New Revision: 43672
URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=43672
Log:
New upstream release
update upstream author email and years of copyright
Added:
trunk/libxml-libxml-iterator-perl/LICENSE
- copied unchanged from r43671, branches/upstream/libxml-libxml-iterator-perl/current/LICENSE
trunk/libxml-libxml-iterator-perl/META.yml
- copied unchanged from r43671, branches/upstream/libxml-libxml-iterator-perl/current/META.yml
trunk/libxml-libxml-iterator-perl/t/02tree.t
- copied unchanged from r43671, branches/upstream/libxml-libxml-iterator-perl/current/t/02tree.t
trunk/libxml-libxml-iterator-perl/t/03list.t
- copied unchanged from r43671, branches/upstream/libxml-libxml-iterator-perl/current/t/03list.t
Modified:
trunk/libxml-libxml-iterator-perl/Changes
trunk/libxml-libxml-iterator-perl/MANIFEST
trunk/libxml-libxml-iterator-perl/debian/changelog
trunk/libxml-libxml-iterator-perl/debian/copyright
trunk/libxml-libxml-iterator-perl/lib/XML/LibXML/Iterator.pm
trunk/libxml-libxml-iterator-perl/lib/XML/LibXML/NodeList/Iterator.pm
trunk/libxml-libxml-iterator-perl/t/01basic.t
Modified: trunk/libxml-libxml-iterator-perl/Changes
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libxml-libxml-iterator-perl/Changes?rev=43672&op=diff
==============================================================================
--- trunk/libxml-libxml-iterator-perl/Changes (original)
+++ trunk/libxml-libxml-iterator-perl/Changes Fri Sep 4 12:01:56 2009
@@ -1,4 +1,20 @@
Revision history for Perl extension XML::LibXML::Iterator.
+
+1.04 Fri Sep 28 2007
+ - fixed RT#29262
+ - minor documentation fixes
+
+1.03 Mon Aug 06 2007
+ - fixed RT#28688 by using the provided patch
+
+1.02 Sat Jun 23 2007
+ - fixed RT#6873
+ - cleaned up the tests
+ - more compliance with the traversal specification
+
+1.01 Sat Jun 23 2007
+ - fixed RT related bugs (though with a huge delay, sorry)
1.00 Fri Nov 8 2002
- extracted the modules from the main XML::LibXML bundle.
+
Modified: trunk/libxml-libxml-iterator-perl/MANIFEST
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libxml-libxml-iterator-perl/MANIFEST?rev=43672&op=diff
==============================================================================
--- trunk/libxml-libxml-iterator-perl/MANIFEST (original)
+++ trunk/libxml-libxml-iterator-perl/MANIFEST Fri Sep 4 12:01:56 2009
@@ -3,6 +3,10 @@
lib/XML/LibXML/NodeList/Iterator.pm
Makefile.PL
MANIFEST
+LICENSE
README
t/01basic.t
+t/02tree.t
+t/03list.t
test.pl
+META.yml Module meta-data (added by MakeMaker)
Modified: trunk/libxml-libxml-iterator-perl/debian/changelog
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libxml-libxml-iterator-perl/debian/changelog?rev=43672&op=diff
==============================================================================
--- trunk/libxml-libxml-iterator-perl/debian/changelog (original)
+++ trunk/libxml-libxml-iterator-perl/debian/changelog Fri Sep 4 12:01:56 2009
@@ -1,4 +1,4 @@
-libxml-libxml-iterator-perl (1.00-2) UNRELEASED; urgency=low
+libxml-libxml-iterator-perl (1.04-1) UNRELEASED; urgency=low
* Take over for the Debian Perl Group on maintainer's request
(http://lists.alioth.debian.org/pipermail/pkg-perl-maintainers/2009-
@@ -15,7 +15,10 @@
* copyright: convert to machine-readable format
* watch: ensure dwo-digit upstream minor version
- -- Damyan Ivanov <dmn at debian.org> Fri, 04 Sep 2009 13:41:11 +0300
+ * New upstream release
+ update upstream author email and years of copyright
+
+ -- Damyan Ivanov <dmn at debian.org> Fri, 04 Sep 2009 14:58:58 +0300
libxml-libxml-iterator-perl (1.00-1) unstable; urgency=low
Modified: trunk/libxml-libxml-iterator-perl/debian/copyright
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libxml-libxml-iterator-perl/debian/copyright?rev=43672&op=diff
==============================================================================
--- trunk/libxml-libxml-iterator-perl/debian/copyright (original)
+++ trunk/libxml-libxml-iterator-perl/debian/copyright Fri Sep 4 12:01:56 2009
@@ -5,7 +5,7 @@
Upstream-Name: XML-LibXML-Iterator
Files: *
-Copyright: 2002, Christian Glahn, <christian.glahn at uibk.ac.at>
+Copyright: 2002-2007, Christian Glahn, <phish at cpan.org>
License-Alias: Perl
License: Artistic | GPL-1+
This library is free software; you can redistribute it and/or modify
Modified: trunk/libxml-libxml-iterator-perl/lib/XML/LibXML/Iterator.pm
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libxml-libxml-iterator-perl/lib/XML/LibXML/Iterator.pm?rev=43672&op=diff
==============================================================================
--- trunk/libxml-libxml-iterator-perl/lib/XML/LibXML/Iterator.pm (original)
+++ trunk/libxml-libxml-iterator-perl/lib/XML/LibXML/Iterator.pm Fri Sep 4 12:01:56 2009
@@ -1,4 +1,4 @@
-# $Id: Iterator.pm,v 1.1.1.1 2002/11/08 17:18:36 phish Exp $
+#
#
package XML::LibXML::Iterator;
@@ -8,22 +8,12 @@
use vars qw($VERSION);
-$VERSION = '1.00';
+$VERSION = '1.04';
use overload
- '++' => sub { $_[0]->next; $_[0]; },
- '--' => sub { $_[0]->previous; $_[0]; },
- '<>' => sub {
- if ( wantarray ) {
- my @rv = ();
- while ( $_[0]->next ){
- push @rv;
- }
- return @rv;
- } else {
- return $_[0]->next
- };
- },
+ '++' => sub { $_[0]->nextNode(); $_[0]; },
+ '--' => sub { $_[0]->previousNode(); $_[0]; },
+ '<>' => sub { return wantarray ? $_[0]->_get_all() : $_[0]->nextNode(); },
;
@@ -36,7 +26,11 @@
my $self = bless {}, $class;
$self->{FIRST} = $node;
- $self->first;
+ # $self->first;
+
+ $self->{CURRENT} = undef;
+ $self->{INDEX} = -1;
+
$self->{ITERATOR} = \&default_iterator;
$self->{FILTERS} = [];
@@ -73,33 +67,48 @@
sub current { return $_[0]->{CURRENT}; }
sub index { return $_[0]->{INDEX}; }
-sub next {
+sub next { return $_[0]->nextNode(); }
+sub previous { return $_[0]->previousNode(); }
+
+sub nextNode {
my $self = shift;
my @filters = @{$self->{FILTERS}};
my $node = undef;
- my $fv = FILTER_SKIP;
- unless ( scalar @filters > 0 ) {
- $fv = FILTER_DECLINED;
- }
- while ( 1 ) {
- $node = $self->{ITERATOR}->( $self, 1 );
- last unless defined $node;
- foreach my $f ( @filters ) {
- $fv = $f->accept_node( $node );
- last if $fv;
- }
- last if $fv == FILTER_ACCEPT or $fv == FILTER_DECLINED;
- }
-
+
+ if ( $self->{INDEX} != -1 ) {
+ my $fv = FILTER_SKIP;
+ unless ( scalar @filters > 0 ) {
+ $fv = FILTER_DECLINED;
+ }
+
+ while ( 1 ) {
+ $node = $self->{ITERATOR}->( $self, 1 );
+ last unless defined $node;
+ foreach my $f ( @filters ) {
+ $fv = $f->accept_node( $node );
+ last if $fv;
+ }
+ last if $fv == FILTER_ACCEPT or $fv == FILTER_DECLINED;
+ }
+ }
+ else {
+ $node = $self->first();
+ }
+
if ( defined $node ) {
$self->{CURRENT} = $node;
- $self->{INDEX}++;
+ if ( $node->isSameNode( $self->{FIRST} ) ) {
+ $self->{INDEX} = 0;
+ }
+ else {
+ $self->{INDEX}++;
+ }
}
return $node;
}
-sub previous {
+sub previousNode {
my $self = shift;
my @filters = @{$self->{FILTERS}};
my $node = undef;
@@ -189,24 +198,42 @@
}
}
else {
- return undef if $self->{CURRENT}->isSameNode( $self->{FIRST} )
- and $self->{INDEX} > 0;
-
- if ( $self->{CURRENT}->hasChildNodes ) {
- $node = $self->{CURRENT}->firstChild;
+ if ( defined $self->{CURRENT} ) {
+ return undef if $self->{CURRENT}->isSameNode( $self->{FIRST} )
+ and $self->{INDEX} > 0;
+
+ if ( $self->{CURRENT}->hasChildNodes ) {
+ $node = $self->{CURRENT}->firstChild;
+ }
+ else {
+ $node = $self->{CURRENT}->nextSibling;
+ my $pnode = $self->{CURRENT}->parentNode;
+ while ( not defined $node ) {
+ last unless defined $pnode;
+ $node = $pnode->nextSibling;
+ $pnode = $pnode->parentNode unless defined $node;
+ }
+ }
}
else {
- $node = $self->{CURRENT}->nextSibling;
- my $pnode = $self->{CURRENT}->parentNode;
- while ( not defined $node ) {
- last unless defined $pnode;
- $node = $pnode->nextSibling;
- $pnode = $pnode->parentNode unless defined $node;
- }
+ $self->{CURRENT} = $self->{FIRST};
+ $node = $self->{CURRENT};
}
}
return $node;
+}
+
+# helper function for the <> operator
+# returns all nodes that have not yet been accessed
+sub _get_all {
+ my $self = shift;
+ my @retval = ();
+ my $node;
+ while ( $node = $self->next() ) {
+ push @retval, $node;
+ }
+ return @retval;
}
1;
@@ -227,15 +254,15 @@
my $doc = XML::LibXML->new->parse_string( $somedata );
my $iter= XML::LibXML::Iterator->new( $doc );
- $iter->iterator_function( \&iterate );
+ $iter->iterator_function( \&iterator_function );
# more control on the flow
- while ( $iter->next ) {
+ while ( $iter->nextNode ) {
# do something
}
# operate on the entire tree
- $iter->iterate( \&operate );
+ $iter->iterate( \&callback_function );
=head1 DESCRIPTION
@@ -264,11 +291,11 @@
=over 4
-=item * next()
+=item * nextNode()
=item * current()
-=item * previous()
+=item * previousNode()
=back
@@ -302,7 +329,7 @@
my $iter = XML::LibXML::Iterator->new( $doc->documentElement );
# walk through the document
- while ( $iter->next() ) {
+ while ( $iter->nextNode() ) {
my $curnode = $iter->current();
print $curnode->nodeType();
}
@@ -312,13 +339,13 @@
my $curnode = $iter->current();
print $curnode->nodeType();
-Actually the functions next(), previous(), first(), last() and
+Actually the functions nextNode(), previousNode(), first(), last() and
current() do return the node which is current after the
-operation. E.g. next() moves to the next node if possible and then
+operation. E.g. nextNode() moves to the next node if possible and then
returns the node. Thus the while-loop in the example can be written
as
- while ( $iter->next() ) {
+ while ( $iter->nextNode() ) {
print $_->nodeType();
}
@@ -403,7 +430,7 @@
The following example will show how this works:
- $iter->iterate( sub {shift; map {$_->setNodeName( lc $_->nodeName ) if $_->nodeType != NAMESPACE_DECLARATION } ($_[0], $_[0]->attributes); } );
+ $iter->iterate( sub {my ($iter,$node)=@_; map {$iter->setNodeName( lc $iter->nodeName ) if $iter->nodeType != NAMESPACE_DECLARATION } ($node, $node->attributes); } );
This extra long line lowercases all tagnames and the names of the
attributes in a given subtree.
@@ -416,9 +443,9 @@
=item first()
-=item next()
-
-=item previous()
+=item nextNode()
+
+=item previousNode()
=item last()
@@ -442,11 +469,11 @@
=head1 AUTHOR
-Christian Glahn, E<lt>christian.glahn at uibk.ac.atE<gt>
+Christian Glahn, E<lt>phish at cpan.orgE<gt>
=head1 COPYRIGHT
-(c) 2002, Christian Glahn. All rights reserved.
+(c) 2002-2007, Christian Glahn. All rights reserved.
This package is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
Modified: trunk/libxml-libxml-iterator-perl/lib/XML/LibXML/NodeList/Iterator.pm
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libxml-libxml-iterator-perl/lib/XML/LibXML/NodeList/Iterator.pm?rev=43672&op=diff
==============================================================================
--- trunk/libxml-libxml-iterator-perl/lib/XML/LibXML/NodeList/Iterator.pm (original)
+++ trunk/libxml-libxml-iterator-perl/lib/XML/LibXML/NodeList/Iterator.pm Fri Sep 4 12:01:56 2009
@@ -6,21 +6,13 @@
use XML::NodeFilter qw(:results);
use vars qw($VERSION);
-$VERSION = "1.00";
+$VERSION = "1.03";
use overload
- '++' => sub { $_[0]->next; $_[0]; },
- '--' => sub { $_[0]->previous; $_[0] },
- '<>' => sub {
- if ( wantarray ) {
- my @rv = ();
- while ( $_[0]->next ){ push @rv,$_;}
- return @rv;
- } else {
- return $_[0]->next
- };
- },
-;
+ '++' => sub { $_[0]->nextNode(); $_[0]; },
+ '--' => sub { $_[0]->previousNode(); $_[0] },
+ '<>' => sub {return wantarray ? $_[0]->_get_all : $_[0]->nextNode(); },
+ ;
sub new {
my $class = shift;
@@ -28,10 +20,10 @@
my $self = undef;
if ( defined $list ) {
$self = bless [
- $list,
- 0,
- [],
- ], $class;
+ $list,
+ -1,
+ [],
+ ], $class;
}
return $self;
@@ -57,19 +49,21 @@
return FILTER_ACCEPT;
}
-sub first { $_[0][1]=0;
- my $s = scalar(@{$_[0][0]});
- while ( $_[0][1] < $s ) {
- last if $_[0]->accept_node($_[0][0][$_[0][1]]) == FILTER_ACCEPT;
- $_[0][1]++;
- }
- return undef if $_[0][1] == $s;
- return $_[0][0][$_[0][1]]; }
+sub first {
+ $_[0][1]=0;
+ my $s = scalar(@{$_[0][0]});
+ while ( $_[0][1] < $s ) {
+ last if $_[0]->accept_node($_[0][0][$_[0][1]]) == FILTER_ACCEPT;
+ $_[0][1]++;
+ }
+ return undef if $_[0][1] == $s;
+ return $_[0][0][$_[0][1]];
+}
sub last {
my $i = scalar(@{$_[0][0]})-1;
while($i >= 0){
- if ( $_[0]->accept_node($_[0][0][$i] == FILTER_ACCEPT) ) {
+ if ( $_[0]->accept_node($_[0][0][$i]) == FILTER_ACCEPT ) {
$_[0][1] = $i;
last;
}
@@ -83,17 +77,34 @@
return $_[0][0][$i];
}
-sub current { return $_[0][0][$_[0][1]]; }
-sub index { return $_[0][1]; }
-
-sub next {
- if ( (scalar @{$_[0][0]}) <= ($_[0][1] + 1)) {
+sub current {
+ if ( $_[0][1] >= 0 || $_[0][1] < scalar @{$_[0][0]} ) {
+ return $_[0][0][$_[0][1]];
+ }
+ return undef;
+}
+
+sub index {
+ if ( $_[0][1] >= 0 || $_[0][1] < scalar @{$_[0][0]} ) {
+ return $_[0][1];
+ }
+ return undef;
+}
+
+sub next { return $_[0]->nextNode(); }
+sub previous { return $_[0]->previousNode(); }
+
+sub nextNode {
+ my $nlen = scalar @{$_[0][0]};
+ if ( $nlen <= ($_[0][1] + 1)) {
return undef;
}
my $i = $_[0][1];
+ $i = -1 if $i < 0; # assure that we end up with the first
+ # element in the first iteration
while ( 1 ) {
$i++;
- return undef if $i >= scalar @{$_[0][0]};
+ return undef if $i >= $nlen;
if ( $_[0]->accept_node( $_[0][0]->[$i] ) == FILTER_ACCEPT ) {
$_[0][1] = $i;
last;
@@ -102,7 +113,7 @@
return $_[0][0]->[$_[0][1]];
}
-sub previous {
+sub previousNode {
if ( $_[0][1] <= 0 ) {
return undef;
}
@@ -121,13 +132,27 @@
sub iterate {
my $self = shift;
my $funcref = shift;
+ my $rv;
+
return unless defined $funcref && ref( $funcref ) eq 'CODE';
- $self->[1] = -1;
- my $rv;
- while ( $self->next ) {
- $rv = $funcref->( $self, $_ );
+
+ $self->[1] = -1; # first element
+ while ( my $node = $self->next ) {
+ $rv = $funcref->( $self, $node );
}
return $rv;
+}
+
+# helper function for the <> operator
+# returns all nodes that have not yet been accessed
+sub _get_all {
+ my $self = shift;
+ my @retval = ();
+ my $node;
+ while ( $node = $self->next() ) {
+ push @retval, $node;
+ }
+ return @retval;
}
1;
@@ -149,7 +174,7 @@
my $iter= XML::LibXML::NodeList::Iterator->new( $nodelist );
# more control on the flow
- while ( $iter->next ) {
+ while ( $iter->nextNode ) {
# do something
}
@@ -171,11 +196,11 @@
=head1 AUTHOR
-Christian Glahn, E<lt>christian.glahn at uibk.ac.atE<gt>
+Christian Glahn, E<lt>phish at cpan.orgE<gt>
=head1 COPYRIGHT
-(c) 2002, Christian Glahn. All rights reserved.
+(c) 2002-2007, Christian Glahn. All rights reserved.
This package is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
Modified: trunk/libxml-libxml-iterator-perl/t/01basic.t
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libxml-libxml-iterator-perl/t/01basic.t?rev=43672&op=diff
==============================================================================
--- trunk/libxml-libxml-iterator-perl/t/01basic.t (original)
+++ trunk/libxml-libxml-iterator-perl/t/01basic.t Fri Sep 4 12:01:56 2009
@@ -1,49 +1,11 @@
use Test;
-BEGIN { plan tests => 32; }
+BEGIN { plan tests => 1; }
+END { if ($loaded) { ok(1);} }
-use XML::LibXML;
use XML::LibXML::Iterator;
use XML::LibXML::NodeList::Iterator;
-my $doc = XML::LibXML->new->parse_string( <<EOF );
-<test>
- text
- <foo/>
- <foo/>
- text
- <bar><kungfoo/></bar>
-</test>
-EOF
+$loaded = 1;
-print "# TREE ITERATION\n";
-my $iter = XML::LibXML::Iterator->new( $doc->documentElement );
-
-do {
- ok(1); # warn $iter->current->nodeName;
-}while ( $iter->next );
-
-do {
- ok(1); # warn $iter->current->nodeName;
-}while ( $iter->previous );
-
-
-$iter->iterate( sub { ok(1) } );
-
-$iter->first;
-ok( $iter->current->nodeName, "test" );
-
-my $n = $iter->last;
-ok( $iter->current->nodeName, "text" );
-
-
-print "# LIST ITERATION\n";
-my $nodelist = $doc->findnodes( '//foo' );
-my $nliter = XML::LibXML::NodeList::Iterator->new( $nodelist );
-
-while ( $nliter->next ) {
- ok(1);
-}
-
-$nliter->iterate( sub {ok(1)} );
More information about the Pkg-perl-cvs-commits
mailing list