summaryrefslogtreecommitdiff
path: root/t/07-class-xpath.t
diff options
context:
space:
mode:
Diffstat (limited to 't/07-class-xpath.t')
-rw-r--r--t/07-class-xpath.t25
1 files changed, 23 insertions, 2 deletions
diff --git a/t/07-class-xpath.t b/t/07-class-xpath.t
index 891ddff..9aa8040 100644
--- a/t/07-class-xpath.t
+++ b/t/07-class-xpath.t
@@ -13,6 +13,10 @@ sub findnodes {
my ($self,$expr,$node)=@_;
return PPIx::XPath->new($node)->match($expr);
}
+
+sub PPI::Document::parent {
+ return $_[0];
+}
}
package PPITransform;{
@@ -22,9 +26,17 @@ package PPITransform;{
engine_class 'CXpEngine';
- default_rules;
+ #default_rules;
+ tree_rule match => '/', priority => 0, action => sub {
+ print '# root';
+ $_[0]->apply_rules
+ };
+ tree_rule match => '*', priority => 0, action => sub {
+ print '# ',$_[0]->it->xpath;
+ $_[0]->apply_rules
+ };
- tree_rule match => '//Statement::Sub', action => sub {
+ tree_rule match => 'Statement::Sub', action => sub {
return $_[0]->it->name.'('.$_[0]->it->prototype.')';
};
@@ -34,6 +46,8 @@ package main;
use strict;
use warnings;
use PPI;
+use Devel::TraceCalls;
+
plan tests=>1;
{
@@ -48,6 +62,13 @@ my $x=PPIx::XPath->new($doc);
diag "$_\n" for $x->match('//Statement::Sub');
my $trans=PPITransform->new();
+#trace_calls {
+# Package => 'PPIx::XPath',
+# Class => 'PPI::Node',
+# ShowStack => 1,
+# CaptureAll => 1,
+#};
+
my @results=$trans->transform($doc);
is_deeply \@results,['gino($%)','pino'],'PPI example';
}