Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PPI::Document bug or some special subroutine name?

Tags:

parsing

perl

ppi

i have some problems with PPI module:

assume i have Foo.pm:

package Foo;

sub foo0 { 1; }
sub foo1 { 1; }
sub foo2 { 1; }
sub foo3 { 1; }

1;

and i want to use PPI to get all the subs:

#!/usr/bin/env perl
use PPI;
my $filename = shift;
my $Document = PPI::Document->new($filename);
my $subs = $Document->find('PPI::Statement::Sub');
warn $#$subs;

as result i got '3' which is correct.

but when one of my subs in Foo.pm is called 'sub vN...', where N is a number, f.e.:

sub v1foo {}

or

sub v3bar {}

or simply

sub v2 {}

PPI::Document find seems to break parsing and returns only the already found subs. So if i modify Foo:

package Foo;

sub foo0 { 1; }
sub foo1 { 1; }
sub v2xx { 1; }
sub foo3 { 1; }

1;

Result of my test would be "1" (found subs are foo0 and foo1)

Is declaring subroutines names like v[0..9] somehow forbidden?

Greetings.

like image 983
Robert Avatar asked Jan 30 '12 11:01

Robert


1 Answers

This is a (unknown) bug.

It is related to the concept of "v-numbers" or "version numbers".

A v number looks something like v1.2.3 and parsers into an PPI::Token::Number::Version object.

The problem you are seeing is the parses spotting "v, digit, ...", parsing it as a v-number and then starting the next token at the character after it (which it shouldn't do).

Additionally, in the sub v1 { } case the v1 should be parsed as the subroutine name "v1" instead of a v-number anyway.

You should report this PPI bug tracker at https://rt.cpan.org/Public/Dist/Display.html?Name=PPI

like image 191
Adam Kennedy Avatar answered Sep 23 '22 21:09

Adam Kennedy