| Test-HTML-Content documentation | Contained in the Test-HTML-Content distribution. |
Test::HTML::Content::XPathExtensions - Perlish XPath extensions
# This module patches the XML::XPath::Function namespace use Test::HTML::Content::XPathExtensions;
This is the module that provides RE support for XML::XPath
and support for matching comments through the two functions
matches and comment.
The two functions are modeled after what I found on the Saxon
website on the fn: namespace :
Nothing. It stomps over the XML::XPath::Function namespace.
This code may be distributed under the same terms as Perl itself.
Max Maischein, corion@cpan.org
| Test-HTML-Content documentation | Contained in the Test-HTML-Content distribution. |
package Test::HTML::Content::XPathExtensions; require 5.005_62; use strict; use File::Spec; use HTML::TokeParser; # we want to stay compatible to 5.5 and use warnings if # we can eval 'use warnings;' if ($] >= 5.006); use vars qw( $HTML_PARSER_StripsTags $VERSION @exports ); $VERSION = '0.08'; @exports = qw( matches comment ); sub matches { my $self = shift; my ($node, @params) = @_; die "starts-with: incorrect number of params\n" unless @params == 2; my $re = $params[1]->string_value; return($params[0]->string_value =~ /$re/) ? XML::XPath::Boolean->True : XML::XPath::Boolean->False; } sub comment { my $self = shift; my ($node, @params) = @_; die "starts-with: incorrect number of params\n" unless @params == 1; my $re = $params[1]->string_value; return(ref $node =~ /Comment$/) ? XML::XPath::Boolean->True : XML::XPath::Boolean->False; }; sub import { for (@exports) { no strict 'refs'; # Install our extensions unless they already exist : *{"XML::XPath::Function::$_"} = *{"Test::HTML::Content::XPathExtensions::$_"} unless defined *{"XML::XPath::Function::$_"}{CODE}; }; }; 1; __END__