From b34b289109c1511ae58aa81fdc2ca0571d9a82e1 Mon Sep 17 00:00:00 2001 From: dakkar Date: Mon, 29 Aug 2016 16:35:08 +0100 Subject: re-arrange POD (we're now using Pod::Weaver) --- lib/PPIx/XPath.pm | 209 +++++++++++++++++++++++++----------------------------- weaver.ini | 1 - 2 files changed, 95 insertions(+), 115 deletions(-) diff --git a/lib/PPIx/XPath.pm b/lib/PPIx/XPath.pm index 05e8743..4853fe6 100644 --- a/lib/PPIx/XPath.pm +++ b/lib/PPIx/XPath.pm @@ -6,8 +6,58 @@ use Carp; use Scalar::Util qw(reftype blessed); use Tree::XPathEngine; use 5.006; +# VERSION -our $VERSION='2.01'; +# ABSTRACT: an XPath implementation for the PDOM + +=head1 SYNOPSIS + + use PPI; + use PPIx::XPath; + use Tree::XPathEngine; + + my $pdom = PPI::Document->new('some_code.pl'); + my $xpath = Tree::XPathEngine->new(); + my @subs = $xpath->findnodes('//Statement-Sub',$pdom); + my @vars = $xpath->findnodes('//Token-Symbol',$pdom); + +Deprecated interface, backward-compatible with C version +1: + + use PPIx::XPath; + + my $pxp = PPIx::XPath->new("some_code.pl"); + my @subs = $pxp->match("//Statement::Sub"); + my $vars = $pxp->match("//Token::Symbol"); + +=head1 DESCRIPTION + +This module augments L's classes with the methods required by +L, allowing you to perform complex XPath matches +against any PDOM tree. + +See L for details about its methods. + +=head2 Mapping the PDOM to the XPath data model + +=begin :list + +* Each node in the PDOM is an element as seen by XPath + +* The name of the element is the class name of the node, minus the +initial C, with C<::> replaced by C<->. That is: + + ($xpath_name = substr($pdom_node->class,5)) =~ s/::/-/g; + +* Only "significant" nodes are seen by XPath + +* all scalar-valued accessors of PDOM nodes are visible as attributes + +* "here-docs" contents are I mapped + +=end :list + +=cut sub new { my ($class,$source) = @_; @@ -70,7 +120,7 @@ sub new { } } } - $legacy_names_rx='\b('.join('|', + $legacy_names_rx='\b('.join(q{|}, sort {length($b) <=> length($a)} @PPI_Packs ).')\b'; $legacy_names_rx=qr{$legacy_names_rx}; @@ -84,7 +134,31 @@ sub match { Tree::XPathEngine->new()->findnodes($expr,$self->{doc}); } -package PPI::Element; + +=head1 BUGS and LIMITATIONS + +=for :list +* "here-docs" contents are I mapped +* node ordering is slow, because I could not find a way in PPI to +compare two nodes for document order; suggestions are most welcome + +=head1 SEE ALSO + +L + +L + +L (the XPath specification) + +=head1 AUTHORS + +Dan Brook original author + +Gianni Ceccarelli Tree::XPathEngine-based re-implementation + +=cut + +package PPI::Element; ## no critic(ProhibitMultiplePackages) use strict; use warnings; @@ -177,13 +251,13 @@ sub _xpath_ancestors { return @ancestors; } -package PPI::Token; +package PPI::Token; ## no critic(ProhibitMultiplePackages) use strict; use warnings; sub xpath_get_child_nodes { return } -package PPI::Token::Quote::Double; +package PPI::Token::Quote::Double; ## no critic(ProhibitMultiplePackages) use strict; use warnings; @@ -192,7 +266,7 @@ sub xpath_get_attributes { PPIx::XPath::Attr->new($_[0],'interpolations'), } -package PPI::Token::Number; +package PPI::Token::Number; ## no critic(ProhibitMultiplePackages) use strict; use warnings; @@ -201,7 +275,7 @@ sub xpath_get_attributes { PPIx::XPath::Attr->new($_[0],'base'), } -package PPI::Token::Word; +package PPI::Token::Word; ## no critic(ProhibitMultiplePackages) use strict; use warnings; @@ -210,7 +284,7 @@ sub xpath_get_attributes { PPIx::XPath::Attr->new($_[0],'method-call'), } -package PPI::Token::Comment; +package PPI::Token::Comment; ## no critic(ProhibitMultiplePackages) use strict; use warnings; @@ -219,7 +293,7 @@ sub xpath_get_attributes { PPIx::XPath::Attr->new($_[0],'line'), } -package PPI::Token::HereDoc; +package PPI::Token::HereDoc; ## no critic(ProhibitMultiplePackages) use strict; use warnings; @@ -230,7 +304,7 @@ sub xpath_get_attributes { PPIx::XPath::Attr->new($_[0],'terminator'), } -package PPI::Token::Prototype; +package PPI::Token::Prototype; ## no critic(ProhibitMultiplePackages) use strict; use warnings; @@ -238,7 +312,7 @@ sub xpath_to_literal { $_[0]->prototype } sub xpath_get_value { $_[0]->prototype } sub xpath_string_value { $_[0]->prototype } -package PPI::Node; +package PPI::Node; ## no critic(ProhibitMultiplePackages) use strict; use warnings; @@ -248,7 +322,7 @@ sub xpath_get_attributes { PPIx::XPath::Attr->new($_[0],'scope'), } -package PPI::Token::Attribute; +package PPI::Token::Attribute; ## no critic(ProhibitMultiplePackages) use strict; use warnings; @@ -258,7 +332,7 @@ sub xpath_get_attributes { PPIx::XPath::Attr->new($_[0],'parameters'), } -package PPI::Token::Symbol; +package PPI::Token::Symbol; ## no critic(ProhibitMultiplePackages) use strict; use warnings; @@ -270,7 +344,7 @@ sub xpath_get_attributes { PPIx::XPath::Attr->new($_[0],'symbol_typel'), } -package PPI::Statement; +package PPI::Statement; ## no critic(ProhibitMultiplePackages) use strict; use warnings; @@ -281,7 +355,7 @@ sub xpath_get_attributes { PPIx::XPath::Attr->new($_[0],'type'), } -package PPI::Statement::Sub; +package PPI::Statement::Sub; ## no critic(ProhibitMultiplePackages) use strict; use warnings; @@ -293,7 +367,7 @@ sub xpath_get_attributes { PPIx::XPath::Attr->new($_[0],'reserved'), } -package PPI::Statement::Package; +package PPI::Statement::Package; ## no critic(ProhibitMultiplePackages) use strict; use warnings; @@ -303,7 +377,7 @@ sub xpath_get_attributes { PPIx::XPath::Attr->new($_[0],'file-scoped'), } -package PPI::Statement::Include; +package PPI::Statement::Include; ## no critic(ProhibitMultiplePackages) use strict; use warnings; @@ -316,7 +390,7 @@ sub xpath_get_attributes { PPIx::XPath::Attr->new($_[0],'pragma'), } -package PPI::Structure; +package PPI::Structure; ## no critic(ProhibitMultiplePackages) use strict; use warnings; @@ -327,7 +401,7 @@ sub xpath_get_attributes { PPIx::XPath::Attr->new($_[0],'braces'), } -package PPI::Document; +package PPI::Document; ## no critic(ProhibitMultiplePackages) use strict; use warnings; @@ -336,7 +410,7 @@ sub xpath_get_parent_node { return } sub xpath_is_attribute_node { 0 } sub xpath_is_document_node { 1 } -package PPIx::XPath::Attr; +package PPIx::XPath::Attr; ## no critic(ProhibitMultiplePackages) use strict; use warnings; @@ -365,7 +439,7 @@ sub xpath_get_value { $_[0]->{value} } sub xpath_string_value { $_[0]->{value} } sub xpath_to_number { Tree::XPathEngine::Number->new($_[0]->{value}) } -sub xpath_cmp($$) { +sub xpath_cmp { my( $a, $b)= @_; if ( UNIVERSAL::isa( $b, 'PPIx::XPath::Attr')) { # 2 attributes, compare their elements, then their name @@ -384,96 +458,3 @@ sub xpath_cmp($$) { } 1; -__END__ - -=head1 NAME - -PPIx::XPath - an XPath implementation for the PDOM - -=head1 SYNOPSIS - - use PPI; - use PPIx::XPath; - use Tree::XPathEngine; - - my $pdom = PPI::Document->new('some_code.pl'); - my $xpath = Tree::XPathEngine->new(); - my @subs = $xpath->findnodes('//Statement-Sub',$pdom); - my @vars = $xpath->findnodes('//Token-Symbol',$pdom); - -Deprecated interface, backward-compatible with C version -1: - - use PPIx::XPath; - - my $pxp = PPIx::XPath->new("some_code.pl"); - my @subs = $pxp->match("//Statement::Sub"); - my $vars = $pxp->match("//Token::Symbol"); - -=head1 DESCRIPTION - -This module augments L's classes with the methods required by -L, allowing you to perform complex XPath matches -against any PDOM tree. - -See L for details about its methods. - -=head2 Mapping the PDOM to the XPath data model - -=over 4 - -=item * - -Each node in the PDOM is an element as seen by XPath - -=item * - -The name of the element is the class name of the node, minus the -initial C, with C<::> replaced by C<->. That is: - - ($xpath_name = substr($pdom_node->class,5)) =~ s/::/-/g; - -=item * - -Only "significant" nodes are seen by XPath - -=item * - -all scalar-valued accessors of PDOM nodes are visible as attributes - -=item * - -"here-docs" contents are I mapped - -=back - -=head1 BUGS and LIMITATIONS - -=over 4 - -=item * - -"here-docs" contents are I mapped - -=item * - -node ordering is slow, because I could not find a way in PPI to -compare two nodes for document order; suggestions are most welcome - -=back - -=head1 SEE ALSO - -L - -L - -L (the XPath specification) - -=head1 AUTHOR - -Dan Brook original author - -Gianni Ceccarelli Tree::XPathEngine-based re-implementation - -=cut diff --git a/weaver.ini b/weaver.ini index 4cf1cae..443e9cf 100644 --- a/weaver.ini +++ b/weaver.ini @@ -24,7 +24,6 @@ command = func [Region / postlude] -[Authors] [Legal] [-Transformer / Lists] -- cgit v1.2.3