Subject: | PPI::Statement::Package->namespace doesn't allow all-numeric portions |
If a package name includes an all-numeric portion, say "package
Foo::Bar::1_0;", PPI only recognizes up to the numeric portion as being
part of the namespace, namely "Foo::Bar::".
The attached test fails like this:
1..1
not ok 1 - namespace matches package declaration
# Failed test 'namespace matches package declaration'
# in PPI_bug.t at line 10.
# got: 'Foo::Bar::'
# expected: 'Foo::Bar::1_0'
# Looks like you failed 1 test of 1.
The attached patch fixes this. I'd write the patch to the repository
myself if I was given write access (I promise to be good).
Subject: | 0001-Fix-namespace-so-it-allows-inclusion-of-number-tok.patch |
From 9456ebcea54c95af51739b141c4de3f8235dc464 Mon Sep 17 00:00:00 2001
From: panderson <panderson@gridapp.com>
Date: Sun, 28 Jun 2009 13:54:34 -0400
Subject: [PATCH] Fix namespace() so it allows inclusion of number tokens as well as word tokens.
---
blib/lib/PPI/Statement/Package.pm | 13 +++++++++----
blib/man3/PPI::Statement::Package.3pm | 2 +-
lib/PPI/Statement/Package.pm | 13 +++++++++----
3 files changed, 19 insertions(+), 9 deletions(-)
diff --git a/blib/lib/PPI/Statement/Package.pm b/blib/lib/PPI/Statement/Package.pm
index 329c4e6..791e165 100644
--- a/blib/lib/PPI/Statement/Package.pm
+++ b/blib/lib/PPI/Statement/Package.pm
@@ -64,10 +64,15 @@ If the package statement is done any different way, it returns false.
sub namespace {
my $self = shift;
- my $namespace = $self->schild(1) or return '';
- $namespace->isa('PPI::Token::Word')
- ? $namespace->content
- : '';
+ my @children = $self->schildren or return '';
+ shift @children; # discard 'package'
+ my $namespace = q{};
+ foreach my $child ( @children ) {
+ $namespace .= $child->isa('PPI::Token::Word') ? $child->content
+ : $child->isa('PPI::Token::Number') ? $child->content
+ : q{};
+ }
+ return $namespace;
}
=pod
diff --git a/blib/man3/PPI::Statement::Package.3pm b/blib/man3/PPI::Statement::Package.3pm
index fabcd99..d523b08 100644
--- a/blib/man3/PPI::Statement::Package.3pm
+++ b/blib/man3/PPI::Statement::Package.3pm
@@ -129,7 +129,7 @@
.\" ========================================================================
.\"
.IX Title "PPI::Statement::Package 3"
-.TH PPI::Statement::Package 3 "2008-05-14" "perl v5.8.6" "User Contributed Perl Documentation"
+.TH PPI::Statement::Package 3 "2009-06-28" "perl v5.8.6" "User Contributed Perl Documentation"
.SH "NAME"
PPI::Statement::Package \- A package statement
.SH "INHERITANCE"
diff --git a/lib/PPI/Statement/Package.pm b/lib/PPI/Statement/Package.pm
index 329c4e6..791e165 100644
--- a/lib/PPI/Statement/Package.pm
+++ b/lib/PPI/Statement/Package.pm
@@ -64,10 +64,15 @@ If the package statement is done any different way, it returns false.
sub namespace {
my $self = shift;
- my $namespace = $self->schild(1) or return '';
- $namespace->isa('PPI::Token::Word')
- ? $namespace->content
- : '';
+ my @children = $self->schildren or return '';
+ shift @children; # discard 'package'
+ my $namespace = q{};
+ foreach my $child ( @children ) {
+ $namespace .= $child->isa('PPI::Token::Word') ? $child->content
+ : $child->isa('PPI::Token::Number') ? $child->content
+ : q{};
+ }
+ return $namespace;
}
=pod
--
1.6.2.1
Subject: | PPI_bug.t |
use strict;
use PPI;
use Test::More tests => 1;
my $package_name = "Foo::Bar::1_0";
my $doc = PPI::Document->new(\"package $package_name;");
my $pkg = $doc->find_first('PPI::Statement::Package');
my $ns = $pkg->namespace;
is( $ns, $package_name, 'namespace matches package declaration');