From 96ff473be5ce85b3c3bde70b835b85f8419a8bc9 Mon Sep 17 00:00:00 2001 From: Dominique Quatravaux Date: Wed, 20 Jun 2018 15:38:27 +0200 Subject: [PATCH 1/5] Test-first for new feature: namespacing support --- t/19namespace.t | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 t/19namespace.t diff --git a/t/19namespace.t b/t/19namespace.t new file mode 100644 index 0000000..2069bab --- /dev/null +++ b/t/19namespace.t @@ -0,0 +1,27 @@ +use strict; +use warnings; + +use Test::More "no_plan"; # I, for one, don't like it when a plan + # comes together + +use XML::XPathScript; + +my $xps = XML::XPathScript->new; + +my $noop_stylesheet = '<%= apply_templates() %>'; +my $result = $xps->transform( <<'NAMESPACED_XML', $noop_stylesheet); + + + Geography Channel + 1.2 + + +NAMESPACED_XML + +my ($rss_attributes) = $result =~ m/^]*)>/; +my @rss_attributes = split m/ /, $rss_attributes; +is scalar(grep { $_ eq 'version="2.0"' } @rss_attributes), 1; +is scalar(grep { $_ =~ m/^xmlns:/ } @rss_attributes), 3; +unlike $result, qr{xmlns:xmlns:}; +like $result, qr{1.2}; +like $result, qr{Geography Channel}; From b1b585fd516e0bbae503d0ab4f25f5659785f5ce Mon Sep 17 00:00:00 2001 From: Dominique Quatravaux Date: Wed, 20 Jun 2018 15:54:16 +0200 Subject: [PATCH 2/5] Fix t/19namespace.t #1 * Remove bizarre assumption that xmlns: is the only namespace in play * At any rate, just calling ->getName() does the right thing these days, so do that --- lib/XML/XPathScript/Processor/LibXML.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/XML/XPathScript/Processor/LibXML.pm b/lib/XML/XPathScript/Processor/LibXML.pm index 6e29c29..5b49746 100644 --- a/lib/XML/XPathScript/Processor/LibXML.pm +++ b/lib/XML/XPathScript/Processor/LibXML.pm @@ -30,7 +30,7 @@ sub is_nodelist { return $_[1]->isa( 'XML::LibXML::NodeList' ); } sub get_attribute { return $_[1]->isa( 'XML::LibXML::Namespace' ) - ? ' xmlns:' . $_[1]->getName() . q{="} . $_[1]->value() . q{" } + ? sprintf(q{ %s="%s"}, $_[1]->getName(), $_[1]->value()) : $_[1]->toString( 0, 1 ) ; } From ee215dd83876dd4a4c1a6e567398a992f4017384 Mon Sep 17 00:00:00 2001 From: Dominique Quatravaux Date: Wed, 20 Jun 2018 16:24:17 +0200 Subject: [PATCH 3/5] Must use "our", or that line has no effect (Perl 5.26 Mac OS X) --- lib/XML/XPathScript.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/XML/XPathScript.pm b/lib/XML/XPathScript.pm index 6c46833..8d5a738 100644 --- a/lib/XML/XPathScript.pm +++ b/lib/XML/XPathScript.pm @@ -241,7 +241,7 @@ use XML::XPathScript::Template; our $VERSION = '1.54'; -$XML_parser = 'XML::LibXML'; +our $XML_parser = 'XML::LibXML'; my %use_parser = ( 'XML::LibXML' => 'use XML::LibXML', From 7f7783c50a462b67a5460d28b03ac7dc69063423 Mon Sep 17 00:00:00 2001 From: Dominique Quatravaux Date: Wed, 20 Jun 2018 16:37:30 +0200 Subject: [PATCH 4/5] Get the bar green again Also tested by flipping line 244 of lib/XML/XPathScript.pm to our $XML_parser = 'XML::XPath'; * Add get_qualified_name() in all the XML parser adapters, and provide suitable implementations for all three APIs. (For B::XPath it is more of a shot in the dark - I don't suppose B opcodes have namespaces) * By default, pretty-print the opening and closing tags of a node in terms of their get_qualified_name() instead of their get_name() --- lib/XML/XPathScript/Processor.pm | 4 ++-- lib/XML/XPathScript/Processor/B.pm | 2 ++ lib/XML/XPathScript/Processor/LibXML.pm | 17 +++++++++-------- lib/XML/XPathScript/Processor/XPath.pm | 21 +++++++++++---------- 4 files changed, 24 insertions(+), 20 deletions(-) diff --git a/lib/XML/XPathScript/Processor.pm b/lib/XML/XPathScript/Processor.pm index 2828f31..742a8fb 100644 --- a/lib/XML/XPathScript/Processor.pm +++ b/lib/XML/XPathScript/Processor.pm @@ -632,7 +632,7 @@ sub translate_comment_node { sub start_tag { my( $self, $node, $name ) = @_; - $name ||= $self->get_node_name( $node ) or return; + $name ||= $self->get_qualified_name( $node ) or return; my $string = '<'.$name; @@ -653,7 +653,7 @@ sub start_tag { sub end_tag { my $self = shift; - if (my $name = $_[1] || $self->get_node_name( $_[0] ) ) { + if (my $name = $_[1] || $self->get_qualified_name( $_[0] ) ) { return ""; } return ''; diff --git a/lib/XML/XPathScript/Processor/B.pm b/lib/XML/XPathScript/Processor/B.pm index 22d09bf..bd7a92e 100644 --- a/lib/XML/XPathScript/Processor/B.pm +++ b/lib/XML/XPathScript/Processor/B.pm @@ -31,6 +31,8 @@ sub to_string { sub get_node_name { $_[1]->get_name } +sub get_qualified_name { $_[1]->get_name } + sub get_attributes { if ( $_[1]->can( 'get_attr_names' ) ) { return map { ( [ $_ => $_[1]->get_attr_value( $_ ) ] ) diff --git a/lib/XML/XPathScript/Processor/LibXML.pm b/lib/XML/XPathScript/Processor/LibXML.pm index 5b49746..9abaea1 100644 --- a/lib/XML/XPathScript/Processor/LibXML.pm +++ b/lib/XML/XPathScript/Processor/LibXML.pm @@ -19,14 +19,15 @@ sub is_text_node { && !$_[1]->isa('XML::LibXML::Comment'); } -sub get_attributes { return $_[1]->attributes } -sub get_text_content { return $_[1]->textContent } -sub get_child_nodes { return $_[1]->childNodes } -sub get_node_name { return $_[1]->localname } -sub is_element_node { return $_[1]->isa( 'XML::LibXML::Element' ); } -sub is_comment_node { return $_[1]->isa( 'XML::LibXML::Comment' ); } -sub is_pi_node { return $_[1]->isa( 'XML::LibXML::PI' ); } -sub is_nodelist { return $_[1]->isa( 'XML::LibXML::NodeList' ); } +sub get_attributes { return $_[1]->attributes } +sub get_text_content { return $_[1]->textContent } +sub get_child_nodes { return $_[1]->childNodes } +sub get_node_name { return $_[1]->localname } +sub get_qualified_name { return $_[1]->nodeName } +sub is_element_node { return $_[1]->isa( 'XML::LibXML::Element' ); } +sub is_comment_node { return $_[1]->isa( 'XML::LibXML::Comment' ); } +sub is_pi_node { return $_[1]->isa( 'XML::LibXML::PI' ); } +sub is_nodelist { return $_[1]->isa( 'XML::LibXML::NodeList' ); } sub get_attribute { return $_[1]->isa( 'XML::LibXML::Namespace' ) diff --git a/lib/XML/XPathScript/Processor/XPath.pm b/lib/XML/XPathScript/Processor/XPath.pm index 3b3df41..0ecbc4c 100644 --- a/lib/XML/XPathScript/Processor/XPath.pm +++ b/lib/XML/XPathScript/Processor/XPath.pm @@ -12,15 +12,16 @@ sub get_namespace { return $_[1]->getNamespace( $prefix )->getExpanded(); } -sub get_attributes { $_[1]->getAttributeNodes } -sub get_text_content { $_[1]->getData } -sub get_child_nodes { $_[1]->getChildNodes } -sub get_node_name { $_[1]->getName && $_[1]->getLocalName } -sub is_element_node { $_[1]->isa( 'XML::XPath::Node::Element' ); } -sub is_text_node { $_[1]->isa( 'XML::XPath::Node::Text' ); } -sub is_comment_node { $_[1]->isa( 'XML::XPath::Node::Comment' ); } -sub is_pi_node { $_[1]->isa( "XML::XPath::Node::PI" ); } -sub is_nodelist { $_[1]->isa( 'XML::XPath::NodeSet' ); } -sub get_attribute { $_[1]->toString } +sub get_attributes { $_[1]->getAttributeNodes } +sub get_text_content { $_[1]->getData } +sub get_child_nodes { $_[1]->getChildNodes } +sub get_node_name { $_[1]->getName && $_[1]->getLocalName } +sub get_qualified_name { $_[1]->getName } +sub is_element_node { $_[1]->isa( 'XML::XPath::Node::Element' ); } +sub is_text_node { $_[1]->isa( 'XML::XPath::Node::Text' ); } +sub is_comment_node { $_[1]->isa( 'XML::XPath::Node::Comment' ); } +sub is_pi_node { $_[1]->isa( "XML::XPath::Node::PI" ); } +sub is_nodelist { $_[1]->isa( 'XML::XPath::NodeSet' ); } +sub get_attribute { $_[1]->toString } 1; From e1eb1d22944f4af2b51fd8e931dd75274a740864 Mon Sep 17 00:00:00 2001 From: Dominique Quatravaux Date: Wed, 20 Jun 2018 16:41:18 +0200 Subject: [PATCH 5/5] Prepare version for release * Bump version to 1.55 everywhere * Add Changes entry (almost 10 years since the last one!) * ./Build dist --- Changes | 5 ++ MANIFEST | 1 + META.yml | 64 ++++++++++--------- Makefile.PL | 19 +++--- lib/XML/XPathScript.pm | 2 +- lib/XML/XPathScript/Processor.pm | 2 +- lib/XML/XPathScript/Processor/B.pm | 2 +- lib/XML/XPathScript/Processor/LibXML.pm | 2 +- lib/XML/XPathScript/Processor/XPath.pm | 2 +- .../XPathScript/Stylesheet/DocBook2LaTeX.pm | 2 +- lib/XML/XPathScript/Template.pm | 2 +- lib/XML/XPathScript/Template/Tag.pm | 2 +- script/xpathscript | 2 +- 13 files changed, 60 insertions(+), 47 deletions(-) diff --git a/Changes b/Changes index 3515548..ea68639 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,10 @@ Revision history for Perl module XML::XPathScript +1.55 June 20, 2018 + - Improve namespace support + - Fix a bug where "xmlns:" was duplicated in the top-level element + - Fix a bug that prevented manual switching between XML::XPath and XML::LibXML as the back-end parser + 1.54 July 26, 2008 - Fix bugs in stylesheet DocBook2LaTex - Fix bug in X::X::Processor::B where there is no whitespace diff --git a/MANIFEST b/MANIFEST index b963d6a..025ea05 100644 --- a/MANIFEST +++ b/MANIFEST @@ -86,3 +86,4 @@ examples/docbook2latex.xps examples/sample-docbook.xml SIGNATURE Added here by Module::Build +META.json diff --git a/META.yml b/META.yml index 3fe1d6f..b5c9c0c 100644 --- a/META.yml +++ b/META.yml @@ -1,55 +1,59 @@ --- -name: XML-XPathScript -version: 1.54 +abstract: 'a Perl framework for XML stylesheets' author: - 'Yanick Champoux ' - 'Dominique Quatravaux ' - 'Matt Sergeant ' -abstract: a Perl framework for XML stylesheets -license: artistic -resources: - license: http://opensource.org/licenses/artistic-license.php -requires: - Carp: 0 - Clone: 0 - Data::Dumper: 0 - File::Basename: 0 - IO::File: 0 - Readonly: 0 - Scalar::Util: 0 - Symbol: 0 - XML::LibXML: 0 build_requires: - File::Find: 0 - File::Spec: 0 + File::Find: '0' + File::Spec: '0' +configure_requires: + Module::Build: '0.42' +dynamic_config: 1 +generated_by: 'Module::Build version 0.4224, CPAN::Meta::Converter version 2.150010' +license: artistic +meta-spec: + url: http://module-build.sourceforge.net/META-spec-v1.4.html + version: '1.4' +name: XML-XPathScript provides: XML::XPathScript: file: lib/XML/XPathScript.pm - version: 1.54 + version: '1.55' XML::XPathScript::Processor: file: lib/XML/XPathScript/Processor.pm - version: 1.54 + version: '1.55' XML::XPathScript::Processor::B: file: lib/XML/XPathScript/Processor/B.pm - version: 1.54 + version: '1.55' XML::XPathScript::Processor::LibXML: file: lib/XML/XPathScript/Processor/LibXML.pm - version: 1.54 + version: '1.55' XML::XPathScript::Processor::XPath: file: lib/XML/XPathScript/Processor/XPath.pm - version: 1.54 + version: '1.55' XML::XPathScript::Stylesheet::DocBook2LaTeX: file: lib/XML/XPathScript/Stylesheet/DocBook2LaTeX.pm - version: 1.54 + version: '1.55' XML::XPathScript::Template: file: lib/XML/XPathScript/Template.pm - version: 1.54 + version: '1.55' XML::XPathScript::Template::Content: file: lib/XML/XPathScript/Processor.pm XML::XPathScript::Template::Tag: file: lib/XML/XPathScript/Template/Tag.pm - version: 1.54 -generated_by: Module::Build version 0.280801 -meta-spec: - url: http://module-build.sourceforge.net/META-spec-v1.2.html - version: 1.2 + version: '1.55' +requires: + Carp: '0' + Clone: '0' + Data::Dumper: '0' + File::Basename: '0' + IO::File: '0' + Readonly: '0' + Scalar::Util: '0' + Symbol: '0' + XML::LibXML: '0' +resources: + license: http://opensource.org/licenses/artistic-license.php +version: '1.54' +x_serialization_backend: 'CPAN::Meta::YAML version 0.018' diff --git a/Makefile.PL b/Makefile.PL index a28a3aa..4a12b12 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -1,31 +1,34 @@ -# Note: this file was auto-generated by Module::Build::Compat version 0.2808_01 - +# Note: this file was auto-generated by Module::Build::Compat version 0.4224 + unless (eval "use Module::Build::Compat 0.02; 1" ) { print "This module requires Module::Build to install itself.\n"; - + require ExtUtils::MakeMaker; my $yn = ExtUtils::MakeMaker::prompt (' Install Module::Build now from CPAN?', 'y'); - + unless ($yn =~ /^y/i) { die " *** Cannot install without Module::Build. Exiting ...\n"; } - + require Cwd; require File::Spec; require CPAN; - + # Save this 'cause CPAN will chdir all over the place. my $cwd = Cwd::cwd(); - + CPAN::Shell->install('Module::Build::Compat'); CPAN::Shell->expand("Module", "Module::Build::Compat")->uptodate or die "Couldn't install Module::Build, giving up.\n"; - + chdir $cwd or die "Cannot chdir() back to $cwd: $!"; } eval "use Module::Build::Compat 0.02; 1" or die $@; use lib '_build/lib'; Module::Build::Compat->run_build_pl(args => \@ARGV); + my $build_script = 'Build'; + $build_script .= '.com' if $^O eq 'VMS'; + exit(0) unless(-e $build_script); # cpantesters convention require MyModuleBuilder; Module::Build::Compat->write_makefile(build_class => 'MyModuleBuilder'); diff --git a/lib/XML/XPathScript.pm b/lib/XML/XPathScript.pm index 8d5a738..d3c3d1a 100644 --- a/lib/XML/XPathScript.pm +++ b/lib/XML/XPathScript.pm @@ -239,7 +239,7 @@ use File::Basename; use XML::XPathScript::Processor; use XML::XPathScript::Template; -our $VERSION = '1.54'; +our $VERSION = '1.55'; our $XML_parser = 'XML::LibXML'; diff --git a/lib/XML/XPathScript/Processor.pm b/lib/XML/XPathScript/Processor.pm index 742a8fb..6463c1f 100644 --- a/lib/XML/XPathScript/Processor.pm +++ b/lib/XML/XPathScript/Processor.pm @@ -9,7 +9,7 @@ use base qw/ Exporter /; use XML::XPathScript::Template; use Readonly; -our $VERSION = '1.54'; +our $VERSION = '1.55'; our @EXPORT = qw/ $DO_SELF_AS_CHILD diff --git a/lib/XML/XPathScript/Processor/B.pm b/lib/XML/XPathScript/Processor/B.pm index bd7a92e..cb8e393 100644 --- a/lib/XML/XPathScript/Processor/B.pm +++ b/lib/XML/XPathScript/Processor/B.pm @@ -5,7 +5,7 @@ package XML::XPathScript::Processor::B; use base qw/ XML::XPathScript::Processor /; -our $VERSION = '1.54'; +our $VERSION = '1.55'; # No namespaces here sub get_namespace { } diff --git a/lib/XML/XPathScript/Processor/LibXML.pm b/lib/XML/XPathScript/Processor/LibXML.pm index 9abaea1..8fbbdf7 100644 --- a/lib/XML/XPathScript/Processor/LibXML.pm +++ b/lib/XML/XPathScript/Processor/LibXML.pm @@ -5,7 +5,7 @@ use warnings; use base qw/ XML::XPathScript::Processor /; -our $VERSION = '1.54'; +our $VERSION = '1.55'; sub get_namespace { my $ns = $_[1]->getNamespaces(); diff --git a/lib/XML/XPathScript/Processor/XPath.pm b/lib/XML/XPathScript/Processor/XPath.pm index 0ecbc4c..4cf990e 100644 --- a/lib/XML/XPathScript/Processor/XPath.pm +++ b/lib/XML/XPathScript/Processor/XPath.pm @@ -5,7 +5,7 @@ package XML::XPathScript::Processor::XPath; use base qw/ XML::XPathScript::Processor /; -our $VERSION = '1.54'; +our $VERSION = '1.55'; sub get_namespace { my $prefix = $_[1]->getPrefix or return; diff --git a/lib/XML/XPathScript/Stylesheet/DocBook2LaTeX.pm b/lib/XML/XPathScript/Stylesheet/DocBook2LaTeX.pm index d9d45e6..1263f45 100644 --- a/lib/XML/XPathScript/Stylesheet/DocBook2LaTeX.pm +++ b/lib/XML/XPathScript/Stylesheet/DocBook2LaTeX.pm @@ -6,7 +6,7 @@ use strict; use XML::XPathScript::Processor; use Carp; -our $VERSION = '1.54'; +our $VERSION = '1.55'; our $processor; diff --git a/lib/XML/XPathScript/Template.pm b/lib/XML/XPathScript/Template.pm index adb4c36..0042ec3 100644 --- a/lib/XML/XPathScript/Template.pm +++ b/lib/XML/XPathScript/Template.pm @@ -13,7 +13,7 @@ use Scalar::Util qw/ refaddr /; use overload '&{}' => \&_overload_func, q{""} => \&_overload_quote; -our $VERSION = '1.54'; +our $VERSION = '1.55'; sub new { my( $class ) = @_; diff --git a/lib/XML/XPathScript/Template/Tag.pm b/lib/XML/XPathScript/Template/Tag.pm index f8be79f..73baccd 100644 --- a/lib/XML/XPathScript/Template/Tag.pm +++ b/lib/XML/XPathScript/Template/Tag.pm @@ -9,7 +9,7 @@ use Scalar::Util qw/ reftype /; use overload '&{}' => \&_overload_func, q{""} => \&_overload_quote; -our $VERSION = '1.54'; +our $VERSION = '1.55'; our @ALLOWED_ATTRIBUTES = qw{ pre post diff --git a/script/xpathscript b/script/xpathscript index 8dfdfb3..f114df2 100755 --- a/script/xpathscript +++ b/script/xpathscript @@ -9,7 +9,7 @@ use Symbol; use File::Basename; use Carp; -my $VERSION = '1.54'; +my $VERSION = '1.55'; my ( $query, $interpolate ); GetOptions( 'query=s' => \$query,