diff -Nru libxml-libxml-iterator-perl-1.00/Changes libxml-libxml-iterator-perl-1.04/Changes --- libxml-libxml-iterator-perl-1.00/Changes 2002-11-08 17:18:36.000000000 +0000 +++ libxml-libxml-iterator-perl-1.04/Changes 2007-09-28 20:53:44.000000000 +0100 @@ -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. + diff -Nru /tmp/amUn2N6zj5/libxml-libxml-iterator-perl-1.00/debian/changelog /tmp/IyTKfzy7Tc/libxml-libxml-iterator-perl-1.04/debian/changelog --- libxml-libxml-iterator-perl-1.00/debian/changelog 2009-11-05 13:36:47.000000000 +0000 +++ libxml-libxml-iterator-perl-1.04/debian/changelog 2009-11-05 13:36:47.000000000 +0000 @@ -1,3 +1,27 @@ +libxml-libxml-iterator-perl (1.04-1) unstable; urgency=low + + * Take over for the Debian Perl Group on maintainer's request + (http://lists.alioth.debian.org/pipermail/pkg-perl-maintainers/2009- + September/025053.html) + * debian/control + + added: Vcs-* fields and Homepage fields + + added ${misc:Depends} to Depends: + + changed Maintainer to Debian Perl Group + * debian/watch: use dist-based URL. + * add myself to Uploaders + * use debhelper 7 short rules; bump build-dependency; add debian/compat + + do not ship redundant README + * add libxml-libxml-perl to (build-) dependencies + * add libxml-nodefilter-perl to B-D-I + * copyright: convert to machine-readable format + * watch: ensure dwo-digit upstream minor version + + * New upstream release + update upstream author email and years of copyright + * bump Standards-Version to 3.8.3 (no changes needed) + + -- Damyan Ivanov Fri, 04 Sep 2009 15:11:09 +0300 + libxml-libxml-iterator-perl (1.00-1) unstable; urgency=low * first Debian release of XML::LibXML::Iterator diff -Nru /tmp/amUn2N6zj5/libxml-libxml-iterator-perl-1.00/debian/compat /tmp/IyTKfzy7Tc/libxml-libxml-iterator-perl-1.04/debian/compat --- libxml-libxml-iterator-perl-1.00/debian/compat 1970-01-01 01:00:00.000000000 +0100 +++ libxml-libxml-iterator-perl-1.04/debian/compat 2009-11-05 13:36:47.000000000 +0000 @@ -0,0 +1 @@ +7 diff -Nru /tmp/amUn2N6zj5/libxml-libxml-iterator-perl-1.00/debian/control /tmp/IyTKfzy7Tc/libxml-libxml-iterator-perl-1.04/debian/control --- libxml-libxml-iterator-perl-1.00/debian/control 2009-11-05 13:36:47.000000000 +0000 +++ libxml-libxml-iterator-perl-1.04/debian/control 2009-11-05 13:36:47.000000000 +0000 @@ -1,13 +1,19 @@ Source: libxml-libxml-iterator-perl Section: perl Priority: optional -Build-Depends: debhelper, perl -Maintainer: Adrian von Bidder -Standards-Version: 3.7.2.2 +Build-Depends: debhelper (>= 7), perl +Build-Depends-Indep: libxml-libxml-perl, libxml-nodefilter-perl +Maintainer: Debian Perl Group +Uploaders: Damyan Ivanov +Standards-Version: 3.8.3 +Homepage: http://search.cpan.org/dist/XML-LibXML-Iterator/ +Vcs-Svn: svn://svn.debian.org/pkg-perl/trunk/libxml-libxml-iterator-perl/ +Vcs-Browser: http://svn.debian.org/viewsvn/pkg-perl/trunk/libxml-libxml-iterator-perl/ Package: libxml-libxml-iterator-perl Architecture: all -Depends: ${perl:Depends}, libxml-nodefilter-perl +Depends: ${misc:Depends}, ${perl:Depends}, libxml-nodefilter-perl, + libxml-libxml-perl Description: Iterator for XML parse-trees genereated by XML::LibXML This class allows to iterate through a DOM as it is done through an ordinary array, i.e. it implements the iterator part of the DOM Traversal and Range diff -Nru /tmp/amUn2N6zj5/libxml-libxml-iterator-perl-1.00/debian/copyright /tmp/IyTKfzy7Tc/libxml-libxml-iterator-perl-1.04/debian/copyright --- libxml-libxml-iterator-perl-1.00/debian/copyright 2009-11-05 13:36:47.000000000 +0000 +++ libxml-libxml-iterator-perl-1.04/debian/copyright 2009-11-05 13:36:47.000000000 +0000 @@ -1,24 +1,31 @@ -Download: - http://search.cpan.org/dist/XML-LibXML-Iterator/ - -Copyright: - Copyright 2002 by Christian Glahn - - This library is free software; you can redistribute it and/or modify - it under the same terms as Perl itself: +Format-Specification: + http://wiki.debian.org/Proposals/CopyrightFormat?action=recall&rev=196 +Upstream-Maintainer: Christian Glahn, +Upstream-Source: http://search.cpan.org/dist/XML-LibXML-Iterator/ +Upstream-Name: XML-LibXML-Iterator + +Files: * +Copyright: 2002-2007, Christian Glahn, +License-Alias: Perl +License: Artistic | GPL-1+ + This library is free software; you can redistribute it and/or modify + it under the same terms as Perl itself + +Files: debian/* +Copyright: 2007, Adrian von Bidder + 2009, Damyan Ivanov +License: Artistic | GPL-1+ +License: Artistic This program is free software; you can redistribute it and/or modify - it under the terms of either: - - a) the GNU General Public License as published by the Free Software - Foundation; either version 1, or (at your option) any later - version, or - - b) the "Artistic License" which comes with Perl. + it under the terms of the Artistic License, which comes with Perl. + On Debian GNU/Linux systems, the complete text of the Artistic License + can be found in `/usr/share/common-licenses/Artistic' +License: GPL-1+ + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 1, or (at your option) + any later version. On Debian GNU/Linux systems, the complete text of the GNU General - Public License can be found in `/usr/share/common-licenses/GPL' and - the Artistic Licence in `/usr/share/common-licenses/Artistic'. - -Debian: - The Debian package was prepared by Adrian von Bidder + Public License can be found in `/usr/share/common-licenses/GPL' diff -Nru /tmp/amUn2N6zj5/libxml-libxml-iterator-perl-1.00/debian/rules /tmp/IyTKfzy7Tc/libxml-libxml-iterator-perl-1.04/debian/rules --- libxml-libxml-iterator-perl-1.00/debian/rules 2009-11-05 13:36:47.000000000 +0000 +++ libxml-libxml-iterator-perl-1.04/debian/rules 2009-11-05 13:36:47.000000000 +0000 @@ -1,52 +1,4 @@ #!/usr/bin/make -f -export DH_COMPAT=4 - -PACKAGE=$(shell dh_listpackages) -PREFIX=$(PWD)/debian/$(PACKAGE)/usr - -ifndef PERL -PERL=/usr/bin/perl -endif - -build: build-stamp -build-stamp: - dh_testdir - $(PERL) Makefile.PL INSTALLDIRS=vendor - $(MAKE) - touch $@ - -clean: - dh_testdir - dh_testroot - rm -f build-stamp - -$(MAKE) realclean - rm -f Makefile Makefile.old - dh_clean - -install: - dh_testdir - dh_testroot - dh_clean -k - dh_installdirs - $(MAKE) install PREFIX="$(PREFIX)" - find "$(PREFIX)" -type d -name .svn | xargs rm -rf - -binary-arch: build install - -binary-indep: build install - dh_testdir - dh_testroot - dh_installdocs README - dh_installchangelogs Changes - dh_link - dh_compress - dh_fixperms - dh_installdeb - dh_perl - dh_gencontrol - dh_md5sums - dh_builddeb - -binary: binary-indep binary-arch -.PHONY: build clean install binary-indep binary-arch binary +%: + dh $@ diff -Nru /tmp/amUn2N6zj5/libxml-libxml-iterator-perl-1.00/debian/watch /tmp/IyTKfzy7Tc/libxml-libxml-iterator-perl-1.04/debian/watch --- libxml-libxml-iterator-perl-1.00/debian/watch 2009-11-05 13:36:47.000000000 +0000 +++ libxml-libxml-iterator-perl-1.04/debian/watch 2009-11-05 13:36:47.000000000 +0000 @@ -1,2 +1,2 @@ -version=2 -http://search.cpan.org/CPAN/authors/id/W/WI/WILLMOJG/Net-NTP-(.*)\.tar\.gz +version=3 +http://search.cpan.org/dist/XML-LibXML-Iterator/ .*/XML-LibXML-Iterator-v?(\d[\d.-]+)\.(?:tar(?:\.gz|\.bz2)?|tgz|zip) diff -Nru /tmp/amUn2N6zj5/libxml-libxml-iterator-perl-1.00/lib/XML/LibXML/Iterator.pm /tmp/IyTKfzy7Tc/libxml-libxml-iterator-perl-1.04/lib/XML/LibXML/Iterator.pm --- libxml-libxml-iterator-perl-1.00/lib/XML/LibXML/Iterator.pm 2002-11-08 17:18:36.000000000 +0000 +++ libxml-libxml-iterator-perl-1.04/lib/XML/LibXML/Iterator.pm 2007-09-28 20:53:15.000000000 +0100 @@ -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; + + if ( $self->{INDEX} != -1 ) { + my $fv = FILTER_SKIP; + unless ( scalar @filters > 0 ) { + $fv = FILTER_DECLINED; } - last if $fv == FILTER_ACCEPT or $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,26 +198,44 @@ } } else { - return undef if $self->{CURRENT}->isSameNode( $self->{FIRST} ) - and $self->{INDEX} > 0; + if ( defined $self->{CURRENT} ) { + return undef if $self->{CURRENT}->isSameNode( $self->{FIRST} ) + and $self->{INDEX} > 0; - if ( $self->{CURRENT}->hasChildNodes ) { - $node = $self->{CURRENT}->firstChild; + 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; __END__ @@ -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 nextNode() -=item previous() +=item previousNode() =item last() @@ -442,11 +469,11 @@ =head1 AUTHOR -Christian Glahn, Echristian.glahn@uibk.ac.atE +Christian Glahn, Ephish@cpan.orgE =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. diff -Nru /tmp/amUn2N6zj5/libxml-libxml-iterator-perl-1.00/lib/XML/LibXML/NodeList/Iterator.pm /tmp/IyTKfzy7Tc/libxml-libxml-iterator-perl-1.04/lib/XML/LibXML/NodeList/Iterator.pm --- libxml-libxml-iterator-perl-1.00/lib/XML/LibXML/NodeList/Iterator.pm 2002-11-08 17:18:36.000000000 +0000 +++ libxml-libxml-iterator-perl-1.04/lib/XML/LibXML/NodeList/Iterator.pm 2007-09-28 20:52:22.000000000 +0100 @@ -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 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 next { - if ( (scalar @{$_[0][0]}) <= ($_[0][1] + 1)) { +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,15 +132,29 @@ sub iterate { my $self = shift; my $funcref = shift; - return unless defined $funcref && ref( $funcref ) eq 'CODE'; - $self->[1] = -1; my $rv; - while ( $self->next ) { - $rv = $funcref->( $self, $_ ); + + return unless defined $funcref && ref( $funcref ) eq 'CODE'; + + $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; =pod @@ -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, Echristian.glahn@uibk.ac.atE +Christian Glahn, Ephish@cpan.orgE =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. diff -Nru /tmp/amUn2N6zj5/libxml-libxml-iterator-perl-1.00/LICENSE /tmp/IyTKfzy7Tc/libxml-libxml-iterator-perl-1.04/LICENSE --- libxml-libxml-iterator-perl-1.00/LICENSE 1970-01-01 01:00:00.000000000 +0100 +++ libxml-libxml-iterator-perl-1.04/LICENSE 2007-06-23 14:43:22.000000000 +0100 @@ -0,0 +1,15 @@ +LICENSE +======= + +XML::LibXML::Iterator is free software, you may use it and distribute +it under the same terms as Perl itself. + +Copyright 2002-2007, Christian Glahn, All rights reserved. + +DISCLAIMER +========== + +THIS PROGRAM IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, BUT WITHOUT ANY +WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR A +PARTICULAR PURPOSE. + diff -Nru /tmp/amUn2N6zj5/libxml-libxml-iterator-perl-1.00/MANIFEST /tmp/IyTKfzy7Tc/libxml-libxml-iterator-perl-1.04/MANIFEST --- libxml-libxml-iterator-perl-1.00/MANIFEST 2002-11-08 17:18:36.000000000 +0000 +++ libxml-libxml-iterator-perl-1.04/MANIFEST 2007-09-28 20:54:16.000000000 +0100 @@ -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) diff -Nru /tmp/amUn2N6zj5/libxml-libxml-iterator-perl-1.00/META.yml /tmp/IyTKfzy7Tc/libxml-libxml-iterator-perl-1.04/META.yml --- libxml-libxml-iterator-perl-1.00/META.yml 1970-01-01 01:00:00.000000000 +0100 +++ libxml-libxml-iterator-perl-1.04/META.yml 2007-09-28 20:54:15.000000000 +0100 @@ -0,0 +1,12 @@ +# http://module-build.sourceforge.net/META-spec.html +#XXXXXXX This is a prototype!!! It will change in the future!!! XXXXX# +name: XML-LibXML-Iterator +version: 1.04 +version_from: lib/XML/LibXML/Iterator.pm +installdirs: site +requires: + XML::LibXML: 1.52 + XML::NodeFilter: 0 + +distribution_type: module +generated_by: ExtUtils::MakeMaker version 6.30_01 diff -Nru /tmp/amUn2N6zj5/libxml-libxml-iterator-perl-1.00/t/01basic.t /tmp/IyTKfzy7Tc/libxml-libxml-iterator-perl-1.04/t/01basic.t --- libxml-libxml-iterator-perl-1.00/t/01basic.t 2002-11-08 17:18:36.000000000 +0000 +++ libxml-libxml-iterator-perl-1.04/t/01basic.t 2007-06-23 14:33:13.000000000 +0100 @@ -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( < - text - - - text - - -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)} ); diff -Nru /tmp/amUn2N6zj5/libxml-libxml-iterator-perl-1.00/t/02tree.t /tmp/IyTKfzy7Tc/libxml-libxml-iterator-perl-1.04/t/02tree.t --- libxml-libxml-iterator-perl-1.00/t/02tree.t 1970-01-01 01:00:00.000000000 +0100 +++ libxml-libxml-iterator-perl-1.04/t/02tree.t 2007-06-23 14:32:26.000000000 +0100 @@ -0,0 +1,231 @@ +use Test; + +BEGIN { plan tests => 7; } + +use XML::LibXML; +use XML::LibXML::Iterator; + +my $xmlstr = "T"; +my $libversion; +eval { $libversion = XML::LibXML::LIBXML_VERSION(); }; + +sub t01_tree_first_element { + my $doc = XML::LibXML->new->parse_string( ''); + + unless ( defined $doc ) { + print "# XML string was not parsed properly\n"; + return 0; + } + + my $iterator = XML::LibXML::Iterator->new( $doc->documentElement ); + + my $node = $iterator->nextNode(); + + unless ( defined $node ) { + print "# next did not return a node\n"; + return 0; + } + + unless ( $node->nodeName() eq 'test' ) { + print "# expected 'test' received '" . $node->nodeName() . "'\n"; + return 0; + } + + return 1; +} + +ok(t01_tree_first_element()); + +sub t06_set_first { + my $doc = XML::LibXML->new->parse_string( $xmlstr ); + + unless ( defined $doc ) { + print "# XML string was not parsed properly\n"; + return 0; + } + + my $iterator = XML::LibXML::Iterator->new( $doc->documentElement ); + + $iterator->first(); + + unless ( defined $iterator->current() ) { + print "# there is no first node\n"; + return 0; + } + + unless ( $iterator->current()->nodeName() eq "A" ) { + print "# expected nodeName 'A' received '" + . $iterator->current()->nodeName() + . "'\n"; + return 0; + } + + return 1; +} +ok(t06_set_first()); + +sub t07_set_last { + my $doc = XML::LibXML->new->parse_string( $xmlstr ); + + unless ( defined $doc ) { + print "# XML string was not parsed properly\n"; + return 0; + } + + my $iterator = XML::LibXML::Iterator->new( $doc->documentElement ); + + $iterator->last(); + + unless ( defined $iterator->current() ) { + print "# there is no last node\n"; + return 0; + } + + unless ( $iterator->current()->nodeName() eq "D" ) { + print "# expected nodeName 'D' received '" + . $iterator->current()->nodeName() + . "'\n"; + return 0; + } + + return 1; +} + +ok(t07_set_last()); + +sub t02_loop_forward { + my $doc = XML::LibXML->new->parse_string( $xmlstr ); + + unless ( defined $doc ) { + print "# XML string was not parsed properly\n"; + return 0; + } + + my $iterator = XML::LibXML::Iterator->new( $doc->documentElement ); + + my $i = 0; + + while ( $iterator->nextNode() ) { + $i++; + } + + unless ( $i == 6 ) { + print "# expected 6 iterations done " . $i . "\n"; + return 0; + } + + $iterator->first(); + $i = 0; + + while ( $iterator->nextNode() ) { + $i++; + } + + unless ( $i == 5 ) { + print "# expected 5 iterations done " . $i . "\n"; + return 0; + } + + unless ( defined $iterator->current() ) { + print "# wen out of scope\n"; + return 0; + } + + unless ( $iterator->current()->nodeName() eq "D" ) { + print "# expected nodeName 'D' received '" + . $iterator->current()->nodeName() + . "'\n"; + return 0; + } + + return 1; +} +ok(t02_loop_forward()); + +sub t03_loop_backward { + my $doc = XML::LibXML->new->parse_string( $xmlstr ); + + unless ( defined $doc ) { + print "# XML string was not parsed properly\n"; + return 0; + } + + my $iterator = XML::LibXML::Iterator->new( $doc->documentElement ); + + my $i = 0; + + $iterator->last(); + while ( $iterator->previousNode() ) { + $i++; + } + + unless ( $i == 5 ) { + print "# expected 5 iterations done " . $i . "\n"; + return 0; + } + + return 1; +} +ok(t03_loop_backward()); + +sub t04_loop_forward_backward { + my $doc = XML::LibXML->new->parse_string( $xmlstr ); + + unless ( defined $doc ) { + print "# XML string was not parsed properly\n"; + return 0; + } + + my $iterator = XML::LibXML::Iterator->new( $doc->documentElement ); + + my $i = 0; + + while ( $iterator->nextNode() ) { + $i++; + } + while ( $iterator->previousNode() ) { + $i++; + } + + unless ( $i == 11 ) { + print "# expected 11 iterations done " . $i . "\n"; + return 0; + } + + unless ( defined $iterator->current() ) { + print "# went out of scope!\n"; + return 0; + } + + unless ( $iterator->current()->nodeName() eq "A" ) { + print "# expected nodeName 'A' received '" + . $iterator->current()->nodeName() + . "'\n"; + return 0; + } + + return 1; +} +ok(t04_loop_forward_backward()); + +sub t05_run_iterate { + my $doc = XML::LibXML->new->parse_string( $xmlstr ); + + unless ( defined $doc ) { + print "# XML string was not parsed properly\n"; + return 0; + } + + my $iterator = XML::LibXML::Iterator->new( $doc->documentElement ); + + my $i = 0; + $iterator->iterate( sub { $i++; } ); + + unless ( $i == 6 ) { + print "# expected 6 iterations done " . $i . "\n"; + return 0; + } + + return 1; +} +ok(t05_run_iterate()); diff -Nru /tmp/amUn2N6zj5/libxml-libxml-iterator-perl-1.00/t/03list.t /tmp/IyTKfzy7Tc/libxml-libxml-iterator-perl-1.04/t/03list.t --- libxml-libxml-iterator-perl-1.00/t/03list.t 1970-01-01 01:00:00.000000000 +0100 +++ libxml-libxml-iterator-perl-1.04/t/03list.t 2007-09-28 20:52:52.000000000 +0100 @@ -0,0 +1,342 @@ +use Test; + + +BEGIN { plan tests => 9; } + +use XML::LibXML; +use XML::LibXML::NodeList::Iterator; + +my $xmlstr = "T"; + +sub t01_list_first_element { + my $doc = XML::LibXML->new->parse_string( ''); + + unless ( defined $doc ) { + print "# XML string was not parsed properly\n"; + return 0; + } + + my $nodelist = $doc->findnodes( '/test/*' ); + my $iterator = XML::LibXML::NodeList::Iterator->new( $nodelist ); + + my $node = $iterator->next(); + + unless ( defined $node ) { + print "# next did not return a node\n"; + return 0; + } + + unless ( $node->nodeName() eq 'n1' ) { + print "# expected 'n1' received '" . $node->nodeName() . "'\n"; + return 0; + } + + return 1; +} + +ok(t01_list_first_element()); + +sub t06_set_first { + my $doc = XML::LibXML->new->parse_string( $xmlstr ); + + unless ( defined $doc ) { + print "# XML string was not parsed properly\n"; + return 0; + } + + my $nodelist = $doc->findnodes( '//A | //B | //C' ); + my $iterator = XML::LibXML::NodeList::Iterator->new( $nodelist ); + + $iterator->first(); + + unless ( defined $iterator->current() ) { + print "# there is no first node\n"; + return 0; + } + + unless ( $iterator->current()->nodeName() eq "A" ) { + print "# expected nodeName 'A' received '" + . $iterator->current()->nodeName() + . "'\n"; + return 0; + } + + return 1; +} +ok(t06_set_first()); + +sub t07_set_last { + my $doc = XML::LibXML->new->parse_string( $xmlstr ); + + unless ( defined $doc ) { + print "# XML string was not parsed properly\n"; + return 0; + } + + my $nodelist = $doc->findnodes( '//A | //B | //C' ); + my $iterator = XML::LibXML::NodeList::Iterator->new( $nodelist ); + + $iterator->last(); + + unless ( defined $iterator->current() ) { + print "# there is no last node\n"; + return 0; + } + + unless ( $iterator->current()->nodeName() eq "C" ) { + print "# expected nodeName 'C' received '" + . $iterator->current()->nodeName() + . "'\n"; + return 0; + } + + return 1; +} + +ok(t07_set_last()); + +sub t02_loop_forward { + my $doc = XML::LibXML->new->parse_string( $xmlstr ); + + unless ( defined $doc ) { + print "# XML string was not parsed properly\n"; + return 0; + } + my $nodelist = $doc->findnodes( '//A|//B|//C' ); + my $iterator = XML::LibXML::NodeList::Iterator->new( $nodelist ); + + my $i = 0; + + while ( $iterator->nextNode() ) { + $i++; + } + + unless ( $i == 4 ) { + print "# expected 4 iterations done " . $i . "\n"; + return 0; + } + + unless ( defined $iterator->current() ) { + print "# wen out of scope\n"; + return 0; + } + + unless ( $iterator->current()->nodeName() eq "C" ) { + print "# expected nodeName 'C' received '" + . $iterator->current()->nodeName() + . "'\n"; + return 0; + } + + $iterator->first(); + $i = 0; + + while ( $iterator->nextNode() ) { + $i++; + } + + unless ( $i == 3 ) { + print "# expected 3 iterations done " . $i . "\n"; + return 0; + } + + unless ( defined $iterator->current() ) { + print "# wen out of scope\n"; + return 0; + } + + unless ( $iterator->current()->nodeName() eq "C" ) { + print "# expected nodeName 'C' received '" + . $iterator->current()->nodeName() + . "'\n"; + return 0; + } + + return 1; +} +ok(t02_loop_forward()); + +sub t03_loop_backward { + my $doc = XML::LibXML->new->parse_string( $xmlstr ); + + unless ( defined $doc ) { + print "# XML string was not parsed properly\n"; + return 0; + } + + my $nodelist = $doc->findnodes( '//A | //B | //C' ); + my $iterator = XML::LibXML::NodeList::Iterator->new( $nodelist ); + + my $i = 0; + + $iterator->last(); + while ( $iterator->previousNode() ) { + $i++; + } + + unless ( $i == 3 ) { + print "# expected 3 iterations done " . $i . "\n"; + return 0; + } + + unless ( defined $iterator->current() ) { + print "# went out of scope!\n"; + return 0; + } + + unless ( $iterator->current()->nodeName() eq "A" ) { + print "# expected nodeName 'A' received '" + . $iterator->current()->nodeName() + . "'\n"; + return 0; + } + return 1; +} +ok(t03_loop_backward()); + +sub t04_loop_forward_backward { + my $doc = XML::LibXML->new->parse_string( $xmlstr ); + + unless ( defined $doc ) { + print "# XML string was not parsed properly\n"; + return 0; + } + + my $nodelist = $doc->findnodes( '//A | //B | //C' ); + my $iterator = XML::LibXML::NodeList::Iterator->new( $nodelist ); + + my $i = 0; + + while ( $iterator->nextNode() ) { + $i++; + } + while ( $iterator->previousNode() ) { + $i++; + } + + unless ( $i == 7 ) { + print "# expected 7 iterations done " . $i . "\n"; + return 0; + } + + unless ( defined $iterator->current() ) { + print "# went out of scope!\n"; + return 0; + } + + unless ( $iterator->current()->nodeName() eq "A" ) { + print "# expected nodeName 'A' received '" + . $iterator->current()->nodeName() + . "'\n"; + return 0; + } + + return 1; +} +ok(t04_loop_forward_backward()); + +sub t05_run_iterate { + my $doc = XML::LibXML->new->parse_string( $xmlstr ); + + unless ( defined $doc ) { + print "# XML string was not parsed properly\n"; + return 0; + } + + my $nodelist = $doc->findnodes( '//A | //B | //C' ); + my $iterator = XML::LibXML::NodeList::Iterator->new( $nodelist ); + + my $i = 0; + $iterator->iterate( sub { $i++; } ); + + unless ( $i == 4 ) { + print "# expected 4 iterations done " . $i . "\n"; + return 0; + } + + return 1; +} +ok(t05_run_iterate()); + +# RT#28688 +package MyFilter; + +use base qw(XML::NodeFilter); +use XML::NodeFilter qw(:results); +use UNIVERSAL; + +sub accept_node { + my $self = shift; + my $node = shift; + if (!UNIVERSAL::isa($node, 'XML::LibXML::Element')) { + die "invalid node in MyFilter::accept_node()"; + } + return FILTER_DECLINED; +} + +package main; + +sub t08_last_with_filter { + my $doc = XML::LibXML->new->parse_string( $xmlstr ); + + unless ( defined $doc ) { + print "# XML string was not parsed properly\n"; + return 0; + } + + my $nodelist = $doc->findnodes( '//*' ); + my $iterator = XML::LibXML::NodeList::Iterator->new( $nodelist ); + $iterator->add_filter( MyFilter->new() ); + + $iterator->last(); + + unless ( defined $iterator->current() ) { + print "# there is no last node\n"; + return 0; + } + + unless ( $iterator->current()->nodeName() eq "D" ) { + print "# expected nodeName 'D' received '" + . $iterator->current()->nodeName() + . "'\n"; + return 0; + } + + return 1; +} +ok(t08_last_with_filter()); + +# END RT#28688 + +# RT#29262 + +sub t09_pass_nodes { + my $doc = XML::LibXML->new->parse_string( '' ); + + my $nodelist = $doc->findnodes('/a/*'); + my $iterator = XML::LibXML::NodeList::Iterator->new( $nodelist ); + + my $i = 0; + my $cstr = ''; + $iterator->iterate( sub { my($s, $n) = @_; + if ( defined $n && $n->can('nodeName') ) { + $i++; + $cstr.=$n->nodeName(); + } + }); + + unless ( $i == 2 ) { + print "# wrong number of nodes has been processed! $i\n"; + return 0; + } + unless ( $cstr eq 'bc' ) { + print "# wrong nodes have been processed! '$cstr'\n"; + return 0; + } + + return 1; +} + +ok(t09_pass_nodes()); + +# END RT#29262