r18491 - in /trunk/libxml-xpathengine-perl: Changes META.yml debian/changelog lib/XML/XPathEngine.pm lib/XML/XPathEngine/Step.pm t/00-load.t t/01_basic.t t/minitree.pm
gregoa-guest at users.alioth.debian.org
gregoa-guest at users.alioth.debian.org
Sat Apr 12 11:07:45 UTC 2008
Author: gregoa-guest
Date: Sat Apr 12 11:07:45 2008
New Revision: 18491
URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=18491
Log:
New upstream release.
Modified:
trunk/libxml-xpathengine-perl/Changes
trunk/libxml-xpathengine-perl/META.yml
trunk/libxml-xpathengine-perl/debian/changelog
trunk/libxml-xpathengine-perl/lib/XML/XPathEngine.pm
trunk/libxml-xpathengine-perl/lib/XML/XPathEngine/Step.pm
trunk/libxml-xpathengine-perl/t/00-load.t
trunk/libxml-xpathengine-perl/t/01_basic.t
trunk/libxml-xpathengine-perl/t/minitree.pm
Modified: trunk/libxml-xpathengine-perl/Changes
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libxml-xpathengine-perl/Changes?rev=18491&op=diff
==============================================================================
--- trunk/libxml-xpathengine-perl/Changes (original)
+++ trunk/libxml-xpathengine-perl/Changes Sat Apr 12 11:07:45 2008
@@ -1,25 +1,51 @@
Revision history for XML::XPathEngine
-0.08 Fixed bug in XML::XPathEngine::Step::axis_preceding
+version: 0.09
+fix: namespace processing was a bit dodgy, it's been cleaned up now.
+ Tested through XML::Twig::XPath and XML::DOM::XPath
+fix: count did not work (RT #34854), found and patched by
+ Yasuhiro Matsumoto
+ http://rt.cpan.org/Ticket/Display.html?id=34854
+added: XML::XPathEngine set_strict_namespaces method, which makes
+ namespace processing more standard compliant, and probably often
+ more of a pain.
+ Tested through XML::Twig::XPath
+ Thanks to Timothy Appnel for his input in that matter
+added: XML::XPathEngine findnodes_as_strings method, which returns an
+ array of strings (the getValue of the nodes).
+fixed: findnodes_as_string now returns the empty string if the result
+ of the XPath query is a boolean (XML::XPathEngine::Boolean), as
+ when querying //@id="foo" for example. This makes the behaviour
+ similar to XML::LibXML's.
+
+version:0.08
+fix: Fixed bug in XML::XPathEngine::Step::axis_preceding
(same bug as with axis_following)
-0.07 Fixed bug in the previous bug fix
+version: 0.07
+fix: Fixed bug in the previous bug fix
-0.06 Fixed bug in XML::XPathEngine::Step::axis_following
+version: 0.06
+fix: Fixed bug in XML::XPathEngine::Step::axis_following
that messed up queries using the 'following' axis
(tested by HTML::TreeBuilder::XPath 0.07)
-0.05 Fixed bug in XML::XPathEngine::Function::as_xml
+version: 0.05
+fix: Fixed bug in XML::XPathEngine::Function::as_xml
as per RT #21951 (spotted by BJOERN)
see http://rt.cpan.org/Ticket/Display.html?id=21951
-0.04 Fixed bug in Step.pm
+version: 0.04
+fix: Fixed bug in Step.pm
-0.03 Bug fixes for queries involving elt="text" (through XML::Twig::XPath),
+version: 0.03
+fix: Bug fixes for queries involving elt="text" (tested through
+ XML::Twig::XPath),
the lang() function
-0.02 First version on CPAN
+version: 0.02
+released: First version on CPAN
-0.01 Date/time
- First version, released on an unsuspecting world.
+version: 0.01
+created: First version, released on an unsuspecting world.
Modified: trunk/libxml-xpathengine-perl/META.yml
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libxml-xpathengine-perl/META.yml?rev=18491&op=diff
==============================================================================
--- trunk/libxml-xpathengine-perl/META.yml (original)
+++ trunk/libxml-xpathengine-perl/META.yml Sat Apr 12 11:07:45 2008
@@ -1,14 +1,14 @@
--- #YAML:1.0
name: XML-XPathEngine
-version: 0.08
+version: 0.09
abstract: a re-usable XPath engine for DOM-like trees
license: ~
-generated_by: ExtUtils::MakeMaker version 6.31
+author:
+ - Michel Rodriguez <mirod at cpan.org>
+generated_by: ExtUtils::MakeMaker version 6.44
distribution_type: module
requires:
Test::More: 0
meta-spec:
- url: http://module-build.sourceforge.net/META-spec-v1.2.html
- version: 1.2
-author:
- - Michel Rodriguez <mirod at cpan.org>
+ url: http://module-build.sourceforge.net/META-spec-v1.3.html
+ version: 1.3
Modified: trunk/libxml-xpathengine-perl/debian/changelog
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libxml-xpathengine-perl/debian/changelog?rev=18491&op=diff
==============================================================================
--- trunk/libxml-xpathengine-perl/debian/changelog (original)
+++ trunk/libxml-xpathengine-perl/debian/changelog Sat Apr 12 11:07:45 2008
@@ -1,3 +1,9 @@
+libxml-xpathengine-perl (0.09-1) UNRELEASED; urgency=low
+
+ * New upstream release.
+
+ -- gregor herrmann <gregor+debian at comodo.priv.at> Sat, 12 Apr 2008 13:05:21 +0200
+
libxml-xpathengine-perl (0.08-2) unstable; urgency=low
[ gregor herrmann ]
Modified: trunk/libxml-xpathengine-perl/lib/XML/XPathEngine.pm
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libxml-xpathengine-perl/lib/XML/XPathEngine.pm?rev=18491&op=diff
==============================================================================
--- trunk/libxml-xpathengine-perl/lib/XML/XPathEngine.pm (original)
+++ trunk/libxml-xpathengine-perl/lib/XML/XPathEngine.pm Sat Apr 12 11:07:45 2008
@@ -5,7 +5,7 @@
use vars qw($VERSION $AUTOLOAD $revision);
-$VERSION = '0.08';
+$VERSION = '0.09';
$XML::XPathEngine::Namespaces = 0;
$XML::XPathEngine::DEBUG = 0;
@@ -106,7 +106,7 @@
if ($results->isa('XML::XPathEngine::NodeSet'))
{ return wantarray ? $results->get_nodelist : $results; }
else
- { return wantarray ? () : XML::XPathEngine::NodeSet->new(); }
+ { return wantarray ? ($results) : $results; } # result should be SCALAR
}
@@ -116,14 +116,38 @@
my $results = $self->find( $path, $context);
+
if ($results->isa('XML::XPathEngine::NodeSet')) {
- return join('', map { $_->toString } $results->get_nodelist);
+ return join '', map { $_->toString } $results->get_nodelist;
+ }
+ elsif ($results->isa('XML::XPathEngine::Boolean')) {
+ return ''; # to behave like XML::LibXML
}
elsif ($results->isa('XML::XPathEngine::Node')) {
return $results->toString;
}
else {
- return XML::XPathEngine::Node::XMLescape($results->value);
+ return _xml_escape_text($results->value);
+ }
+}
+
+sub findnodes_as_strings {
+ my $self = shift;
+ my ($path, $context) = @_;
+
+ my $results = $self->find( $path, $context);
+
+ if ($results->isa('XML::XPathEngine::NodeSet')) {
+ return map { $_->getValue } $results->get_nodelist;
+ }
+ elsif ($results->isa('XML::XPathEngine::Boolean')) {
+ return (); # to behave like XML::LibXML
+ }
+ elsif ($results->isa('XML::XPathEngine::Node')) {
+ return $results->getValue;
+ }
+ else {
+ return _xml_escape_text($results->value);
}
}
@@ -160,23 +184,29 @@
sub set_namespace {
my $self = shift;
my ($prefix, $expanded) = @_;
+ $self->{uses_namespaces}=1;
$self->{namespaces}{$prefix} = $expanded;
}
sub clear_namespaces {
my $self = shift;
+ $self->{uses_namespaces}=0;
$self->{namespaces} = {};
}
sub get_namespace {
my $self = shift;
my ($prefix, $node) = @_;
- if (my $ns = $self->{namespaces}{$prefix}) {
- return $ns;
- }
- if (my $nsnode = $node->getNamespace($prefix)) {
- return $nsnode->getValue();
- }
+
+ my $ns= $node ? $node->getNamespace($prefix)
+ : $self->{uses_namespaces} ? $self->{namespaces}->{$prefix}
+ : $prefix;
+ return $ns;
+}
+
+sub set_strict_namespaces {
+ my( $self, $strict) = @_;
+ $self->{strict_namespaces}= $strict;
}
sub _get_context_set { $_[0]->{context_set}; }
@@ -189,9 +219,12 @@
sub _parse {
my $self = shift;
my $path = shift;
- if ($CACHE{$path}) {
- return $CACHE{$path};
- }
+
+ my $context= join( '&&', $path, map { "$_=>$self->{namespaces}->{$_}" } sort keys %{$self->{namespaces}});
+ #warn "context: $context\n";
+
+ if ($CACHE{$context}) { return $CACHE{$context}; }
+
my $tokens = $self->_tokenize($path);
$self->{_tokpos} = 0;
@@ -201,8 +234,11 @@
# didn't manage to parse entire expression - throw an exception
die "Parse of expression $path failed - junk after end of expression: $tokens->[$self->{_tokpos}]";
}
-
- $CACHE{$path} = $tree;
+
+ $tree->{uses_namespaces}= $self->{uses_namespaces};
+ $tree->{strict_namespaces}= $self->{strict_namespaces};
+
+ $CACHE{$context} = $tree;
_debug("PARSED Expr to:\n", $tree->as_string, "\n") if( $XML::XPathEngine::DEBUG);
@@ -914,6 +950,16 @@
}
}
+{ my %ENT;
+ BEGIN { %ENT= ( '&' => '&', '<' => '<', '>' => '>', '"' => '"e;'); }
+
+ sub _xml_escape_text
+ { my( $text)= @_;
+ $text=~ s{([&<>])}{$ENT{$1}}g;
+ return $text;
+ }
+}
+
sub _debug {
my ($pkg, $file, $line, $sub) = caller(1);
@@ -989,8 +1035,13 @@
=head2 findnodes_as_string ($path, $context)
-Returns the nodes found reproduced as XML. The result is not guaranteed
-to be valid XML though.
+Returns the nodes found as a single string. The result is
+not guaranteed to be valid XML though (it could for example be just text
+if the query returns attribute values).
+
+=head2 findnodes_as_strings ($path, $context)
+
+Returns the nodes found as a list of strings, one per node found.
=head2 findvalue ($path, $context)
@@ -1045,6 +1096,18 @@
Returns the uri associated to the prefix for the node (mostly for internal usage)
+=head2 set_strict_namespaces ($strict)
+
+By default, for historical as well as convenience reasons, XML::XPathEngine
+has a slightly non-standard way of dealing with the default namespace.
+
+If you search for C<//tag> it will return elements C<tag>. As far as I understand it,
+if the document has a default namespace, this should not return anything.
+You would have to first do a C<set_namespace>, and then search using the namespace.
+
+Passing a true value to C<set_strict_namespaces> will activate this behaviour, passing a
+false value will return it to its default behaviour.
+
=head2 set_var ($var. $val)
Sets an XPath variable (that can be used in queries as C<$var>)
Modified: trunk/libxml-xpathengine-perl/lib/XML/XPathEngine/Step.pm
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libxml-xpathengine-perl/lib/XML/XPathEngine/Step.pm?rev=18491&op=diff
==============================================================================
--- trunk/libxml-xpathengine-perl/lib/XML/XPathEngine/Step.pm (original)
+++ trunk/libxml-xpathengine-perl/lib/XML/XPathEngine/Step.pm Sat Apr 12 11:07:45 2008
@@ -129,7 +129,7 @@
my $from = shift; # context nodeset
if( $from && !$from->isa( 'XML::XPathEngine::NodeSet'))
- { #warn "fixing $from!\n";
+ {
my $from_nodeset= XML::XPathEngine::NodeSet->new();
$from_nodeset->push( $from);
$from= $from_nodeset;
@@ -387,24 +387,15 @@
if ($test == test_ncwild) {
return unless $node->isElementNode;
- my $match_ns = $self->{pp}->get_namespace($self->{literal}, $node);
- if (my $node_nsnode = $node->getNamespace()) {
- return 1 if $match_ns eq $node_nsnode->getValue;
- }
+ return _match_ns( $self, $node);
}
elsif ($test == test_qname) {
return unless $node->isElementNode;
- if ($self->{literal} =~ /:/) {
- my ($prefix, $name) = split(':', $self->{literal}, 2);
- my $match_ns = $self->{pp}->get_namespace($prefix, $node);
- if (my $node_nsnode = $node->getNamespace()) {
-# warn "match: '$self->{literal}' match NS: '$match_ns' got NS: '", $node_nsnode->getValue, "'\n";
- return 1 if ($match_ns eq $node_nsnode->getValue) &&
- ($name eq $node->getLocalName);
+ if ($self->{literal} =~ /:/ || $self->{pp}->{strict_namespaces}) {
+ my ($prefix, $name) = _name2prefix_and_local_name( $self->{literal});
+ return 1 if( ($name eq $node->getLocalName) && _match_ns( $self, $node));
}
- }
else {
-# warn "Node test: ", $node->getName, "\n";
return 1 if $node->getName eq $self->{literal};
}
}
@@ -430,32 +421,57 @@
return; # fallthrough returns false
}
+sub _name2prefix_and_local_name
+ { my $name= shift;
+ return $name =~ /:/ ? split(':', $name, 2) : ( '', $name);
+ }
+sub _name2prefix
+ { my $name= shift;
+ if( $name=~ m{^(.*?):}) { return $1; } else { return ''; }
+ }
+
+sub _match_ns
+ { my( $self, $node)= @_;
+ my $pp= $self->{pp};
+ my $prefix= _name2prefix( $self->{literal});
+ my( $match_ns, $node_ns);
+ if( $pp->{uses_namespaces} || $pp->{strict_namespaces})
+ { $match_ns = $pp->get_namespace($prefix);
+ if( $match_ns || $pp->{strict_namespaces})
+ { $node_ns= $node->getNamespace->getValue; }
+ else
+ { # non-standard behaviour: if the query prefix is not declared
+ # compare the 2 prefixes
+ $match_ns = $prefix;
+ $node_ns = _name2prefix( $node->getName);
+ }
+ }
+ else
+ { $match_ns = $prefix;
+ $node_ns = _name2prefix( $node->getName);
+ }
+
+ return $match_ns eq $node_ns;
+ }
+
+
sub test_attribute {
my $self = shift;
my $node = shift;
-
-# warn "test_attrib: '$self->{test}' against: ", $node->getName, "\n";
-# warn "node type: $node->[node_type]\n";
my $test = $self->{test};
return 1 if ($test == test_attr_any) || ($test == test_nt_node);
if ($test == test_attr_ncwild) {
- my $match_ns = $self->{pp}->get_namespace($self->{literal}, $node);
- if (my $node_nsnode = $node->getNamespace()) {
- return 1 if $match_ns eq $node_nsnode->getValue;
- }
+ return 1 if _match_ns( $self, $node);
}
elsif ($test == test_attr_qname) {
if ($self->{literal} =~ /:/) {
- my ($prefix, $name) = split(':', $self->{literal}, 2);
- my $match_ns = $self->{pp}->get_namespace($prefix, $node);
- if (my $node_nsnode = $node->getNamespace()) {
- return 1 if ($match_ns eq $node_nsnode->getValue) &&
- ($name eq $node->getLocalName);
+ my ($prefix, $name) = _name2prefix_and_local_name( $self->{literal});
+
+ return 1 if ( ($name eq $node->getLocalName) && ( _match_ns( $self, $node)) );
}
- }
else {
return 1 if $node->getName eq $self->{literal};
}
@@ -509,7 +525,6 @@
$self->{pp}->_set_context_set($nodeset);
$self->{pp}->_set_context_pos($i);
my $result = $predicate->evaluate($nodeset->get_node($i));
- #warn "\$result is a ", ref( $result), ": '$result', \$i: '$i'\n";
if ($result->isa('XML::XPathEngine::Boolean')) {
if ($result->value) {
$newset->push($nodeset->get_node($i));
Modified: trunk/libxml-xpathengine-perl/t/00-load.t
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libxml-xpathengine-perl/t/00-load.t?rev=18491&op=diff
==============================================================================
--- trunk/libxml-xpathengine-perl/t/00-load.t (original)
+++ trunk/libxml-xpathengine-perl/t/00-load.t Sat Apr 12 11:07:45 2008
@@ -4,4 +4,4 @@
use_ok( 'XML::XPathEngine' );
}
-diag( "Testing XML::XPathEngine $XML::XPathEngine::VERSION, Perl 5.008007, /usr/bin/perl" );
+diag( "Testing XML::XPathEngine $XML::XPathEngine::VERSION, Perl $], /usr/bin/perl" );
Modified: trunk/libxml-xpathengine-perl/t/01_basic.t
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libxml-xpathengine-perl/t/01_basic.t?rev=18491&op=diff
==============================================================================
--- trunk/libxml-xpathengine-perl/t/01_basic.t (original)
+++ trunk/libxml-xpathengine-perl/t/01_basic.t Sat Apr 12 11:07:45 2008
@@ -3,7 +3,7 @@
use strict;
use warnings;
-use Test::More tests => 14;
+use Test::More tests => 15;
use XML::XPathEngine;
BEGIN { push @INC, './t'; }
@@ -44,6 +44,7 @@
is( $xp->findvalue( '//kid1[@att1="v3"]/preceding::gkid2[1]', $tree), 'gkid2 2', "preceding axis[1]");
is( $xp->findvalue( '//kid1[@att1="v3"]/preceding::gkid2[2]', $tree), 'gkid2 1', "preceding axis[1]");
is( $xp->findvalue( '//kid1[@att1="v3"]/preceding::gkid2', $tree), 'gkid2 1gkid2 2', "preceding axis");
+is( $xp->findvalue( 'count(//kid1)', $tree), '3', 'preceding count');
sub init_tree
{ my $tree = tree->new( 'att', name => 'tree', value => 'tree');
Modified: trunk/libxml-xpathengine-perl/t/minitree.pm
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libxml-xpathengine-perl/t/minitree.pm?rev=18491&op=diff
==============================================================================
--- trunk/libxml-xpathengine-perl/t/minitree.pm (original)
+++ trunk/libxml-xpathengine-perl/t/minitree.pm Sat Apr 12 11:07:45 2008
@@ -93,7 +93,7 @@
# qw( parent next_sibling previous_sibling first_child)
# )
# . ' : '
- . join ( " - ", map { "$_ : " . $self->$_ } qw( name value pos))
+ . join ( " - ", map { "$_ : " . $self->$_ } (qw( name value pos)) )
. " : " . join( " - ", map { $_->dump } @{$self->attributes})
;
}
More information about the Pkg-perl-cvs-commits
mailing list